(self)
| 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 |
nothing calls this directly
no test coverage detected