Unittests: Account for b979fe19e5 (fix one test and add two more)

- Unused XML namespace declarations *are supposed* to be removed
- XML namespace declarations that are used as prefix for elements/attributes *must not* be removed
This commit is contained in:
Eduard Braun 2015-12-07 00:27:25 +01:00
parent ab1aa0e2f8
commit 32e7e5517f
2 changed files with 20 additions and 4 deletions

View file

@ -931,12 +931,26 @@ class WellFormedXMLAmpersandInTextContent(unittest.TestCase):
self.assertTrue( wellformed.find('<desc>Peanut Butter &amp; Jelly</desc>') != -1, self.assertTrue( wellformed.find('<desc>Peanut Butter &amp; Jelly</desc>') != -1,
'Improperly serialized &amp; in text content') 'Improperly serialized &amp; in text content')
class WellFormedXMLNamespacePrefix(unittest.TestCase): class WellFormedXMLNamespacePrefixRemoveUnused(unittest.TestCase):
def runTest(self): def runTest(self):
with open('unittests/xml-well-formed.svg') as f: with open('unittests/xml-well-formed.svg') as f:
wellformed = scour.scourString(f.read()) wellformed = scour.scourString(f.read())
self.assertTrue( wellformed.find('xmlns:foo=') != -1, self.assertTrue( wellformed.find('xmlns:foo=') == -1,
'Improperly serialized namespace prefix declarations') 'Improperly serialized namespace prefix declarations: Unused namespace decaration not removed')
class WellFormedXMLNamespacePrefixKeepUsedElementPrefix(unittest.TestCase):
def runTest(self):
with open('unittests/xml-well-formed.svg') as f:
wellformed = scour.scourString(f.read())
self.assertTrue( wellformed.find('xmlns:bar=') != -1,
'Improperly serialized namespace prefix declarations: Used element prefix removed')
class WellFormedXMLNamespacePrefixKeepUsedAttributePrefix(unittest.TestCase):
def runTest(self):
with open('unittests/xml-well-formed.svg') as f:
wellformed = scour.scourString(f.read())
self.assertTrue( wellformed.find('xmlns:baz=') != -1,
'Improperly serialized namespace prefix declarations: Used attribute prefix removed')
class NamespaceDeclPrefixesInXMLWhenNotInDefaultNamespace(unittest.TestCase): class NamespaceDeclPrefixesInXMLWhenNotInDefaultNamespace(unittest.TestCase):
def runTest(self): def runTest(self):

View file

@ -1,9 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:foo="http://foo/"> <svg xmlns="http://www.w3.org/2000/svg" xmlns:foo="http://foo/" xmlns:bar="http://bar/" xmlns:baz="http://baz/">
<!-- &lt;Jack &amp; Jill&gt; --> <!-- &lt;Jack &amp; Jill&gt; -->
<title>2 &lt; 5</title> <title>2 &lt; 5</title>
<desc>Peanut Butter &amp; Jelly</desc> <desc>Peanut Butter &amp; Jelly</desc>
<glyph id="lt" unicode="&lt;"/> <glyph id="lt" unicode="&lt;"/>
<glyph id="amp" unicode="&amp;"/> <glyph id="amp" unicode="&amp;"/>
<glyph id="gt" unicode="&gt;" bar:attr="xyz"/>
<baz:glyph id="quot" unicode="&quot;"/>
<text x="50" y="50">&#x389;TML &#x26; CSS</text> <text x="50" y="50">&#x389;TML &#x26; CSS</text>
</svg> </svg>

Before

Width:  |  Height:  |  Size: 344 B

After

Width:  |  Height:  |  Size: 481 B

Before After
Before After