[GRASS-SVN] r61266 - in grass/trunk/lib/python/gunittest: . testsuite testsuite/data

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Jul 17 11:38:42 PDT 2014


Author: wenzeslaus
Date: 2014-07-17 11:38:42 -0700 (Thu, 17 Jul 2014)
New Revision: 61266

Added:
   grass/trunk/lib/python/gunittest/testsuite/data/simple_vector_map_ascii_4p_2l_2c_3b_dp14.txt
   grass/trunk/lib/python/gunittest/testsuite/data/simple_vector_map_ascii_4p_2l_2c_3b_dp14_diff_header.txt
   grass/trunk/lib/python/gunittest/testsuite/data/simple_vector_map_ascii_4p_2l_2c_3b_dp14_modified.txt
Modified:
   grass/trunk/lib/python/gunittest/case.py
   grass/trunk/lib/python/gunittest/main.py
   grass/trunk/lib/python/gunittest/testsuite/test_assertions_vect.py
Log:
gunittest: assert methods for testing vector equality based on v.info and diff of ascii, most notably assertVectorEqualsVector and assertVectorEqualsAscii (with tests)

Modified: grass/trunk/lib/python/gunittest/case.py
===================================================================
--- grass/trunk/lib/python/gunittest/case.py	2014-07-17 03:51:31 UTC (rev 61265)
+++ grass/trunk/lib/python/gunittest/case.py	2014-07-17 18:38:42 UTC (rev 61266)
@@ -38,6 +38,7 @@
     longMessage = True  # to get both standard and custom message
     maxDiff = None  # we can afford long diffs
     _temp_region = None  # to control the temporary region
+    html_reports = False  # output additional HTML files with failure details
 
     def __init__(self, methodName):
         super(TestCase, self).__init__(methodName)
@@ -339,6 +340,24 @@
                                   reference=reference, msg=msg, sep='=',
                                   precision=0)
 
+    def assertVectorInfoEqualsVectorInfo(self, actual, reference, precision,
+                                         msg=None):
+        """Test that two vectors are equal according to ``v.info -tg``.
+
+        This function does not test geometry itself just the region of the
+        vector map and number of features.
+        """
+        module = SimpleModule('v.info', flags='t', map=reference)
+        self.runModule(module)
+        ref_topo = text_to_keyvalue(module.outputs.stdout, sep='=')
+        module = SimpleModule('v.info', flags='g', map=reference)
+        self.runModule(module)
+        ref_info = text_to_keyvalue(module.outputs.stdout, sep='=')
+        self.assertVectorFitsTopoInfo(vector=actual, reference=ref_topo,
+                                      msg=msg)
+        self.assertVectorFitsRegionInfo(vector=actual, reference=ref_info,
+                                        precision=precision, msg=msg)
+
     def assertVectorFitsUnivar(self, map, column, reference, msg=None,
                                layer=None, type=None, where=None,
                                precision=None):
@@ -551,6 +570,38 @@
         #     If 0 or not given, the category is not written
         return diff
 
+    # TODO: -z and 3D support
+    def _import_ascii_vector(self, filename, name_part):
+        """Import a vector stored in GRASS vector ASCII format.
+
+        :returns: name of a new vector
+        """
+        import hashlib
+        # hash is the easiest way how to get a valied vector name
+        # TODO: introduce some function which will make file valid
+        hasher = hashlib.md5()
+        hasher.update(filename)
+        namehash = hasher.hexdigest()
+        vector = ('tmp_' + self.id().replace('.', '_')
+                  + '_import_ascii_vector_'
+                  + name_part + '_' + namehash)
+        call_module('v.in.ascii', input=filename,
+                    output=vector, format='standard')
+        return vector
+
+    # TODO: -z and 3D support
+    def _export_ascii_vector(self, vector, name_part, digits):
+        """Import a vector stored in GRASS vector ASCII format.
+
+        :returns: name of a new vector
+        """
+        # TODO: perhaps we can afford just simple file name
+        filename = ('tmp_' + self.id() + '_export_ascii_vector_'
+                    + name_part + '_' + vector)
+        call_module('v.out.ascii', input=vector,
+                    output=filename, format='standard', layer='-1', dp=digits)
+        return filename
+
     def assertRastersNoDifference(self, actual, reference,
                                   precision, statistics=None, msg=None):
         """Test that `actual` raster is not different from `reference` raster
@@ -623,7 +674,7 @@
             # TODO: we are using r.info min max and r.univar min max interchangably
             # but they might be different if region is different from map
             # not considered as an huge issue since we expect the tested maps
-            # to match with region, however a documentation should containe a notice
+            # to match with region, however a documentation should contain a notice
             self.assertRasters3dDifference(actual=actual, reference=reference,
                                            statistics=statistics,
                                            precision=precision, msg=msg)
@@ -654,16 +705,9 @@
         """
         # TODO: if msg is None: add info specific to this function
         layer = '-1'
-        module = SimpleModule('v.info', flags='t', map=reference)
-        self.runModule(module)
-        ref_topo = text_to_keyvalue(module.outputs.stdout, sep='=')
-        module = SimpleModule('v.info', flags='g', map=reference)
-        self.runModule(module)
-        ref_info = text_to_keyvalue(module.outputs.stdout, sep='=')
-        self.assertVectorFitsTopoInfo(vector=actual, reference=ref_topo,
-                                      msg=msg)
-        self.assertVectorFitsRegionInfo(vector=actual, reference=ref_info,
-                                        msg=msg, precision=precision)
+        self.assertVectorInfoEqualsVectorInfo(actual=actual,
+                                              reference=reference,
+                                              precision=precision, msg=msg)
         remove = []
         buffered = reference + '_buffered'  # TODO: more unique name
         intersection = reference + '_intersection'  # TODO: more unique name
@@ -677,9 +721,20 @@
                            output=intersection, atype='area', btype='area',
                            olayer='')
             remove.append(intersection)
-            self.assertVectorFitsTopoInfo(vector=intersection, reference=ref_topo,
+            # TODO: this would use some refactoring
+            # perhaps different functions or more low level functions would
+            # be more appropriate
+            module = SimpleModule('v.info', flags='t', map=reference)
+            self.runModule(module)
+            ref_topo = text_to_keyvalue(module.outputs.stdout, sep='=')
+            self.assertVectorFitsTopoInfo(vector=intersection,
+                                          reference=ref_topo,
                                           msg=msg)
-            self.assertVectorFitsRegionInfo(vector=intersection, reference=ref_info,
+            module = SimpleModule('v.info', flags='g', map=reference)
+            self.runModule(module)
+            ref_info = text_to_keyvalue(module.outputs.stdout, sep='=')
+            self.assertVectorFitsRegionInfo(vector=intersection,
+                                            reference=ref_info,
                                             msg=msg, precision=precision)
         finally:
             call_module('g.remove', vect=remove)
@@ -717,6 +772,144 @@
         finally:
             call_module('g.remove', vect=diff)
 
+    # TODO: here we have to have significant digits which is not consistent
+    # TODO: documentation for all new asserts
+    # TODO: same can be created for raster and 3D raster
+    def assertVectorEqualsVector(self, actual, reference, digits, precision, msg=None):
+        """Test that two vectors are equal.
+
+        .. note:
+            This test should not be used to test ``v.in.ascii`` and
+            ``v.out.ascii`` modules.
+
+        .. warning:
+            ASCII files for vectors are loaded into memory, so this
+            function works well only for "not too big" vector maps.
+        """
+        # both vectors to ascii
+        # text diff of two ascii files
+        # may also do other comparisons on vectors themselves (asserts)
+        self.assertVectorInfoEqualsVectorInfo(actual=actual, reference=reference, precision=precision, msg=msg)
+        factual = self._export_ascii_vector(vector=actual,
+                                            name_part='assertVectorEqualsVector_actual',
+                                            digits=digits)
+        freference = self._export_ascii_vector(vector=reference,
+                                               name_part='assertVectorEqualsVector_reference',
+                                               digits=digits)
+        self.assertVectorAsciiEqualsVectorAscii(actual=factual,
+                                                reference=freference,
+                                                remove_files=True,
+                                                msg=msg)
+
+    def assertVectorEqualsAscii(self, actual, reference, digits, precision, msg=None):
+        """Test that vector is equal to the vector stored in GRASS ASCII file.
+
+        .. note:
+            This test should not be used to test ``v.in.ascii`` and
+            ``v.out.ascii`` modules.
+
+        .. warning:
+            ASCII files for vectors are loaded into memory, so this
+            function works well only for "not too big" vector maps.
+        """
+        # vector to ascii
+        # text diff of two ascii files
+        # it may actually import the file and do other asserts
+        factual = self._export_ascii_vector(vector=actual,
+                                            name_part='assertVectorEqualsAscii_actual',
+                                            digits=digits)
+        vreference = None
+        try:
+            vreference = self._import_ascii_vector(filename=reference,
+                                               name_part='assertVectorEqualsAscii_reference')
+            self.assertVectorInfoEqualsVectorInfo(actual=actual,
+                                                  reference=vreference,
+                                                  precision=precision, msg=msg)
+            self.assertVectorAsciiEqualsVectorAscii(actual=factual,
+                                                    reference=reference,
+                                                    remove_files=False,
+                                                    msg=msg)
+        finally:
+            # TODO: manage using cleanup settings
+            # we rely on fail method to either raise or return (soon)
+            os.remove(factual)
+            if vreference:
+                self.runModule('g.remove', vect=vreference)
+
+    # TODO: we expect v.out.ascii to give the same order all the time, is that OK?
+    def assertVectorAsciiEqualsVectorAscii(self, actual, reference,
+                                           remove_files=False, msg=None):
+        """Test that two GRASS ASCII vector files are equal.
+
+        .. note:
+            This test should not be used to test ``v.in.ascii`` and
+            ``v.out.ascii`` modules.
+
+        .. warning:
+            ASCII files for vectors are loaded into memory, so this
+            function works well only for "not too big" vector maps.
+        """
+        import difflib
+        # 'U' taken from difflib documentation
+        fromlines = open(actual, 'U').readlines()
+        tolines = open(reference, 'U').readlines()
+        context_lines = 3  # number of context lines
+        # TODO: filenames are set to "actual" and "reference", isn't it too general?
+        # it is even more useful if map names or file names are some generated
+        # with hash or some other unreadable things
+        # other styles of diffs are available too
+        # but unified is a good choice if you are used to svn or git
+        # workaround for missing -h (do not print header) flag in v.out.ascii
+        num_lines_of_header = 10
+        diff = difflib.unified_diff(fromlines[num_lines_of_header:],
+                                    tolines[num_lines_of_header:],
+                                    'reference', 'actual', n=context_lines)
+        # TODO: this should be solved according to cleanup policy
+        # but the parameter should be kept if it is an existing file
+        # or using this method by itself
+        if remove_files:
+            os.remove(actual)
+            os.remove(reference)
+        stdmsg = ("There is a difference between vectors when compared as"
+                  " ASCII files.\n")
+        import StringIO
+
+        output = StringIO.StringIO()
+        # TODO: there is a diff size constant which we can use
+        # we are setting it unlimited but we can just set it large
+        maxlines = 100
+        i = 0
+        for line in diff:
+            if i >= maxlines:
+                break
+            output.write(line)
+            i += 1
+        stdmsg += output.getvalue()
+        output.close()
+        # it seems that there is not better way of asking whether there was
+        # a difference (always a iterator object is returned)
+        if i > 0:
+            # do HTML diff only if there is not too many lines
+            # TODO: this might be tough to do with some more sophisticated way of reports
+            if self.html_reports and i < maxlines:
+                # TODO: this might be here and somehow stored as file or done in reporter again if right information is stored
+                # i.e., files not deleted or the whole strings passed
+                # alternative is make_table() which is the same but creates just a table not a whole document
+                # TODO: all HTML files might be collected by the main reporter
+                # TODO: standardize the format of name of HTML file
+                # for one test id there is only one possible file of this name
+                htmldiff_file_name = self.id() + '_ascii_diff' + '.html'
+                htmldiff = difflib.HtmlDiff().make_file(fromlines, tolines,
+                                                        'reference', 'actual',
+                                                        context=True,
+                                                        numlines=context_lines)
+                htmldiff_file = open(htmldiff_file_name, 'w')
+                for line in htmldiff:
+                    htmldiff_file.write(line)
+                htmldiff_file.close()
+
+            self.fail(self._formatMessage(msg, stdmsg))
+
     @classmethod
     def runModule(cls, module, **kwargs):
         """Run PyGRASS module.

Modified: grass/trunk/lib/python/gunittest/main.py
===================================================================
--- grass/trunk/lib/python/gunittest/main.py	2014-07-17 03:51:31 UTC (rev 61265)
+++ grass/trunk/lib/python/gunittest/main.py	2014-07-17 18:38:42 UTC (rev 61266)
@@ -63,6 +63,9 @@
     """
     # TODO: put the link to to the report only if available
     # TODO: how to disable Python code coverage for module and C tests?
+    # TODO: we probably need to have different test  functions for C, Python modules, and Python code
+    # TODO: combine the results using python -m coverage --help | grep combine
+    # TODO: function to anonymize/beautify file names (in content and actual filenames)
     doing_coverage = False
     try:
         import coverage

Added: grass/trunk/lib/python/gunittest/testsuite/data/simple_vector_map_ascii_4p_2l_2c_3b_dp14.txt
===================================================================
--- grass/trunk/lib/python/gunittest/testsuite/data/simple_vector_map_ascii_4p_2l_2c_3b_dp14.txt	                        (rev 0)
+++ grass/trunk/lib/python/gunittest/testsuite/data/simple_vector_map_ascii_4p_2l_2c_3b_dp14.txt	2014-07-17 18:38:42 UTC (rev 61266)
@@ -0,0 +1,67 @@
+ORGANIZATION: 
+DIGIT DATE:   
+DIGIT NAME:   John User
+MAP NAME:     
+MAP DATE:     Thu Jul 17 10:48:49 2014
+MAP SCALE:    1
+OTHER INFO:   
+ZONE:         0
+MAP THRESH:   0.000000
+VERTI:
+P  1 1
+ 158.22136448266869 271.58220193881516
+ 1     1         
+P  1 1
+ 165.11292819449133 150.54911424993
+ 1     2         
+P  1 1
+ 413.63994455209536 293.54906127024987
+ 1     3         
+P  1 1
+ 438.62186300745248 222.04908776008995
+ 1     4         
+L  6 1
+ 148.74546437891254 204.82017848053334
+ 275.80867031564253 304.31712956997274
+ 484.27847259827752 272.01292467080407
+ 473.51040429855459 199.22078296467743
+ 426.56162651176282 188.88343739694346
+ 392.96525341662743 270.72075647483734
+ 1     5         
+L  3 1
+ 167.2665418544359 85.07925898761491
+ 315.00443892663384 110.4919001749609
+ 350.75442568171377 97.13949548330453
+ 1     6         
+B  6 1
+ 424.52940565143189 166.64372618002309
+ 396.52865681615208 104.95457640229719
+ 450.78010768450673 83.95401477583732
+ 473.53071611317159 150.45579325962694
+ 433.27963966245687 169.70630808388182
+ 424.52940565143189 166.64372618002309
+ 1     10        
+C  1 1
+ 436.7797332668668 129.8927433337183
+ 1     11        
+B  5 1
+ 251.27477223313787 263.77132370240003
+ 211.02369578242312 160.95607407285686
+ 381.21574729685835 151.33081666072943
+ 366.77786117866719 271.20902261177127
+ 251.27477223313787 263.77132370240003
+ 1     12        
+B  9 1
+ 291.52584868385264 229.20789935885148
+ 278.83800936786645 191.5818931114442
+ 329.15185493125995 191.14438141089295
+ 354.09002186268106 234.45803976546645
+ 327.83931982960621 252.83353118861885
+ 319.96410921968373 211.70743133680159
+ 305.96373480204386 257.20864819413134
+ 287.15073167834021 250.20846098531138
+ 291.52584868385264 229.20789935885148
+ 1     13        
+C  1 1
+ 258.71247114250912 206.45729093018662
+ 1     14        

Added: grass/trunk/lib/python/gunittest/testsuite/data/simple_vector_map_ascii_4p_2l_2c_3b_dp14_diff_header.txt
===================================================================
--- grass/trunk/lib/python/gunittest/testsuite/data/simple_vector_map_ascii_4p_2l_2c_3b_dp14_diff_header.txt	                        (rev 0)
+++ grass/trunk/lib/python/gunittest/testsuite/data/simple_vector_map_ascii_4p_2l_2c_3b_dp14_diff_header.txt	2014-07-17 18:38:42 UTC (rev 61266)
@@ -0,0 +1,67 @@
+ORGANIZATION: Big University
+DIGIT DATE:   May 2014
+DIGIT NAME:   Tracy User
+MAP NAME:     
+MAP DATE:     Thu Jul 17 10:48:49 2014
+MAP SCALE:    1
+OTHER INFO:   A very useful note about this map.
+ZONE:         0
+MAP THRESH:   0.000000
+VERTI:
+P  1 1
+ 158.22136448266869 271.58220193881516
+ 1     1         
+P  1 1
+ 165.11292819449133 150.54911424993
+ 1     2         
+P  1 1
+ 413.63994455209536 293.54906127024987
+ 1     3         
+P  1 1
+ 438.62186300745248 222.04908776008995
+ 1     4         
+L  6 1
+ 148.74546437891254 204.82017848053334
+ 275.80867031564253 304.31712956997274
+ 484.27847259827752 272.01292467080407
+ 473.51040429855459 199.22078296467743
+ 426.56162651176282 188.88343739694346
+ 392.96525341662743 270.72075647483734
+ 1     5         
+L  3 1
+ 167.2665418544359 85.07925898761491
+ 315.00443892663384 110.4919001749609
+ 350.75442568171377 97.13949548330453
+ 1     6         
+B  6 1
+ 424.52940565143189 166.64372618002309
+ 396.52865681615208 104.95457640229719
+ 450.78010768450673 83.95401477583732
+ 473.53071611317159 150.45579325962694
+ 433.27963966245687 169.70630808388182
+ 424.52940565143189 166.64372618002309
+ 1     10        
+C  1 1
+ 436.7797332668668 129.8927433337183
+ 1     11        
+B  5 1
+ 251.27477223313787 263.77132370240003
+ 211.02369578242312 160.95607407285686
+ 381.21574729685835 151.33081666072943
+ 366.77786117866719 271.20902261177127
+ 251.27477223313787 263.77132370240003
+ 1     12        
+B  9 1
+ 291.52584868385264 229.20789935885148
+ 278.83800936786645 191.5818931114442
+ 329.15185493125995 191.14438141089295
+ 354.09002186268106 234.45803976546645
+ 327.83931982960621 252.83353118861885
+ 319.96410921968373 211.70743133680159
+ 305.96373480204386 257.20864819413134
+ 287.15073167834021 250.20846098531138
+ 291.52584868385264 229.20789935885148
+ 1     13        
+C  1 1
+ 258.71247114250912 206.45729093018662
+ 1     14        

Added: grass/trunk/lib/python/gunittest/testsuite/data/simple_vector_map_ascii_4p_2l_2c_3b_dp14_modified.txt
===================================================================
--- grass/trunk/lib/python/gunittest/testsuite/data/simple_vector_map_ascii_4p_2l_2c_3b_dp14_modified.txt	                        (rev 0)
+++ grass/trunk/lib/python/gunittest/testsuite/data/simple_vector_map_ascii_4p_2l_2c_3b_dp14_modified.txt	2014-07-17 18:38:42 UTC (rev 61266)
@@ -0,0 +1,67 @@
+ORGANIZATION: 
+DIGIT DATE:   
+DIGIT NAME:   John User
+MAP NAME:     
+MAP DATE:     Thu Jul 17 10:48:49 2014
+MAP SCALE:    1
+OTHER INFO:   
+ZONE:         0
+MAP THRESH:   0.000000
+VERTI:
+P  1 1
+ 158.22136448266869 271.582204882214
+ 1     1         
+P  1 1
+ 165.11292819449133 150.54911424993
+ 1     2         
+P  1 1
+ 413.63994455209536 293.54906127024987
+ 1     3         
+P  1 1
+ 438.62186300745248 222.04908776008995
+ 1     4         
+L  6 1
+ 148.74546437891254 204.82017848053334
+ 275.80867031564253 304.31712956997274
+ 484.27847259827752 272.01292467085862
+ 473.51040429855459 199.22078296467743
+ 426.56162651176282 188.88343739694346
+ 392.96525341662743 270.72075647483734
+ 1     5         
+L  3 1
+ 167.2665418544359 85.07925898761491
+ 315.00443892663384 110.4919001749609
+ 350.75442568171377 97.13949548330453
+ 1     6         
+B  6 1
+ 424.52940565143189 166.64372618002309
+ 396.52865681615208 104.95457640229719
+ 450.78010768450673 83.95401477583732
+ 473.53071611317159 150.45579325962694
+ 433.27963966245687 169.70630808388182
+ 424.52940565143189 166.64372618002309
+ 1     10        
+C  1 1
+ 436.7797332668668 129.8927433337183
+ 1     11        
+B  5 1
+ 251.27477223313787 263.77132370240003
+ 211.02369578242312 160.95607407285686
+ 381.21574729685835 151.33081666072943
+ 366.77786117866719 271.20902261177127
+ 251.27477223313787 263.77132370240003
+ 1     12        
+B  9 1
+ 291.52584868385264 229.20789935885148
+ 278.83800936786645 191.5818931114442
+ 329.15185493125995 191.14438141089295
+ 354.09002186268106 234.45803976546645
+ 327.83931915547823 252.83353118861885
+ 319.96410921968373 211.70743133680159
+ 305.96373480204386 257.20864819413134
+ 287.15073167834021 250.20846098531138
+ 291.52584868385264 229.20789935885148
+ 1     13        
+C  1 1
+ 258.71247114250912 206.45729095422489
+ 1     14        

Modified: grass/trunk/lib/python/gunittest/testsuite/test_assertions_vect.py
===================================================================
--- grass/trunk/lib/python/gunittest/testsuite/test_assertions_vect.py	2014-07-17 03:51:31 UTC (rev 61265)
+++ grass/trunk/lib/python/gunittest/testsuite/test_assertions_vect.py	2014-07-17 18:38:42 UTC (rev 61266)
@@ -4,6 +4,7 @@
 Tests assertion methods for vectors.
 """
 
+from grass.exceptions import CalledModuleError
 import grass.gunittest as gunittest
 
 
@@ -53,7 +54,7 @@
 )
 
 
-class TestVectorMapAssertions(gunittest.TestCase):
+class TestVectorInfoAssertions(gunittest.TestCase):
     """Test assertions of map meta and statistics"""
     # pylint: disable=R0904
     def test_assertVectorFitsUnivar(self):
@@ -110,5 +111,120 @@
                           'bridges',
                           V_UNIVAR_BRIDGES_TOPO)
 
+    def test_assertVectorInfoEqualsVectorInfo(self):
+        self.assertVectorInfoEqualsVectorInfo('bridges', 'bridges', precision=0.00000001)
+        self.assertRaises(self.failureException,
+                          self.assertVectorInfoEqualsVectorInfo,
+                          'lakes', 'bridges', precision=0.00000001)
+        self.assertRaises(CalledModuleError,
+                          self.assertVectorInfoEqualsVectorInfo,
+                          'bridges', 'does_not_exist', precision=0.00000001)
+
+
+class TestVectorGeometryAssertions(gunittest.TestCase):
+    """Test assertions of map geometry"""
+    # pylint: disable=R0904
+    maps_to_remove = []
+    simple_base_file = 'data/simple_vector_map_ascii_4p_2l_2c_3b_dp14.txt'
+    simple_modified_file = 'data/simple_vector_map_ascii_4p_2l_2c_3b_dp14_modified.txt'
+    simple_diff_header_file = 'data/simple_vector_map_ascii_4p_2l_2c_3b_dp14_diff_header.txt'
+    precision = 0.00001
+    digits = 14
+
+    @classmethod
+    def tearDownClass(cls):
+        # TODO: this should be decided globaly by cleanup variable
+        # perhaps cls.gremove() wheoul be the right option
+        # when invoking separately, no need to delete maps since mapset
+        # is deleted
+        if cls.maps_to_remove:
+            cls.runModule('g.remove', vect=','.join(cls.maps_to_remove))
+
+    def test_assertVectorEqualsVector_basic(self):
+        """Check completely different maps."""
+        self.assertVectorEqualsVector(actual='bridges', reference='bridges',
+                                      precision=0.01, digits=15)
+        self.assertRaises(self.failureException,
+                          self.assertVectorEqualsVector,
+                          actual='bridges', reference='lakes',
+                          precision=0.01, digits=7)
+        self.assertRaises(CalledModuleError,
+                          self.assertVectorEqualsVector,
+                          actual='does_not_exist', reference='lakes',
+                          precision=0.01, digits=7)
+
+    def test_assertVectorEqualsVector_geometry_same_header(self):
+        """Check small slighlty different maps with same header in ASCII."""
+        amap = 'simple_vector_map_base_geom'
+        bmap = 'simple_vector_map_modified_geom'
+        self.runModule('v.in.ascii', format='standard',
+                       input=self.simple_base_file,
+                       output=amap)
+        self.maps_to_remove.append(amap)
+        self.runModule('v.in.ascii', format='standard',
+                       input=self.simple_modified_file,
+                       output=bmap)
+        self.maps_to_remove.append(bmap)
+        self.assertVectorEqualsVector(actual=amap, reference=amap,
+                                      precision=self.precision, digits=self.digits)
+        self.assertRaises(self.failureException,
+                          self.assertVectorEqualsVector,
+                          actual=amap, reference=bmap,
+                          precision=self.precision, digits=self.digits)
+
+    def test_assertVectorEqualsVector_geometry(self):
+        """Check small slighlty different maps with different headers in ASCII."""
+        amap = 'simple_vector_map_base'
+        bmap = 'simple_vector_map_different_header'
+        self.runModule('v.in.ascii', format='standard',
+                       input=self.simple_base_file,
+                       output=amap)
+        self.maps_to_remove.append(amap)
+        self.runModule('v.in.ascii', format='standard',
+                       input=self.simple_diff_header_file,
+                       output=bmap)
+        self.maps_to_remove.append(bmap)
+        self.assertVectorEqualsVector(actual=amap, reference=bmap,
+                                      precision=self.precision, digits=self.digits)
+
+    def test_assertVectorAsciiEqualsVectorAscii_diff_header(self):
+        """Test ASCII files with different header.
+
+        Prove that files were not deleted if not requested.
+        """
+        self.assertVectorAsciiEqualsVectorAscii(actual=self.simple_base_file,
+                                                reference=self.simple_diff_header_file)
+        self.assertFileExists(self.simple_base_file)
+        self.assertFileExists(self.simple_diff_header_file)
+
+    def test_assertVectorAsciiEqualsVectorAscii_diff_content(self):
+        """Test ASCII files with slighlty different content.
+
+        Prove that files were not deleted if not requested.
+        """
+        self.assertRaises(self.failureException,
+                          self.assertVectorAsciiEqualsVectorAscii,
+                          actual=self.simple_base_file,
+                          reference=self.simple_modified_file)
+        self.assertFileExists(self.simple_base_file)
+        self.assertFileExists(self.simple_modified_file)
+
+    def test_assertVectorEqualsAscii_by_import(self):
+        amap = 'simple_vector_map_imported_base'
+        self.runModule('v.in.ascii', format='standard',
+                       input=self.simple_base_file,
+                       output=amap)
+        self.maps_to_remove.append(amap)
+        self.assertVectorEqualsAscii(amap, self.simple_diff_header_file,
+                                     precision=self.precision, digits=self.digits)
+        self.assertRaises(self.failureException,
+                          self.assertVectorEqualsAscii,
+                          amap, self.simple_modified_file,
+                          precision=self.precision, digits=self.digits)
+        self.assertFileExists(self.simple_base_file)
+        self.assertFileExists(self.simple_modified_file)
+        self.assertFileExists(self.simple_diff_header_file)
+
+
 if __name__ == '__main__':
     gunittest.test()



More information about the grass-commit mailing list