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

Method test_update

Lib/test/mapping_tests.py:384–428  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

382 self.assertRaises(TypeError, d.clear, None)
383
384 def test_update(self):
385 BasicTestMappingProtocol.test_update(self)
386 # mapping argument
387 d = self._empty_mapping()
388 d.update({1:100})
389 d.update({2:20})
390 d.update({1:1, 2:2, 3:3})
391 self.assertEqual(d, {1:1, 2:2, 3:3})
392
393 # no argument
394 d.update()
395 self.assertEqual(d, {1:1, 2:2, 3:3})
396
397 # keyword arguments
398 d = self._empty_mapping()
399 d.update(x=100)
400 d.update(y=20)
401 d.update(x=1, y=2, z=3)
402 self.assertEqual(d, {"x":1, "y":2, "z":3})
403
404 # item sequence
405 d = self._empty_mapping()
406 d.update([("x", 100), ("y", 20)])
407 self.assertEqual(d, {"x":100, "y":20})
408
409 # Both item sequence and keyword arguments
410 d = self._empty_mapping()
411 d.update([("x", 100), ("y", 20)], x=1, y=2)
412 self.assertEqual(d, {"x":1, "y":2})
413
414 # iterator
415 d = self._full_mapping({1:3, 2:4})
416 d.update(self._full_mapping({1:2, 3:4, 5:6}).items())
417 self.assertEqual(d, {1:2, 2:4, 3:4, 5:6})
418
419 class SimpleUserDict:
420 def __init__(self):
421 self.d = {1:1, 2:2, 3:3}
422 def keys(self):
423 return self.d.keys()
424 def __getitem__(self, i):
425 return self.d[i]
426 d.clear()
427 d.update(SimpleUserDict())
428 self.assertEqual(d, {1:1, 2:2, 3:3})
429
430 def test_fromkeys(self):
431 self.assertEqual(self.type2test.fromkeys('abc'), {'a':None, 'b':None, 'c':None})

Callers

nothing calls this directly

Calls 7

SimpleUserDictClass · 0.70
_empty_mappingMethod · 0.45
updateMethod · 0.45
assertEqualMethod · 0.45
_full_mappingMethod · 0.45
itemsMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected