Commits

Armin Rigo committed b0cec01

Test and fix.

  • Participants
  • Parent commits f602348

Comments (0)

Files changed (4)

lib_pypy/_collections.py

             recurse.remove(id(self))
 
     def copy(self):
-        return type(self)(self, default_factory=self.default_factory)
+        return type(self)(self.default_factory, self)
     
     def __copy__(self):
         return self.copy()

pypy/module/_collections/app_defaultdict.py

             recurse.remove(id(self))
 
     def copy(self):
-        return type(self)(self, default_factory=self.default_factory)
+        return type(self)(self.default_factory, self)
     
     def __copy__(self):
         return self.copy()

pypy/module/_collections/test/test_defaultdict.py

         from _collections import defaultdict
         d = defaultdict(default_factory=5)
         assert d.keys() == ['default_factory']
+
+    def test_copy(self):
+        import _collections
+        def f():
+            return 42
+        d = _collections.defaultdict(f, {2: 3})
+        #
+        d1 = d.copy()
+        assert type(d1) is _collections.defaultdict
+        assert len(d1) == 1
+        assert d1[2] == 3
+        assert d1[3] == 42
+        #
+        import copy
+        d2 = copy.deepcopy(d)
+        assert type(d2) is _collections.defaultdict
+        assert len(d2) == 1
+        assert d2[2] == 3
+        assert d2[3] == 42

pypy/module/test_lib_pypy/test_collections.py

+
+"""
+Extra tests for the pure Python PyPy _collections module
+(not used in normal PyPy's)
+"""
+
+from pypy.conftest import gettestobjspace
+
+class AppTestcStringIO:
+    def test_copy(self):
+        import _collections
+        def f():
+            return 42
+        d = _collections.defaultdict(f, {2: 3})
+        #
+        d1 = d.copy()
+        assert type(d1) is _collections.defaultdict
+        assert len(d1) == 1
+        assert d1[2] == 3
+        assert d1[3] == 42
+        #
+        import copy
+        d2 = copy.deepcopy(d)
+        assert type(d2) is _collections.defaultdict
+        assert len(d2) == 1
+        assert d2[2] == 3
+        assert d2[3] == 42