[GRASS-SVN] r61107 - sandbox/wenzeslaus/gunittest
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Jul 1 14:56:06 PDT 2014
Author: wenzeslaus
Date: 2014-07-01 14:56:06 -0700 (Tue, 01 Jul 2014)
New Revision: 61107
Modified:
sandbox/wenzeslaus/gunittest/main.py
Log:
gunittest: remove overridden method, original is enough when passing loader instance
Modified: sandbox/wenzeslaus/gunittest/main.py
===================================================================
--- sandbox/wenzeslaus/gunittest/main.py 2014-07-01 21:52:11 UTC (rev 61106)
+++ sandbox/wenzeslaus/gunittest/main.py 2014-07-01 21:56:06 UTC (rev 61107)
@@ -10,73 +10,33 @@
class GrassTestProgram(TestProgram):
- def _do_discovery(self, argv, Loader=None):
- """
+ def __init__(self, grass_location=None, clean_outputs=True,
+ unittest_argv=None,
+ exit_at_end=True, verbosity=1,
+ failfast=None, catchbreak=None):
+ """Prepares the tests in GRASS way and then runs the tests.
- Taken from Python's ``unittest.main.TestProgram._do_discovery()``.
- Line::
-
- Loader = lambda: self.testLoader
-
- changed to::
-
- Loader = self.testLoader
+ :param bool clean_outputs: if outputs in mapset and in ?
"""
- if Loader is None:
- Loader = self.testLoader
+ self.test = None
+ self.grass_location = grass_location
+ # it is unclear what the exact behavior is unittest
+ # buffer stdout and stderr during tests
+ buffer_stdout_stderr = False
- # handle command line args for test discovery
- self.progName = '%s discover' % self.progName
- import optparse
- parser = optparse.OptionParser()
- parser.prog = self.progName
- parser.add_option('-v', '--verbose', dest='verbose', default=False,
- help='Verbose output', action='store_true')
- if self.failfast != False:
- parser.add_option('-f', '--failfast', dest='failfast', default=False,
- help='Stop on first fail or error',
- action='store_true')
- if self.catchbreak != False:
- parser.add_option('-c', '--catch', dest='catchbreak', default=False,
- help='Catch ctrl-C and display results so far',
- action='store_true')
- if self.buffer != False:
- parser.add_option('-b', '--buffer', dest='buffer', default=False,
- help='Buffer stdout and stderr during tests',
- action='store_true')
- parser.add_option('-s', '--start-directory', dest='start', default='.',
- help="Directory to start discovery ('.' default)")
- parser.add_option('-p', '--pattern', dest='pattern', default='test*.py',
- help="Pattern to match tests ('test*.py' default)")
- parser.add_option('-t', '--top-level-directory', dest='top', default=None,
- help='Top level directory of project (defaults to start directory)')
+ grass_loader = GrassTestLoader(grass_location=self.grass_location)
+ grass_runner = GrassTestRunner(verbosity=verbosity,
+ failfast=failfast,
+ buffer=buffer_stdout_stderr)
- options, args = parser.parse_args(argv)
- if len(args) > 3:
- self.usageExit()
+ super(GrassTestProgram, self).__init__(module=None, argv=unittest_argv,
+ testLoader=grass_loader,
+ testRunner=grass_runner,
+ exit=exit_at_end,
+ verbosity=verbosity,
+ failfast=failfast,
+ catchbreak=catchbreak,
+ buffer=buffer_stdout_stderr)
- for name, value in zip(('start', 'pattern', 'top'), args):
- setattr(options, name, value)
-
- # only set options from the parsing here
- # if they weren't set explicitly in the constructor
- if self.failfast is None:
- self.failfast = options.failfast
- if self.catchbreak is None:
- self.catchbreak = options.catchbreak
- if self.buffer is None:
- self.buffer = options.buffer
-
- if options.verbose:
- self.verbosity = 2
-
- start_dir = options.start
- pattern = options.pattern
- top_level_dir = options.top
-
- loader = Loader()
- self.test = loader.discover(start_dir, pattern, top_level_dir)
-
-
if __name__ == '__main__':
- GrassTestProgram(module=None, testLoader=GrassTestLoader, testRunner=GrassTestRunner)
+ GrassTestProgram(grass_location='nc')
More information about the grass-commit
mailing list