From 59ac1aa357e3c41405cbf79f25eab2f1768f6304 Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Fri, 13 Jul 2018 18:50:02 +0100 Subject: [PATCH] test_plistlib: use ufoLib.etree --- Lib/ufoLib/test/test_plistlib.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/Lib/ufoLib/test/test_plistlib.py b/Lib/ufoLib/test/test_plistlib.py index 1fcd960f1..9ba16d0dd 100644 --- a/Lib/ufoLib/test/test_plistlib.py +++ b/Lib/ufoLib/test/test_plistlib.py @@ -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 "" )