Skip to content

Commit 57010a7

Browse files
committed
Address review
1 parent 994b8e1 commit 57010a7

File tree

1 file changed

+56
-34
lines changed

1 file changed

+56
-34
lines changed

Lib/test/test_pprint.py

Lines changed: 56 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -648,16 +648,21 @@ def test_set_of_sets_reprs(self):
648648
import textwrap
649649

650650
# Single-line, always ordered:
651+
data = frozenset((frozenset(), frozenset((1, 2, 3))))
651652
self.assertEqual(
652-
pprint.pformat(frozenset((frozenset(), frozenset((1, 2, 3))))),
653+
pprint.pformat(data),
653654
'frozenset({frozenset(), frozenset({1, 2, 3})})',
654655
)
656+
self.assertEqual(pprint.pformat(data), repr(data))
657+
658+
data = {
659+
frozenset((1, 2)): frozenset((frozenset(), frozenset((1, 2, 3)))),
660+
}
655661
self.assertEqual(
656-
pprint.pformat({
657-
frozenset((1, 2)): frozenset((frozenset(), frozenset((1, 2, 3)))),
658-
}),
662+
pprint.pformat(data),
659663
'{frozenset({1, 2}): frozenset({frozenset(), frozenset({1, 2, 3})})}',
660664
)
665+
self.assertEqual(pprint.pformat(data), repr(data))
661666

662667
# Single-line, unordered:
663668
self.assertIn(
@@ -677,13 +682,60 @@ def test_set_of_sets_reprs(self):
677682
"frozenset({frozenset({'spam', 'abcd'}), frozenset({'xyz', 'qwerty'})})",
678683
"frozenset({frozenset({'abcd', 'spam'}), frozenset({'qwerty', 'xyz'})})",
679684
"frozenset({frozenset({'abcd', 'spam'}), frozenset({'xyz', 'qwerty'})})",
685+
680686
],
681687
)
682688

683689
# Multiline, unordered:
684690
def check(res, invariants):
685691
self.assertIn(res, [textwrap.dedent(i).strip() for i in invariants])
686692

693+
# Inner-most frozensets are singleline, result is multiline, unordered:
694+
check(
695+
pprint.pformat(
696+
frozenset((
697+
frozenset(('regular string', 'other string')),
698+
frozenset(('third string', 'one more string')),
699+
))
700+
),
701+
[
702+
"""
703+
frozenset({frozenset({'regular string', 'other string'}),
704+
frozenset({'third string', 'one more string'})})
705+
""",
706+
"""
707+
frozenset({frozenset({'regular string', 'other string'}),
708+
frozenset({'one more string', 'third string'})})
709+
""",
710+
"""
711+
frozenset({frozenset({'other string', 'regular string'}),
712+
frozenset({'third string', 'one more string'})})
713+
""",
714+
"""
715+
frozenset({frozenset({'other string', 'regular string'}),
716+
frozenset({'one more string', 'third string'})})
717+
""",
718+
# -
719+
"""
720+
frozenset({frozenset({'third string', 'one more string'}),
721+
frozenset({'regular string', 'other string'})})
722+
""",
723+
"""
724+
frozenset({frozenset({'third string', 'one more string'}),
725+
frozenset({'other string', 'regular string'})})
726+
""",
727+
"""
728+
frozenset({frozenset({'one more string', 'third string'}),
729+
frozenset({'regular string', 'other string'})})
730+
""",
731+
"""
732+
frozenset({frozenset({'one more string', 'third string'}),
733+
frozenset({'other string', 'regular string'})})
734+
""",
735+
],
736+
)
737+
738+
# Everything is multiline, unordered:
687739
check(
688740
pprint.pformat(
689741
frozenset((
@@ -712,22 +764,6 @@ def check(res, invariants):
712764
'qwerty is also absurdly long'})})
713765
""",
714766

715-
"""
716-
frozenset({frozenset({'spam is not so long',
717-
'abcd is even longer that before'}),
718-
frozenset({'qwerty is also absurdly long',
719-
'xyz very-very long string'})})
720-
""",
721-
722-
"""
723-
frozenset({frozenset({'spam is not so long',
724-
'abcd is even longer that before'}),
725-
frozenset({'xyz very-very long string',
726-
'qwerty is also absurdly long'})})
727-
""",
728-
729-
# -
730-
731767
"""
732768
frozenset({frozenset({'qwerty is also absurdly long',
733769
'xyz very-very long string'}),
@@ -741,20 +777,6 @@ def check(res, invariants):
741777
frozenset({'spam is not so long',
742778
'abcd is even longer that before'})})
743779
""",
744-
745-
"""
746-
frozenset({frozenset({'xyz very-very long string',
747-
'qwerty is also absurdly long'}),
748-
frozenset({'abcd is even longer that before',
749-
'spam is not so long'})})
750-
""",
751-
752-
"""
753-
frozenset({frozenset({'xyz very-very long string',
754-
'qwerty is also absurdly long'}),
755-
frozenset({'spam is not so long',
756-
'abcd is even longer that before'})})
757-
""",
758780
],
759781
)
760782

0 commit comments

Comments
 (0)