Fix flake errors.
This commit is contained in:
parent
ec7d06f925
commit
798eb299e5
2 changed files with 28 additions and 24 deletions
|
|
@ -1801,26 +1801,26 @@ def repairStyle(node, options):
|
||||||
num += 1
|
num += 1
|
||||||
|
|
||||||
if node.nodeType == Node.ELEMENT_NODE:
|
if node.nodeType == Node.ELEMENT_NODE:
|
||||||
if options.style_type == "inline":
|
if options.style_type == "inline":
|
||||||
# Prefer inline style
|
# Prefer inline style
|
||||||
# Remove known SVG attributes and store their values in style attribute
|
# Remove known SVG attributes and store their values in style attribute
|
||||||
attributes = [node.attributes.item(i).nodeName for i in range(node.attributes.length)]
|
attributes = [node.attributes.item(i).nodeName for i in range(node.attributes.length)]
|
||||||
for attribute in attributes:
|
for attribute in attributes:
|
||||||
if attribute in svgAttributes:
|
if attribute in svgAttributes:
|
||||||
styleMap[attribute] = node.getAttribute(attribute)
|
styleMap[attribute] = node.getAttribute(attribute)
|
||||||
node.removeAttribute(attribute)
|
node.removeAttribute(attribute)
|
||||||
elif options.style_type == "preserve":
|
elif options.style_type == "preserve":
|
||||||
# Keep whatever style of attribute versus style the file currently has
|
# Keep whatever style of attribute versus style the file currently has
|
||||||
pass
|
pass
|
||||||
elif options.style_to_xml or options.style_type == "attributes":
|
elif options.style_to_xml or options.style_type == "attributes":
|
||||||
# now if any of the properties match known SVG attributes we prefer attributes
|
# now if any of the properties match known SVG attributes we prefer attributes
|
||||||
# over style so emit them and remove them from the style map
|
# over style so emit them and remove them from the style map
|
||||||
for propName in list(styleMap):
|
for propName in list(styleMap):
|
||||||
if propName in svgAttributes:
|
if propName in svgAttributes:
|
||||||
node.setAttribute(propName, styleMap[propName])
|
node.setAttribute(propName, styleMap[propName])
|
||||||
del styleMap[propName]
|
del styleMap[propName]
|
||||||
|
|
||||||
_setStyle(node, styleMap)
|
_setStyle(node, styleMap)
|
||||||
|
|
||||||
# recurse for our child elements
|
# recurse for our child elements
|
||||||
for child in node.childNodes:
|
for child in node.childNodes:
|
||||||
|
|
@ -3999,7 +3999,8 @@ _option_group_optimization.add_option("--disable-style-to-xml",
|
||||||
help="won't convert styles into XML attributes")
|
help="won't convert styles into XML attributes")
|
||||||
_option_group_optimization.add_option("--style",
|
_option_group_optimization.add_option("--style",
|
||||||
action="store", type="string", dest="style_type", default="none", metavar="TYPE",
|
action="store", type="string", dest="style_type", default="none", metavar="TYPE",
|
||||||
help="styles type (override style_to_xml): none, preserve, inline, attributes (default: %none)")
|
help="style type (overrides style-to-xml): none, preserve, inline,"\
|
||||||
|
"attributes (default: %none)")
|
||||||
_option_group_optimization.add_option("--disable-group-collapsing",
|
_option_group_optimization.add_option("--disable-group-collapsing",
|
||||||
action="store_false", dest="group_collapse", default=True,
|
action="store_false", dest="group_collapse", default=True,
|
||||||
help="won't collapse <g> elements")
|
help="won't collapse <g> elements")
|
||||||
|
|
|
||||||
|
|
@ -2212,11 +2212,12 @@ class StyleToAttr(unittest.TestCase):
|
||||||
self.assertEqual(line.getAttribute('marker-mid'), 'url(#m)')
|
self.assertEqual(line.getAttribute('marker-mid'), 'url(#m)')
|
||||||
self.assertEqual(line.getAttribute('marker-end'), 'url(#m)')
|
self.assertEqual(line.getAttribute('marker-end'), 'url(#m)')
|
||||||
|
|
||||||
|
|
||||||
class AttrToStyle(unittest.TestCase):
|
class AttrToStyle(unittest.TestCase):
|
||||||
|
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
doc = scourXmlFile('unittests/attr-to-style.svg',
|
doc = scourXmlFile('unittests/attr-to-style.svg',
|
||||||
parse_args(['--style=inline']))
|
parse_args(['--style=inline']))
|
||||||
line = doc.getElementsByTagName('line')[0]
|
line = doc.getElementsByTagName('line')[0]
|
||||||
self.assertEqual(line.getAttribute('stroke'), '')
|
self.assertEqual(line.getAttribute('stroke'), '')
|
||||||
self.assertEqual(line.getAttribute('marker-start'), '')
|
self.assertEqual(line.getAttribute('marker-start'), '')
|
||||||
|
|
@ -2231,26 +2232,28 @@ class AttrToStyle(unittest.TestCase):
|
||||||
self.assertTrue("marker-end:url(#m)" in rawStyles)
|
self.assertTrue("marker-end:url(#m)" in rawStyles)
|
||||||
self.assertTrue("marker-mid:url(#m)" in rawStyles)
|
self.assertTrue("marker-mid:url(#m)" in rawStyles)
|
||||||
|
|
||||||
|
|
||||||
class StylePreserve(unittest.TestCase):
|
class StylePreserve(unittest.TestCase):
|
||||||
|
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
doc = scourXmlFile('unittests/attr-to-style.svg',
|
doc = scourXmlFile('unittests/attr-to-style.svg',
|
||||||
parse_args(['--style=preserve']))
|
parse_args(['--style=preserve']))
|
||||||
|
|
||||||
#First line uses attributes.
|
# First line uses attributes.
|
||||||
line = doc.getElementsByTagName('line')[0]
|
line = doc.getElementsByTagName('line')[0]
|
||||||
self.assertNotEqual(line.getAttribute('stroke'), '')
|
self.assertNotEqual(line.getAttribute('stroke'), '')
|
||||||
self.assertNotEqual(line.getAttribute('marker-start'), '')
|
self.assertNotEqual(line.getAttribute('marker-start'), '')
|
||||||
self.assertNotEqual(line.getAttribute('marker-mid'), '')
|
self.assertNotEqual(line.getAttribute('marker-mid'), '')
|
||||||
self.assertNotEqual(line.getAttribute('marker-end'), '')
|
self.assertNotEqual(line.getAttribute('marker-end'), '')
|
||||||
|
|
||||||
#Second line uses style attribute.
|
# Second line uses style attribute.
|
||||||
line = doc.getElementsByTagName('line')[1]
|
line = doc.getElementsByTagName('line')[1]
|
||||||
self.assertEqual(line.getAttribute('stroke'), '')
|
self.assertEqual(line.getAttribute('stroke'), '')
|
||||||
self.assertEqual(line.getAttribute('marker-start'), '')
|
self.assertEqual(line.getAttribute('marker-start'), '')
|
||||||
self.assertEqual(line.getAttribute('marker-mid'), '')
|
self.assertEqual(line.getAttribute('marker-mid'), '')
|
||||||
self.assertEqual(line.getAttribute('marker-end'), '')
|
self.assertEqual(line.getAttribute('marker-end'), '')
|
||||||
|
|
||||||
|
|
||||||
class PathCommandRewrites(unittest.TestCase):
|
class PathCommandRewrites(unittest.TestCase):
|
||||||
|
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue