[GRASS-SVN] r61203 - sandbox/wenzeslaus/gunittest
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Jul 8 19:54:41 PDT 2014
Author: wenzeslaus
Date: 2014-07-08 19:54:41 -0700 (Tue, 08 Jul 2014)
New Revision: 61203
Modified:
sandbox/wenzeslaus/gunittest/case.py
sandbox/wenzeslaus/gunittest/gutils.py
sandbox/wenzeslaus/gunittest/invoker.py
Log:
gunittest: add method to compare two raster using difference and r.univar (or just max difference/precision)
Modified: sandbox/wenzeslaus/gunittest/case.py
===================================================================
--- sandbox/wenzeslaus/gunittest/case.py 2014-07-08 21:37:37 UTC (rev 61202)
+++ sandbox/wenzeslaus/gunittest/case.py 2014-07-09 02:54:41 UTC (rev 61203)
@@ -347,6 +347,40 @@
reference)
self.fail(self._formatMessage(msg, stdmsg))
+ # TODO: add tests for this method
+ def assertRastersNoDifference(self, actual, reference,
+ precision, statistics=None, msg=None):
+ """Test that `actual` raster is not different from `reference` raster
+
+ Method behaves in the same way as `assertRasterFitsUnivar()`
+ but works on difference ``referece - actual``.
+ If statistics is not given ``dict(min=-precision, max=precision)``
+ is used.
+ """
+ if statistics is None:
+ statistics = dict(min=-precision, max=precision)
+ self.assertRastersDifference(actual=actual, reference=reference,
+ statistics=statistics, precision=precision,
+ msg=msg)
+
+ def assertRastersDifference(self, actual, reference,
+ statistics, precision, msg=None):
+ """Test statistical values of differece of reference and actual rasters
+
+ For cases when you are interested in no or minimal difference,
+ use `assertRastersNoDifference()` instead.
+ """
+ diff = ('tmp__' + self.id() + '__assertRastersDifference_diff'
+ + actual + '__diff__' + reference)
+ call_module('r.mapcalc', stdin='"{d}" = "{r}" - "{a}"'.format(d=diff,
+ a=actual,
+ r=reference))
+ try:
+ self.assertRasterFitsUnivar(raster=diff, reference=statistics,
+ precision=precision, msg=msg)
+ finally:
+ call_module('g.remove', rast=diff)
+
@classmethod
def runModule(cls, module, **kwargs):
"""Run PyGRASS module.
@@ -382,10 +416,20 @@
# because we want to capture it
module.run()
if module.popen.returncode:
+ errors = module.outputs['stderr'].value
+ # provide diagnostic at least in English locale
+ # TODO: standardized error code would be handy here
+ import re
+ if re.search('Raster map.*not found', errors, flags=re.DOTALL):
+ errors += "\nSee available raster maps:\n"
+ errors += call_module('g.list', type='rast')
+ if re.search('Vector map.*not found', errors, flags=re.DOTALL):
+ errors += "\nSee available vector maps:\n"
+ errors += call_module('g.list', type='vect')
# TODO: message format, parameters
raise CalledModuleError(module.popen.returncode, module.name,
module.get_python(),
- errors=module.outputs['stderr'].value)
+ errors=errors)
# TODO: we can also comapre time to some expected but that's tricky
# maybe we should measure time but the real benchmarks with stdin/stdout
Modified: sandbox/wenzeslaus/gunittest/gutils.py
===================================================================
--- sandbox/wenzeslaus/gunittest/gutils.py 2014-07-08 21:37:37 UTC (rev 61202)
+++ sandbox/wenzeslaus/gunittest/gutils.py 2014-07-09 02:54:41 UTC (rev 61203)
@@ -6,6 +6,6 @@
from .gmodules import call_module
-def get_curret_mapset():
+def get_current_mapset():
"""Get curret mapset name as a string"""
return call_module('g.mapset', flags='p').strip()
Modified: sandbox/wenzeslaus/gunittest/invoker.py
===================================================================
--- sandbox/wenzeslaus/gunittest/invoker.py 2014-07-08 21:37:37 UTC (rev 61202)
+++ sandbox/wenzeslaus/gunittest/invoker.py 2014-07-09 02:54:41 UTC (rev 61203)
@@ -68,6 +68,10 @@
def _run_test_module(self, module, results_dir, gisdbase, location):
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):
+ shutil.copytree(data_dir, os.path.join(cwd, 'data'),
+ ignore=shutil.ignore_patterns('*.svn*'))
ensure_dir(os.path.abspath(cwd))
# TODO: put this to constructor and copy here again
env = os.environ.copy()
More information about the grass-commit
mailing list