[Python-checkins] python/dist/src/Lib/test test_copy.py,1.2,1.3
gvanrossum@users.sourceforge.net
gvanrossum@users.sourceforge.net
Thu, 06 Feb 2003 11:53:24 -0800
Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1:/tmp/cvs-serv15843/test
Modified Files:
test_copy.py
Log Message:
Support all the new stuff supported by the new pickle code:
- subclasses of list or dict
- __reduce__ returning a 4-tuple or 5-tuple
- slots
Index: test_copy.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_copy.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** test_copy.py 6 Feb 2003 18:18:23 -0000 1.2
--- test_copy.py 6 Feb 2003 19:53:22 -0000 1.3
***************
*** 42,50 ****
def test_copy_cant(self):
! class C(object):
def __getattribute__(self, name):
if name == "__reduce__":
raise AttributeError, name
return object.__getattribute__(self, name)
x = C()
self.assertRaises(copy.Error, copy.copy, x)
--- 42,52 ----
def test_copy_cant(self):
! class Meta(type):
def __getattribute__(self, name):
if name == "__reduce__":
raise AttributeError, name
return object.__getattribute__(self, name)
+ class C:
+ __metaclass__ = Meta
x = C()
self.assertRaises(copy.Error, copy.copy, x)
***************
*** 190,198 ****
def test_deepcopy_cant(self):
! class C(object):
def __getattribute__(self, name):
if name == "__reduce__":
raise AttributeError, name
return object.__getattribute__(self, name)
x = C()
self.assertRaises(copy.Error, copy.deepcopy, x)
--- 192,202 ----
def test_deepcopy_cant(self):
! class Meta(type):
def __getattribute__(self, name):
if name == "__reduce__":
raise AttributeError, name
return object.__getattribute__(self, name)
+ class C:
+ __metaclass__ = Meta
x = C()
self.assertRaises(copy.Error, copy.deepcopy, x)
***************
*** 411,414 ****
--- 415,457 ----
self.assert_(x is not y)
self.assert_(x["foo"] is not y["foo"])
+
+ def test_copy_slots(self):
+ class C(object):
+ __slots__ = ["foo"]
+ x = C()
+ x.foo = [42]
+ y = copy.copy(x)
+ self.assert_(x.foo is y.foo)
+
+ def test_deepcopy_slots(self):
+ class C(object):
+ __slots__ = ["foo"]
+ x = C()
+ x.foo = [42]
+ y = copy.deepcopy(x)
+ self.assertEqual(x.foo, y.foo)
+ self.assert_(x.foo is not y.foo)
+
+ def test_copy_list_subclass(self):
+ class C(list):
+ pass
+ x = C([[1, 2], 3])
+ x.foo = [4, 5]
+ y = copy.copy(x)
+ self.assertEqual(list(x), list(y))
+ self.assertEqual(x.foo, y.foo)
+ self.assert_(x[0] is y[0])
+ self.assert_(x.foo is y.foo)
+
+ def test_deepcopy_list_subclass(self):
+ class C(list):
+ pass
+ x = C([[1, 2], 3])
+ x.foo = [4, 5]
+ y = copy.deepcopy(x)
+ self.assertEqual(list(x), list(y))
+ self.assertEqual(x.foo, y.foo)
+ self.assert_(x[0] is not y[0])
+ self.assert_(x.foo is not y.foo)
def test_main():