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

Method test_dict_copy_order

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

Source from the content-addressed store, hash-verified

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