[pypy-dev] testfailure on test_unicode.py in trivial object space
Roeland Rengelink
roeland.rengelink at chello.nl
Wed Aug 11 18:51:13 MEST 2004
Hi,
I just checked out the source code and ran the unittest as per
instructions on
http://codespeak.net/pypy/index.cgi?source
i.e.
python pypy/pypy/testall.py
(Note that there is a typo in the filename there (should be
test_all.py), and that this runs the tests in trivial objectspace.)
There is a test failure in
objspace/std/test/test_unicodestring.py
which is reproduced by
python py.py -T
PyPy in TrivialObjSpace on top of Python 2.3.3
>>>> u'a' == 'a'
||Traceback (interpreter-level):
...
Traceback (application-level):
File "<inline>", line 1 in ?
'a' == u'a'
(application-level) TypeError: unicode.__cmp__(x,y) requires y to be a
'unicode', not a 'str'
This works correctly in standard object space.
As far as I can tell pypy -T tries u'a'.__cmp__('a'), which raises the
exception, while CPython ends up doing 'a'.__eq__(str(u'a'))
I do think that pypy approaches this more rationally in standard object
space (i.e., implementing __eq__ and __lt__ for unicode, rather than
__cmp__, as CPython does). So it's probably a good idea to accept the
exception in trivila object space, rather than trying to emulate the
convoluted rules for comparison in CPython.
It would probably be a good idea to skip the test in trivial object
space (see patch).
Cheers,
Roeland Rengelink
Index: test_unicodestring.py
===================================================================
--- test_unicodestring.py (revision 5925)
+++ test_unicodestring.py (working copy)
@@ -5,13 +5,17 @@
from pypy.tool import testit
-class TestUnicodeString(testit.AppTestCase):
+class TestUnicodeStringStdOnly(testit.AppTestCase):
+ def setUp(self):
+ self.space = testit.objspace('std')
+
def test_compares(self):
self.assertEqual(u'a', 'a')
self.assertEqual('a', u'a')
self.assertNotEqual(u'a', 'b')
self.assertNotEqual('a', u'b')
+class TestUnicodeString(testit.AppTestCase):
def test_addition(self):
def check(a, b):
self.assertEqual(a, b)
More information about the pypy-dev
mailing list