diff options
Diffstat (limited to 'Lib/test/test_pprint.py')
-rw-r--r-- | Lib/test/test_pprint.py | 192 |
1 files changed, 192 insertions, 0 deletions
diff --git a/Lib/test/test_pprint.py b/Lib/test/test_pprint.py index 8698907..8d75d58 100644 --- a/Lib/test/test_pprint.py +++ b/Lib/test/test_pprint.py @@ -1,6 +1,7 @@ import pprint import test.test_support import unittest +import test.test_set # list, tuple and dict subclasses that do or don't overwrite __repr__ class list2(list): @@ -189,6 +190,197 @@ class QueryTestCase(unittest.TestCase): others.should.not.be: like.this}""" self.assertEqual(DottedPrettyPrinter().pformat(o), exp) + def test_set_reprs(self): + self.assertEqual(pprint.pformat(set()), 'set()') + self.assertEqual(pprint.pformat(set(range(3))), '{0, 1, 2}') + self.assertEqual(pprint.pformat(frozenset()), 'frozenset()') + self.assertEqual(pprint.pformat(frozenset(range(3))), 'frozenset({0, 1, 2})') + cube_repr_tgt = """\ +{frozenset(): frozenset({frozenset({2}), frozenset({0}), frozenset({1})}), + frozenset({0}): frozenset([frozenset(), + frozenset({0, 2}), + frozenset({0, 1})]), + frozenset({1}): frozenset([frozenset(), + frozenset({1, 2}), + frozenset({0, 1})]), + frozenset({2}): frozenset([frozenset(), + frozenset({1, 2}), + frozenset({0, 2})]), + frozenset({1, 2}): frozenset([frozenset({2}), + frozenset({1}), + frozenset({0, 1, 2})]), + frozenset({0, 2}): frozenset([frozenset({2}), + frozenset({0}), + frozenset({0, 1, 2})]), + frozenset({0, 1}): frozenset([frozenset({0}), + frozenset({1}), + frozenset({0, 1, 2})]), + frozenset({0, 1, 2}): frozenset([frozenset({1, 2}), + frozenset({0, 2}), + frozenset({0, 1})])}""" + cube = test.test_set.cube(3) + self.assertEqual(pprint.pformat(cube), cube_repr_tgt) + cubo_repr_tgt = """\ +{frozenset({frozenset({0, 2}), frozenset({0})}): frozenset([frozenset([frozenset([0, + 2]), + frozenset([0, + 1, + 2])]), + frozenset([frozenset([0]), + frozenset([0, + 1])]), + frozenset([frozenset(), + frozenset([0])]), + frozenset([frozenset([2]), + frozenset([0, + 2])])]), + frozenset({frozenset({0, 1}), frozenset({1})}): frozenset([frozenset([frozenset([0, + 1]), + frozenset([0, + 1, + 2])]), + frozenset([frozenset([0]), + frozenset([0, + 1])]), + frozenset([frozenset([1]), + frozenset([1, + 2])]), + frozenset([frozenset(), + frozenset([1])])]), + frozenset({frozenset({1, 2}), frozenset({1})}): frozenset([frozenset([frozenset([1, + 2]), + frozenset([0, + 1, + 2])]), + frozenset([frozenset([2]), + frozenset([1, + 2])]), + frozenset([frozenset(), + frozenset([1])]), + frozenset([frozenset([1]), + frozenset([0, + 1])])]), + frozenset({frozenset({1, 2}), frozenset({2})}): frozenset([frozenset([frozenset([1, + 2]), + frozenset([0, + 1, + 2])]), + frozenset([frozenset([1]), + frozenset([1, + 2])]), + frozenset([frozenset([2]), + frozenset([0, + 2])]), + frozenset([frozenset(), + frozenset([2])])]), + frozenset({frozenset(), frozenset({0})}): frozenset([frozenset([frozenset([0]), + frozenset([0, + 1])]), + frozenset([frozenset([0]), + frozenset([0, + 2])]), + frozenset([frozenset(), + frozenset([1])]), + frozenset([frozenset(), + frozenset([2])])]), + frozenset({frozenset(), frozenset({1})}): frozenset([frozenset([frozenset(), + frozenset([0])]), + frozenset([frozenset([1]), + frozenset([1, + 2])]), + frozenset([frozenset(), + frozenset([2])]), + frozenset([frozenset([1]), + frozenset([0, + 1])])]), + frozenset({frozenset({2}), frozenset()}): frozenset([frozenset([frozenset([2]), + frozenset([1, + 2])]), + frozenset([frozenset(), + frozenset([0])]), + frozenset([frozenset(), + frozenset([1])]), + frozenset([frozenset([2]), + frozenset([0, + 2])])]), + frozenset({frozenset({0, 1, 2}), frozenset({0, 1})}): frozenset([frozenset([frozenset([1, + 2]), + frozenset([0, + 1, + 2])]), + frozenset([frozenset([0, + 2]), + frozenset([0, + 1, + 2])]), + frozenset([frozenset([0]), + frozenset([0, + 1])]), + frozenset([frozenset([1]), + frozenset([0, + 1])])]), + frozenset({frozenset({0}), frozenset({0, 1})}): frozenset([frozenset([frozenset(), + frozenset([0])]), + frozenset([frozenset([0, + 1]), + frozenset([0, + 1, + 2])]), + frozenset([frozenset([0]), + frozenset([0, + 2])]), + frozenset([frozenset([1]), + frozenset([0, + 1])])]), + frozenset({frozenset({2}), frozenset({0, 2})}): frozenset([frozenset([frozenset([0, + 2]), + frozenset([0, + 1, + 2])]), + frozenset([frozenset([2]), + frozenset([1, + 2])]), + frozenset([frozenset([0]), + frozenset([0, + 2])]), + frozenset([frozenset(), + frozenset([2])])]), + frozenset({frozenset({0, 1, 2}), frozenset({0, 2})}): frozenset([frozenset([frozenset([1, + 2]), + frozenset([0, + 1, + 2])]), + frozenset([frozenset([0, + 1]), + frozenset([0, + 1, + 2])]), + frozenset([frozenset([0]), + frozenset([0, + 2])]), + frozenset([frozenset([2]), + frozenset([0, + 2])])]), + frozenset({frozenset({1, 2}), frozenset({0, 1, 2})}): frozenset([frozenset([frozenset([0, + 2]), + frozenset([0, + 1, + 2])]), + frozenset([frozenset([0, + 1]), + frozenset([0, + 1, + 2])]), + frozenset([frozenset([2]), + frozenset([1, + 2])]), + frozenset([frozenset([1]), + frozenset([1, + 2])])])}""" + + cubo = test.test_set.linegraph(cube) + self.assertEqual(pprint.pformat(cubo), cubo_repr_tgt) + class DottedPrettyPrinter(pprint.PrettyPrinter): |