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

cfbolz at codespeak.net cfbolz at codespeak.net
Sat Oct 17 02:12:03 CEST 2009


Author: cfbolz
Date: Sat Oct 17 02:12:03 2009
New Revision: 68564

Modified:
   pypy/trunk/pypy/objspace/std/setobject.py
   pypy/trunk/pypy/objspace/std/test/test_setobject.py
Log:
Add a test for .copy(). I don't see a reason to use the typedef in those
multimethod implementations.


Modified: pypy/trunk/pypy/objspace/std/setobject.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/setobject.py	(original)
+++ pypy/trunk/pypy/objspace/std/setobject.py	Sat Oct 17 02:12:03 2009
@@ -4,8 +4,6 @@
 from pypy.rlib.rarithmetic import intmask, r_uint
 from pypy.interpreter import gateway
 from pypy.interpreter.argument import Signature
-from pypy.objspace.std.settype import set_typedef as settypedef
-from pypy.objspace.std.frozensettype import frozenset_typedef as frozensettypedef
 
 class W_BaseSetObject(W_Object):
 
@@ -582,14 +580,14 @@
 
 iter__Frozenset = iter__Set
 
-def cmp__Set_settypedef(space, w_left, w_other):
+def cmp__Set_Set(space, w_left, w_other):
     # hack hack until we get the expected result
     raise OperationError(space.w_TypeError,
             space.wrap('cannot compare sets using cmp()'))
 
-cmp__Set_frozensettypedef = cmp__Set_settypedef
-cmp__Frozenset_settypedef = cmp__Set_settypedef
-cmp__Frozenset_frozensettypedef = cmp__Set_settypedef
+cmp__Set_Frozenset = cmp__Set_Set
+cmp__Frozenset_Set = cmp__Set_Set
+cmp__Frozenset_Frozenset = cmp__Set_Set
 
 init_signature = Signature(['some_iterable'], None, None)
 init_defaults = [None]

Modified: pypy/trunk/pypy/objspace/std/test/test_setobject.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/test/test_setobject.py	(original)
+++ pypy/trunk/pypy/objspace/std/test/test_setobject.py	Sat Oct 17 02:12:03 2009
@@ -90,6 +90,30 @@
         assert (frozenset('abc') != frozenset('abcd'))
         assert (frozenset('abc') != set('abcd'))
 
+    def test_copy(self):
+        s1 = set('abc')
+        s2 = s1.copy()
+        assert s1 is not s2
+        assert s1 == s2
+        assert type(s2) is set
+        s1 = frozenset('abc')
+        s2 = s1.copy()
+        assert s1 is s2
+        assert s1 == s2
+        class myfrozen(frozenset):
+            pass
+        s1 = myfrozen('abc')
+        s2 = s1.copy()
+        assert s1 is not s2
+        assert s1 == s2
+        assert type(s2) is myfrozen
+        class myfrozen(frozenset):
+            def __new__(cls):
+                return frozenset.__new__(cls, 'abc')
+        s1 = myfrozen()
+        raises(TypeError, s1.copy)
+
+
     def test_recursive_repr(self):
         class A(object):
             def __init__(self, s):



More information about the Pypy-commit mailing list