[pypy-svn] r5619 - in pypy/trunk/src/pypy/objspace/std: . test

mwh at codespeak.net mwh at codespeak.net
Thu Jul 22 18:22:46 CEST 2004


Author: mwh
Date: Thu Jul 22 18:22:45 2004
New Revision: 5619

Modified:
   pypy/trunk/src/pypy/objspace/std/dictobject.py
   pypy/trunk/src/pypy/objspace/std/test/test_dictobject.py
Log:
make dict(aDict) work (yes, that really is how CPython detects a mapping)
enable the tests of dict.__new__, adding one for above
delete some very dead, long since commented out, tests


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 Jul 22 18:22:45 2004
@@ -111,14 +111,20 @@
         pass
     elif len(args) == 1:
         # XXX do dict({...}) with dict_update__Dict_Dict()
-        list_of_w_pairs = space.unpackiterable(args[0])
-        for w_pair in list_of_w_pairs:
-            pair = space.unpackiterable(w_pair)
-            if len(pair)!=2:
-                raise OperationError(space.w_ValueError,
-                             space.wrap("dict() takes a sequence of pairs"))
-            w_k, w_v = pair
-            setitem__Dict_ANY_ANY(space, w_dict, w_k, w_v)
+        try:
+            space.getattr(args[0], space.wrap("keys"))
+        except OperationError:
+            list_of_w_pairs = space.unpackiterable(args[0])
+            for w_pair in list_of_w_pairs:
+                pair = space.unpackiterable(w_pair)
+                if len(pair)!=2:
+                    raise OperationError(space.w_ValueError,
+                                 space.wrap("dict() takes a sequence of pairs"))
+                w_k, w_v = pair
+                setitem__Dict_ANY_ANY(space, w_dict, w_k, w_v)
+        else:
+            from pypy.objspace.std.dicttype import dict_update__ANY_ANY
+            dict_update__ANY_ANY(space, w_dict, args[0])
     else:
         raise OperationError(space.w_TypeError,
                              space.wrap("dict() takes at most 1 argument"))

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 Jul 22 18:22:45 2004
@@ -47,50 +47,6 @@
         self.assertRaises_w(self.space.w_KeyError,
                             space.getitem,d,space.wrap('one'))
 
-##    def test_cell(self):
-##       space = self.space
-##       wk1 = space.wrap('key')
-##       d = W_DictObject(space, [])
-##       w_cell = d.cell(space,wk1)
-##       cell = space.unwrap(w_cell)
-##       self.failUnless(cell.is_empty())
-##       cell.set(space.wrap(1))
-##       self.assertEqual_w(space.getitem(d,wk1),space.wrap(1))
-##       wk2 = space.wrap('key2')
-##       space.setitem(d,wk2,space.wrap(2))
-##       cell = space.unwrap(d.cell(space,wk2))
-##       self.assertEqual_w(cell.get(),space.wrap(2))
-
-##    def test_empty_cell(self):
-##        space = self.space
-##        d = W_DictObject(space,
-##                         [(space.wrap('colour'), space.wrap(0)),
-##                          (space.wrap('of'),     space.wrap(2)),
-##                          (space.wrap('magic'),  space.wrap(1))])
-##        w_cell = d.cell(space, space.wrap('of'))
-##        d2 = W_DictObject(space,
-##                          [(space.wrap('colour'), space.wrap(0)),
-##                           (space.wrap('magic'),  space.wrap(1))])
-##        self.assertNotEqual_w(d, d2)
-##        space.delitem(d, space.wrap('of'))
-##        self.assertEqual_w(d, d2)
-
-##    def test_empty_cell2(self):
-##        space = self.space
-##        d = W_DictObject(space,
-##                         [(space.wrap('colour'), space.wrap(0)),
-##                          (space.wrap('of'),     space.wrap(2)),
-##                          (space.wrap('magic'),  space.wrap(1))])
-##        w_cell = d.cell(space, space.wrap('of'))
-##        d2 = W_DictObject(space,
-##                          [(space.wrap('colour'), space.wrap(0)),
-##                           (space.wrap('magic'),  space.wrap(1))])
-##        self.assertNotEqual_w(d, d2)
-##        cell = space.unwrap(w_cell)
-##        cell.make_empty()
-##        self.assertEqual_w(d, d2)
-
-
     def test_wrap_dict(self):
         self.assert_(isinstance(self.space.wrap({}), W_DictObject))
 
@@ -320,7 +276,7 @@
         self.assertEqual("{'ba': 'bo'}", repr({'ba': 'bo'}))
         self.assert_(str({1: 2, 'ba': 'bo'}) in ok_reprs)
         
-    def tooslow_test_new(self):
+    def test_new(self):
         d = dict()
         self.assertEqual(d, {})
         args = [['a',2], [23,45]]
@@ -330,6 +286,8 @@
         self.assertEqual(d, {'a':33, 'b':44, 23:45})
         d = dict(a=33, b=44)
         self.assertEqual(d, {'a':33, 'b':44})
+        d = dict({'a':33, 'b':44})
+        self.assertEqual(d, {'a':33, 'b':44})        
         try: d = dict(23)
         except (TypeError, ValueError): pass
         else: self.fail("dict(23) should raise!")



More information about the Pypy-commit mailing list