[GRASS-SVN] r61106 - sandbox/wenzeslaus/gunittest
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Jul 1 14:52:11 PDT 2014
Author: wenzeslaus
Date: 2014-07-01 14:52:11 -0700 (Tue, 01 Jul 2014)
New Revision: 61106
Modified:
sandbox/wenzeslaus/gunittest/loader.py
Log:
gunittest: look at the Python module's LOCATIONS global variable when loading tests
Modified: sandbox/wenzeslaus/gunittest/loader.py
===================================================================
--- sandbox/wenzeslaus/gunittest/loader.py 2014-07-01 17:49:08 UTC (rev 61105)
+++ sandbox/wenzeslaus/gunittest/loader.py 2014-07-01 21:52:11 UTC (rev 61106)
@@ -7,6 +7,7 @@
import fnmatch
import unittest
import collections
+import importlib
import suite
@@ -23,7 +24,12 @@
testsuite_dir = 'testsuite'
files_in_testsuite = '*.py'
suiteClass = suite.GrassTestSuite
+ all_tests_value = 'all'
+ universal_tests_value = 'universal'
+ def __init__(self, grass_location):
+ self.grass_location = grass_location
+
# TODO: we ignore all parameters
def discover(self, start_dir, pattern='test*.py', top_level_dir=None):
modules = []
@@ -35,21 +41,35 @@
dirs.remove(skip)
if self.testsuite_dir in dirs:
+ dirs.remove(self.testsuite_dir) # do not recurse to testsuite
full = os.path.join(root, self.testsuite_dir)
files = fnmatch.filter(os.listdir(full), self.files_in_testsuite)
module_names = [f[:-3] for f in files if not f == '__init__.py']
for name in module_names:
sys.path.insert(0, full)
try:
- import importlib
m = importlib.import_module(name)
- #__import__(name)
- modules.append(GrassTestPythonModule(name=name,
- module=m,
- tested_dir=root,
- file_dir=full))
- tests.append(self.loadTestsFromModule(m))
- except ImportError as e:
+ run = False
+ if self.grass_location == self.all_tests_value:
+ run = True
+ else:
+ try:
+ locations = m.LOCATIONS
+ except AttributeError:
+ run = True # test is universal
+ else:
+ if self.universal_tests_value in locations:
+ run = True # cases when it is explicit
+ if self.grass_location in locations:
+ run = True # standard case with given location
+ if run:
+ modules.append(GrassTestPythonModule(name=name,
+ module=m,
+ tested_dir=root,
+ file_dir=full))
+ tests.append(self.loadTestsFromModule(m))
+ # in else with some verbose we could tell about skiped test
+ except ImportError:
raise ImportError('No module named %s in %s' % (name, full))
# alternative is to create TestClass which will raise
# see unittest.loader
@@ -57,4 +77,4 @@
if __name__ == '__main__':
- GrassTestLoader().discoverGrassTestDirs()
+ GrassTestLoader().discover()
More information about the grass-commit
mailing list