[Thuban-commits] r2847 - in trunk/thuban/Extensions/importMP: . test

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Jun 20 16:21:16 CEST 2008


Author: elachuni
Date: 2008-06-20 16:21:15 +0200 (Fri, 20 Jun 2008)
New Revision: 2847

Modified:
   trunk/thuban/Extensions/importMP/pfm.py
   trunk/thuban/Extensions/importMP/test/snippets.py
   trunk/thuban/Extensions/importMP/test/test_pfm.py
Log:
Two small bugfixes to importMP:
 - polyline types were being taken from the polygon type list
 - polygon type parsing was too silly (0xe wasn't accepted as 0x0e, for 
example)


Modified: trunk/thuban/Extensions/importMP/pfm.py
===================================================================
--- trunk/thuban/Extensions/importMP/pfm.py	2008-06-20 05:27:40 UTC (rev 2846)
+++ trunk/thuban/Extensions/importMP/pfm.py	2008-06-20 14:21:15 UTC (rev 2847)
@@ -318,7 +318,7 @@
                     poly['lat'].append (-float (match.group('lat')))
                     data = data[match.end() + 1:]
             try:
-                poly['parsedType'] = polygonTypes[poly['Type'], ""]
+                poly['parsedType'] = polygonTypes[poly['Type']]
             except KeyError, e:
                 # Attempt to read 0xe as 0x0e, for example
                 newType = '0x0' + poly['Type'][2:]
@@ -341,6 +341,6 @@
             except KeyError, e:
                 # Attempt to read 0xe as 0x0e, for example
                 newType = '0x0' + poly['Type'][2:]
-                poly['parsedType'] = polygonTypes.get(newType, "")
+                poly['parsedType'] = polylineTypes.get(newType, "")
         return parsed
 

Modified: trunk/thuban/Extensions/importMP/test/snippets.py
===================================================================
--- trunk/thuban/Extensions/importMP/test/snippets.py	2008-06-20 05:27:40 UTC (rev 2846)
+++ trunk/thuban/Extensions/importMP/test/snippets.py	2008-06-20 14:21:15 UTC (rev 2847)
@@ -158,6 +158,26 @@
 
 """
 
+missingZeroType = """
+[IMG ID]
+[END]
+
+[POLYGON]
+Type=0x0e
+Label=An Airport Runway
+EndLevel=6
+Data0=(-35.76743,-58.49350),(-35.76776,-58.49378),(-35.76782,-58.49371)
+[END]
+
+[POLYGON]
+Type=0xe
+Label=Another Airport Runway
+EndLevel=6
+Data0=(-35.76743,-58.49350),(-35.76776,-58.49378),(-35.76782,-58.49371)
+[END]
+
+"""
+
 mixedPois = """
 [IMG ID]
 [END]
@@ -285,6 +305,22 @@
 
 nothingness = ""
 
+polyTypes = """
+[IMG ID]
+[END]
+
+[POLYLINE]
+Type=0x1
+Data0=(-35.38428,-59.32179),(-35.37814,-59.31504)
+[END]
+
+[POLYGON]
+Type=0x1
+Data0=(-35.40273,-59.32503),(-35.40338,-59.32611)
+[END]
+
+"""
+
 RGN10s = """
 [IMG ID]
 [END]

Modified: trunk/thuban/Extensions/importMP/test/test_pfm.py
===================================================================
--- trunk/thuban/Extensions/importMP/test/test_pfm.py	2008-06-20 05:27:40 UTC (rev 2846)
+++ trunk/thuban/Extensions/importMP/test/test_pfm.py	2008-06-20 14:21:15 UTC (rev 2847)
@@ -116,8 +116,23 @@
         self.assertEquals(len(parser.pois), 3)
         self.assertEquals(len(parser.polylines), 2)
         self.assertEquals(len(parser.polygons), 1)
-       
 
+    def testMissingTwoCharFormatWorks (self):
+        """ Test that if the type 0xe works as well as 0x0e, for example"""
+        parser = MPParser()
+        parser.parse (StringIO(snippets.missingZeroType))
+        self.assertEquals(len(parser.polygons), 2)
+        self.assertEquals(parser.polygons[0]['parsedType'], "Airport Runway")
+        self.assertEquals(parser.polygons[1]['parsedType'], "Airport Runway")
+
+    def testTypesAreTheRightKind (self):
+        """ Test that types from polylines and polygons come from the
+            right list of types """
+        p = MPParser()
+        p.parse (StringIO(snippets.polyTypes))
+        self.assertEquals(p.polygons[0]['parsedType'], "City")
+        self.assertEquals(p.polylines[0]['parsedType'], "Major Highway-thick")
+
 if __name__ == "__main__":
     unittest.main()
 



More information about the Thuban-commits mailing list