[GRASS-SVN] r60952 - in sandbox/wenzeslaus/gunittest: . testsuite
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Jun 24 20:57:07 PDT 2014
Author: wenzeslaus
Date: 2014-06-24 20:57:07 -0700 (Tue, 24 Jun 2014)
New Revision: 60952
Modified:
sandbox/wenzeslaus/gunittest/case.py
sandbox/wenzeslaus/gunittest/grass_py_static_check.py
sandbox/wenzeslaus/gunittest/testsuite/test_assertions.py
sandbox/wenzeslaus/gunittest/testsuite/test_checkers.py
Log:
gunittest: assertaion for vector map based on v.univar
Modified: sandbox/wenzeslaus/gunittest/case.py
===================================================================
--- sandbox/wenzeslaus/gunittest/case.py 2014-06-25 03:49:21 UTC (rev 60951)
+++ sandbox/wenzeslaus/gunittest/case.py 2014-06-25 03:57:07 UTC (rev 60952)
@@ -27,7 +27,6 @@
cov = coverage.coverage(omit="*testsuite*")
cov.start()
-
class GrassTestCase(unittest.TestCase):
# we dissable R0904 for all TestCase classes because their purpose is to
# provide a lot of assert methods
@@ -48,12 +47,12 @@
safe_repr(reference))
self.fail(self._formatMessage(msg, standardMsg))
- def assertWithCommandKeyValue(self, module, parameters, reference,
- msg=None, sep='='):
+ def assertCommandKeyValue(self, module, parameters, reference, sep,
+ msg=None):
if isinstance(reference, basestring):
- reference = text_to_keyvalue(reference, sep='=')
+ reference = text_to_keyvalue(reference, sep=sep)
stdout = gcore.read_command(module, **parameters)
- raster_univar = text_to_keyvalue(stdout, sep='=')
+ raster_univar = text_to_keyvalue(stdout, sep=sep)
if not compare_keyvalue(dict_a=reference, dict_b=raster_univar,
a_is_subset=True):
unused, missing, mismatch = diff_keyvalue(dict_a=reference,
@@ -62,26 +61,45 @@
if missing:
raise ValueError("%s output does not contain"
" the following keys"
- " provided in reference_univar"
- ": %s\n" % (module, missing))
+ " provided in reference"
+ ": %s\n" % (module, ", ".join(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, msg=None):
- self.assertWithCommandKeyValue(module='r.univar',
- parameters=dict(map=raster,
- separator='=',
- flags='ge'),
- reference=reference, msg=msg, sep='=')
+ self.assertCommandKeyValue(module='r.univar',
+ parameters=dict(map=raster,
+ separator='=',
+ flags='g'),
+ reference=reference, msg=msg, sep='=')
def assertRasterFitsInfo(self, raster, reference, msg=None):
- self.assertWithCommandKeyValue(module='r.info',
- parameters=dict(map=raster, flags='ge'),
- reference=reference, msg=msg, sep='=')
+ self.assertCommandKeyValue(module='r.info',
+ parameters=dict(map=raster, flags='g'),
+ reference=reference, msg=msg, sep='=')
+ def assertVectorFitsUnivar(self, map, column, reference, msg=None,
+ layer=None, type=None, where=None):
+ """
+ Use keyword arguments syntax for all function parameters.
+
+ Does not support -d (geometry distances) flag, -e (extended statistics)
+ flag and few other, use `assertCommandKeyValue` for the full interface.
+ """
+ parameters = dict(map=map, column=column, flags='g')
+ if layer:
+ parameters.update(layer=layer)
+ if type:
+ parameters.update(type=type)
+ if where:
+ parameters.update(where=where)
+ self.assertCommandKeyValue(module='v.univar',
+ parameters=parameters,
+ reference=reference, msg=msg, sep='=')
+
# the following lines are for code coverage
def endcov(cov):
cov.stop()
Modified: sandbox/wenzeslaus/gunittest/grass_py_static_check.py
===================================================================
--- sandbox/wenzeslaus/gunittest/grass_py_static_check.py 2014-06-25 03:49:21 UTC (rev 60951)
+++ sandbox/wenzeslaus/gunittest/grass_py_static_check.py 2014-06-25 03:57:07 UTC (rev 60952)
@@ -163,7 +163,7 @@
# a lot of special treatment is needed to get packages nicely shown
grass_packages = ['script', 'pygrass', 'temporal']
- #, 'imaging', 'pydispatch', 'lib']
+ # not included: 'imaging', 'pydispatch', 'lib'
ensure_dir('pylint_report/grass')
index = open('pylint_report/grass/index.html', 'w')
for package in grass_packages:
Modified: sandbox/wenzeslaus/gunittest/testsuite/test_assertions.py
===================================================================
--- sandbox/wenzeslaus/gunittest/testsuite/test_assertions.py 2014-06-25 03:49:21 UTC (rev 60951)
+++ sandbox/wenzeslaus/gunittest/testsuite/test_assertions.py 2014-06-25 03:57:07 UTC (rev 60952)
@@ -19,8 +19,9 @@
self.assertLooksLike("Generated map is <elevation>",
"Generated map is <...>")
self.assertRaises(self.failureException,
- self.assertLooksLike, "Generated map is elevation.",
- "Generated map is <...>")
+ self.assertLooksLike,
+ "Generated map is elevation.",
+ "Generated map is <...>")
R_UNIVAR_ELEVATION_SUBSET = """n=2025000
@@ -40,6 +41,16 @@
datatype=FCELL
"""
+V_UNIVAR_BRIDGES_WIDTH_SUBSET = """n=10938
+nmissing=0
+nnull=0
+min=0
+max=1451
+range=1451
+sum=2.6299e+06
+mean=240.437
+"""
+
class TestRasterMapAssertations(GrassTestCase):
# pylint: disable=R0904
def test_assertRasterFitsUnivar(self):
@@ -59,3 +70,18 @@
self.assertRaises(ValueError,
self.assertRasterFitsInfo,
'elevation', RANDOM_KEYVALUES)
+
+
+class TestVectorMapAssertations(GrassTestCase):
+ # pylint: disable=R0904
+ def test_assertVectorFitsUnivar(self):
+ self.assertVectorFitsUnivar(map='bridges', column='WIDTH',
+ reference=V_UNIVAR_BRIDGES_WIDTH_SUBSET)
+ self.assertRaises(self.failureException,
+ self.assertVectorFitsUnivar,
+ map='bridges', column='YEAR_BUILT',
+ reference=V_UNIVAR_BRIDGES_WIDTH_SUBSET)
+ self.assertRaises(ValueError,
+ self.assertVectorFitsUnivar,
+ map='bridges', column='WIDTH',
+ reference=RANDOM_KEYVALUES)
Modified: sandbox/wenzeslaus/gunittest/testsuite/test_checkers.py
===================================================================
--- sandbox/wenzeslaus/gunittest/testsuite/test_checkers.py 2014-06-25 03:49:21 UTC (rev 60951)
+++ sandbox/wenzeslaus/gunittest/testsuite/test_checkers.py 2014-06-25 03:57:07 UTC (rev 60952)
@@ -230,11 +230,11 @@
class TestParseKeyvalue(GrassTestCase):
-
+
def test_shell_script_style(self):
-
+
self.assertDictEqual(parse_key_val(R_UNIVAR_KEYVAL_INT, val_type=int),
- R_UNIVAR_KEYVAL_INT_DICT)
+ R_UNIVAR_KEYVAL_INT_DICT)
R_UNIVAR_ELEVATION = """n=2025000
@@ -300,7 +300,7 @@
sep='='),
a_is_subset=True))
self.assertFalse(compare_keyvalue(text_to_keyvalue(R_UNIVAR_ELEVATION,
- sep='='),
+ sep='='),
text_to_keyvalue(R_UNIVAR_ELEVATION_SUBSET,
sep='='),
a_is_subset=True))
More information about the grass-commit
mailing list