Lines Matching refs:self
20 def test_exceptions(self):
21 self.assertIs(copy.Error, copy.error)
22 self.assertTrue(issubclass(copy.Error, Exception))
26 def test_copy_basic(self):
29 self.assertEqual(x, y)
31 def test_copy_copy(self):
33 def __init__(self, foo):
34 self.foo = foo
35 def __copy__(self):
36 return C(self.foo)
39 self.assertEqual(y.__class__, x.__class__)
40 self.assertEqual(y.foo, x.foo)
42 def test_copy_registry(self):
51 self.assertRaises(TypeError, copy.copy, x)
54 self.assertIsNot(x, y)
55 self.assertEqual(type(y), C)
56 self.assertEqual(y.foo, x.foo)
58 def test_copy_reduce_ex(self):
60 def __reduce_ex__(self, proto):
63 def __reduce__(self):
64 self.fail("shouldn't call this")
68 self.assertIs(y, x)
69 self.assertEqual(c, [1])
71 def test_copy_reduce(self):
73 def __reduce__(self):
79 self.assertIs(y, x)
80 self.assertEqual(c, [1])
82 def test_copy_cant(self):
84 def __getattribute__(self, name):
87 return object.__getattribute__(self, name)
89 self.assertRaises(copy.Error, copy.copy, x)
93 def test_copy_atomic(self):
108 self.assertIs(copy.copy(x), x)
110 def test_copy_list(self):
113 self.assertEqual(y, x)
114 self.assertIsNot(y, x)
117 self.assertEqual(y, x)
118 self.assertIsNot(y, x)
120 def test_copy_tuple(self):
122 self.assertIs(copy.copy(x), x)
124 self.assertIs(copy.copy(x), x)
126 self.assertIs(copy.copy(x), x)
128 def test_copy_dict(self):
131 self.assertEqual(y, x)
132 self.assertIsNot(y, x)
135 self.assertEqual(y, x)
136 self.assertIsNot(y, x)
138 def test_copy_set(self):
141 self.assertEqual(y, x)
142 self.assertIsNot(y, x)
145 self.assertEqual(y, x)
146 self.assertIsNot(y, x)
148 def test_copy_frozenset(self):
150 self.assertIs(copy.copy(x), x)
152 self.assertIs(copy.copy(x), x)
154 def test_copy_bytearray(self):
157 self.assertEqual(y, x)
158 self.assertIsNot(y, x)
161 self.assertEqual(y, x)
162 self.assertIsNot(y, x)
164 def test_copy_inst_vanilla(self):
166 def __init__(self, foo):
167 self.foo = foo
168 def __eq__(self, other):
169 return self.foo == other.foo
171 self.assertEqual(copy.copy(x), x)
173 def test_copy_inst_copy(self):
175 def __init__(self, foo):
176 self.foo = foo
177 def __copy__(self):
178 return C(self.foo)
179 def __eq__(self, other):
180 return self.foo == other.foo
182 self.assertEqual(copy.copy(x), x)
184 def test_copy_inst_getinitargs(self):
186 def __init__(self, foo):
187 self.foo = foo
188 def __getinitargs__(self):
189 return (self.foo,)
190 def __eq__(self, other):
191 return self.foo == other.foo
193 self.assertEqual(copy.copy(x), x)
195 def test_copy_inst_getnewargs(self):
198 self = int.__new__(cls)
199 self.foo = foo
200 return self
201 def __getnewargs__(self):
202 return self.foo,
203 def __eq__(self, other):
204 return self.foo == other.foo
207 self.assertIsInstance(y, C)
208 self.assertEqual(y, x)
209 self.assertIsNot(y, x)
210 self.assertEqual(y.foo, x.foo)
212 def test_copy_inst_getnewargs_ex(self):
215 self = int.__new__(cls)
216 self.foo = foo
217 return self
218 def __getnewargs_ex__(self):
219 return (), {'foo': self.foo}
220 def __eq__(self, other):
221 return self.foo == other.foo
224 self.assertIsInstance(y, C)
225 self.assertEqual(y, x)
226 self.assertIsNot(y, x)
227 self.assertEqual(y.foo, x.foo)
229 def test_copy_inst_getstate(self):
231 def __init__(self, foo):
232 self.foo = foo
233 def __getstate__(self):
234 return {"foo": self.foo}
235 def __eq__(self, other):
236 return self.foo == other.foo
238 self.assertEqual(copy.copy(x), x)
240 def test_copy_inst_setstate(self):
242 def __init__(self, foo):
243 self.foo = foo
244 def __setstate__(self, state):
245 self.foo = state["foo"]
246 def __eq__(self, other):
247 return self.foo == other.foo
249 self.assertEqual(copy.copy(x), x)
251 def test_copy_inst_getstate_setstate(self):
253 def __init__(self, foo):
254 self.foo = foo
255 def __getstate__(self):
256 return self.foo
257 def __setstate__(self, state):
258 self.foo = state
259 def __eq__(self, other):
260 return self.foo == other.foo
262 self.assertEqual(copy.copy(x), x)
265 self.assertEqual(copy.copy(x), x)
269 def test_deepcopy_basic(self):
272 self.assertEqual(y, x)
274 def test_deepcopy_memo(self):
280 self.assertEqual(y, x)
281 self.assertIsNot(y, x)
282 self.assertIsNot(y[0], x[0])
283 self.assertIs(y[0], y[1])
285 def test_deepcopy_issubclass(self):
294 self.assertEqual(copy.deepcopy(C), C)
296 def test_deepcopy_deepcopy(self):
298 def __init__(self, foo):
299 self.foo = foo
300 def __deepcopy__(self, memo=None):
301 return C(self.foo)
304 self.assertEqual(y.__class__, x.__class__)
305 self.assertEqual(y.foo, x.foo)
307 def test_deepcopy_registry(self):
316 self.assertRaises(TypeError, copy.deepcopy, x)
319 self.assertIsNot(x, y)
320 self.assertEqual(type(y), C)
321 self.assertEqual(y.foo, x.foo)
323 def test_deepcopy_reduce_ex(self):
325 def __reduce_ex__(self, proto):
328 def __reduce__(self):
329 self.fail("shouldn't call this")
333 self.assertIs(y, x)
334 self.assertEqual(c, [1])
336 def test_deepcopy_reduce(self):
338 def __reduce__(self):
344 self.assertIs(y, x)
345 self.assertEqual(c, [1])
347 def test_deepcopy_cant(self):
349 def __getattribute__(self, name):
352 return object.__getattribute__(self, name)
354 self.assertRaises(copy.Error, copy.deepcopy, x)
358 def test_deepcopy_atomic(self):
369 self.assertIs(copy.deepcopy(x), x)
371 def test_deepcopy_list(self):
374 self.assertEqual(y, x)
375 self.assertIsNot(x, y)
376 self.assertIsNot(x[0], y[0])
378 def test_deepcopy_reflexive_list(self):
383 self.assertRaises(RecursionError, op, y, x)
384 self.assertIsNot(y, x)
385 self.assertIs(y[0], y)
386 self.assertEqual(len(y), 1)
388 def test_deepcopy_empty_tuple(self):
391 self.assertIs(x, y)
393 def test_deepcopy_tuple(self):
396 self.assertEqual(y, x)
397 self.assertIsNot(x, y)
398 self.assertIsNot(x[0], y[0])
400 def test_deepcopy_tuple_of_immutables(self):
403 self.assertIs(x, y)
405 def test_deepcopy_reflexive_tuple(self):
410 self.assertRaises(RecursionError, op, y, x)
411 self.assertIsNot(y, x)
412 self.assertIsNot(y[0], x[0])
413 self.assertIs(y[0][0], y)
415 def test_deepcopy_dict(self):
418 self.assertEqual(y, x)
419 self.assertIsNot(x, y)
420 self.assertIsNot(x["foo"], y["foo"])
422 def test_deepcopy_reflexive_dict(self):
427 self.assertRaises(TypeError, op, y, x)
429 self.assertRaises(RecursionError, op, y, x)
430 self.assertIsNot(y, x)
431 self.assertIs(y['foo'], y)
432 self.assertEqual(len(y), 1)
434 def test_deepcopy_keepalive(self):
438 self.assertIs(memo[id(memo)][0], x)
440 def test_deepcopy_dont_memo_immutable(self):
444 self.assertEqual(y, x)
446 self.assertEqual(len(memo), 2)
451 self.assertEqual(y, x)
453 self.assertEqual(len(memo), 2)
455 def test_deepcopy_inst_vanilla(self):
457 def __init__(self, foo):
458 self.foo = foo
459 def __eq__(self, other):
460 return self.foo == other.foo
463 self.assertEqual(y, x)
464 self.assertIsNot(y.foo, x.foo)
466 def test_deepcopy_inst_deepcopy(self):
468 def __init__(self, foo):
469 self.foo = foo
470 def __deepcopy__(self, memo):
471 return C(copy.deepcopy(self.foo, memo))
472 def __eq__(self, other):
473 return self.foo == other.foo
476 self.assertEqual(y, x)
477 self.assertIsNot(y, x)
478 self.assertIsNot(y.foo, x.foo)
480 def test_deepcopy_inst_getinitargs(self):
482 def __init__(self, foo):
483 self.foo = foo
484 def __getinitargs__(self):
485 return (self.foo,)
486 def __eq__(self, other):
487 return self.foo == other.foo
490 self.assertEqual(y, x)
491 self.assertIsNot(y, x)
492 self.assertIsNot(y.foo, x.foo)
494 def test_deepcopy_inst_getnewargs(self):
497 self = int.__new__(cls)
498 self.foo = foo
499 return self
500 def __getnewargs__(self):
501 return self.foo,
502 def __eq__(self, other):
503 return self.foo == other.foo
506 self.assertIsInstance(y, C)
507 self.assertEqual(y, x)
508 self.assertIsNot(y, x)
509 self.assertEqual(y.foo, x.foo)
510 self.assertIsNot(y.foo, x.foo)
512 def test_deepcopy_inst_getnewargs_ex(self):
515 self = int.__new__(cls)
516 self.foo = foo
517 return self
518 def __getnewargs_ex__(self):
519 return (), {'foo': self.foo}
520 def __eq__(self, other):
521 return self.foo == other.foo
524 self.assertIsInstance(y, C)
525 self.assertEqual(y, x)
526 self.assertIsNot(y, x)
527 self.assertEqual(y.foo, x.foo)
528 self.assertIsNot(y.foo, x.foo)
530 def test_deepcopy_inst_getstate(self):
532 def __init__(self, foo):
533 self.foo = foo
534 def __getstate__(self):
535 return {"foo": self.foo}
536 def __eq__(self, other):
537 return self.foo == other.foo
540 self.assertEqual(y, x)
541 self.assertIsNot(y, x)
542 self.assertIsNot(y.foo, x.foo)
544 def test_deepcopy_inst_setstate(self):
546 def __init__(self, foo):
547 self.foo = foo
548 def __setstate__(self, state):
549 self.foo = state["foo"]
550 def __eq__(self, other):
551 return self.foo == other.foo
554 self.assertEqual(y, x)
555 self.assertIsNot(y, x)
556 self.assertIsNot(y.foo, x.foo)
558 def test_deepcopy_inst_getstate_setstate(self):
560 def __init__(self, foo):
561 self.foo = foo
562 def __getstate__(self):
563 return self.foo
564 def __setstate__(self, state):
565 self.foo = state
566 def __eq__(self, other):
567 return self.foo == other.foo
570 self.assertEqual(y, x)
571 self.assertIsNot(y, x)
572 self.assertIsNot(y.foo, x.foo)
576 self.assertEqual(y, x)
577 self.assertIsNot(y, x)
578 self.assertIsNot(y.foo, x.foo)
580 def test_deepcopy_reflexive_inst(self):
586 self.assertIsNot(y, x)
587 self.assertIs(y.foo, y)
591 def test_reconstruct_string(self):
593 def __reduce__(self):
597 self.assertIs(y, x)
599 self.assertIs(y, x)
601 def test_reconstruct_nostate(self):
603 def __reduce__(self):
608 self.assertIs(y.__class__, x.__class__)
610 self.assertIs(y.__class__, x.__class__)
612 def test_reconstruct_state(self):
614 def __reduce__(self):
615 return (C, (), self.__dict__)
616 def __eq__(self, other):
617 return self.__dict__ == other.__dict__
621 self.assertEqual(y, x)
623 self.assertEqual(y, x)
624 self.assertIsNot(y.foo, x.foo)
626 def test_reconstruct_state_setstate(self):
628 def __reduce__(self):
629 return (C, (), self.__dict__)
630 def __setstate__(self, state):
631 self.__dict__.update(state)
632 def __eq__(self, other):
633 return self.__dict__ == other.__dict__
637 self.assertEqual(y, x)
639 self.assertEqual(y, x)
640 self.assertIsNot(y.foo, x.foo)
642 def test_reconstruct_reflexive(self):
648 self.assertIsNot(y, x)
649 self.assertIs(y.foo, y)
653 def test_reduce_4tuple(self):
655 def __reduce__(self):
656 return (C, (), self.__dict__, iter(self))
657 def __eq__(self, other):
658 return (list(self) == list(other) and
659 self.__dict__ == other.__dict__)
662 self.assertEqual(x, y)
663 self.assertIsNot(x, y)
664 self.assertIs(x[0], y[0])
666 self.assertEqual(x, y)
667 self.assertIsNot(x, y)
668 self.assertIsNot(x[0], y[0])
670 def test_reduce_5tuple(self):
672 def __reduce__(self):
673 return (C, (), self.__dict__, None, self.items())
674 def __eq__(self, other):
675 return (dict(self) == dict(other) and
676 self.__dict__ == other.__dict__)
679 self.assertEqual(x, y)
680 self.assertIsNot(x, y)
681 self.assertIs(x["foo"], y["foo"])
683 self.assertEqual(x, y)
684 self.assertIsNot(x, y)
685 self.assertIsNot(x["foo"], y["foo"])
687 def test_reduce_6tuple(self):
689 self.fail("shouldn't call this")
691 def __reduce__(self):
692 return C, (), self.__dict__, None, None, state_setter
694 with self.assertRaises(TypeError):
696 with self.assertRaises(TypeError):
699 def test_reduce_6tuple_none(self):
701 def __reduce__(self):
702 return C, (), self.__dict__, None, None, None
704 with self.assertRaises(TypeError):
706 with self.assertRaises(TypeError):
709 def test_copy_slots(self):
715 self.assertIs(x.foo, y.foo)
717 def test_deepcopy_slots(self):
723 self.assertEqual(x.foo, y.foo)
724 self.assertIsNot(x.foo, y.foo)
726 def test_deepcopy_dict_subclass(self):
728 def __init__(self, d=None):
731 self._keys = list(d.keys())
733 def __setitem__(self, key, item):
735 if key not in self._keys:
736 self._keys.append(key)
739 self.assertEqual(x, y)
740 self.assertEqual(x._keys, y._keys)
741 self.assertIsNot(x, y)
743 self.assertNotEqual(x, y)
744 self.assertNotEqual(x._keys, y._keys)
746 def test_copy_list_subclass(self):
752 self.assertEqual(list(x), list(y))
753 self.assertEqual(x.foo, y.foo)
754 self.assertIs(x[0], y[0])
755 self.assertIs(x.foo, y.foo)
757 def test_deepcopy_list_subclass(self):
763 self.assertEqual(list(x), list(y))
764 self.assertEqual(x.foo, y.foo)
765 self.assertIsNot(x[0], y[0])
766 self.assertIsNot(x.foo, y.foo)
768 def test_copy_tuple_subclass(self):
772 self.assertEqual(tuple(x), (1, 2, 3))
774 self.assertEqual(tuple(y), (1, 2, 3))
776 def test_deepcopy_tuple_subclass(self):
780 self.assertEqual(tuple(x), ([1, 2], 3))
782 self.assertEqual(tuple(y), ([1, 2], 3))
783 self.assertIsNot(x, y)
784 self.assertIsNot(x[0], y[0])
786 def test_getstate_exc(self):
788 def __getstate__(self):
790 self.assertRaises(ValueError, copy.copy, EvilState())
792 def test_copy_function(self):
793 self.assertEqual(copy.copy(global_foo), global_foo)
795 self.assertEqual(copy.copy(foo), foo)
797 self.assertEqual(copy.copy(bar), bar)
799 def test_deepcopy_function(self):
800 self.assertEqual(copy.deepcopy(global_foo), global_foo)
802 self.assertEqual(copy.deepcopy(foo), foo)
804 self.assertEqual(copy.deepcopy(bar), bar)
806 def _check_weakref(self, _copy):
812 self.assertIs(y, x)
815 self.assertIs(y, x)
817 def test_copy_weakref(self):
818 self._check_weakref(copy.copy)
820 def test_deepcopy_weakref(self):
821 self._check_weakref(copy.deepcopy)
823 def _check_copy_weakdict(self, _dicttype):
831 self.assertIsNot(v, u)
832 self.assertEqual(v, u)
833 self.assertEqual(v[a], b)
834 self.assertEqual(v[c], d)
835 self.assertEqual(len(v), 2)
838 self.assertEqual(len(v), 1)
842 self.assertNotIn(x, u)
844 def test_copy_weakkeydict(self):
845 self._check_copy_weakdict(weakref.WeakKeyDictionary)
847 def test_copy_weakvaluedict(self):
848 self._check_copy_weakdict(weakref.WeakValueDictionary)
850 def test_deepcopy_weakkeydict(self):
852 def __init__(self, i):
853 self.i = i
860 self.assertNotEqual(v, u)
861 self.assertEqual(len(v), 2)
862 self.assertIsNot(v[a], b)
863 self.assertIsNot(v[c], d)
864 self.assertEqual(v[a].i, b.i)
865 self.assertEqual(v[c].i, d.i)
868 self.assertEqual(len(v), 1)
870 def test_deepcopy_weakvaluedict(self):
872 def __init__(self, i):
873 self.i = i
880 self.assertNotEqual(v, u)
881 self.assertEqual(len(v), 2)
883 self.assertIsNot(x, a)
884 self.assertEqual(x.i, a.i)
885 self.assertIs(y, b)
886 self.assertIsNot(z, c)
887 self.assertEqual(z.i, c.i)
888 self.assertIs(t, d)
892 self.assertEqual(len(v), 1)
894 def test_deepcopy_bound_method(self):
896 def m(self):
901 self.assertEqual(g.m, g.b)
902 self.assertIs(g.b.__self__, g)