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

Method test_weak_keyed_union_operators

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

Source from the content-addressed store, hash-verified

1833 self.assertEqual(list(d.keys()), [o2])
1834
1835 def test_weak_keyed_union_operators(self):
1836 o1 = C()
1837 o2 = C()
1838 o3 = C()
1839 wkd1 = weakref.WeakKeyDictionary({o1: 1, o2: 2})
1840 wkd2 = weakref.WeakKeyDictionary({o3: 3, o1: 4})
1841 wkd3 = wkd1.copy()
1842 d1 = {o2: '5', o3: '6'}
1843 pairs = [(o2, 7), (o3, 8)]
1844
1845 tmp1 = wkd1 | wkd2 # Between two WeakKeyDictionaries
1846 self.assertEqual(dict(tmp1), dict(wkd1) | dict(wkd2))
1847 self.assertIs(type(tmp1), weakref.WeakKeyDictionary)
1848 wkd1 |= wkd2
1849 self.assertEqual(wkd1, tmp1)
1850
1851 tmp2 = wkd2 | d1 # Between WeakKeyDictionary and mapping
1852 self.assertEqual(dict(tmp2), dict(wkd2) | d1)
1853 self.assertIs(type(tmp2), weakref.WeakKeyDictionary)
1854 wkd2 |= d1
1855 self.assertEqual(wkd2, tmp2)
1856
1857 tmp3 = wkd3.copy() # Between WeakKeyDictionary and iterable key, value
1858 tmp3 |= pairs
1859 self.assertEqual(dict(tmp3), dict(wkd3) | dict(pairs))
1860 self.assertIs(type(tmp3), weakref.WeakKeyDictionary)
1861
1862 tmp4 = d1 | wkd3 # Testing .__ror__
1863 self.assertEqual(dict(tmp4), d1 | dict(wkd3))
1864 self.assertIs(type(tmp4), weakref.WeakKeyDictionary)
1865
1866 del o1
1867 self.assertNotIn(4, tmp1.values())
1868 self.assertNotIn(4, tmp2.values())
1869 self.assertNotIn(1, tmp3.values())
1870 self.assertNotIn(1, tmp4.values())
1871
1872 def test_weak_valued_delitem(self):
1873 d = weakref.WeakValueDictionary()

Callers

nothing calls this directly

Calls 7

copyMethod · 0.95
assertNotInMethod · 0.80
CClass · 0.70
assertEqualMethod · 0.45
assertIsMethod · 0.45
copyMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected