Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
test.test_copy.TestCopy Class Reference

List of all members.

Public Member Functions

def test_exceptions
def test_copy_basic
def test_copy_copy
def test_copy_registry
def test_copy_reduce_ex
def test_copy_reduce
def test_copy_cant
def test_copy_atomic
def test_copy_list
def test_copy_tuple
def test_copy_dict
def test_copy_inst_vanilla
def test_copy_inst_copy
def test_copy_inst_getinitargs
def test_copy_inst_getstate
def test_copy_inst_setstate
def test_copy_inst_getstate_setstate
def test_deepcopy_basic
def test_deepcopy_memo
def test_deepcopy_issubclass
def test_deepcopy_deepcopy
def test_deepcopy_registry
def test_deepcopy_reduce_ex
def test_deepcopy_reduce
def test_deepcopy_cant
def test_deepcopy_atomic
def test_deepcopy_list
def test_deepcopy_reflexive_list
def test_deepcopy_tuple
def test_deepcopy_reflexive_tuple
def test_deepcopy_dict
def test_deepcopy_reflexive_dict
def test_deepcopy_keepalive
def test_deepcopy_inst_vanilla
def test_deepcopy_inst_deepcopy
def test_deepcopy_inst_getinitargs
def test_deepcopy_inst_getstate
def test_deepcopy_inst_setstate
def test_deepcopy_inst_getstate_setstate
def test_deepcopy_reflexive_inst
def test_reconstruct_string
def test_reconstruct_nostate
def test_reconstruct_state
def test_reconstruct_state_setstate
def test_reconstruct_reflexive
def test_reduce_4tuple
def test_reduce_5tuple
def test_copy_slots
def test_deepcopy_slots
def test_deepcopy_dict_subclass
def test_copy_list_subclass
def test_deepcopy_list_subclass
def test_copy_tuple_subclass
def test_deepcopy_tuple_subclass
def test_getstate_exc
def test_copy_function
def test_deepcopy_function
def test_copy_weakref
def test_deepcopy_weakref
def test_copy_weakkeydict
def test_copy_weakvaluedict
def test_deepcopy_weakkeydict
def test_deepcopy_weakvaluedict
def test_deepcopy_bound_method

Public Attributes

 foo
 i

Private Member Functions

def _check_weakref
def _check_copy_weakdict

Private Attributes

 __dict__
 _keys

Detailed Description

Definition at line 15 of file test_copy.py.


Member Function Documentation

def test.test_copy.TestCopy._check_copy_weakdict (   self,
  _dicttype 
) [private]

Definition at line 632 of file test_copy.py.

00632 
00633     def _check_copy_weakdict(self, _dicttype):
00634         class C(object):
00635             pass
00636         a, b, c, d = [C() for i in range(4)]
00637         u = _dicttype()
00638         u[a] = b
00639         u[c] = d
00640         v = copy.copy(u)
00641         self.assertFalse(v is u)
00642         self.assertEqual(v, u)
00643         self.assertEqual(v[a], b)
00644         self.assertEqual(v[c], d)
00645         self.assertEqual(len(v), 2)
00646         del c, d
00647         self.assertEqual(len(v), 1)
00648         x, y = C(), C()
00649         # The underlying containers are decoupled
00650         v[x] = y
00651         self.assertNotIn(x, u)

Here is the caller graph for this function:

def test.test_copy.TestCopy._check_weakref (   self,
  _copy 
) [private]

Definition at line 615 of file test_copy.py.

00615 
00616     def _check_weakref(self, _copy):
00617         class C(object):
00618             pass
00619         obj = C()
00620         x = weakref.ref(obj)
00621         y = _copy(x)
00622         self.assertTrue(y is x)
00623         del obj
00624         y = _copy(x)
00625         self.assertTrue(y is x)

Here is the caller graph for this function:

Definition at line 83 of file test_copy.py.

00083 
00084     def test_copy_atomic(self):
00085         class Classic:
00086             pass
00087         class NewStyle(object):
00088             pass
00089         def f():
00090             pass
00091         tests = [None, 42, 2**100, 3.14, True, False, 1j,
00092                  "hello", "hello\u1234", f.__code__,
00093                  NewStyle, range(10), Classic, max]
00094         for x in tests:
00095             self.assertTrue(copy.copy(x) is x, repr(x))

Definition at line 25 of file test_copy.py.

00025 
00026     def test_copy_basic(self):
00027         x = 42
00028         y = copy.copy(x)
00029         self.assertEqual(x, y)

Here is the call graph for this function:

Definition at line 72 of file test_copy.py.

00072 
00073     def test_copy_cant(self):
00074         class C(object):
00075             def __getattribute__(self, name):
00076                 if name.startswith("__reduce"):
00077                     raise AttributeError(name)
00078                 return object.__getattribute__(self, name)
00079         x = C()
00080         self.assertRaises(copy.Error, copy.copy, x)

Here is the call graph for this function:

Definition at line 30 of file test_copy.py.

00030 
00031     def test_copy_copy(self):
00032         class C(object):
00033             def __init__(self, foo):
00034                 self.foo = foo
00035             def __copy__(self):
00036                 return C(self.foo)
00037         x = C(42)
00038         y = copy.copy(x)
00039         self.assertEqual(y.__class__, x.__class__)
00040         self.assertEqual(y.foo, x.foo)

Here is the call graph for this function:

Definition at line 104 of file test_copy.py.

00104 
00105     def test_copy_dict(self):
00106         x = {"foo": 1, "bar": 2}
00107         self.assertEqual(copy.copy(x), x)

Here is the call graph for this function:

Definition at line 601 of file test_copy.py.

00601 
00602     def test_copy_function(self):
00603         self.assertEqual(copy.copy(global_foo), global_foo)
00604         def foo(x, y): return x+y
00605         self.assertEqual(copy.copy(foo), foo)
00606         bar = lambda: None
00607         self.assertEqual(copy.copy(bar), bar)

Here is the call graph for this function:

Definition at line 117 of file test_copy.py.

00117 
00118     def test_copy_inst_copy(self):
00119         class C:
00120             def __init__(self, foo):
00121                 self.foo = foo
00122             def __copy__(self):
00123                 return C(self.foo)
00124             def __eq__(self, other):
00125                 return self.foo == other.foo
00126         x = C(42)
00127         self.assertEqual(copy.copy(x), x)

Here is the call graph for this function:

Definition at line 128 of file test_copy.py.

00128 
00129     def test_copy_inst_getinitargs(self):
00130         class C:
00131             def __init__(self, foo):
00132                 self.foo = foo
00133             def __getinitargs__(self):
00134                 return (self.foo,)
00135             def __eq__(self, other):
00136                 return self.foo == other.foo
00137         x = C(42)
00138         self.assertEqual(copy.copy(x), x)

Here is the call graph for this function:

Definition at line 139 of file test_copy.py.

00139 
00140     def test_copy_inst_getstate(self):
00141         class C:
00142             def __init__(self, foo):
00143                 self.foo = foo
00144             def __getstate__(self):
00145                 return {"foo": self.foo}
00146             def __eq__(self, other):
00147                 return self.foo == other.foo
00148         x = C(42)
00149         self.assertEqual(copy.copy(x), x)

Here is the call graph for this function:

Definition at line 161 of file test_copy.py.

00161 
00162     def test_copy_inst_getstate_setstate(self):
00163         class C:
00164             def __init__(self, foo):
00165                 self.foo = foo
00166             def __getstate__(self):
00167                 return self.foo
00168             def __setstate__(self, state):
00169                 self.foo = state
00170             def __eq__(self, other):
00171                 return self.foo == other.foo
00172         x = C(42)
00173         self.assertEqual(copy.copy(x), x)

Here is the call graph for this function:

Definition at line 150 of file test_copy.py.

00150 
00151     def test_copy_inst_setstate(self):
00152         class C:
00153             def __init__(self, foo):
00154                 self.foo = foo
00155             def __setstate__(self, state):
00156                 self.foo = state["foo"]
00157             def __eq__(self, other):
00158                 return self.foo == other.foo
00159         x = C(42)
00160         self.assertEqual(copy.copy(x), x)

Here is the call graph for this function:

Definition at line 108 of file test_copy.py.

00108 
00109     def test_copy_inst_vanilla(self):
00110         class C:
00111             def __init__(self, foo):
00112                 self.foo = foo
00113             def __eq__(self, other):
00114                 return self.foo == other.foo
00115         x = C(42)
00116         self.assertEqual(copy.copy(x), x)

Here is the call graph for this function:

Definition at line 96 of file test_copy.py.

00096 
00097     def test_copy_list(self):
00098         x = [1, 2, 3]
00099         self.assertEqual(copy.copy(x), x)

Here is the call graph for this function:

Definition at line 555 of file test_copy.py.

00555 
00556     def test_copy_list_subclass(self):
00557         class C(list):
00558             pass
00559         x = C([[1, 2], 3])
00560         x.foo = [4, 5]
00561         y = copy.copy(x)
00562         self.assertEqual(list(x), list(y))
00563         self.assertEqual(x.foo, y.foo)
00564         self.assertTrue(x[0] is y[0])
00565         self.assertTrue(x.foo is y.foo)

Definition at line 64 of file test_copy.py.

00064 
00065     def test_copy_reduce(self):
00066         class C(object):
00067             def __reduce__(self):
00068                 return ""
00069         x = C()
00070         y = copy.copy(x)
00071         self.assertTrue(y is x)

Here is the call graph for this function:

Definition at line 54 of file test_copy.py.

00054 
00055     def test_copy_reduce_ex(self):
00056         class C(object):
00057             def __reduce_ex__(self, proto):
00058                 return ""
00059             def __reduce__(self):
00060                 raise support.TestFailed("shouldn't call this")
00061         x = C()
00062         y = copy.copy(x)
00063         self.assertTrue(y is x)

Here is the call graph for this function:

Definition at line 41 of file test_copy.py.

00041 
00042     def test_copy_registry(self):
00043         class C(object):
00044             def __new__(cls, foo):
00045                 obj = object.__new__(cls)
00046                 obj.foo = foo
00047                 return obj
00048         def pickle_C(obj):
00049             return (C, (obj.foo,))
00050         x = C(42)
00051         self.assertRaises(TypeError, copy.copy, x)
00052         copyreg.pickle(C, pickle_C, C)
00053         y = copy.copy(x)

Here is the call graph for this function:

Definition at line 518 of file test_copy.py.

00518 
00519     def test_copy_slots(self):
00520         class C(object):
00521             __slots__ = ["foo"]
00522         x = C()
00523         x.foo = [42]
00524         y = copy.copy(x)
00525         self.assertTrue(x.foo is y.foo)

Here is the call graph for this function:

Definition at line 100 of file test_copy.py.

00100 
00101     def test_copy_tuple(self):
00102         x = (1, 2, 3)
00103         self.assertEqual(copy.copy(x), x)

Here is the call graph for this function:

Definition at line 577 of file test_copy.py.

00577 
00578     def test_copy_tuple_subclass(self):
00579         class C(tuple):
00580             pass
00581         x = C([1, 2, 3])
00582         self.assertEqual(tuple(x), (1, 2, 3))
00583         y = copy.copy(x)
00584         self.assertEqual(tuple(y), (1, 2, 3))

Definition at line 652 of file test_copy.py.

Here is the call graph for this function:

Definition at line 626 of file test_copy.py.

00626 
00627     def test_copy_weakref(self):
00628         self._check_weakref(copy.copy)

Here is the call graph for this function:

Definition at line 655 of file test_copy.py.

Here is the call graph for this function:

Definition at line 256 of file test_copy.py.

00256 
00257     def test_deepcopy_atomic(self):
00258         class Classic:
00259             pass
00260         class NewStyle(object):
00261             pass
00262         def f():
00263             pass
00264         tests = [None, 42, 2**100, 3.14, True, False, 1j,
00265                  "hello", "hello\u1234", f.__code__,
00266                  NewStyle, range(10), Classic, max]
00267         for x in tests:
00268             self.assertTrue(copy.deepcopy(x) is x, repr(x))

Definition at line 176 of file test_copy.py.

00176 
00177     def test_deepcopy_basic(self):
00178         x = 42
00179         y = copy.deepcopy(x)
00180         self.assertEqual(y, x)

Here is the call graph for this function:

Definition at line 700 of file test_copy.py.

00700 
00701     def test_deepcopy_bound_method(self):
00702         class Foo(object):
00703             def m(self):
00704                 pass
00705         f = Foo()
00706         f.b = f.m
00707         g = copy.deepcopy(f)
00708         self.assertEqual(g.m, g.b)
00709         self.assertTrue(g.b.__self__ is g)
00710         g.b()
00711 

Definition at line 245 of file test_copy.py.

00245 
00246     def test_deepcopy_cant(self):
00247         class C(object):
00248             def __getattribute__(self, name):
00249                 if name.startswith("__reduce"):
00250                     raise AttributeError(name)
00251                 return object.__getattribute__(self, name)
00252         x = C()
00253         self.assertRaises(copy.Error, copy.deepcopy, x)

Here is the call graph for this function:

Definition at line 203 of file test_copy.py.

00203 
00204     def test_deepcopy_deepcopy(self):
00205         class C(object):
00206             def __init__(self, foo):
00207                 self.foo = foo
00208             def __deepcopy__(self, memo=None):
00209                 return C(self.foo)
00210         x = C(42)
00211         y = copy.deepcopy(x)
00212         self.assertEqual(y.__class__, x.__class__)
00213         self.assertEqual(y.foo, x.foo)

Here is the call graph for this function:

Definition at line 303 of file test_copy.py.

00303 
00304     def test_deepcopy_dict(self):
00305         x = {"foo": [1, 2], "bar": 3}
00306         y = copy.deepcopy(x)
00307         self.assertEqual(y, x)
00308         self.assertTrue(x is not y)
00309         self.assertTrue(x["foo"] is not y["foo"])

Here is the call graph for this function:

Definition at line 535 of file test_copy.py.

00535 
00536     def test_deepcopy_dict_subclass(self):
00537         class C(dict):
00538             def __init__(self, d=None):
00539                 if not d:
00540                     d = {}
00541                 self._keys = list(d.keys())
00542                 super().__init__(d)
00543             def __setitem__(self, key, item):
00544                 super().__setitem__(key, item)
00545                 if key not in self._keys:
00546                     self._keys.append(key)
00547         x = C(d={'foo':0})
00548         y = copy.deepcopy(x)
00549         self.assertEqual(x, y)
00550         self.assertEqual(x._keys, y._keys)
00551         self.assertTrue(x is not y)
00552         x['bar'] = 1
00553         self.assertNotEqual(x, y)
00554         self.assertNotEqual(x._keys, y._keys)

Here is the call graph for this function:

Definition at line 608 of file test_copy.py.

00608 
00609     def test_deepcopy_function(self):
00610         self.assertEqual(copy.deepcopy(global_foo), global_foo)
00611         def foo(x, y): return x+y
00612         self.assertEqual(copy.deepcopy(foo), foo)
00613         bar = lambda: None
00614         self.assertEqual(copy.deepcopy(bar), bar)

Here is the call graph for this function:

Definition at line 339 of file test_copy.py.

00339 
00340     def test_deepcopy_inst_deepcopy(self):
00341         class C:
00342             def __init__(self, foo):
00343                 self.foo = foo
00344             def __deepcopy__(self, memo):
00345                 return C(copy.deepcopy(self.foo, memo))
00346             def __eq__(self, other):
00347                 return self.foo == other.foo
00348         x = C([42])
00349         y = copy.deepcopy(x)
00350         self.assertEqual(y, x)
00351         self.assertTrue(y is not x)
00352         self.assertTrue(y.foo is not x.foo)

Here is the call graph for this function:

Definition at line 353 of file test_copy.py.

00353 
00354     def test_deepcopy_inst_getinitargs(self):
00355         class C:
00356             def __init__(self, foo):
00357                 self.foo = foo
00358             def __getinitargs__(self):
00359                 return (self.foo,)
00360             def __eq__(self, other):
00361                 return self.foo == other.foo
00362         x = C([42])
00363         y = copy.deepcopy(x)
00364         self.assertEqual(y, x)
00365         self.assertTrue(y is not x)
00366         self.assertTrue(y.foo is not x.foo)

Here is the call graph for this function:

Definition at line 367 of file test_copy.py.

00367 
00368     def test_deepcopy_inst_getstate(self):
00369         class C:
00370             def __init__(self, foo):
00371                 self.foo = foo
00372             def __getstate__(self):
00373                 return {"foo": self.foo}
00374             def __eq__(self, other):
00375                 return self.foo == other.foo
00376         x = C([42])
00377         y = copy.deepcopy(x)
00378         self.assertEqual(y, x)
00379         self.assertTrue(y is not x)
00380         self.assertTrue(y.foo is not x.foo)

Here is the call graph for this function:

Definition at line 395 of file test_copy.py.

00395 
00396     def test_deepcopy_inst_getstate_setstate(self):
00397         class C:
00398             def __init__(self, foo):
00399                 self.foo = foo
00400             def __getstate__(self):
00401                 return self.foo
00402             def __setstate__(self, state):
00403                 self.foo = state
00404             def __eq__(self, other):
00405                 return self.foo == other.foo
00406         x = C([42])
00407         y = copy.deepcopy(x)
00408         self.assertEqual(y, x)
00409         self.assertTrue(y is not x)
00410         self.assertTrue(y.foo is not x.foo)

Here is the call graph for this function:

Definition at line 381 of file test_copy.py.

00381 
00382     def test_deepcopy_inst_setstate(self):
00383         class C:
00384             def __init__(self, foo):
00385                 self.foo = foo
00386             def __setstate__(self, state):
00387                 self.foo = state["foo"]
00388             def __eq__(self, other):
00389                 return self.foo == other.foo
00390         x = C([42])
00391         y = copy.deepcopy(x)
00392         self.assertEqual(y, x)
00393         self.assertTrue(y is not x)
00394         self.assertTrue(y.foo is not x.foo)

Here is the call graph for this function:

Definition at line 328 of file test_copy.py.

00328 
00329     def test_deepcopy_inst_vanilla(self):
00330         class C:
00331             def __init__(self, foo):
00332                 self.foo = foo
00333             def __eq__(self, other):
00334                 return self.foo == other.foo
00335         x = C([42])
00336         y = copy.deepcopy(x)
00337         self.assertEqual(y, x)
00338         self.assertTrue(y.foo is not x.foo)

Here is the call graph for this function:

Definition at line 192 of file test_copy.py.

00192 
00193     def test_deepcopy_issubclass(self):
00194         # XXX Note: there's no way to test the TypeError coming out of
00195         # issubclass() -- this can only happen when an extension
00196         # module defines a "type" that doesn't formally inherit from
00197         # type.
00198         class Meta(type):
00199             pass
00200         class C(metaclass=Meta):
00201             pass
00202         self.assertEqual(copy.deepcopy(C), C)

Definition at line 322 of file test_copy.py.

00322 
00323     def test_deepcopy_keepalive(self):
00324         memo = {}
00325         x = 42
00326         y = copy.deepcopy(x, memo)
00327         self.assertTrue(memo[id(x)] is x)

Here is the call graph for this function:

Definition at line 269 of file test_copy.py.

00269 
00270     def test_deepcopy_list(self):
00271         x = [[1, 2], 3]
00272         y = copy.deepcopy(x)
00273         self.assertEqual(y, x)
00274         self.assertTrue(x is not y)
00275         self.assertTrue(x[0] is not y[0])

Here is the call graph for this function:

Definition at line 566 of file test_copy.py.

00566 
00567     def test_deepcopy_list_subclass(self):
00568         class C(list):
00569             pass
00570         x = C([[1, 2], 3])
00571         x.foo = [4, 5]
00572         y = copy.deepcopy(x)
00573         self.assertEqual(list(x), list(y))
00574         self.assertEqual(x.foo, y.foo)
00575         self.assertTrue(x[0] is not y[0])
00576         self.assertTrue(x.foo is not y.foo)

Definition at line 181 of file test_copy.py.

00181 
00182     def test_deepcopy_memo(self):
00183         # Tests of reflexive objects are under type-specific sections below.
00184         # This tests only repetitions of objects.
00185         x = []
00186         x = [x, x]
00187         y = copy.deepcopy(x)
00188         self.assertEqual(y, x)
00189         self.assertTrue(y is not x)
00190         self.assertTrue(y[0] is not x[0])
00191         self.assertTrue(y[0] is y[1])

Here is the call graph for this function:

Definition at line 237 of file test_copy.py.

00237 
00238     def test_deepcopy_reduce(self):
00239         class C(object):
00240             def __reduce__(self):
00241                 return ""
00242         x = C()
00243         y = copy.deepcopy(x)
00244         self.assertTrue(y is x)

Here is the call graph for this function:

Definition at line 227 of file test_copy.py.

00227 
00228     def test_deepcopy_reduce_ex(self):
00229         class C(object):
00230             def __reduce_ex__(self, proto):
00231                 return ""
00232             def __reduce__(self):
00233                 raise support.TestFailed("shouldn't call this")
00234         x = C()
00235         y = copy.deepcopy(x)
00236         self.assertTrue(y is x)

Here is the call graph for this function:

Definition at line 310 of file test_copy.py.

00310 
00311     def test_deepcopy_reflexive_dict(self):
00312         x = {}
00313         x['foo'] = x
00314         y = copy.deepcopy(x)
00315         for op in order_comparisons:
00316             self.assertRaises(TypeError, op, y, x)
00317         for op in equality_comparisons:
00318             self.assertRaises(RuntimeError, op, y, x)
00319         self.assertTrue(y is not x)
00320         self.assertTrue(y['foo'] is y)
00321         self.assertEqual(len(y), 1)

Here is the call graph for this function:

Definition at line 411 of file test_copy.py.

00411 
00412     def test_deepcopy_reflexive_inst(self):
00413         class C:
00414             pass
00415         x = C()
00416         x.foo = x
00417         y = copy.deepcopy(x)
00418         self.assertTrue(y is not x)
00419         self.assertTrue(y.foo is y)

Definition at line 276 of file test_copy.py.

00276 
00277     def test_deepcopy_reflexive_list(self):
00278         x = []
00279         x.append(x)
00280         y = copy.deepcopy(x)
00281         for op in comparisons:
00282             self.assertRaises(RuntimeError, op, y, x)
00283         self.assertTrue(y is not x)
00284         self.assertTrue(y[0] is y)
00285         self.assertEqual(len(y), 1)

Here is the call graph for this function:

Definition at line 293 of file test_copy.py.

00293 
00294     def test_deepcopy_reflexive_tuple(self):
00295         x = ([],)
00296         x[0].append(x)
00297         y = copy.deepcopy(x)
00298         for op in comparisons:
00299             self.assertRaises(RuntimeError, op, y, x)
00300         self.assertTrue(y is not x)
00301         self.assertTrue(y[0] is not x[0])
00302         self.assertTrue(y[0][0] is y)

Here is the call graph for this function:

Definition at line 214 of file test_copy.py.

00214 
00215     def test_deepcopy_registry(self):
00216         class C(object):
00217             def __new__(cls, foo):
00218                 obj = object.__new__(cls)
00219                 obj.foo = foo
00220                 return obj
00221         def pickle_C(obj):
00222             return (C, (obj.foo,))
00223         x = C(42)
00224         self.assertRaises(TypeError, copy.deepcopy, x)
00225         copyreg.pickle(C, pickle_C, C)
00226         y = copy.deepcopy(x)

Here is the call graph for this function:

Definition at line 526 of file test_copy.py.

00526 
00527     def test_deepcopy_slots(self):
00528         class C(object):
00529             __slots__ = ["foo"]
00530         x = C()
00531         x.foo = [42]
00532         y = copy.deepcopy(x)
00533         self.assertEqual(x.foo, y.foo)
00534         self.assertTrue(x.foo is not y.foo)

Here is the call graph for this function:

Definition at line 286 of file test_copy.py.

00286 
00287     def test_deepcopy_tuple(self):
00288         x = ([1, 2], 3)
00289         y = copy.deepcopy(x)
00290         self.assertEqual(y, x)
00291         self.assertTrue(x is not y)
00292         self.assertTrue(x[0] is not y[0])

Here is the call graph for this function:

Definition at line 585 of file test_copy.py.

00585 
00586     def test_deepcopy_tuple_subclass(self):
00587         class C(tuple):
00588             pass
00589         x = C([[1, 2], 3])
00590         self.assertEqual(tuple(x), ([1, 2], 3))
00591         y = copy.deepcopy(x)
00592         self.assertEqual(tuple(y), ([1, 2], 3))
00593         self.assertTrue(x is not y)
00594         self.assertTrue(x[0] is not y[0])

Definition at line 658 of file test_copy.py.

00658 
00659     def test_deepcopy_weakkeydict(self):
00660         class C(object):
00661             def __init__(self, i):
00662                 self.i = i
00663         a, b, c, d = [C(i) for i in range(4)]
00664         u = weakref.WeakKeyDictionary()
00665         u[a] = b
00666         u[c] = d
00667         # Keys aren't copied, values are
00668         v = copy.deepcopy(u)
00669         self.assertNotEqual(v, u)
00670         self.assertEqual(len(v), 2)
00671         self.assertFalse(v[a] is b)
00672         self.assertFalse(v[c] is d)
00673         self.assertEqual(v[a].i, b.i)
00674         self.assertEqual(v[c].i, d.i)
00675         del c
00676         self.assertEqual(len(v), 1)

Here is the call graph for this function:

Definition at line 629 of file test_copy.py.

00629 
00630     def test_deepcopy_weakref(self):
00631         self._check_weakref(copy.deepcopy)

Here is the call graph for this function:

Definition at line 677 of file test_copy.py.

00677 
00678     def test_deepcopy_weakvaluedict(self):
00679         class C(object):
00680             def __init__(self, i):
00681                 self.i = i
00682         a, b, c, d = [C(i) for i in range(4)]
00683         u = weakref.WeakValueDictionary()
00684         u[a] = b
00685         u[c] = d
00686         # Keys are copied, values aren't
00687         v = copy.deepcopy(u)
00688         self.assertNotEqual(v, u)
00689         self.assertEqual(len(v), 2)
00690         (x, y), (z, t) = sorted(v.items(), key=lambda pair: pair[0].i)
00691         self.assertFalse(x is a)
00692         self.assertEqual(x.i, a.i)
00693         self.assertTrue(y is b)
00694         self.assertFalse(z is c)
00695         self.assertEqual(z.i, c.i)
00696         self.assertTrue(t is d)
00697         del x, y, z, t
00698         del d
00699         self.assertEqual(len(v), 1)

Here is the call graph for this function:

Definition at line 19 of file test_copy.py.

00019 
00020     def test_exceptions(self):
00021         self.assertTrue(copy.Error is copy.error)
00022         self.assertTrue(issubclass(copy.Error, Exception))

Here is the call graph for this function:

Definition at line 595 of file test_copy.py.

00595 
00596     def test_getstate_exc(self):
00597         class EvilState(object):
00598             def __getstate__(self):
00599                 raise ValueError("ain't got no stickin' state")
00600         self.assertRaises(ValueError, copy.copy, EvilState())

Here is the call graph for this function:

Definition at line 432 of file test_copy.py.

00432 
00433     def test_reconstruct_nostate(self):
00434         class C(object):
00435             def __reduce__(self):
00436                 return (C, ())
00437         x = C()
00438         x.foo = 42
00439         y = copy.copy(x)
00440         self.assertTrue(y.__class__ is x.__class__)
00441         y = copy.deepcopy(x)
00442         self.assertTrue(y.__class__ is x.__class__)

Here is the call graph for this function:

Definition at line 473 of file test_copy.py.

00473 
00474     def test_reconstruct_reflexive(self):
00475         class C(object):
00476             pass
00477         x = C()
00478         x.foo = x
00479         y = copy.deepcopy(x)
00480         self.assertTrue(y is not x)
00481         self.assertTrue(y.foo is y)

Definition at line 443 of file test_copy.py.

00443 
00444     def test_reconstruct_state(self):
00445         class C(object):
00446             def __reduce__(self):
00447                 return (C, (), self.__dict__)
00448             def __eq__(self, other):
00449                 return self.__dict__ == other.__dict__
00450         x = C()
00451         x.foo = [42]
00452         y = copy.copy(x)
00453         self.assertEqual(y, x)
00454         y = copy.deepcopy(x)
00455         self.assertEqual(y, x)
00456         self.assertTrue(y.foo is not x.foo)

Here is the call graph for this function:

Definition at line 457 of file test_copy.py.

00457 
00458     def test_reconstruct_state_setstate(self):
00459         class C(object):
00460             def __reduce__(self):
00461                 return (C, (), self.__dict__)
00462             def __setstate__(self, state):
00463                 self.__dict__.update(state)
00464             def __eq__(self, other):
00465                 return self.__dict__ == other.__dict__
00466         x = C()
00467         x.foo = [42]
00468         y = copy.copy(x)
00469         self.assertEqual(y, x)
00470         y = copy.deepcopy(x)
00471         self.assertEqual(y, x)
00472         self.assertTrue(y.foo is not x.foo)

Here is the call graph for this function:

Definition at line 422 of file test_copy.py.

00422 
00423     def test_reconstruct_string(self):
00424         class C(object):
00425             def __reduce__(self):
00426                 return ""
00427         x = C()
00428         y = copy.copy(x)
00429         self.assertTrue(y is x)
00430         y = copy.deepcopy(x)
00431         self.assertTrue(y is x)

Here is the call graph for this function:

Definition at line 484 of file test_copy.py.

00484 
00485     def test_reduce_4tuple(self):
00486         class C(list):
00487             def __reduce__(self):
00488                 return (C, (), self.__dict__, iter(self))
00489             def __eq__(self, other):
00490                 return (list(self) == list(other) and
00491                         self.__dict__ == other.__dict__)
00492         x = C([[1, 2], 3])
00493         y = copy.copy(x)
00494         self.assertEqual(x, y)
00495         self.assertTrue(x is not y)
00496         self.assertTrue(x[0] is y[0])
00497         y = copy.deepcopy(x)
00498         self.assertEqual(x, y)
00499         self.assertTrue(x is not y)
00500         self.assertTrue(x[0] is not y[0])

Here is the call graph for this function:

Definition at line 501 of file test_copy.py.

00501 
00502     def test_reduce_5tuple(self):
00503         class C(dict):
00504             def __reduce__(self):
00505                 return (C, (), self.__dict__, None, self.items())
00506             def __eq__(self, other):
00507                 return (dict(self) == dict(other) and
00508                         self.__dict__ == other.__dict__)
00509         x = C([("foo", [1, 2]), ("bar", 3)])
00510         y = copy.copy(x)
00511         self.assertEqual(x, y)
00512         self.assertTrue(x is not y)
00513         self.assertTrue(x["foo"] is y["foo"])
00514         y = copy.deepcopy(x)
00515         self.assertEqual(x, y)
00516         self.assertTrue(x is not y)
00517         self.assertTrue(x["foo"] is not y["foo"])

Here is the call graph for this function:


Member Data Documentation

Definition at line 448 of file test_copy.py.

Definition at line 540 of file test_copy.py.

Definition at line 33 of file test_copy.py.

Definition at line 661 of file test_copy.py.


The documentation for this class was generated from the following file: