1
2 import unittest
3 import sys
4 import os.path
5
6 this_dir = os.path.dirname(__file__)
7 if this_dir not in sys.path:
8 sys.path.insert(0, this_dir)
9
10 from common_imports import StringIO, etree, SillyFileLike, HelperTestCase
11 from common_imports import _str, _bytes
12
13 try:
14 unicode
15 except NameError:
16 unicode = str
17
18 ascii_uni = _bytes('a').decode('utf8')
19
20 klingon = _bytes("\\uF8D2").decode("unicode_escape")
21
22 invalid_tag = _bytes("test").decode('utf8') + klingon
23
24 uni = _bytes('\\xc3\\u0680\\u3120').decode("unicode_escape")
25
26 uxml = _bytes("<test><title>test \\xc3\\xa1\\u3120</title><h1>page \\xc3\\xa1\\u3120 title</h1></test>"
27 ).decode("unicode_escape")
28
29
34
36 if sys.maxunicode < 1114111:
37 return
38 tree = etree.XML(_bytes('<p>\\U00026007</p>').decode('unicode_escape'))
39 self.assertEqual(1, len(tree.text))
40 self.assertEqual(_bytes('\\U00026007').decode('unicode_escape'),
41 tree.text)
42
44 uxml = ('<?xml version="1.0" encoding="UTF-8"?>' +
45 '<p>%s</p>' % uni)
46 self.assertRaises(ValueError, etree.XML, uxml)
47
51
55
60
65
70
76
79
83
87
91
92
93
94
95
96
97
98
99
109
110
112 suite = unittest.TestSuite()
113 suite.addTests([unittest.makeSuite(UnicodeTestCase)])
114 suite.addTests([unittest.makeSuite(EncodingsTestCase)])
115 return suite
116