Armin Rigo avatar Armin Rigo committed b0cec01

Test and fix.

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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.