bernhard: thuban/Extensions/svgexport/test test_svgmapwriter.py, 1.14, 1.15

cvs@intevation.de cvs at intevation.de
Sat Dec 18 00:06:05 CET 2004


Author: bernhard

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

Modified Files:
	test_svgmapwriter.py 
Log Message:
	Refactored svgexport tests: 9 double tests runs eliminated; 
	code size reduced by 8 lines.

	* Extensions/svgexport/test/test_svgmapwriter.py:
	(class TestWithDC): Renamed to BaseTestWithDC, moved to top.
	(class BaseWithDCtools): New, subclass from BaseTestWithDC.
	(class TestDrawSplines): now subclass from BaseTestWithDCtools, 
	this fixed the double running of the nine tests of TestVirtualDC.
	(class TestVirtualDC): Using self.dc and self.file from setUp().


Index: test_svgmapwriter.py
===================================================================
RCS file: /thubanrepository/thuban/Extensions/svgexport/test/test_svgmapwriter.py,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- test_svgmapwriter.py	13 Dec 2004 14:59:24 -0000	1.14
+++ test_svgmapwriter.py	17 Dec 2004 23:06:03 -0000	1.15
@@ -46,12 +46,33 @@
 # We use xmlsupport to verify the SVG output
 import xmlsupport
 
-class TestVirtualDC(unittest.TestCase):
-    '''Test VirtualDC capabilities that imitates a wxDC and writes
-    SVGRenderer instead.'''
+class BaseTestWithDC(unittest.TestCase):
+    """Add dc creation and self.to_destroy list to setUp() and tearDown().
 
+    This is a baseclass for tests needing a dc.
+    """
     def setUp(self):
-        '''Initialize our tools.'''
+        """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 = []
+
+        self.file = StringIO.StringIO()
+        self.dc = VirtualDC(self.file)
+
+    def tearDown(self):
+        for obj in self.to_destroy:
+            obj.Destroy()
+
+
+class BaseTestWithDCtools(BaseTestWithDC):
+    """Add standard colors and polygon to setUp() for DC tests."""
+    def setUp(self):
+        """Initialize tools."""
+        BaseTestWithDC.setUp(self)
         self.black = Black
         self.solid_pen = Pen(Color(1.0, 0.0, 1.0), 3, SOLID)
         self.trans_pen = TRANSPARENT_PEN
@@ -61,31 +82,32 @@
                 Point(5.0,95.0), Point(5.0,5.0)]
         self.meta = {"Object":"test", "Label":"nothing"}
         self.font = Font("Helvetica", 12)
-    
+
+
+class TestVirtualDC(BaseTestWithDCtools):
+    '''Test VirtualDC imitating a wxDC and writing SVGRenderer instead.'''
+
     def test_clippath(self):
         '''Define a clipping region and close it afterwards.'''
         data = '<clipPath id="testid">\n</clipPath>'
-        file = StringIO.StringIO()
-        dc = VirtualDC(file)
-        dc.BeginClipPath('testid')
-        dc.EndClipPath()
-        self.assertEquals(xmlsupport.sax_eventlist(data = data), 
-                          xmlsupport.sax_eventlist(data = file.getvalue()))
-        
+        self.dc.BeginClipPath('testid')
+        self.dc.EndClipPath()
+        self.assertEquals(xmlsupport.sax_eventlist(data=data),
+                          xmlsupport.sax_eventlist(data=self.file.getvalue()))
+
     def test_polygon_closed(self):
         '''Set drawing properties and draw a polygon onto the dc.'''
         data = ('<path style="stroke-linejoin:round; stroke:#ff00ff; '
                 'stroke-width:3; stroke-linecap:round; fill:#00ff00" ' 
                 'meta="Object:test; Label:nothing" d="M 5.6 5.5 '
                 'L 95.4 5.3 L 95.2 95.1 L 5.0 95.0 L 5.0 5.0 Z"/>')
-        file = StringIO.StringIO()
-        dc = VirtualDC(file)
+        dc = self.dc
         dc.SetPen(self.solid_pen)
         dc.SetMeta(self.meta)
         dc.SetBrush(self.solid_brush)
         dc.DrawPolygon(self.polygon, 1)
-        self.assertEquals(xmlsupport.sax_eventlist(data = data), 
-                          xmlsupport.sax_eventlist(data = file.getvalue()))
+        self.assertEquals(xmlsupport.sax_eventlist(data=data), 
+                          xmlsupport.sax_eventlist(data=self.file.getvalue()))
     
     def test_polygon_opened(self):
         '''Set drawing properties and draw a polygon onto the dc.'''
@@ -93,14 +115,13 @@
                 'stroke-width:3; stroke-linecap:round; fill:#00ff00" ' 
                 'meta="Object:test; Label:nothing" d="M 5.6 5.5'
                 '\nL 95.4 5.3\nL 95.2 95.1\nL 5.0 95.0\nL 5.0 5.0"/>')
-        file = StringIO.StringIO()
-        dc = VirtualDC(file)
+        dc = self.dc
         dc.SetPen(self.solid_pen)
         dc.SetMeta(self.meta)
         dc.SetBrush(self.solid_brush)
         dc.DrawPolygon(self.polygon, 0)
-        self.assertEquals(xmlsupport.sax_eventlist(data = data), 
-                          xmlsupport.sax_eventlist(data = file.getvalue()))
+        self.assertEquals(xmlsupport.sax_eventlist(data=data), 
+                          xmlsupport.sax_eventlist(data=self.file.getvalue()))
 
     def test_transparent_polygon(self):
         '''Test dc drawing a transparent polygon.'''
@@ -108,87 +129,80 @@
                 'stroke-width:3; stroke-linecap:round; fill:none" ' 
                 'meta="Object:test; Label:nothing" d="M 5.6 5.5'
                 ' L 95.4 5.3\nL 95.2 95.1\nL 5.0 95.0\nL 5.0 5.0"/>')
-        file = StringIO.StringIO()
-        dc = VirtualDC(file)
+        dc = self.dc
         dc.SetPen(self.solid_pen)
         dc.SetMeta(self.meta)
         dc.SetBrush(self.trans_brush)
         dc.DrawPolygon(self.polygon, 0)
-        self.assertEquals(xmlsupport.sax_eventlist(data = data), 
-                          xmlsupport.sax_eventlist(data = file.getvalue()))
-    
+        self.assertEquals(xmlsupport.sax_eventlist(data=data), 
+                          xmlsupport.sax_eventlist(data=self.file.getvalue()))
+
     def test_rect(self):
         '''Set drawing properties and draw a rectangle'''
         data = ('<rect x="5.5" y="5.4" width="90.3" height="90.2" '
                 'style="stroke-linejoin:round; stroke:#ff00ff; '
                 'stroke-width:3; stroke-linecap:round; fill:none" '
                 'meta="Object:test; Label:nothing"/>')
-        file = StringIO.StringIO()
-        dc = VirtualDC(file)
+        dc = self.dc
         dc.SetPen(self.solid_pen)
         dc.SetMeta(self.meta)
         dc.SetBrush(self.trans_brush)
         dc.DrawRectangle(5.5, 5.4, 90.3, 90.2)
-        self.assertEquals(xmlsupport.sax_eventlist(data = data), 
-                          xmlsupport.sax_eventlist(data = file.getvalue()))
-    
+        self.assertEquals(xmlsupport.sax_eventlist(data=data), 
+                          xmlsupport.sax_eventlist(data=self.file.getvalue()))
+
     def test_circle(self):
         '''Set drawing properties and draw a circle'''
         data = ('<circle cx="5.5" cy="5.3" r="90.1"  style="'
                 'fill:#00ff00" meta="Object:test; Label:nothing"/>')
-        file = StringIO.StringIO()
-        dc = VirtualDC(file)
+        dc = self.dc
         dc.SetPen(self.trans_pen)
         dc.SetMeta(self.meta)
         dc.SetBrush(self.solid_brush)
         dc.DrawCircle(5.5, 5.3, 90.1)
-        self.assertEquals(xmlsupport.sax_eventlist(data = data), 
-                          xmlsupport.sax_eventlist(data = file.getvalue()))
-    
+        self.assertEquals(xmlsupport.sax_eventlist(data=data),
+                          xmlsupport.sax_eventlist(data=self.file.getvalue()))
+
     def test_ellipse(self):
         '''Set drawing properties and draw a circle'''
         data = ('<ellipse cx="5.5" cy="5.3" rx="90.1" ry="100.321"  style="'
                 'fill:#00ff00" meta="Object:test; Label:nothing"/>')
-        file = StringIO.StringIO()
-        dc = VirtualDC(file)
+        dc = self.dc
         dc.SetPen(self.trans_pen)
         dc.SetMeta(self.meta)
         dc.SetBrush(self.solid_brush)
         dc.DrawEllipse(5.5, 5.3, 90.1, 100.321)
-        self.assertEquals(xmlsupport.sax_eventlist(data = data), 
-                          xmlsupport.sax_eventlist(data = file.getvalue()))
-    
+        self.assertEquals(xmlsupport.sax_eventlist(data=data), 
+                          xmlsupport.sax_eventlist(data=self.file.getvalue()))
+
     def test_text(self):
         '''Set drawing properties and draw a circle'''
         data = ('<text x="123.321" y="1515.5151" style="font-size:12; '
                 'font-family:Helvetica; fill:#000000" >Some text.</text>')
-        file = StringIO.StringIO()
-        dc = VirtualDC(file)
+        dc = self.dc
         dc.SetTextForeground(self.black)
         dc.SetFont(self.font)
         dc.DrawText('Some text.', 123.321, 1515.5151)
-        self.assertEquals(xmlsupport.sax_eventlist(data = data), 
-                          xmlsupport.sax_eventlist(data = file.getvalue()))
-    
+        self.assertEquals(xmlsupport.sax_eventlist(data=data),
+                          xmlsupport.sax_eventlist(data=self.file.getvalue()))
+
     def test_document(self):
         '''Set up a document with a dimension and 
         latin encoding'''
         data = ('<?xml version="1.0" encoding="ISO-8859-1" standalone'
                 '="yes"?>\n<svg>\n</svg>')
-        file = StringIO.StringIO()
-        dc = VirtualDC(file)
-        dc.BeginExport()
-        dc.EndExport()
-        self.assertEquals(xmlsupport.sax_eventlist(data = data), 
-                          xmlsupport.sax_eventlist(data = file.getvalue()))
+        self.dc.BeginExport()
+        self.dc.EndExport()
+        self.assertEquals(xmlsupport.sax_eventlist(data=data), 
+                          xmlsupport.sax_eventlist(data=self.file.getvalue()))
 
-class TestDrawSplines(TestVirtualDC):
+class TestDrawSplines(BaseTestWithDCtools):
     """Testing DrawSpline variations.
     See comments in DrawSpline().
     """
 
     def setUp(self):
-        TestVirtualDC.setUp(self)
+        BaseTestWithDCtools.setUp(self)
         self.dataframe = ('<path style="stroke-linejoin:round; stroke:#ff00ff; '
                 'stroke-width:3; stroke-linecap:round; fill:none" ' 
                 'meta="Object:test; Label:nothing" d="%s"/>')
@@ -227,29 +241,8 @@
                           xmlsupport.sax_eventlist(data = self.file.getvalue()))
 
 
-class TestWithDC(unittest.TestCase):
-    """Add dc creation and self.to_destroy list to setUp() and tearDown().
-
-    This is a baseclass for tests needing a dc.
-    """
-
-    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()
 
-class TestSVGRendererIDHandling(TestWithDC):
+class TestSVGRendererIDHandling(BaseTestWithDC):
 
     def test_make_id_nonintegersetid(self):
         """Test that exception is raised when SetID was called with chars."""
@@ -342,7 +335,7 @@
         self.assertRaises(SVGMapWriterError,
                 renderer.RenderMap, None, None)
 
-class Testobjectexport(TestWithDC):
+class Testobjectexport(BaseTestWithDC):
 
     def test_transparent_polygon(self):
         """ Create layer with non-filled polygon and test svg rendering."""





More information about the Thuban-devel mailing list

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