More unit tests for removing stroke properties (for stroke-width=0 or stroke=none)

This commit is contained in:
JSCHILL1 2009-04-23 08:12:46 -05:00
parent f4b328ea4b
commit d9866c99e9
7 changed files with 91 additions and 40 deletions

View file

@ -1,10 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg">
<defs>
</defs>
<g/>
<g></g>
<metadata />
<g>Foo</g>
</svg>

Before

Width:  |  Height:  |  Size: 117 B

View file

@ -1,5 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg">
<defs>
</defs>
</svg>

Before

Width:  |  Height:  |  Size: 69 B

View file

@ -1,9 +0,0 @@
<foo xmlns:xlink="http://www.w3.org/1999/xlink">
<bar id="johansen" />
<baz xlink:href="#johansen"/>
<bar id="scarlett">
<fudge id="f1" fill="url(#scarlett)"/>
</bar>
<fudge id="f2" stroke="url(#scarlett)"/>
</foo>

View file

@ -228,48 +228,117 @@ class KeepReferencedFonts(unittest.TestCase):
class ConvertStyleToAttrs(unittest.TestCase):
def runTest(self):
doc = scour.scourXmlFile('unittests/stroke-linejoin.svg')
doc = scour.scourXmlFile('unittests/stroke-transparent.svg')
self.assertEquals(doc.getElementsByTagNameNS(SVGNS, 'path')[0].getAttribute('style'), '',
"style attribute not emptied" )
class RemoveStrokeWhenStrokeTransparent(unittest.TestCase):
def runTest(self):
doc = scour.scourXmlFile('unittests/stroke-linejoin.svg')
doc = scour.scourXmlFile('unittests/stroke-transparent.svg')
self.assertEquals(doc.getElementsByTagNameNS(SVGNS, 'path')[0].getAttribute('stroke'), '',
"stroke attribute not emptied" )
"stroke attribute not emptied when stroke opacity zero" )
class RemoveStrokeWidthWhenStrokeTransparent(unittest.TestCase):
def runTest(self):
doc = scour.scourXmlFile('unittests/stroke-linejoin.svg')
doc = scour.scourXmlFile('unittests/stroke-transparent.svg')
self.assertEquals(doc.getElementsByTagNameNS(SVGNS, 'path')[0].getAttribute('stroke-width'), '',
"stroke-width attribute not emptied" )
"stroke-width attribute not emptied when stroke opacity zero" )
class RemoveStrokeLinecapWhenStrokeTransparent(unittest.TestCase):
def runTest(self):
doc = scour.scourXmlFile('unittests/stroke-linejoin.svg')
doc = scour.scourXmlFile('unittests/stroke-transparent.svg')
self.assertEquals(doc.getElementsByTagNameNS(SVGNS, 'path')[0].getAttribute('stroke-linecap'), '',
"stroke-linecap attribute not emptied" )
"stroke-linecap attribute not emptied when stroke opacity zero" )
class RemoveStrokeLinejoinWhenStrokeTransparent(unittest.TestCase):
def runTest(self):
doc = scour.scourXmlFile('unittests/stroke-linejoin.svg')
doc = scour.scourXmlFile('unittests/stroke-transparent.svg')
self.assertEquals(doc.getElementsByTagNameNS(SVGNS, 'path')[0].getAttribute('stroke-linejoin'), '',
"stroke-linejoin attribute not emptied" )
"stroke-linejoin attribute not emptied when stroke opacity zero" )
class RemoveStrokeDasharrayWhenStrokeTransparent(unittest.TestCase):
def runTest(self):
doc = scour.scourXmlFile('unittests/stroke-linejoin.svg')
doc = scour.scourXmlFile('unittests/stroke-transparent.svg')
self.assertEquals(doc.getElementsByTagNameNS(SVGNS, 'path')[0].getAttribute('stroke-dasharray'), '',
"stroke-dasharray attribute not emptied" )
"stroke-dasharray attribute not emptied when stroke opacity zero" )
class RemoveStrokeDashoffsetWhenStrokeTransparent(unittest.TestCase):
def runTest(self):
doc = scour.scourXmlFile('unittests/stroke-linejoin.svg')
doc = scour.scourXmlFile('unittests/stroke-transparent.svg')
self.assertEquals(doc.getElementsByTagNameNS(SVGNS, 'path')[0].getAttribute('stroke-dashoffset'), '',
"stroke-dashoffset attribute not emptied" )
"stroke-dashoffset attribute not emptied when stroke opacity zero" )
# TODO : add in duplicate tests for when the stroke-width is 0
# TODO : add in duplicate tests for when the stroke is none
class RemoveStrokeWhenStrokeWidthZero(unittest.TestCase):
def runTest(self):
doc = scour.scourXmlFile('unittests/stroke-nowidth.svg')
self.assertEquals(doc.getElementsByTagNameNS(SVGNS, 'path')[0].getAttribute('stroke'), '',
"stroke attribute not emptied when width zero" )
class RemoveStrokeOpacityWhenStrokeWidthZero(unittest.TestCase):
def runTest(self):
doc = scour.scourXmlFile('unittests/stroke-nowidth.svg')
self.assertEquals(doc.getElementsByTagNameNS(SVGNS, 'path')[0].getAttribute('stroke-opacity'), '',
"stroke-opacity attribute not emptied when width zero" )
class RemoveStrokeLinecapWhenStrokeWidthZero(unittest.TestCase):
def runTest(self):
doc = scour.scourXmlFile('unittests/stroke-nowidth.svg')
self.assertEquals(doc.getElementsByTagNameNS(SVGNS, 'path')[0].getAttribute('stroke-linecap'), '',
"stroke-linecap attribute not emptied when width zero" )
class RemoveStrokeLinejoinWhenStrokeWidthZero(unittest.TestCase):
def runTest(self):
doc = scour.scourXmlFile('unittests/stroke-nowidth.svg')
self.assertEquals(doc.getElementsByTagNameNS(SVGNS, 'path')[0].getAttribute('stroke-linejoin'), '',
"stroke-linejoin attribute not emptied when width zero" )
class RemoveStrokeDasharrayWhenStrokeWidthZero(unittest.TestCase):
def runTest(self):
doc = scour.scourXmlFile('unittests/stroke-nowidth.svg')
self.assertEquals(doc.getElementsByTagNameNS(SVGNS, 'path')[0].getAttribute('stroke-dasharray'), '',
"stroke-dasharray attribute not emptied when width zero" )
class RemoveStrokeDashoffsetWhenStrokeWidthZero(unittest.TestCase):
def runTest(self):
doc = scour.scourXmlFile('unittests/stroke-nowidth.svg')
self.assertEquals(doc.getElementsByTagNameNS(SVGNS, 'path')[0].getAttribute('stroke-dashoffset'), '',
"stroke-dashoffset attribute not emptied when width zero" )
class RemoveStrokeWhenStrokeNone(unittest.TestCase):
def runTest(self):
doc = scour.scourXmlFile('unittests/stroke-none.svg')
self.assertEquals(doc.getElementsByTagNameNS(SVGNS, 'path')[0].getAttribute('stroke-width'), '',
"stroke-width attribute not emptied when no stroke" )
class RemoveStrokeOpacityWhenStrokeNone(unittest.TestCase):
def runTest(self):
doc = scour.scourXmlFile('unittests/stroke-none.svg')
self.assertEquals(doc.getElementsByTagNameNS(SVGNS, 'path')[0].getAttribute('stroke-opacity'), '',
"stroke-opacity attribute not emptied when no stroke" )
class RemoveStrokeLinecapWhenStrokeNone(unittest.TestCase):
def runTest(self):
doc = scour.scourXmlFile('unittests/stroke-none.svg')
self.assertEquals(doc.getElementsByTagNameNS(SVGNS, 'path')[0].getAttribute('stroke-linecap'), '',
"stroke-linecap attribute not emptied when no stroke" )
class RemoveStrokeLinejoinWhenStrokeNone(unittest.TestCase):
def runTest(self):
doc = scour.scourXmlFile('unittests/stroke-none.svg')
self.assertEquals(doc.getElementsByTagNameNS(SVGNS, 'path')[0].getAttribute('stroke-linejoin'), '',
"stroke-linejoin attribute not emptied when no stroke" )
class RemoveStrokeDasharrayWhenStrokeNone(unittest.TestCase):
def runTest(self):
doc = scour.scourXmlFile('unittests/stroke-none.svg')
self.assertEquals(doc.getElementsByTagNameNS(SVGNS, 'path')[0].getAttribute('stroke-dasharray'), '',
"stroke-dasharray attribute not emptied when no stroke" )
class RemoveStrokeDashoffsetWhenStrokeNone(unittest.TestCase):
def runTest(self):
doc = scour.scourXmlFile('unittests/stroke-none.svg')
self.assertEquals(doc.getElementsByTagNameNS(SVGNS, 'path')[0].getAttribute('stroke-dashoffset'), '',
"stroke-dashoffset attribute not emptied when no stroke" )
#class RemoveUnreferencedFonts(unittest.TestCase):
# def runTest(self):
@ -277,6 +346,6 @@ class RemoveStrokeDashoffsetWhenStrokeTransparent(unittest.TestCase):
# fonts = doc.documentElement.getElementsByTagNameNS('http://www.w3.org/2000/svg','font')
# self.assertEquals(len(fonts), 0,
# "Font was not removed from <defs>" )
if __name__ == '__main__':
unittest.main()

View file

@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg">
<path id="p" fill="black" style="stroke: none; stroke-width: 1px; stroke-linecap: butt; stroke-dasharray: none; stroke-dashoffset: 2; stroke-linejoin: miter; stroke-opacity: 1;" d="M 7.7592046,36.982095 C 7.8831049,40.873696 7.8339808,45.305308 7.8339808,49.436888 Z" />
</svg>

After

Width:  |  Height:  |  Size: 323 B

View file

@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg">
<path id="p" fill="black" style="stroke: rgb(0, 0, 0); stroke-width: 0; stroke-linecap: butt; stroke-dasharray: none; stroke-dashoffset: 2; stroke-linejoin: miter; stroke-opacity: 1;" d="M 7.7592046,36.982095 C 7.8831049,40.873696 7.8339808,45.305308 7.8339808,49.436888 Z" />
</svg>

After

Width:  |  Height:  |  Size: 329 B

View file

Before

Width:  |  Height:  |  Size: 331 B

After

Width:  |  Height:  |  Size: 331 B

Before After
Before After