Redefine the unichr and bytes-variant of chr at module level.

Needed to appease Travis; it's python 2.6 and 2.7 builds are weird and the `__builtins__` dict is not following CPython conventions.
This commit is contained in:
Martijn Pieters
2012-10-25 18:22:07 +02:00
parent 25f2806f23
commit a4be9a2578
+5 -2
View File
@@ -12,6 +12,11 @@ import requests.utils
from requests.compat import is_py3, bytes
if is_py3:
unichr = chr
chr = lambda c: bytes([c])
class GuessJSONUTFTests(unittest.TestCase):
"""Tests for the JSON UTF encoding guessing code."""
@@ -24,7 +29,6 @@ class GuessJSONUTFTests(unittest.TestCase):
def test_guess_encoding(self):
# Throw 4-character ASCII strings (encoded to a UTF encoding)
# at the guess routine; it should correctly guess all codecs.
unichr = chr if is_py3 else __builtins__.unichr
guess = requests.utils.guess_json_utf
for c in range(33, 127): # printable only
sample = unichr(c) * 4
@@ -36,7 +40,6 @@ class GuessJSONUTFTests(unittest.TestCase):
# Throw random 4-byte strings at the guess function.
# Any guess for a UTF encoding is verified, a decode exception
# is a test failure.
chr = (lambda c: bytes([c])) if is_py3 else __builtins__.chr
guess = requests.utils.guess_json_utf
for i in range(1000):
sample = bytes().join(