[GRASS-SVN] r60949 - in sandbox/wenzeslaus/gunittest: . testsuite
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Jun 24 12:27:40 PDT 2014
Author: wenzeslaus
Date: 2014-06-24 12:27:40 -0700 (Tue, 24 Jun 2014)
New Revision: 60949
Modified:
sandbox/wenzeslaus/gunittest/case.py
sandbox/wenzeslaus/gunittest/testsuite/test_assertions.py
Log:
gunittest: sunset option for keyvalue comparison, keyvalue difference, and functions for comparing raster maps using r.univar output
Modified: sandbox/wenzeslaus/gunittest/case.py
===================================================================
--- sandbox/wenzeslaus/gunittest/case.py 2014-06-24 19:16:28 UTC (rev 60948)
+++ sandbox/wenzeslaus/gunittest/case.py 2014-06-24 19:27:40 UTC (rev 60949)
@@ -43,6 +43,26 @@
safe_repr(reference))
self.fail(self._formatMessage(msg, standardMsg))
+ def assertWithCommandKeyValue(self, module, parameters, reference, msg=None):
+ if isinstance(reference, basestring):
+ reference = text_to_keyvalue(reference, sep='=')
+ stdout = gcore.read_command(module, **parameters)
+ raster_univar = text_to_keyvalue(stdout, sep='=')
+ if not compare_keyvalue(dict_a=reference_univar, dict_b=raster_univar,
+ a_is_subset=True):
+ unused, missing, mismatch = diff_keyvalue(dict_a=reference_univar,
+ dict_b=raster_univar,
+ a_is_subset=True)
+ if missing:
+ raise ValueError("%s output does not contain"
+ " the following keys"
+ " provided in reference_univar"
+ ": %s\n" % (module, missing))
+ standardMsg = "%s difference:\n" % module
+ if mismatch:
+ standardMsg += "mismatch values: %s\n" % mismatch
+ self.fail(self._formatMessage(msg, standardMsg))
+
def assertRasterFitsUnivar(self, raster, reference_univar, msg=None):
if isinstance(reference_univar, basestring):
reference_univar = text_to_keyvalue(reference_univar, sep='=')
@@ -64,6 +84,11 @@
": %s\n" % missing)
self.fail(self._formatMessage(msg, standardMsg))
+ def assertRasterFitsInfo(self, raster, reference, msg=None):
+ self.assertWithCommandKeyValue(module='r.info',
+ parameters=dict('r.univar', map=raster,
+ separator='=', flags='ge'),
+ reference, msg)
# the following lines are for code coverage
Modified: sandbox/wenzeslaus/gunittest/testsuite/test_assertions.py
===================================================================
--- sandbox/wenzeslaus/gunittest/testsuite/test_assertions.py 2014-06-24 19:16:28 UTC (rev 60948)
+++ sandbox/wenzeslaus/gunittest/testsuite/test_assertions.py 2014-06-24 19:27:40 UTC (rev 60949)
@@ -45,3 +45,9 @@
self.assertRaises(ValueError,
self.assertRasterFitsUnivar,
'elevation', RANDOM_KEYVALUES)
+
+ def test_assertRasterFitsInfo(self):
+ self.assertRasterFitsInfo('elevation', R_UNIVAR_ELEVATION_SUBSET)
+ self.assertRaises(self.failureException,
+ self.assertRasterFitsInfo,
+ 'aspect', R_UNIVAR_ELEVATION_SUBSET)
\ No newline at end of file
More information about the grass-commit
mailing list