MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_new_child

Method test_new_child

Lib/test/test_collections.py:229–263  ·  view source on GitHub ↗

Tests for changes for issue #16613.

(self)

Source from the content-addressed store, hash-verified

227 self.assertEqual(dict(d.items()), dict(a=1, b=2, c=30))
228
229 def test_new_child(self):
230 'Tests for changes for issue #16613.'
231 c = ChainMap()
232 c['a'] = 1
233 c['b'] = 2
234 m = {'b':20, 'c': 30}
235 d = c.new_child(m)
236 self.assertEqual(d.maps, [{'b':20, 'c':30}, {'a':1, 'b':2}]) # check internal state
237 self.assertIs(m, d.maps[0])
238
239 # Use a different map than a dict
240 class lowerdict(dict):
241 def __getitem__(self, key):
242 if isinstance(key, str):
243 key = key.lower()
244 return dict.__getitem__(self, key)
245 def __contains__(self, key):
246 if isinstance(key, str):
247 key = key.lower()
248 return dict.__contains__(self, key)
249
250 c = ChainMap()
251 c['a'] = 1
252 c['b'] = 2
253 m = lowerdict(b=20, c=30)
254 d = c.new_child(m)
255 self.assertIs(m, d.maps[0])
256 for key in 'abc': # check contains
257 self.assertIn(key, d)
258 for k, v in dict(a=1, B=20, C=30, z=100).items(): # check get
259 self.assertEqual(d.get(k, 100), v)
260
261 c = ChainMap({'a': 1, 'b': 2})
262 d = c.new_child(b=20, c=30)
263 self.assertEqual(d.maps, [{'b': 20, 'c': 30}, {'a': 1, 'b': 2}])
264
265 def test_union_operators(self):
266 cm1 = ChainMap(dict(a=1, b=2), dict(c=3, d=4))

Callers

nothing calls this directly

Calls 8

new_childMethod · 0.95
ChainMapClass · 0.90
lowerdictClass · 0.85
assertInMethod · 0.80
assertEqualMethod · 0.45
assertIsMethod · 0.45
itemsMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected