Re: [Repoze-dev] venusian scanning test code

2010-12-28 Thread Chris McDonough
On Tue, 2010-12-28 at 20:35 +0100, Wichert Akkerman wrote:
> > I actually argue that moving imports out of module scope in testcase
> > modules is best practice:
> 
> I agree, but in this case TestBrowser is not something that is tested 
> but a utility to help writing tests. It is similar to DummyRequest, 
> DummyModel, etc. That is why I moved it out to testing.py as well.

I could add features to venusian to allow it to skip certain
package/module names by regex, but this may be a case where having the
test code as a subpackage of the distributed package (a opposed to a
"tests" directory in the setuptools project directory, as a peer of
"setup.py) is a lose. 

- C


___
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev


Re: [Repoze-dev] venusian scanning test code

2010-12-28 Thread Wichert Akkerman
On 2010-12-28 20:34, Tres Seaver wrote:
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
>
> On 12/28/2010 01:39 PM, Wichert Akkerman wrote:
>> On 2010-12-28 19:16, Chris McDonough wrote:
>>> On Tue, 2010-12-28 at 15:36 +0100, Wichert Akkerman wrote:
 I recently refactored a package to move all test infrastructure out of
 tests/ to testing.py. This has one unfortunate side effect: on installs
 without test dependencies my app will now no longer start since the
 venusian scan aborts on test imports in testing.py. Is there a way block
 venusian from scanning testing.py?
>>>
>>> I'm afraid not.  But I'm not sure why it worked under tests/ but not
>>> under testing.py, as Venusian scans everything?
>>
>> That turned out to due to some other test refactoring I was doing at the
>> same time. It did surprise me to see that venusian was scanning tests;
>> somehow that feels undesirable. For reference this is the code that was
>> showing this problem:
>>
>> from wsgi_intercept import zope_testbrowser
>>
>> class TestBrowser(zope_testbrowser.WSGI_Browser):
>>   """A test browser which does not check robots.txt."""
>>   def __init__(self, *args, **kwargs):
>>   zope_testbrowser.WSGI_Browser.__init__(self, *args, **kwargs)
>>   self.mech_browser.set_handle_robots(False)
>>
>>
>> since wsgi_intercept is only a test dependency this caused an
>> ImportError. As a workaround I hade to rewrite the code to look like this:
>>
>> def TestBrowser():
>>   from wsgi_intercept import zope_testbrowser
>>   class TestBrowser(zope_testbrowser.WSGI_Browser):
>>   """A test browser which does not check robots.txt."""
>>   def __init__(self, *args, **kwargs):
>>   zope_testbrowser.WSGI_Browser.__init__(self, *args, **kwargs)
>>   self.mech_browser.set_handle_robots(False)
>>   return TestBrowser()
>>
>> this works, but it isn't very pretty.
>
> I actually argue that moving imports out of module scope in testcase
> modules is best practice:

I agree, but in this case TestBrowser is not something that is tested 
but a utility to help writing tests. It is similar to DummyRequest, 
DummyModel, etc. That is why I moved it out to testing.py as well.

Wichert.

-- 
Wichert AkkermanIt is simple to make things.
http://www.wiggy.net/  It is hard to make things simple.
___
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev


Re: [Repoze-dev] venusian scanning test code

2010-12-28 Thread Tres Seaver
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 12/28/2010 01:39 PM, Wichert Akkerman wrote:
> On 2010-12-28 19:16, Chris McDonough wrote:
>> On Tue, 2010-12-28 at 15:36 +0100, Wichert Akkerman wrote:
>>> I recently refactored a package to move all test infrastructure out of
>>> tests/ to testing.py. This has one unfortunate side effect: on installs
>>> without test dependencies my app will now no longer start since the
>>> venusian scan aborts on test imports in testing.py. Is there a way block
>>> venusian from scanning testing.py?
>>
>> I'm afraid not.  But I'm not sure why it worked under tests/ but not
>> under testing.py, as Venusian scans everything?
> 
> That turned out to due to some other test refactoring I was doing at the 
> same time. It did surprise me to see that venusian was scanning tests; 
> somehow that feels undesirable. For reference this is the code that was 
> showing this problem:
> 
> from wsgi_intercept import zope_testbrowser
> 
> class TestBrowser(zope_testbrowser.WSGI_Browser):
>  """A test browser which does not check robots.txt."""
>  def __init__(self, *args, **kwargs):
>  zope_testbrowser.WSGI_Browser.__init__(self, *args, **kwargs)
>  self.mech_browser.set_handle_robots(False)
> 
> 
> since wsgi_intercept is only a test dependency this caused an 
> ImportError. As a workaround I hade to rewrite the code to look like this:
> 
> def TestBrowser():
>  from wsgi_intercept import zope_testbrowser
>  class TestBrowser(zope_testbrowser.WSGI_Browser):
>  """A test browser which does not check robots.txt."""
>  def __init__(self, *args, **kwargs):
>  zope_testbrowser.WSGI_Browser.__init__(self, *args, **kwargs)
>  self.mech_browser.set_handle_robots(False)
>  return TestBrowser()
> 
> this works, but it isn't very pretty.

I actually argue that moving imports out of module scope in testcase
modules is best practice:


http://palladion.com/home/tseaver/obzervationz/2008/unit_testing_notes-20080724#guideline-minimize-module-scope-dependencies


Tres.
- -- 
===
Tres Seaver  +1 540-429-0999  tsea...@palladion.com
Palladion Software   "Excellence by Design"http://palladion.com
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk0aO6sACgkQ+gerLs4ltQ5wmgCgnx0atuO2dwU1YJBJvNisz+17
05AAn3lhYtOsQkYYDLdy/DyjXYgdhAHE
=y+bZ
-END PGP SIGNATURE-
___
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev


Re: [Repoze-dev] venusian scanning test code

2010-12-28 Thread Wichert Akkerman
On 2010-12-28 19:16, Chris McDonough wrote:
> On Tue, 2010-12-28 at 15:36 +0100, Wichert Akkerman wrote:
>> I recently refactored a package to move all test infrastructure out of
>> tests/ to testing.py. This has one unfortunate side effect: on installs
>> without test dependencies my app will now no longer start since the
>> venusian scan aborts on test imports in testing.py. Is there a way block
>> venusian from scanning testing.py?
>
> I'm afraid not.  But I'm not sure why it worked under tests/ but not
> under testing.py, as Venusian scans everything?

That turned out to due to some other test refactoring I was doing at the 
same time. It did surprise me to see that venusian was scanning tests; 
somehow that feels undesirable. For reference this is the code that was 
showing this problem:

from wsgi_intercept import zope_testbrowser

class TestBrowser(zope_testbrowser.WSGI_Browser):
 """A test browser which does not check robots.txt."""
 def __init__(self, *args, **kwargs):
 zope_testbrowser.WSGI_Browser.__init__(self, *args, **kwargs)
 self.mech_browser.set_handle_robots(False)


since wsgi_intercept is only a test dependency this caused an 
ImportError. As a workaround I hade to rewrite the code to look like this:

def TestBrowser():
 from wsgi_intercept import zope_testbrowser
 class TestBrowser(zope_testbrowser.WSGI_Browser):
 """A test browser which does not check robots.txt."""
 def __init__(self, *args, **kwargs):
 zope_testbrowser.WSGI_Browser.__init__(self, *args, **kwargs)
 self.mech_browser.set_handle_robots(False)
 return TestBrowser()

this works, but it isn't very pretty.

Wichert.

-- 
Wichert AkkermanIt is simple to make things.
http://www.wiggy.net/  It is hard to make things simple.
___
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev


Re: [Repoze-dev] venusian scanning test code

2010-12-28 Thread Chris McDonough
On Tue, 2010-12-28 at 15:36 +0100, Wichert Akkerman wrote:
> I recently refactored a package to move all test infrastructure out of 
> tests/ to testing.py. This has one unfortunate side effect: on installs 
> without test dependencies my app will now no longer start since the 
> venusian scan aborts on test imports in testing.py. Is there a way block 
> venusian from scanning testing.py?

I'm afraid not.  But I'm not sure why it worked under tests/ but not
under testing.py, as Venusian scans everything?

- C


___
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev