diff options
Diffstat (limited to 'Lib/test/test_weakref.py')
-rw-r--r-- | Lib/test/test_weakref.py | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/Lib/test/test_weakref.py b/Lib/test/test_weakref.py index 67abd0d29e..536a987fe4 100644 --- a/Lib/test/test_weakref.py +++ b/Lib/test/test_weakref.py @@ -54,10 +54,10 @@ class ReferencesTestCase(TestBase): # Live reference: o = C() wr = weakref.ref(o) - `wr` + repr(wr) # Dead reference: del o - `wr` + repr(wr) def test_basic_callback(self): self.check_basic_callback(C) @@ -169,7 +169,8 @@ class ReferencesTestCase(TestBase): p.append(12) self.assertEqual(len(L), 1) self.assertTrue(p, "proxy for non-empty UserList should be true") - p[:] = [2, 3] + with test_support.check_py3k_warnings(): + p[:] = [2, 3] self.assertEqual(len(L), 2) self.assertEqual(len(p), 2) self.assertIn(3, p, "proxy didn't support __contains__() properly") @@ -182,10 +183,11 @@ class ReferencesTestCase(TestBase): ## self.assertEqual(repr(L2), repr(p2)) L3 = UserList.UserList(range(10)) p3 = weakref.proxy(L3) - self.assertEqual(L3[:], p3[:]) - self.assertEqual(L3[5:], p3[5:]) - self.assertEqual(L3[:5], p3[:5]) - self.assertEqual(L3[2:5], p3[2:5]) + with test_support.check_py3k_warnings(): + self.assertEqual(L3[:], p3[:]) + self.assertEqual(L3[5:], p3[5:]) + self.assertEqual(L3[:5], p3[:5]) + self.assertEqual(L3[2:5], p3[2:5]) def test_proxy_unicode(self): # See bug 5037 @@ -831,7 +833,7 @@ class MappingTestCase(TestBase): def test_weak_keys(self): # # This exercises d.copy(), d.items(), d[] = v, d[], del d[], - # len(d), d.has_key(). + # len(d), in d. # dict, objects = self.make_weak_keyed_dict() for o in objects: @@ -853,8 +855,8 @@ class MappingTestCase(TestBase): "deleting the keys did not clear the dictionary") o = Object(42) dict[o] = "What is the meaning of the universe?" - self.assertTrue(dict.has_key(o)) - self.assertTrue(not dict.has_key(34)) + self.assertIn(o, dict) + self.assertNotIn(34, dict) def test_weak_keyed_iters(self): dict, objects = self.make_weak_keyed_dict() @@ -866,7 +868,6 @@ class MappingTestCase(TestBase): objects2 = list(objects) for wr in refs: ob = wr() - self.assertTrue(dict.has_key(ob)) self.assertIn(ob, dict) self.assertEqual(ob.arg, dict[ob]) objects2.remove(ob) @@ -877,7 +878,6 @@ class MappingTestCase(TestBase): self.assertEqual(len(list(dict.iterkeyrefs())), len(objects)) for wr in dict.iterkeyrefs(): ob = wr() - self.assertTrue(dict.has_key(ob)) self.assertIn(ob, dict) self.assertEqual(ob.arg, dict[ob]) objects2.remove(ob) @@ -991,16 +991,16 @@ class MappingTestCase(TestBase): " -- value parameters must be distinct objects") weakdict = klass() o = weakdict.setdefault(key, value1) - self.assertTrue(o is value1) - self.assertTrue(weakdict.has_key(key)) - self.assertTrue(weakdict.get(key) is value1) - self.assertTrue(weakdict[key] is value1) + self.assertIs(o, value1) + self.assertIn(key, weakdict) + self.assertIs(weakdict.get(key), value1) + self.assertIs(weakdict[key], value1) o = weakdict.setdefault(key, value2) - self.assertTrue(o is value1) - self.assertTrue(weakdict.has_key(key)) - self.assertTrue(weakdict.get(key) is value1) - self.assertTrue(weakdict[key] is value1) + self.assertIs(o, value1) + self.assertIn(key, weakdict) + self.assertIs(weakdict.get(key), value1) + self.assertIs(weakdict[key], value1) def test_weak_valued_dict_setdefault(self): self.check_setdefault(weakref.WeakValueDictionary, @@ -1012,24 +1012,24 @@ class MappingTestCase(TestBase): def check_update(self, klass, dict): # - # This exercises d.update(), len(d), d.keys(), d.has_key(), + # This exercises d.update(), len(d), d.keys(), in d, # d.get(), d[]. # weakdict = klass() weakdict.update(dict) - self.assertTrue(len(weakdict) == len(dict)) + self.assertEqual(len(weakdict), len(dict)) for k in weakdict.keys(): - self.assertTrue(dict.has_key(k), + self.assertIn(k, dict, "mysterious new key appeared in weak dict") v = dict.get(k) - self.assertTrue(v is weakdict[k]) - self.assertTrue(v is weakdict.get(k)) + self.assertIs(v, weakdict[k]) + self.assertIs(v, weakdict.get(k)) for k in dict.keys(): - self.assertTrue(weakdict.has_key(k), + self.assertIn(k, weakdict, "original key disappeared in weak dict") v = dict[k] - self.assertTrue(v is weakdict[k]) - self.assertTrue(v is weakdict.get(k)) + self.assertIs(v, weakdict[k]) + self.assertIs(v, weakdict.get(k)) def test_weak_valued_dict_update(self): self.check_update(weakref.WeakValueDictionary, |