[pypy-commit] pypy py3.5: Adapt the test to py3.5

arigo pypy.commits at gmail.com
Sat Dec 10 09:15:38 EST 2016


Author: Armin Rigo <arigo at tunes.org>
Branch: py3.5
Changeset: r88994:e985a2343147
Date: 2016-12-10 15:14 +0100
http://bitbucket.org/pypy/pypy/changeset/e985a2343147/

Log:	Adapt the test to py3.5

diff --git a/pypy/interpreter/test/test_unicodehelper.py b/pypy/interpreter/test/test_unicodehelper.py
--- a/pypy/interpreter/test/test_unicodehelper.py
+++ b/pypy/interpreter/test/test_unicodehelper.py
@@ -1,26 +1,34 @@
+import py
 from pypy.interpreter.unicodehelper import encode_utf8, decode_utf8
 
+
+class Hit(Exception):
+    pass
+
 class FakeSpace:
-    pass
+    def __getattr__(self, name):
+        if name in ('w_UnicodeEncodeError', 'w_UnicodeDecodeError'):
+            raise Hit
+        raise AttributeError(name)
+
 
 def test_encode_utf8():
     space = FakeSpace()
     assert encode_utf8(space, u"abc") == "abc"
     assert encode_utf8(space, u"\u1234") == "\xe1\x88\xb4"
-    assert encode_utf8(space, u"\ud800") == "\xed\xa0\x80"
-    assert encode_utf8(space, u"\udc00") == "\xed\xb0\x80"
+    py.test.raises(Hit, encode_utf8, space, u"\ud800")
+    py.test.raises(Hit, encode_utf8, space, u"\udc00")
     # for the following test, go to lengths to avoid CPython's optimizer
     # and .pyc file storage, which collapse the two surrogates into one
     c = u"\udc00"
-    assert encode_utf8(space, u"\ud800" + c) == "\xf0\x90\x80\x80"
+    py.test.raises(Hit, encode_utf8, space, u"\ud800" + c)
 
 def test_decode_utf8():
     space = FakeSpace()
     assert decode_utf8(space, "abc") == u"abc"
     assert decode_utf8(space, "\xe1\x88\xb4") == u"\u1234"
-    assert decode_utf8(space, "\xed\xa0\x80") == u"\ud800"
-    assert decode_utf8(space, "\xed\xb0\x80") == u"\udc00"
-    got = decode_utf8(space, "\xed\xa0\x80\xed\xb0\x80")
-    assert map(ord, got) == [0xd800, 0xdc00]
+    py.test.raises(Hit, decode_utf8, space, "\xed\xa0\x80")
+    py.test.raises(Hit, decode_utf8, space, "\xed\xb0\x80")
+    py.test.raises(Hit, decode_utf8, space, "\xed\xa0\x80\xed\xb0\x80")
     got = decode_utf8(space, "\xf0\x90\x80\x80")
     assert map(ord, got) == [0x10000]


More information about the pypy-commit mailing list