[GRASS-SVN] r61173 - sandbox/wenzeslaus/gunittest
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Jul 7 13:25:39 PDT 2014
Author: wenzeslaus
Date: 2014-07-07 13:25:39 -0700 (Mon, 07 Jul 2014)
New Revision: 61173
Modified:
sandbox/wenzeslaus/gunittest/case.py
Log:
gunittest: provide also interface for passing individual parameters (suggested in r61158)
Modified: sandbox/wenzeslaus/gunittest/case.py
===================================================================
--- sandbox/wenzeslaus/gunittest/case.py 2014-07-07 20:11:16 UTC (rev 61172)
+++ sandbox/wenzeslaus/gunittest/case.py 2014-07-07 20:25:39 UTC (rev 61173)
@@ -17,6 +17,8 @@
import unittest
from unittest.util import safe_repr
+from grass.pygrass.modules import Module
+
from .gmodules import call_module, CalledModuleError
from .checkers import (check_text_ellipsis,
text_to_keyvalue, compare_keyvalue, diff_keyvalue,
@@ -325,7 +327,8 @@
output = call_module(module, stdin, merge_stderr=False, **kwargs)
return output
- def runModule(self, module):
+ @classmethod
+ def runModule(cls, module, **kwargs):
"""Run PyGRASS module.
Runs the module and raises an expception if the module ends with
@@ -339,6 +342,15 @@
:raises CalledModuleError: if the module failed
"""
+ # TODO: using call_module for compatibility with run_command rules
+ call_module(module, **kwargs)
+ return
+
+ if kwargs:
+ if not isinstance(module, basestring):
+ raise ValueError('module can be only string or PyGRASS Module')
+ module = Module(module, run_=False, **kwargs)
+
if module.run_:
raise ValueError('Do not run the module manually, set run_=False')
if not module.finish_:
@@ -368,7 +380,7 @@
# the original idea was to run this method just once for test method
# but for "integration" tests (script-like tests with more than one module)
# it would be better to be able to use this multiple times
- def assertModule(self, module, msg=None):
+ def assertModule(self, module, msg=None, **kwargs):
"""Run PyGRASS module in controled way and assert non-zero return code.
You should use this method to invoke module you are testing.
@@ -387,6 +399,13 @@
Runs the module and causes test failure if module ends with
non-zero return code.
"""
+ if kwargs:
+ if not isinstance(module, basestring):
+ raise ValueError('module can be only string or PyGRASS Module')
+ if isinstance(module, Module):
+ raise ValueError('module can be only string if other parameters are given')
+ module = Module(module, run_=False, **kwargs)
+
# TODO: merge stderr to stdout? if caller gives PIPE, for sure not
if module.run_:
raise ValueError('Do not run the module manually, set run_=False')
More information about the grass-commit
mailing list