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

Method test_sort_unorderable_values

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

Source from the content-addressed store, hash-verified

755 self.assertEqual(pprint.pformat(nested_list, depth=1), lv1_list)
756
757 def test_sort_unorderable_values(self):
758 # Issue 3976: sorted pprints fail for unorderable values.
759 n = 20
760 keys = [Unorderable() for i in range(n)]
761 random.shuffle(keys)
762 skeys = sorted(keys, key=id)
763 clean = lambda s: s.replace(' ', '').replace('\n','')
764
765 self.assertEqual(clean(pprint.pformat(set(keys))),
766 '{' + ','.join(map(repr, skeys)) + '}')
767 self.assertEqual(clean(pprint.pformat(frozenset(keys))),
768 'frozenset({' + ','.join(map(repr, skeys)) + '})')
769 self.assertEqual(clean(pprint.pformat(dict.fromkeys(keys))),
770 '{' + ','.join('%r:None' % k for k in skeys) + '}')
771
772 # Issue 10017: TypeError on user-defined types as dict keys.
773 self.assertEqual(pprint.pformat({Unorderable: 0, 1: 0}),
774 '{1: 0, ' + repr(Unorderable) +': 0}')
775
776 # Issue 14998: TypeError on tuples with NoneTypes as dict keys.
777 keys = [(1,), (None,)]
778 self.assertEqual(pprint.pformat(dict.fromkeys(keys, 0)),
779 '{%r: 0, %r: 0}' % tuple(sorted(keys, key=id)))
780
781 def test_sort_orderable_and_unorderable_values(self):
782 # Issue 22721: sorted pprints is not stable

Callers

nothing calls this directly

Calls 10

UnorderableClass · 0.85
sortedFunction · 0.85
setFunction · 0.85
reprFunction · 0.85
shuffleMethod · 0.80
pformatMethod · 0.80
replaceMethod · 0.45
assertEqualMethod · 0.45
joinMethod · 0.45
fromkeysMethod · 0.45

Tested by

no test coverage detected