[GRASS-SVN] r60950 - in sandbox/wenzeslaus/gunittest: . testsuite

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jun 24 12:59:46 PDT 2014


Author: wenzeslaus
Date: 2014-06-24 12:59:46 -0700 (Tue, 24 Jun 2014)
New Revision: 60950

Modified:
   sandbox/wenzeslaus/gunittest/case.py
   sandbox/wenzeslaus/gunittest/testsuite/test_assertions.py
Log:
gunittest: common function for r.info, r.univar and other comparisons (following r60948 and unintentional r60949)

Modified: sandbox/wenzeslaus/gunittest/case.py
===================================================================
--- sandbox/wenzeslaus/gunittest/case.py	2014-06-24 19:27:40 UTC (rev 60949)
+++ sandbox/wenzeslaus/gunittest/case.py	2014-06-24 19:59:46 UTC (rev 60950)
@@ -32,7 +32,12 @@
     # we dissable R0904 for all TestCase classes because their purpose is to
     # provide a lot of assert methods
     # pylint: disable=R0904
+    """
 
+    Always use keyword arguments for all parameters other than first two. For
+    the firt two, it is recommened to use keyword arguments but not required.
+    """
+
     def assertLooksLike(self, actual, reference, msg=None):
         self.assert_(isinstance(actual, basestring), (
                      'actual argument is not a string'))
@@ -43,14 +48,15 @@
                                                                   safe_repr(reference))
             self.fail(self._formatMessage(msg, standardMsg))
 
-    def assertWithCommandKeyValue(self, module, parameters, reference, msg=None):
+    def assertWithCommandKeyValue(self, module, parameters, reference,
+                                  msg=None, sep='='):
         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,
+        if not compare_keyvalue(dict_a=reference, dict_b=raster_univar,
                                 a_is_subset=True):
-            unused, missing, mismatch = diff_keyvalue(dict_a=reference_univar,
+            unused, missing, mismatch = diff_keyvalue(dict_a=reference,
                                                       dict_b=raster_univar,
                                                       a_is_subset=True)
             if missing:
@@ -63,32 +69,17 @@
                 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='=')
-        stdout = gcore.read_command('r.univar',
-                                    map=raster, separator='=', flags='ge')
-        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)
-            standardMsg = "r.univar difference:\n"
-            if mismatch:
-                standardMsg += "mismatch values: %s\n" % mismatch
-            if missing:
-                raise ValueError("r.univar output does not contain"
-                                 " the following keys"
-                                 " provided in reference_univar"
-                                 ": %s\n" % missing)
-            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='=')
 
     def assertRasterFitsInfo(self, raster, reference, msg=None):
         self.assertWithCommandKeyValue(module='r.info',
-                                       parameters=dict('r.univar', map=raster,
-                                                       separator='=', flags='ge'),
-                                       reference, msg)
+                                       parameters=dict(map=raster, flags='ge'),
+                                       reference=reference, msg=msg, sep='=')
 
 
 # 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:27:40 UTC (rev 60949)
+++ sandbox/wenzeslaus/gunittest/testsuite/test_assertions.py	2014-06-24 19:59:46 UTC (rev 60950)
@@ -34,6 +34,11 @@
 bbb=156.329864501953
 """
 
+R_INFO_ELEVATION_SUBSET = """rows=1350
+cols=1500
+cells=2025000
+datatype=FCELL
+"""
 
 class TestRasterMapAssertations(GrassTestCase):
     # pylint: disable=R0904
@@ -46,8 +51,11 @@
                           self.assertRasterFitsUnivar,
                           'elevation', RANDOM_KEYVALUES)
 
-   def test_assertRasterFitsInfo(self):
-       self.assertRasterFitsInfo('elevation', R_UNIVAR_ELEVATION_SUBSET)
-       self.assertRaises(self.failureException,
+    def test_assertRasterFitsInfo(self):
+        self.assertRasterFitsInfo('elevation', R_INFO_ELEVATION_SUBSET)
+        self.assertRaises(self.failureException,
                           self.assertRasterFitsInfo,
-                          'aspect', R_UNIVAR_ELEVATION_SUBSET)
\ No newline at end of file
+                          'elev_lid792_1m', R_INFO_ELEVATION_SUBSET)
+        self.assertRaises(ValueError,
+                          self.assertRasterFitsInfo,
+                          'elevation', RANDOM_KEYVALUES)



More information about the grass-commit mailing list