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 = __builtins__["unicode"]
13 except (NameError, KeyError):
14 unicode = str
15
16 ascii_uni = _str('a')
17
18 klingon = _bytes("\\uF8D2").decode("unicode_escape")
19
20 invalid_tag = _str("test") + 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 uxml = _str('<?xml version="1.0" encoding="UTF-8"?>') + \
34 _str('<p>%s</p>') % uni
35 self.assertRaises(ValueError, etree.XML, uxml)
36
40
44
49
54
60
63
67
71
75
76
77
78
79
80
81
82
84 suite = unittest.TestSuite()
85 suite.addTests([unittest.makeSuite(UnicodeTestCase)])
86 return suite
87