fonttools/Lib/fontTools/misc/testTools_test.py
Sascha Brawer d63885e337 [otTables] Use XML snippets for testing fromXML() methods
This should make the unit tests more readable, and it also prevents
failures where a changed fromXML() implementation fails to ignore
interspersed whitespace. This has recently caused some developer
nuisance; see https://github.com/behdad/fonttools/pull/367.

Instead of having a custom parser implementation, it would be nicer
to call the actual XMLReader. However, XMLReader has a deeply built-in
assumption that it is processing an entire TTX file. Changing this
assumption would certainly be possible, but it would need a re-write
of the XMLReader code; having a custom parser just for unit tests
seems less involved.
2015-09-11 15:44:29 +02:00

31 lines
866 B
Python

from __future__ import print_function, division, absolute_import
from __future__ import unicode_literals
from fontTools.misc.py23 import *
import fontTools.misc.testTools as testTools
import os
import unittest
class TestToolsTest(unittest.TestCase):
def test_parseXML(self):
self.assertEqual(testTools.parseXML(
'<Foo n="1"/>'
'<Foo n="2">'
' some text'
' <Bar color="red"/>'
' some more text'
'</Foo>'
'<Foo n="3"/>'), [
("Foo", {"n": "1"}, []),
("Foo", {"n": "2"}, [
" some text ",
("Bar", {"color": "red"}, []),
" some more text",
]),
("Foo", {"n": "3"}, [])
])
if __name__ == "__main__":
unittest.main()