[GRASS-SVN] r61223 - sandbox/wenzeslaus/gunittest

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Jul 9 14:47:37 PDT 2014


Author: wenzeslaus
Date: 2014-07-09 14:47:37 -0700 (Wed, 09 Jul 2014)
New Revision: 61223

Modified:
   sandbox/wenzeslaus/gunittest/invoker.py
   sandbox/wenzeslaus/gunittest/loader.py
   sandbox/wenzeslaus/gunittest/main.py
Log:
gunittest: add missing docstrings

Modified: sandbox/wenzeslaus/gunittest/invoker.py
===================================================================
--- sandbox/wenzeslaus/gunittest/invoker.py	2014-07-09 21:01:57 UTC (rev 61222)
+++ sandbox/wenzeslaus/gunittest/invoker.py	2014-07-09 21:47:37 UTC (rev 61223)
@@ -28,6 +28,7 @@
 
 
 class GrassTestFilesInvoker(object):
+    """A class used to invoke test files and create the main report"""
 
     # TODO: it is not clear what clean_outputs mean, if should be split
     # std stream, random outputs, saved results, profiling
@@ -39,7 +40,8 @@
         """
 
         :param bool clean_mapsets: if the mapsets should be removed
-        :param bool clean_outputs: unclear: random tests outputs, saved images from maps, profiling
+        :param bool clean_outputs: meaning is unclear: random tests outputs,
+            saved images from maps, profiling?
         :param bool clean_before: if mapsets, outputs, and results
             should be removed before the tests start
             (advantageous when the previous run left everything behind)
@@ -78,6 +80,7 @@
         return mapset, mapset_dir
 
     def _run_test_module(self, module, results_dir, gisdbase, location):
+        """Run one test file."""
         cwd = os.path.join(results_dir, module.tested_dir, module.name)
         data_dir = os.path.join(module.file_dir, 'data')
         if os.path.exists(data_dir):
@@ -115,6 +118,7 @@
 
     def run_in_location(self, gisdbase, location, location_shortcut,
                         results_dir):
+        """Run tests in a given location"""
         if os.path.abspath(results_dir) == os.path.abspath(self.start_dir):
             raise RuntimeError("Results root directory should not be the same"
                                " as discovery start directory")

Modified: sandbox/wenzeslaus/gunittest/loader.py
===================================================================
--- sandbox/wenzeslaus/gunittest/loader.py	2014-07-09 21:01:57 UTC (rev 61222)
+++ sandbox/wenzeslaus/gunittest/loader.py	2014-07-09 21:47:37 UTC (rev 61223)
@@ -19,6 +19,7 @@
 import importlib
 
 
+# TODO: resolve test file versus test module
 GrassTestPythonModule = collections.namedtuple('GrassTestPythonModule',
                                                ['name', 'module',
                                                 'tested_dir',
@@ -26,10 +27,38 @@
                                                 'abs_file_path'])
 
 
+# TODO: implement loading without the import
 def discover_modules(start_dir, file_pattern, skip_dirs, testsuite_dir,
                      grass_location,
                      all_locations_value, universal_location_value,
                      import_modules):
+    """Find all test files (modules) in a directory tree.
+
+    The function is designed specifically for GRASS testing framework
+    test layout. It expects some directories to have a "testsuite"
+    directory where test files (test modules) are present.
+    Additionally, it also handles loading of test files which specify
+    in which location they can run.
+
+    :param start_dir: directory to start the search
+    :param file_pattern: pattern of files in a test suite directory
+        (using Unix shell-style wildcards)
+    :param skip_dirs: directories not to recurse to (e.g. ``.svn``)
+    :param testsuite_dir: name of directory where the test files are found,
+        the function will not recurse to this directory
+    :param grass_location: string with an accepted location (shortcut)
+    :param all_locations_value: string used to say that all locations
+        should be loaded (grass_location can be set to this value)
+    :param universal_location_value: string marking a test as
+        location-independent (same as not providing any)
+    :param import_modules: True if files should be imported as modules,
+        False if the files should be just searched for the needed values
+
+    :returns: a list of GrassTestPythonModule objects
+
+    .. todo::
+        Implement import_modules.
+    """
     modules = []
     for root, dirs, files in os.walk(start_dir):
         for dir_pattern in skip_dirs:
@@ -41,7 +70,12 @@
             dirs.remove(testsuite_dir)  # do not recurse to testsuite
             full = os.path.join(root, testsuite_dir)
             files = fnmatch.filter(os.listdir(full), file_pattern)
-            # we just ignore __init__.py
+            # get test/module name without .py
+            # extecting all files to end with .py
+            # this will not work for invoking bat files but it works fine
+            # as long as we handle only Python files (and using Python
+            # interpreter for invoking)
+            # we always ignore __init__.py
             module_names = [f[:-3] for f in files if not f == '__init__.py']
             # TODO: warning (in what way?) about no tests in testsuite
             for name in module_names:
@@ -81,7 +115,10 @@
     return modules
 
 
+# TODO: find out if this is useful for us in some way
+# we are now using only discover_modules directly
 class GrassTestLoader(unittest.TestLoader):
+    """Class handles GRASS-specific loading of test modules."""
 
     skip_dirs = ['.svn', 'dist.*', 'bin.*', 'OBJ.*']
     testsuite_dir = 'testsuite'
@@ -96,6 +133,7 @@
     # probably yes, we need to know grass src or dist root
     # TODO: not using pattern here
     def discover(self, start_dir, pattern='test*.py', top_level_dir=None):
+        """Load test modules from in GRASS testing framework way."""
         modules = discover_modules(start_dir=start_dir,
                                    file_pattern=self.files_in_testsuite,
                                    skip_dirs=self.skip_dirs,

Modified: sandbox/wenzeslaus/gunittest/main.py
===================================================================
--- sandbox/wenzeslaus/gunittest/main.py	2014-07-09 21:01:57 UTC (rev 61222)
+++ sandbox/wenzeslaus/gunittest/main.py	2014-07-09 21:47:37 UTC (rev 61223)
@@ -17,18 +17,19 @@
 from unittest.main import TestProgram, USAGE_AS_MAIN
 TestProgram.USAGE = USAGE_AS_MAIN
 
-from loader import GrassTestLoader
-from runner import GrassTestRunner
-from invoker import GrassTestFilesInvoker
-from utils import silent_rmtree
+from .loader import GrassTestLoader
+from .runner import GrassTestRunner
+from .invoker import GrassTestFilesInvoker
+from .utils import silent_rmtree
 
 import grass.script.core as gcore
 
 
 class GrassTestProgram(TestProgram):
+    """A class to be used by individual test files (wrapped in the function)"""
 
     def __init__(self, exit_at_end, grass_location, clean_outputs=True,
-                 unittest_argv=None,  module=None,
+                 unittest_argv=None, module=None,
                  verbosity=1,
                  failfast=None, catchbreak=None):
         """Prepares the tests in GRASS way and then runs the tests.



More information about the grass-commit mailing list