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

Method test_abc_views

Lib/test/test_pprint.py:628–663  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

626 joiner.join(repr(item) for item in i))
627
628 def test_abc_views(self):
629 empty = {}
630 short = dict(zip('edcba', 'edcba'))
631 long = dict((chr(x), chr(x)) for x in range(90, 64, -1))
632 lengths = {"empty": empty, "short": short, "long": long}
633 # Test that a subclass that doesn't replace __repr__ works with different lengths
634 class MV(MappingView): pass
635
636 for name, d in lengths.items():
637 with self.subTest(length=name, name="Views"):
638 is_short = len(d) < 6
639 joiner = ", " if is_short else ",\n "
640 i = d.items()
641 s = sorted(i)
642 joined_items = "({%s})" % joiner.join(["%r: %r" % (k, v) for (k, v) in i])
643 sorted_items = "({%s})" % joiner.join(["%r: %r" % (k, v) for (k, v) in s])
644 self.assertEqual(pprint.pformat(KeysView(d), sort_dicts=True),
645 KeysView.__name__ + sorted_items)
646 self.assertEqual(pprint.pformat(ItemsView(d), sort_dicts=True),
647 ItemsView.__name__ + sorted_items)
648 self.assertEqual(pprint.pformat(MappingView(d), sort_dicts=True),
649 MappingView.__name__ + sorted_items)
650 self.assertEqual(pprint.pformat(MV(d), sort_dicts=True),
651 MV.__name__ + sorted_items)
652 self.assertEqual(pprint.pformat(ValuesView(d), sort_dicts=True),
653 ValuesView.__name__ + sorted_items)
654 self.assertEqual(pprint.pformat(KeysView(d), sort_dicts=False),
655 KeysView.__name__ + joined_items)
656 self.assertEqual(pprint.pformat(ItemsView(d), sort_dicts=False),
657 ItemsView.__name__ + joined_items)
658 self.assertEqual(pprint.pformat(MappingView(d), sort_dicts=False),
659 MappingView.__name__ + joined_items)
660 self.assertEqual(pprint.pformat(MV(d), sort_dicts=False),
661 MV.__name__ + joined_items)
662 self.assertEqual(pprint.pformat(ValuesView(d), sort_dicts=False),
663 ValuesView.__name__ + joined_items)
664
665 def test_nested_views(self):
666 d = {1: MappingView({1: MappingView({1: MappingView({1: 2})})})}

Callers

nothing calls this directly

Calls 10

KeysViewClass · 0.90
ItemsViewClass · 0.90
MappingViewClass · 0.90
ValuesViewClass · 0.90
MVClass · 0.85
pformatMethod · 0.80
itemsMethod · 0.45
subTestMethod · 0.45
joinMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected