From: Martijn Pieters Date: Thu, 25 Oct 2012 16:22:07 +0000 (+0200) Subject: Redefine the `unichr` and bytes-variant of `chr` at module level. X-Git-Tag: v0.14.2~2^2~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a4be9a2578dcb8f0862cc80f1e37243edfc04bd7;p=services%2Fpython-requests.git 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. --- diff --git a/tests/test_utils.py b/tests/test_utils.py index dabb579..1122fb3 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -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(