diff options
| author | scoder <none@none> | 2008-05-21 21:47:05 +0200 |
|---|---|---|
| committer | scoder <none@none> | 2008-05-21 21:47:05 +0200 |
| commit | 9b4ea933c1e7191639b4be57fad569c72dca1d15 (patch) | |
| tree | 709854769430a976709f9bd468ddd3ec4019b621 /src/lxml/tests/test_unicode.py | |
| parent | 850c59a2fef9991ed8b207f2ae9188ecea02e95a (diff) | |
| download | python-lxml-9b4ea933c1e7191639b4be57fad569c72dca1d15.tar.gz | |
[svn r3708] r4266@delle: sbehnel | 2008-05-21 00:16:13 +0200
Py3 test fixes
--HG--
branch : trunk
Diffstat (limited to 'src/lxml/tests/test_unicode.py')
| -rw-r--r-- | src/lxml/tests/test_unicode.py | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/src/lxml/tests/test_unicode.py b/src/lxml/tests/test_unicode.py index 60b4cdd4..d29dfd91 100644 --- a/src/lxml/tests/test_unicode.py +++ b/src/lxml/tests/test_unicode.py @@ -1,26 +1,37 @@ # -*- coding: utf-8 -*- -import unittest, doctest +import unittest, doctest, sys, os.path + +this_dir = os.path.dirname(__file__) +if this_dir not in sys.path: + sys.path.insert(0, this_dir) # needed for Py3 from common_imports import StringIO, etree, SillyFileLike, HelperTestCase +from common_imports import _str, _bytes + +try: + unicode = __builtins__["unicode"] +except (NameError, KeyError): + unicode = str -ascii_uni = u'a' +ascii_uni = _str('a') -klingon = u"\uF8D2" # not valid for XML names +klingon = _bytes("\\uF8D2").decode("unicode_escape") # not valid for XML names -invalid_tag = "test" + klingon +invalid_tag = _str("test") + klingon -uni = u'Ã\u0680\u3120' # some non-ASCII characters +uni = _bytes('\\xc3\\u0680\\u3120').decode("unicode_escape") # some non-ASCII characters -uxml = u"<test><title>test á\u3120</title><h1>page á\u3120 title</h1></test>" +uxml = _bytes("<test><title>test \\xc3\\xa1\\u3120</title><h1>page \\xc3\\xa1\\u3120 title</h1></test>" + ).decode("unicode_escape") class UnicodeTestCase(HelperTestCase): def test_unicode_xml(self): - tree = etree.XML(u'<p>%s</p>' % uni) + tree = etree.XML(_str('<p>%s</p>') % uni) self.assertEquals(uni, tree.text) def test_unicode_xml_broken(self): - uxml = u'<?xml version="1.0" encoding="UTF-8"?>' + \ - u'<p>%s</p>' % uni + uxml = _str('<?xml version="1.0" encoding="UTF-8"?>') + \ + _str('<p>%s</p>') % uni self.assertRaises(ValueError, etree.XML, uxml) def test_unicode_tag(self): @@ -32,18 +43,18 @@ class UnicodeTestCase(HelperTestCase): self.assertRaises(ValueError, etree.Element, invalid_tag) def test_unicode_nstag(self): - tag = u"{%s}%s" % (uni, uni) + tag = _str("{%s}%s") % (uni, uni) el = etree.Element(tag) self.assertEquals(tag, el.tag) def test_unicode_nstag_invalid(self): # sadly, Klingon is not well-formed - tag = u"{%s}%s" % (uni, invalid_tag) + tag = _str("{%s}%s") % (uni, invalid_tag) self.assertRaises(ValueError, etree.Element, tag) def test_unicode_qname(self): qname = etree.QName(uni, uni) - tag = u"{%s}%s" % (uni, uni) + tag = _str("{%s}%s") % (uni, uni) self.assertEquals(qname.text, tag) self.assertEquals(unicode(qname), tag) @@ -59,7 +70,7 @@ class UnicodeTestCase(HelperTestCase): self.assertEquals(uni, el.text) def test_unicode_parse_stringio(self): - el = etree.parse(StringIO(u'<p>%s</p>' % uni)).getroot() + el = etree.parse(StringIO(_str('<p>%s</p>') % uni)).getroot() self.assertEquals(uni, el.text) ## def test_parse_fileobject_unicode(self): |
