Example #1
0
 def test_is_copy(self) -> None:
     """"""
     group = new_element("g")
     line = new_sub_element(group, "line", x=10, y1=80)
     group_copy = deepcopy_element(group, stroke="black")
     assert (etree.tostring(group_copy) ==
             b'<g stroke="black"><line x="10" y1="80"/></g>')
     assert line in group
     assert line not in group_copy
Example #2
0
 def test_new_params(self) -> None:
     """New params added"""
     elem = new_element("line", x=10, y1=80)
     update_element(elem, stroke_width=2)
     assert etree.tostring(
         elem) == b'<line x="10" y1="80" stroke-width="2"/>'
Example #3
0
 def test_float(self) -> None:
     """Floats at 0.6f precision"""
     elem = new_element("text", x=1 / 3)
     assert etree.tostring(elem) == b'<text x="0.333333"/>'
Example #4
0
 def test_sub_element(self) -> None:
     """New element is a sub-element of parent"""
     parent = new_element("g")
     _ = new_sub_element(parent, "rect")
     assert etree.tostring(parent) == b"<g><rect/></g>"
Example #5
0
 def test_text(self) -> None:
     """Insert text between tags"""
     elem = new_element("text", text="text here")
     assert etree.tostring(elem) == b"<text>text here</text>"
Example #6
0
 def test_param_text(self) -> None:
     """Insert text between tags with parameters"""
     elem = new_element("text", x=120, y=12, text="text here")
     assert etree.tostring(elem) == b'<text x="120" y="12">text here</text>'
Example #7
0
 def test_trailing_underscore(self) -> None:
     """Remove trailing _ from params"""
     elem = new_element("line", x=10, y1=80, in_="SourceAlpha")
     assert etree.tostring(
         elem) == b'<line x="10" y1="80" in="SourceAlpha"/>'
Example #8
0
 def test_qualified_name_string_conversion(self) -> None:
     """If a keyword argument has :, convert to qname"""
     elem = new_element("line", **{"xlink:href": 10})
     assert (
         etree.tostring(elem) ==
         b'<line xmlns:ns0="http://www.w3.org/1999/xlink" ns0:href="10"/>')
Example #9
0
 def test_params(self) -> None:
     """Replace _ with -. Pass params.values() as strings"""
     elem = new_element("line", x=10, y1=80, stroke_width="2")
     assert etree.tostring(
         elem) == b'<line x="10" y1="80" stroke-width="2"/>'