Modified scour and added first unit test
This commit is contained in:
parent
a1f6d9e8dd
commit
8d598b20f2
3 changed files with 35 additions and 3 deletions
12
scour.py
12
scour.py
|
|
@ -550,7 +550,7 @@ def properlySizeDoc(docElement):
|
||||||
# this is the main method
|
# this is the main method
|
||||||
# input is a string representation of the input XML
|
# input is a string representation of the input XML
|
||||||
# returns a string representation of the output XML
|
# returns a string representation of the output XML
|
||||||
def scour(in_string):
|
def scourString(in_string):
|
||||||
global numAttrsRemoved
|
global numAttrsRemoved
|
||||||
global numStylePropsFixed
|
global numStylePropsFixed
|
||||||
global numElemsRemoved
|
global numElemsRemoved
|
||||||
|
|
@ -615,6 +615,14 @@ def scour(in_string):
|
||||||
out_string = doc.documentElement.toxml()
|
out_string = doc.documentElement.toxml()
|
||||||
return out_string
|
return out_string
|
||||||
|
|
||||||
|
# used mostly by unit tests
|
||||||
|
# input is a filename
|
||||||
|
# returns the minidom doc representation of the SVG
|
||||||
|
def scourXmlFile(filename):
|
||||||
|
in_string = open(filename).read()
|
||||||
|
out_string = scourString(in_string)
|
||||||
|
return xml.dom.minidom.parseString(out_string)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
# parse command-line arguments
|
# parse command-line arguments
|
||||||
|
|
@ -656,7 +664,7 @@ if __name__ == '__main__':
|
||||||
|
|
||||||
# do the work
|
# do the work
|
||||||
in_string = input.read()
|
in_string = input.read()
|
||||||
out_string = scour(in_string)
|
out_string = scourString(in_string)
|
||||||
output.write(out_string)
|
output.write(out_string)
|
||||||
|
|
||||||
# Close input and output files
|
# Close input and output files
|
||||||
|
|
|
||||||
19
testscour.py
19
testscour.py
|
|
@ -19,5 +19,24 @@
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
import scour
|
import scour
|
||||||
|
import xml.dom.minidom
|
||||||
|
|
||||||
|
# performs a test on a given node
|
||||||
|
# func must return either True or False
|
||||||
|
def walkTree(elem, func):
|
||||||
|
if func(elem) == False: return False
|
||||||
|
for child in elem.childNodes:
|
||||||
|
if walkTree(child, func) == False: return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
class NoInkscapeElements(unittest.TestCase):
|
||||||
|
def runTest(self):
|
||||||
|
doc = scour.scourXmlFile('unittests/inkscape.svg')
|
||||||
|
self.assertNotEquals( walkTree( doc.documentElement,
|
||||||
|
lambda e: e.namespaceURI != "http://www.inkscape.org/namespaces/inkscape" ), False,
|
||||||
|
'Found Inkscape elements' )
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
|
|
||||||
print "done"
|
print "done"
|
||||||
5
unittests/inkscape.svg
Normal file
5
unittests/inkscape.svg
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
inkscape:version="0.46" version="1.0">
|
||||||
|
<inkscape:perspective inkscape:vp_x="0 : 526.18109 : 1" inkscape:vp_y="0 : 1000 : 0" inkscape:vp_z="744.09448 : 526.18109 : 1" inkscape:persp3d-origin="372.04724 : 350.78739 : 1" id="perspective3104"/>
|
||||||
|
<rect width="300" height="200" fill="green" />
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 396 B |
Loading…
Add table
Add a link
Reference in a new issue