bernhard: thuban/Extensions/svgexport/test test_svgmapwriter.py, 1.3, 1.4

cvs@intevation.de cvs at intevation.de
Tue Sep 21 23:30:38 CEST 2004


Author: bernhard

Update of /thubanrepository/thuban/Extensions/svgexport/test
In directory doto:/tmp/cvs-serv28184/Extensions/svgexport/test

Modified Files:
	test_svgmapwriter.py 
Log Message:
Improved the svgexport to only use unique ids. Will issues 
an error message dialoge when two layer names are the same.
ShapeIDs are now added with a dash within the svg ids.

* Extensions/svgexport/svgmapwriter.py (SVGMapWriterError): New.
* Extensions/svgexport/test/test_svgmapwriter.py: Added imports
(TestSVGRenderer): New test class with test_make_in() and
test_check_for_layer_name_clash()
* Extensions/svgexport/svgmapwriter.py (SVGRenderer): Fixed __init__()
and draw_shape_layer_incrementally() to not use a baseid twice, 
satisfying test_check_for_layer_name_clash()
(VirtualDC.make_id): Use a dash between baseit and id, satisfies
test_make_in().
* Extensions/svexport/svgsaver.py: Import SVGMapWriterError, wxOK
and wxICON_HAND. 
(write_to_svg): Put dc and rendering in a try statement and on
catching SVGmapWriterError notify the user and delete the target file.
-------------------------------------------------------------------


Index: test_svgmapwriter.py
===================================================================
RCS file: /thubanrepository/thuban/Extensions/svgexport/test/test_svgmapwriter.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- test_svgmapwriter.py	28 Jun 2004 10:55:10 -0000	1.3
+++ test_svgmapwriter.py	21 Sep 2004 21:30:36 -0000	1.4
@@ -22,21 +22,31 @@
 if __name__ == "__main__":
     sys.path.append(os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])),
                                  "..", "..", "..", "test"))
+from mockgeo import SimpleShapeStore
 import support
 support.initthuban()
 import Thuban
 
 # Now import needed SVG stuff
 from Extensions.svgexport.svgmapwriter import VirtualDC, \
-     Pen, Brush, SOLID,  Point, Font, TRANSPARENT_PEN, TRANSPARENT_BRUSH
+     Pen, Brush, SOLID,  Point, Font, TRANSPARENT_PEN, TRANSPARENT_BRUSH, \
+     SVGRenderer, SVGMapWriterError
 # Color related classes from the model of thuban
 from Thuban.Model.color import Color, Black
 
+from Thuban.Model.data import SHAPETYPE_ARC
+from Thuban.Model.map import Map
+from Thuban.Model.layer import BaseLayer, Layer
+from Thuban.Model.table import MemoryTable, \
+     FIELDTYPE_DOUBLE, FIELDTYPE_INT, FIELDTYPE_STRING
+
+
+
 # We use xmlsupport to verify the SVG output
 import xmlsupport
 
 class TestVirtualDC(unittest.TestCase):
-    '''Tests the VirtualDC class that imitates a wxDC and writes
+    '''Test VirtualDC capabilities that imitates a wxDC and writes
     SVGRenderer instead.'''
 
     def setUp(self):
@@ -156,6 +166,64 @@
         self.assertEquals(xmlsupport.sax_eventlist(data = data), 
                           xmlsupport.sax_eventlist(data = file.getvalue()))
 
+class TestSVGRenderer(unittest.TestCase):
+
+    def setUp(self):
+        """Create dc for testing and set up self.to_destroy.
+
+        Test should put all objects whose Destroy 
+        should be called at unittest.main
+        the end into this list so that they're destroyed in tearDown
+        """
+        self.to_destroy = []
+
+        file = StringIO.StringIO()
+        self.dc = VirtualDC(file)
+
+    def tearDown(self):
+        for obj in self.to_destroy:
+            obj.Destroy()
+
+    def test_make_id(self):
+        """Check "layer" and "layer1" do not clash; given integer ShapeIDs.
+        """
+        dc=self.dc
+        dc.SetBaseID("layer")
+        dc.SetID(10)
+        id1=dc.make_id()
+        dc.SetBaseID("layer1")
+        dc.SetID(0)
+        id2=dc.make_id()
+
+        self.assertNotEqual(id1,id2)
+
+
+    def test_check_for_layer_name_clash(self):
+        '''Create 2 layers with same name, try to write and check exception.
+        '''
+
+        # BaseLayer is not enough, because BaseRenderer.render_map()
+        # checks on isinstance of Layer not BaseLayer.
+        table = MemoryTable([("type", FIELDTYPE_STRING),
+                             ("value", FIELDTYPE_DOUBLE),
+                             ("code", FIELDTYPE_INT)],
+                            [("UNKNOWN", 0.0, 0)])
+        shapes = [[[(0, 0), (10, 10)]]]
+        store = SimpleShapeStore(SHAPETYPE_ARC, shapes, table)
+
+        map = Map("TestLayerNameClash")
+        self.to_destroy.append(map)
+        layer=Layer("Same Name", store)
+        map.AddLayer(layer)
+        # reusing the same store with the same table and shapes should be okay
+        layer=Layer("Same Name", store)
+        map.AddLayer(layer)
+
+        renderer = SVGRenderer(self.dc, map,
+                    scale=1.0, offset=(0,0), region=(0,0,10,10))
+
+        self.assertRaises(SVGMapWriterError,
+                renderer.RenderMap, None, None)
 
 if __name__ == "__main__":
     support.run_tests()





More information about the Thuban-devel mailing list

This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)