Author: Armin Rigo <[email protected]>
Branch:
Changeset: r50214:b0cec017f8a9
Date: 2011-12-06 17:44 +0100
http://bitbucket.org/pypy/pypy/changeset/b0cec017f8a9/
Log: Test and fix.
diff --git a/lib_pypy/_collections.py b/lib_pypy/_collections.py
--- a/lib_pypy/_collections.py
+++ b/lib_pypy/_collections.py
@@ -406,7 +406,7 @@
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()
diff --git a/pypy/module/_collections/app_defaultdict.py
b/pypy/module/_collections/app_defaultdict.py
--- a/pypy/module/_collections/app_defaultdict.py
+++ b/pypy/module/_collections/app_defaultdict.py
@@ -38,7 +38,7 @@
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()
diff --git a/pypy/module/_collections/test/test_defaultdict.py
b/pypy/module/_collections/test/test_defaultdict.py
--- a/pypy/module/_collections/test/test_defaultdict.py
+++ b/pypy/module/_collections/test/test_defaultdict.py
@@ -38,3 +38,22 @@
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
diff --git a/pypy/module/test_lib_pypy/test_collections.py
b/pypy/module/test_lib_pypy/test_collections.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/test_lib_pypy/test_collections.py
@@ -0,0 +1,27 @@
+
+"""
+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
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit