Commit 05cfe7f2 authored by Martin Owens's avatar Martin Owens 🤖

Fix tag getter attribute error and add test and allow load_svg to strip whitespace.

parent 3e10fece
Pipeline #137428761 passed with stages
in 4 minutes
......@@ -69,8 +69,8 @@ SVG_PARSER.set_element_class_lookup(NodeBasedLookup())
def load_svg(stream):
"""Load SVG file using the SVG_PARSER"""
if (isinstance(stream, str) and stream.startswith('<'))\
or (isinstance(stream, bytes) and stream.startswith(b'<')):
if (isinstance(stream, str) and stream.lstrip().startswith('<'))\
or (isinstance(stream, bytes) and stream.lstrip().startswith(b'<')):
return etree.ElementTree(etree.fromstring(stream, parser=SVG_PARSER))
return etree.parse(stream, parser=SVG_PARSER)
......@@ -94,7 +94,7 @@ class BaseElement(etree.ElementBase):
def TAG(self): # pylint: disable=invalid-name
"""Return the tag_name without NS"""
if not self.tag_name:
return super(etree.ElementBase, self).TAG
return removeNS(super(etree.ElementBase, self).tag)[-1]
return removeNS(self.tag_name)[-1]
@classmethod
......
......@@ -12,7 +12,7 @@ from inkex import (
ShapeElement, Group, Layer, Pattern, Guide, Polyline, Use, Defs,
TextElement, TextPath, Tspan, FlowPara, FlowRoot, FlowRegion, FlowSpan,
PathElement, Rectangle, Circle, Ellipse, Anchor, Line as LineElement,
Transform, Style
Transform, Style, load_svg
)
from inkex.paths import Move, Line
from inkex.utils import FragmentError, PY3
......@@ -45,6 +45,25 @@ class CoreElementTestCase(ElementTestCase):
"""Test core element functionality"""
tag = 'g'
def test_tag_names(self):
"""
Test tag names for custom and unknown tags
"""
doc = load_svg("""
<svg xmlns="http://www.w3.org/2000/svg" xmlns:x="http://x.com/x">
<g id="good"></g>
<badsvg id="bad">Unknown SVG tag</badsvg>
<x:othertag id="ugly"></x:othertag>
</svg>""")
svg = doc.getroot()
good = svg.getElementById("good")
self.assertEqual(good.TAG, "g")
bad = svg.getElementById("bad")
self.assertEqual(bad.TAG, "badsvg")
ugly = svg.getElementById("ugly")
self.assertEqual(ugly.TAG, "othertag")
def test_reference_count(self):
"""
Test inkex.element.BaseElement-derived object type is preserved on adding to group
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment