1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
import fontTools.misc.testTools as testTools
import unittest
class TestToolsTest(unittest.TestCase):
def test_parseXML_str(self):
self.assertEqual(
testTools.parseXML(
'<Foo n="1"/>'
'<Foo n="2">'
" some ünıcòðe text"
' <Bar color="red"/>'
" some more text"
"</Foo>"
'<Foo n="3"/>'
),
[
("Foo", {"n": "1"}, []),
(
"Foo",
{"n": "2"},
[
" some ünıcòðe text ",
("Bar", {"color": "red"}, []),
" some more text",
],
),
("Foo", {"n": "3"}, []),
],
)
def test_parseXML_bytes(self):
self.assertEqual(
testTools.parseXML(
b'<Foo n="1"/>'
b'<Foo n="2">'
b" some \xc3\xbcn\xc4\xb1c\xc3\xb2\xc3\xb0e text"
b' <Bar color="red"/>'
b" some more text"
b"</Foo>"
b'<Foo n="3"/>'
),
[
("Foo", {"n": "1"}, []),
(
"Foo",
{"n": "2"},
[
" some ünıcòðe text ",
("Bar", {"color": "red"}, []),
" some more text",
],
),
("Foo", {"n": "3"}, []),
],
)
def test_parseXML_str_list(self):
self.assertEqual(
testTools.parseXML(['<Foo n="1"/>' '<Foo n="2"/>']),
[("Foo", {"n": "1"}, []), ("Foo", {"n": "2"}, [])],
)
def test_parseXML_bytes_list(self):
self.assertEqual(
testTools.parseXML([b'<Foo n="1"/>' b'<Foo n="2"/>']),
[("Foo", {"n": "1"}, []), ("Foo", {"n": "2"}, [])],
)
def test_getXML(self):
def toXML(writer, ttFont):
writer.simpletag("simple")
writer.newline()
writer.begintag("tag", attr="value")
writer.newline()
writer.write("hello world")
writer.newline()
writer.endtag("tag")
writer.newline() # toXML always ends with a newline
self.assertEqual(
testTools.getXML(toXML),
["<simple/>", '<tag attr="value">', " hello world", "</tag>"],
)
if __name__ == "__main__":
import sys
sys.exit(unittest.main())
|