test_plistlib: use ufoLib.etree

This commit is contained in:
Cosimo Lupo 2018-07-13 18:50:02 +01:00
parent a9a37818cb
commit 59ac1aa357
No known key found for this signature in database
GPG Key ID: 59D54DB0C9976482

View File

@ -6,7 +6,8 @@ import codecs
import collections import collections
from io import BytesIO from io import BytesIO
from numbers import Integral from numbers import Integral
from lxml import etree from fontTools.misc.py23 import tounicode
from ufoLib import etree
import pytest import pytest
@ -271,10 +272,10 @@ def test_controlcharacters():
if i >= 32 or c in "\r\n\t": if i >= 32 or c in "\r\n\t":
# \r, \n and \t are the only legal control chars in XML # \r, \n and \t are the only legal control chars in XML
data = plistlib.dumps(testString) data = plistlib.dumps(testString)
# the stdlib's plistlib writer always replaces \r with \n # the stdlib's plistlib writer, as well as the elementtree
# inside string values; we don't (the ctrl character is # parser, always replace \r with \n inside string values;
# escaped by lxml, so it roundtrips) # lxml doesn't (the ctrl character is escaped), so it roundtrips
# if c != "\r": if c != "\r" or etree._have_lxml:
assert plistlib.loads(data) == testString assert plistlib.loads(data) == testString
else: else:
with pytest.raises(ValueError): with pytest.raises(ValueError):
@ -340,8 +341,9 @@ def test_invalidreal():
(b"utf-8", "utf-8", codecs.BOM_UTF8), (b"utf-8", "utf-8", codecs.BOM_UTF8),
(b"utf-16", "utf-16-le", codecs.BOM_UTF16_LE), (b"utf-16", "utf-16-le", codecs.BOM_UTF16_LE),
(b"utf-16", "utf-16-be", codecs.BOM_UTF16_BE), (b"utf-16", "utf-16-be", codecs.BOM_UTF16_BE),
(b"utf-32", "utf-32-le", codecs.BOM_UTF32_LE), # expat parser (used by ElementTree) does't support UTF-32
(b"utf-32", "utf-32-be", codecs.BOM_UTF32_BE), # (b"utf-32", "utf-32-le", codecs.BOM_UTF32_LE),
# (b"utf-32", "utf-32-be", codecs.BOM_UTF32_BE),
], ],
) )
def test_xml_encodings(pl, xml_encoding, encoding, bom): def test_xml_encodings(pl, xml_encoding, encoding, bom):
@ -359,7 +361,7 @@ def test_fromtree(pl):
def _strip(txt): def _strip(txt):
return ( return (
"".join(l.strip() for l in txt.splitlines()) "".join(l.strip() for l in tounicode(txt, "utf-8").splitlines())
if txt is not None if txt is not None
else "" else ""
) )