[Checkins] SVN: grok/branches/jw-skip-tests/src/grok/ Implement and
test skipping tests and ftests packages and modules
Jan-Wijbrand Kolman
jw at infrae.com
Wed Jun 27 08:12:49 EDT 2007
Log message for revision 77122:
Implement and test skipping tests and ftests packages and modules
by default.
Changed:
U grok/branches/jw-skip-tests/src/grok/scan.py
A grok/branches/jw-skip-tests/src/grok/tests/scan/skiptests.py
A grok/branches/jw-skip-tests/src/grok/tests/scan/withtestsmodules/
A grok/branches/jw-skip-tests/src/grok/tests/scan/withtestsmodules/__init__.py
A grok/branches/jw-skip-tests/src/grok/tests/scan/withtestsmodules/ftests.py
A grok/branches/jw-skip-tests/src/grok/tests/scan/withtestsmodules/subpackage/
A grok/branches/jw-skip-tests/src/grok/tests/scan/withtestsmodules/subpackage/__init__.py
A grok/branches/jw-skip-tests/src/grok/tests/scan/withtestsmodules/tests.py
A grok/branches/jw-skip-tests/src/grok/tests/scan/withtestspackages/
A grok/branches/jw-skip-tests/src/grok/tests/scan/withtestspackages/__init__.py
A grok/branches/jw-skip-tests/src/grok/tests/scan/withtestspackages/ftests/
A grok/branches/jw-skip-tests/src/grok/tests/scan/withtestspackages/ftests/__init__.py
A grok/branches/jw-skip-tests/src/grok/tests/scan/withtestspackages/subpackage/
A grok/branches/jw-skip-tests/src/grok/tests/scan/withtestspackages/subpackage/__init__.py
A grok/branches/jw-skip-tests/src/grok/tests/scan/withtestspackages/tests/
A grok/branches/jw-skip-tests/src/grok/tests/scan/withtestspackages/tests/__init__.py
-=-
Modified: grok/branches/jw-skip-tests/src/grok/scan.py
===================================================================
--- grok/branches/jw-skip-tests/src/grok/scan.py 2007-06-27 10:28:47 UTC (rev 77121)
+++ grok/branches/jw-skip-tests/src/grok/scan.py 2007-06-27 12:12:48 UTC (rev 77122)
@@ -58,7 +58,7 @@
"""
return os.path.join(os.path.dirname(self.path), name)
- def getSubModuleInfos(self):
+ def getSubModuleInfos(self, exclude_tests=True):
if not self.isPackage():
return []
directory = os.path.dirname(self.path)
@@ -68,7 +68,9 @@
entry_path = os.path.join(directory, entry)
name, ext = os.path.splitext(entry)
dotted_name = self.dotted_name + '.' + name
-
+ # By default skip (functional) tests pacakges and modules
+ if exclude_tests and (name in ['tests', 'ftests']):
+ continue
# Case one: modules
if (os.path.isfile(entry_path) and ext in ['.py', '.pyc']):
if name == '__init__':
@@ -97,8 +99,8 @@
'%s.%s' % (self.package_dotted_name, name))
else:
return None
-
+
def getAnnotation(self, key, default):
key = key.replace('.', '_')
key = '__%s__' % key
Added: grok/branches/jw-skip-tests/src/grok/tests/scan/skiptests.py
===================================================================
--- grok/branches/jw-skip-tests/src/grok/tests/scan/skiptests.py (rev 0)
+++ grok/branches/jw-skip-tests/src/grok/tests/scan/skiptests.py 2007-06-27 12:12:48 UTC (rev 77122)
@@ -0,0 +1,87 @@
+"""
+By default functional tests and unit tests are skipped from the grokking
+procedure.
+
+Packages called 'tests' (the "de facto" standard name for packages containing
+unit tests) or 'ftests' (for functional tests) are skipped (and thus not
+grokked)::
+
+ >>> from grok.scan import ModuleInfo, module_info_from_dotted_name
+ >>> module_info = module_info_from_dotted_name(
+ ... 'grok.tests.scan.withtestspackages')
+ >>> module_info
+ <ModuleInfo object for 'grok.tests.scan.withtestspackages'>
+ >>> # Will *not* contain the module info for the tests and ftests packages
+ >>> print module_info.getSubModuleInfos()
+ [<ModuleInfo object for 'grok.tests.scan.withtestspackages.subpackage'>]
+
+Likewise modules called tests.py or ftests.py are skipped::
+
+ >>> from grok.scan import ModuleInfo, module_info_from_dotted_name
+ >>> module_info = module_info_from_dotted_name(
+ ... 'grok.tests.scan.withtestsmodules')
+ >>> module_info
+ <ModuleInfo object for 'grok.tests.scan.withtestsmodules'>
+ >>> # Will *not* contain the module info for the tests and ftests modules
+ >>> print module_info.getSubModuleInfos()
+ [<ModuleInfo object for 'grok.tests.scan.withtestsmodules.subpackage'>]
+
+You can still get to the module info of tests and ftests if you need to::
+
+ >>> module_info = module_info_from_dotted_name(
+ ... 'grok.tests.scan.withtestspackages')
+ >>> module_info
+ <ModuleInfo object for 'grok.tests.scan.withtestspackages'>
+ >>> print module_info.getSubModuleInfos(exclude_tests=False)
+ [<ModuleInfo object for 'grok.tests.scan.withtestspackages.ftests'>,
+ <ModuleInfo object for 'grok.tests.scan.withtestspackages.subpackage'>,
+ <ModuleInfo object for 'grok.tests.scan.withtestspackages.tests'>]
+
+Skipped tests and ftests pacakges are not grokked as part of the grokking
+procedure of the "parent" packages. The registrations therein will not be made::
+
+ >>> import grok
+ >>> grok.grok('grok.tests.scan.withtestspackages')
+ >>> from zope import component
+ >>> from grok.tests.scan.withtestspackages.tests import IMammoth
+ >>> # Test by trying to retrieve a global utility, which is not there
+ >>> component.getUtility(IMammoth)
+ Traceback (most recent call last):
+ ...
+ ComponentLookupError:
+ (<InterfaceClass grok.tests.scan.withtestspackages.tests.IMammoth>, '')
+
+However, tests and ftests can still be grokked when explicitely called for
+(e.g. *inside* tests and ftests - the very fact the other test cases work is
+already proof of this, but still)::
+
+ >>> grok.grok('grok.tests.scan.withtestspackages.tests')
+ >>> from zope import component
+ >>> from grok.tests.scan.withtestspackages.tests import IMammoth
+ >>> # Test by trying to retrieve a global utility
+ >>> component.getUtility(IMammoth)
+ <grok.tests.scan.withtestspackages.tests.Mammoth object at ...>
+
+Likewise tests and ftests modules are not grokked as part of the grokking
+procedure of the "parent" packages. The registrations therein will not be made::
+
+ >>> import grok
+ >>> grok.grok('grok.tests.scan.withtestsmodules')
+ >>> from zope import component
+ >>> from grok.tests.scan.withtestsmodules.tests import IClub
+ >>> # Test by trying to retrieve a global utility, which is not there
+ >>> component.getUtility(IClub)
+ Traceback (most recent call last):
+ ...
+ ComponentLookupError:
+ (<InterfaceClass grok.tests.scan.withtestsmodules.tests.IClub>, '')
+
+Tests and ftests modules can still be grokked when explicitely called for::
+
+ >>> grok.grok('grok.tests.scan.withtestsmodules.tests')
+ >>> from zope import component
+ >>> from grok.tests.scan.withtestsmodules.tests import IClub
+ >>> # Test by trying to retrieve a global utility
+ >>> component.getUtility(IClub)
+ <grok.tests.scan.withtestsmodules.tests.Club object at ...>
+"""
Added: grok/branches/jw-skip-tests/src/grok/tests/scan/withtestsmodules/__init__.py
===================================================================
Added: grok/branches/jw-skip-tests/src/grok/tests/scan/withtestsmodules/ftests.py
===================================================================
--- grok/branches/jw-skip-tests/src/grok/tests/scan/withtestsmodules/ftests.py (rev 0)
+++ grok/branches/jw-skip-tests/src/grok/tests/scan/withtestsmodules/ftests.py 2007-06-27 12:12:48 UTC (rev 77122)
@@ -0,0 +1,12 @@
+from zope.interface import Interface
+import grok
+
+class IClub(Interface):
+ pass
+
+class Club(grok.GlobalUtility):
+ grok.provides(IClub)
+
+import unittest
+def test_suite():
+ return unittest.TestSuite() # return an empty suite
Added: grok/branches/jw-skip-tests/src/grok/tests/scan/withtestsmodules/subpackage/__init__.py
===================================================================
Added: grok/branches/jw-skip-tests/src/grok/tests/scan/withtestsmodules/tests.py
===================================================================
--- grok/branches/jw-skip-tests/src/grok/tests/scan/withtestsmodules/tests.py (rev 0)
+++ grok/branches/jw-skip-tests/src/grok/tests/scan/withtestsmodules/tests.py 2007-06-27 12:12:48 UTC (rev 77122)
@@ -0,0 +1,12 @@
+from zope.interface import Interface
+import grok
+
+class IClub(Interface):
+ pass
+
+class Club(grok.GlobalUtility):
+ grok.provides(IClub)
+
+import unittest
+def test_suite():
+ return unittest.TestSuite() # return an empty suite
Added: grok/branches/jw-skip-tests/src/grok/tests/scan/withtestspackages/__init__.py
===================================================================
Added: grok/branches/jw-skip-tests/src/grok/tests/scan/withtestspackages/ftests/__init__.py
===================================================================
--- grok/branches/jw-skip-tests/src/grok/tests/scan/withtestspackages/ftests/__init__.py (rev 0)
+++ grok/branches/jw-skip-tests/src/grok/tests/scan/withtestspackages/ftests/__init__.py 2007-06-27 12:12:48 UTC (rev 77122)
@@ -0,0 +1,8 @@
+from zope.interface import Interface
+import grok
+
+class IMammoth(Interface):
+ pass
+
+class Mammoth(grok.GlobalUtility):
+ grok.provides(IMammoth)
Added: grok/branches/jw-skip-tests/src/grok/tests/scan/withtestspackages/subpackage/__init__.py
===================================================================
Added: grok/branches/jw-skip-tests/src/grok/tests/scan/withtestspackages/tests/__init__.py
===================================================================
--- grok/branches/jw-skip-tests/src/grok/tests/scan/withtestspackages/tests/__init__.py (rev 0)
+++ grok/branches/jw-skip-tests/src/grok/tests/scan/withtestspackages/tests/__init__.py 2007-06-27 12:12:48 UTC (rev 77122)
@@ -0,0 +1,8 @@
+from zope.interface import Interface
+import grok
+
+class IMammoth(Interface):
+ pass
+
+class Mammoth(grok.GlobalUtility):
+ grok.provides(IMammoth)
More information about the Checkins
mailing list