MCPcopy Index your code
hub / github.com/python/cpython / test_equality

Method test_equality

Lib/test/test_weakref.py:901–936  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

899 self.assertEqual(l, [a])
900
901 def test_equality(self):
902 # Alive weakrefs defer equality testing to their underlying object.
903 x = Object(1)
904 y = Object(1)
905 z = Object(2)
906 a = weakref.ref(x)
907 b = weakref.ref(y)
908 c = weakref.ref(z)
909 d = weakref.ref(x)
910 # Note how we directly test the operators here, to stress both
911 # __eq__ and __ne__.
912 self.assertTrue(a == b)
913 self.assertFalse(a != b)
914 self.assertFalse(a == c)
915 self.assertTrue(a != c)
916 self.assertTrue(a == d)
917 self.assertFalse(a != d)
918 self.assertFalse(a == x)
919 self.assertTrue(a != x)
920 self.assertTrue(a == ALWAYS_EQ)
921 self.assertFalse(a != ALWAYS_EQ)
922 del x, y, z
923 gc.collect()
924 for r in a, b, c:
925 # Sanity check
926 self.assertIs(r(), None)
927 # Dead weakrefs compare by identity: whether `a` and `d` are the
928 # same weakref object is an implementation detail, since they pointed
929 # to the same original object and didn't have a callback.
930 # (see issue #16453).
931 self.assertFalse(a == b)
932 self.assertTrue(a != b)
933 self.assertFalse(a == c)
934 self.assertTrue(a != c)
935 self.assertEqual(a == d, a is d)
936 self.assertEqual(a != d, a is not d)
937
938 def test_ordering(self):
939 # weakrefs cannot be ordered, even if the underlying objects can.

Callers

nothing calls this directly

Calls 7

assertTrueMethod · 0.80
assertFalseMethod · 0.80
ObjectClass · 0.70
rFunction · 0.50
collectMethod · 0.45
assertIsMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected