[pypy-svn] rev 641 - in pypy/trunk/src/pypy/objspace/std: . test
mwh at codespeak.net
mwh at codespeak.net
Thu May 29 11:26:06 CEST 2003
Author: mwh
Date: Thu May 29 11:26:06 2003
New Revision: 641
Modified:
pypy/trunk/src/pypy/objspace/std/dictobject.py
pypy/trunk/src/pypy/objspace/std/test/test_dictobject.py
Log:
beef up tests of eq_dict_dict; fix bugs thus revealed
Modified: pypy/trunk/src/pypy/objspace/std/dictobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/dictobject.py (original)
+++ pypy/trunk/src/pypy/objspace/std/dictobject.py Thu May 29 11:26:06 2003
@@ -24,6 +24,11 @@
def is_empty(self):
return self.w_value is _NoValueInCell
+
+ def __repr__(self):
+ """ representation for debugging purposes """
+ return "%s(%s)" % (self.__class__.__name__, self.w_value)
+
class W_DictObject(W_Object):
@@ -146,15 +151,15 @@
def eq_dict_dict(space, w_left, w_right):
if len(w_left.data) != len(w_right.data):
- return self.newbool(0)
+ return space.newbool(0)
for w_k, cell in w_left.data:
try:
w_v = space.getitem(w_right, w_k)
except OperationError:
- return self.newbool(0)
+ return space.newbool(0)
r = space.is_true(space.eq(cell.w_value, w_v))
if not r:
- return r
+ return space.newbool(r)
return space.newbool(1)
Modified: pypy/trunk/src/pypy/objspace/std/test/test_dictobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/test/test_dictobject.py (original)
+++ pypy/trunk/src/pypy/objspace/std/test/test_dictobject.py Thu May 29 11:26:06 2003
@@ -1,11 +1,10 @@
-import unittest, sys
+import sys
import testsupport
-from pypy.interpreter import unittest_w
from pypy.objspace.std import dictobject as dobj
from pypy.objspace.std.objspace import *
-class TestW_DictObject(unittest_w.TestCase_w):
+class TestW_DictObject(testsupport.TestCase):
def setUp(self):
self.space = StdObjSpace()
@@ -61,8 +60,25 @@
space.setitem(d,wk2,space.wrap(2))
cell = space.unwrap(d.cell(space,wk2))
self.assertEqual_w(cell.get(),space.wrap(2))
-
-
+
+ def test_wrap_dict(self):
+ self.assert_(isinstance(self.space.wrap({}), dobj.W_DictObject))
+
+
+ def test_dict_compare(self):
+ w = self.space.wrap
+ w0, w1, w2, w3 = map(w, range(4))
+ wd1 = self.space.newdict([(w0, w1), (w2, w3)])
+ wd2 = self.space.newdict([(w2, w3), (w0, w1)])
+ self.assertEqual_w(wd1, wd2)
+ wd3 = self.space.newdict([(w2, w2), (w0, w1)])
+ self.assertNotEqual_w(wd1, wd3)
+ wd4 = self.space.newdict([(w3, w3), (w0, w1)])
+ self.assertNotEqual_w(wd1, wd4)
+ wd5 = self.space.newdict([(w3, w3)])
+ self.assertNotEqual_w(wd1, wd4)
+
+
if __name__ == '__main__':
- unittest.main()
+ testsupport.main()
More information about the Pypy-commit
mailing list