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

Method test_dict_copy_order

Lib/test/test_dict.py:1405–1433  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1403 self.assertEqual(list(reversed(A(0, 1).__dict__)), ['y'])
1404
1405 def test_dict_copy_order(self):
1406 # bpo-34320
1407 od = collections.OrderedDict([('a', 1), ('b', 2)])
1408 od.move_to_end('a')
1409 expected = list(od.items())
1410
1411 copy = dict(od)
1412 self.assertEqual(list(copy.items()), expected)
1413
1414 # dict subclass doesn't override __iter__
1415 class CustomDict(dict):
1416 pass
1417
1418 pairs = [('a', 1), ('b', 2), ('c', 3)]
1419
1420 d = CustomDict(pairs)
1421 self.assertEqual(pairs, list(dict(d).items()))
1422
1423 class CustomReversedDict(dict):
1424 def keys(self):
1425 return reversed(list(dict.keys(self)))
1426
1427 __iter__ = keys
1428
1429 def items(self):
1430 return reversed(dict.items(self))
1431
1432 d = CustomReversedDict(pairs)
1433 self.assertEqual(pairs[::-1], list(dict(d).items()))
1434
1435 @support.cpython_only
1436 def test_dict_items_result_gc(self):

Callers

nothing calls this directly

Calls 7

move_to_endMethod · 0.95
itemsMethod · 0.95
listClass · 0.85
CustomDictClass · 0.85
CustomReversedDictClass · 0.85
assertEqualMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected