bernhard: thuban/Extensions/svgexport/test test_svgmapwriter.py, 1.4, 1.5
cvs@intevation.de
cvs at intevation.de
Mon Sep 27 11:56:15 CEST 2004
Author: bernhard
Update of /thubanrepository/thuban/Extensions/svgexport/test
In directory doto:/tmp/cvs-serv1600/Extensions/svgexport/test
Modified Files:
test_svgmapwriter.py
Log Message:
More fixes to svgexport to make used ids unique and
conforming to XML's Name production.
* Extensions/svgexport/test/test_svgmapwriter.py: Added new tests
test_xml_id_constraints(), test_make_ide_nosetbaseid() and
test_make_id_nonintegersetid(). Switched SetID and SetBaseID.
Added Bernhard R. as author.
* Extensions/svgexport/svgmapwriter.py (make_id): Using "_" as
concatenation char now (makes test_make_ide_nosetbaseid() valid).
Also transform second id part with "%d" and catch the TypeError
to raise SVGMapWriterError (making test_make_id_nonintegersetid() ok).
Corrected typo inBernhard's author line.
(SetBaseID): Return the transformed base id. Transform characters
which are not alnum() or in ".-_" to binascii.b2a_hex(). Added
import binascii. If to be set string starts with "xml" or so, add "t".
(draw_shape_layer_incrementally): use the returned value of SetBaseID
for used_baseids checks.
Index: test_svgmapwriter.py
===================================================================
RCS file: /thubanrepository/thuban/Extensions/svgexport/test/test_svgmapwriter.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- test_svgmapwriter.py 21 Sep 2004 21:30:36 -0000 1.4
+++ test_svgmapwriter.py 27 Sep 2004 09:56:13 -0000 1.5
@@ -1,6 +1,7 @@
# Copyright (c) 2001, 2002, 2003, 2004 by Intevation GmbH
# Authors:
-# Markus Rechtien <markus at intevation.de>
+# Markus Rechtien <markus at intevation.de>
+# Bernhard Reiter <bernhard at intevation.de>
#
# This program is free software under the GPL (>=v2)
# Read the file COPYING coming with Thuban for details.
@@ -14,6 +15,7 @@
import os
import sys
+import string
import StringIO
import unittest
@@ -166,7 +168,7 @@
self.assertEquals(xmlsupport.sax_eventlist(data = data),
xmlsupport.sax_eventlist(data = file.getvalue()))
-class TestSVGRenderer(unittest.TestCase):
+class TestSVGRendererIDHandling(unittest.TestCase):
def setUp(self):
"""Create dc for testing and set up self.to_destroy.
@@ -183,6 +185,56 @@
def tearDown(self):
for obj in self.to_destroy:
obj.Destroy()
+
+ def test_make_id_nonintegersetid(self):
+ """Test that exception is raised when SetID was called with chars."""
+ dc=self.dc
+ dc.SetBaseID("a")
+ dc.SetID("abc")
+ self.assertRaises(SVGMapWriterError, dc.make_id)
+
+ def test_make_ide_nosetbaseid(self):
+ """Test as no setbaseid results in valid XML id starting with '_'."""
+ dc=self.dc
+ dc.SetBaseID("")
+ dc.SetID(123)
+ id=dc.make_id() # returns 'id="xxxxxx"'
+ self.assert_(id[4]=='_' or (id[4] in string.ascii_letters))
+
+ def test_xml_id_constraints(self):
+ """Test the checks for the XML id contraints by trying bad id parts."""
+
+ dc=self.dc
+ dc.SetID(42)
+
+ # an xml Name shall better not start with "xml" (case insensitive)
+ dc.SetBaseID("xml")
+ id=dc.make_id() # returns 'id="xxxxxx"'
+ self.assert_(id[4:7].lower() != "xml")
+
+ dc.SetBaseID("XmL")
+ id=dc.make_id()
+ self.assert_(id[4:7].lower() != "xml")
+
+ # recommended to better not use ":"
+ dc.SetBaseID("abc:def")
+ id=dc.make_id()
+ self.assert_(":" not in id )
+
+ # an XML name shall only have:
+ # Letter | Digit | '.' | '-' | '_' | CombiningChar | Extender
+ dc.SetBaseID("abc def")
+ id=dc.make_id()
+ self.assert_(" " not in id )
+
+ dc.SetBaseID("ab!cd")
+ id=dc.make_id()
+ self.assert_("!" not in id )
+
+ dc.SetBaseID("a.b-c_d")
+ id=dc.make_id()
+ self.assert_(id[4:11]=="a.b-c_d")
+
def test_make_id(self):
"""Check "layer" and "layer1" do not clash; given integer ShapeIDs.
More information about the Thuban-devel
mailing list
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)