Ejemplo n.º 1
0
def test_el_to_path(svg_xml, expected_path):
    pb = shapes.PathBuilder()
    pb.add_path_from_element(etree.fromstring(svg_xml))
    if expected_path:
        expected = [expected_path]
    else:
        expected = []
    assert pb.paths == expected
Ejemplo n.º 2
0
def test_el_to_path(svg_xml, expected_path):
    pb = shapes.PathBuilder()
    pb.add_path_from_element(etree.fromstring(svg_xml))
    if expected_path:
        expected = [expected_path]
    else:
        expected = []
    assert pb.paths == expected
Ejemplo n.º 3
0
def strip_xml_whitespace(xml_string):
    def strip_or_none(text):
        text = text.strip() if text else None
        return text if text else None

    tree = etree.fromstring(xml_string)
    for e in tree.iter("*"):
        e.text = strip_or_none(e.text)
        e.tail = strip_or_none(e.tail)
    return etree.tostring(tree, encoding="utf-8")
Ejemplo n.º 4
0
def test_totree(parametrized_pl):
    pl, use_builtin_types = parametrized_pl
    tree = etree.fromstring(TESTDATA)[0]  # ignore root 'plist' element
    tree2 = plistlib.totree(pl, use_builtin_types=use_builtin_types)
    assert tree.tag == tree2.tag == "dict"
    for (_, e1), (_, e2) in zip(etree.iterwalk(tree), etree.iterwalk(tree2)):
        assert e1.tag == e2.tag
        assert e1.attrib == e2.attrib
        assert len(e1) == len(e2)
        # ignore whitespace
        assert _strip(e1.text) == _strip(e2.text)
Ejemplo n.º 5
0
def test_totree(parametrized_pl):
    pl, use_builtin_types = parametrized_pl
    tree = etree.fromstring(TESTDATA)[0]  # ignore root 'plist' element
    tree2 = plistlib.totree(pl, use_builtin_types=use_builtin_types)
    assert tree.tag == tree2.tag == "dict"
    for (_, e1), (_, e2) in zip(etree.iterwalk(tree), etree.iterwalk(tree2)):
        assert e1.tag == e2.tag
        assert e1.attrib == e2.attrib
        assert len(e1) == len(e2)
        # ignore whitespace
        assert _strip(e1.text) == _strip(e2.text)
Ejemplo n.º 6
0
 def fromstring(cls, data, transform=None):
     self = cls(transform=transform)
     self.root = etree.fromstring(data)
     return self
Ejemplo n.º 7
0
def test_roundtrip_string(xml):
    root = etree.fromstring(xml.encode("utf-8"))
    result = etree.tostring(root, encoding="utf-8").decode("utf-8")
    assert result == xml
Ejemplo n.º 8
0
def test_fromtree(parametrized_pl):
    pl, use_builtin_types = parametrized_pl
    tree = etree.fromstring(TESTDATA)
    pl2 = plistlib.fromtree(tree, use_builtin_types=use_builtin_types)
    assert pl == pl2
Ejemplo n.º 9
0
def test_fromtree(parametrized_pl):
    pl, use_builtin_types = parametrized_pl
    tree = etree.fromstring(TESTDATA)
    pl2 = plistlib.fromtree(tree, use_builtin_types=use_builtin_types)
    assert pl == pl2
Ejemplo n.º 10
0
def test_roundtrip_string(xml):
    root = etree.fromstring(xml.encode("utf-8"))
    result = etree.tostring(root, encoding="utf-8").decode("utf-8")
    assert result == xml