Added sodipodi element unit test

This commit is contained in:
JSCHILL1 2009-04-13 11:38:00 -05:00
parent 8d598b20f2
commit ef0f1fe664
2 changed files with 14 additions and 6 deletions

View file

@ -21,8 +21,8 @@ import unittest
import scour import scour
import xml.dom.minidom import xml.dom.minidom
# performs a test on a given node # helper function that performs a test on a given node and all its children
# func must return either True or False # func must return either True (if pass) or False (if fail)
def walkTree(elem, func): def walkTree(elem, func):
if func(elem) == False: return False if func(elem) == False: return False
for child in elem.childNodes: for child in elem.childNodes:
@ -31,12 +31,15 @@ def walkTree(elem, func):
class NoInkscapeElements(unittest.TestCase): class NoInkscapeElements(unittest.TestCase):
def runTest(self): def runTest(self):
doc = scour.scourXmlFile('unittests/inkscape.svg') self.assertNotEquals(walkTree( scour.scourXmlFile('unittests/sodipodi.svg').documentElement,
self.assertNotEquals( walkTree( doc.documentElement,
lambda e: e.namespaceURI != "http://www.inkscape.org/namespaces/inkscape" ), False, lambda e: e.namespaceURI != "http://www.inkscape.org/namespaces/inkscape" ), False,
'Found Inkscape elements' ) 'Found Inkscape elements' )
class NoSodipodiElements(unittest.TestCase):
def runTest(self):
self.assertNotEquals(walkTree( scour.scourXmlFile('unittests/sodipodi.svg').documentElement,
lambda e: e.namespaceURI != "http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" ), False,
'Found Sodipodi elements' )
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
print "done"

5
unittests/sodipodi.svg Normal file
View file

@ -0,0 +1,5 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" sodipodi:version="0.32">
<sodipodi:namedview id="base" pagecolor="#ffffff" bordercolor="#666666" borderopacity="1.0" gridtolerance="10000" guidetolerance="10" objecttolerance="10"/>
<rect width="300" height="200" fill="green" />
</svg>

After

Width:  |  Height:  |  Size: 394 B