[Checkins] SVN: martian/trunk/src/martian/scan. Reenabled grokking of tests and ftests modules.

Uli Fouquet uli at gnufix.de
Thu Aug 16 22:44:01 EDT 2007


Log message for revision 78889:
  Reenabled grokking of tests and ftests modules.

Changed:
  U   martian/trunk/src/martian/scan.py
  U   martian/trunk/src/martian/scan.txt

-=-
Modified: martian/trunk/src/martian/scan.py
===================================================================
--- martian/trunk/src/martian/scan.py	2007-08-17 02:35:47 UTC (rev 78888)
+++ martian/trunk/src/martian/scan.py	2007-08-17 02:44:00 UTC (rev 78889)
@@ -60,7 +60,7 @@
         """
         return os.path.join(os.path.dirname(self.path), name)
 
-    def getSubModuleInfos(self, exclude_tests=True):
+    def getSubModuleInfos(self, exclude_filter=lambda x:False):
         if not self.isPackage():
             return []
         directory = os.path.dirname(self.path)
@@ -70,10 +70,7 @@
             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
-            # XXX This make scan.py less generic and thus we might want to
-            # look for a different solution at some point.
-            if exclude_tests and (name in ['tests', 'ftests']):
+            if exclude_filter(name):
                 continue
             # Case one: modules
             if (os.path.isfile(entry_path) and ext in ['.py', '.pyc']):

Modified: martian/trunk/src/martian/scan.txt
===================================================================
--- martian/trunk/src/martian/scan.txt	2007-08-17 02:35:47 UTC (rev 78888)
+++ martian/trunk/src/martian/scan.txt	2007-08-17 02:44:00 UTC (rev 78889)
@@ -163,52 +163,36 @@
   >>> resource_path == expected_resource_path
   True
 
-Skipping test packages and modules
-----------------------------------
 
-By default functional tests and unit tests are skipped from the grokking
-procedure.
+Skipping packages and modules
+-----------------------------
 
-Packages called 'tests' (the "de facto" standard name for packages containing
-unit tests) or 'ftests' (for functional tests) are skipped (and thus not
-grokked)::
+By default no packages and modules are skipped from the grokking
+procedure to guarantee a generic behaviour::
 
   >>> from martian.scan import ModuleInfo, module_info_from_dotted_name
   >>> module_info = module_info_from_dotted_name(
   ...     'martian.tests.withtestspackages')
   >>> module_info
   <ModuleInfo object for 'martian.tests.withtestspackages'>
-  >>> # Will *not* contain the module info for the tests and ftests packages
+  >>> # *Will* contain the module info for the tests and ftests packages
   >>> print module_info.getSubModuleInfos()
-  [<ModuleInfo object for 'martian.tests.withtestspackages.subpackage'>]
+  [...<ModuleInfo object for 'martian.tests.withtestspackages.tests'>...]
 
-Likewise modules called tests.py or ftests.py are skipped::
+You can, however, tell ``getSubmoduleInfos()`` to skip certain names
+of packages and modules. To do that, you have to give a filter
+function which takes a name and returns a boolean. Names, for which
+the function returns ``True`` are skipped from the result.
 
+For example, to get only those packages, which are *not* named 'tests'
+nor 'ftests' we could do::
+
   >>> from martian.scan import ModuleInfo, module_info_from_dotted_name
   >>> module_info = module_info_from_dotted_name(
   ...     'martian.tests.withtestsmodules')
   >>> module_info
   <ModuleInfo object for 'martian.tests.withtestsmodules'>
-  >>> # Will *not* contain the module info for the tests and ftests modules
-  >>> print module_info.getSubModuleInfos()
+  >>> no_tests_filter = lambda x: x in ['tests', 'ftests']
+  >>> print module_info.getSubModuleInfos(exclude_filter=no_tests_filter)
   [<ModuleInfo object for 'martian.tests.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(
-  ...     'martian.tests.withtestspackages')
-  >>> module_info
-  <ModuleInfo object for 'martian.tests.withtestspackages'>
-  >>> print module_info.getSubModuleInfos(exclude_tests=False)
-  [<ModuleInfo object for 'martian.tests.withtestspackages.ftests'>,
-  <ModuleInfo object for 'martian.tests.withtestspackages.subpackage'>,
-  <ModuleInfo object for 'martian.tests.withtestspackages.tests'>]
-
-You can also explicitely grok tests and ftests packages::
-
-  >>> module_info = module_info_from_dotted_name(
-  ...     'martian.tests.withtestspackages.tests')
-  >>> module_info
-  <ModuleInfo object for 'martian.tests.withtestspackages.tests'>
-  >>> print module_info.getSubModuleInfos()
-  [<ModuleInfo object for 'martian.tests.withtestspackages.tests.subpackage'>]



More information about the Checkins mailing list