Browse files

Enable new unicode tests to run on Python 2 and 3 properly

Change-Id: I5b680279773a13d7bb5490e194f1ebdbbde0f731
  • Loading branch information...
1 parent 399b8cb commit 85a66ede60f4985c82f2fd500c1fe0468e6c2ff2 @rtyler committed Apr 7, 2010
Showing with 21 additions and 5 deletions.
  1. +11 −0 tests/python2.py
  2. +10 −5 tests/unit.py
View
11 tests/python2.py
@@ -0,0 +1,11 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+'''
+ File for keeping Python 2 specific things, that raise SyntaxError
+ exceptions in Python 3
+'''
+
+
+IssueSevenTest_latin1_char = u'f\xe9in'
+# u'早安, 爸爸' # Good morning!
+IssueSevenTest_chinese_char = u'\u65e9\u5b89, \u7238\u7238'
View
15 tests/unit.py
@@ -207,7 +207,10 @@ def test_none_indent(self):
class IssueSevenTest(unittest.TestCase):
def test_latin1(self):
''' Testing with latin-1 for http://github.com/rtyler/py-yajl/issues/#issue/7 '''
- char = u'f\xe9in'
+ char = 'f\xe9in'
+ if not is_python3():
+ from tests import python2
+ char = python2.IssueSevenTest_latin1_char
# The `json` module uses "0123456789abcdef" for its code points
# while the yajl library uses "0123456789ABCDEF", lower()'ing
# to make sure the resulting strings match
@@ -218,23 +221,25 @@ def test_latin1(self):
self.assertEquals(out, '"\\"f\\\\u00e9in\\""')
out = yajl.loads(out)
- self.assertEquals(out, u'"f\\u00e9in"')
+ self.assertEquals(out, '"f\\u00e9in"')
out = yajl.loads(out)
self.assertEquals(out, char)
def test_chinese(self):
''' Testing with simplified chinese for http://github.com/rtyler/py-yajl/issues/#issue/7 '''
- char = u'早安, 爸爸' # Good morning!
- char = u'\u65e9\u5b89, \u7238\u7238'
+ char = '\u65e9\u5b89, \u7238\u7238'
+ if not is_python3():
+ from tests import python2
+ char = python2.IssueSevenTest_chinese_char
out = yajl.dumps(char).lower()
self.assertEquals(out, '"\\u65e9\\u5b89, \\u7238\\u7238"')
out = yajl.dumps(out).lower()
self.assertEquals(out, '"\\"\\\\u65e9\\\\u5b89, \\\\u7238\\\\u7238\\""')
out = yajl.loads(out)
- self.assertEquals(out, u'"\\u65e9\\u5b89, \\u7238\\u7238"')
+ self.assertEquals(out, '"\\u65e9\\u5b89, \\u7238\\u7238"')
out = yajl.loads(out)
self.assertEquals(out, char)

0 comments on commit 85a66ed

Please sign in to comment.