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

Method test_missing

Lib/test/test_collections.py:175–190  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

173 self.assertTrue(ChainMap({}, {1:2}))
174
175 def test_missing(self):
176 class DefaultChainMap(ChainMap):
177 def __missing__(self, key):
178 return 999
179 d = DefaultChainMap(dict(a=1, b=2), dict(b=20, c=30))
180 for k, v in dict(a=1, b=2, c=30, d=999).items():
181 self.assertEqual(d[k], v) # check __getitem__ w/missing
182 for k, v in dict(a=1, b=2, c=30, d=77).items():
183 self.assertEqual(d.get(k, 77), v) # check get() w/ missing
184 for k, v in dict(a=True, b=True, c=True, d=False).items():
185 self.assertEqual(k in d, v) # check __contains__ w/missing
186 self.assertEqual(d.pop('a', 1001), 1, d)
187 self.assertEqual(d.pop('a', 1002), 1002) # check pop() w/missing
188 self.assertEqual(d.popitem(), ('b', 2)) # check popitem() w/missing
189 with self.assertRaises(KeyError):
190 d.popitem()
191
192 def test_order_preservation(self):
193 d = ChainMap(

Callers

nothing calls this directly

Calls 7

DefaultChainMapClass · 0.85
itemsMethod · 0.45
assertEqualMethod · 0.45
getMethod · 0.45
popMethod · 0.45
popitemMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected