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