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 = _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
59
65
68
72
76
80
81
82
83
84
85
86
87
89 suite = unittest.TestSuite()
90 suite.addTests([unittest.makeSuite(UnicodeTestCase)])
91 return suite
92