1
2 import unittest, doctest, sys, os.path
3
4 this_dir = os.path.dirname(__file__)
5 if this_dir not in sys.path:
6 sys.path.insert(0, this_dir)
7
8 from common_imports import StringIO, etree, SillyFileLike, HelperTestCase
9 from common_imports import _str, _bytes
10
11 try:
12 unicode
13 except NameError:
14 unicode = str
15
16 ascii_uni = _bytes('a').decode('utf8')
17
18 klingon = _bytes("\\uF8D2").decode("unicode_escape")
19
20 invalid_tag = _bytes("test").decode('utf8') + klingon
21
22 uni = _bytes('\\xc3\\u0680\\u3120').decode("unicode_escape")
23
24 uxml = _bytes("<test><title>test \\xc3\\xa1\\u3120</title><h1>page \\xc3\\xa1\\u3120 title</h1></test>"
25 ).decode("unicode_escape")
26
31
33 if sys.maxunicode < 1114111:
34 return
35 tree = etree.XML(_bytes('<p>\\U00026007</p>').decode('unicode_escape'))
36 self.assertEqual(1, len(tree.text))
37 self.assertEqual(_bytes('\\U00026007').decode('unicode_escape'),
38 tree.text)
39
41 uxml = ('<?xml version="1.0" encoding="UTF-8"?>' +
42 '<p>%s</p>' % uni)
43 self.assertRaises(ValueError, etree.XML, uxml)
44
48
52
57
62
67
73
76
80
84
88
89
90
91
92
93
94
95
97 suite = unittest.TestSuite()
98 suite.addTests([unittest.makeSuite(UnicodeTestCase)])
99 return suite
100