MCPcopy Create free account
hub / github.com/RustPython/RustPython / test_missing

Method test_missing

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

Source from the content-addressed store, hash-verified

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