Skip to content

Commit

Permalink
Address review
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn committed Nov 16, 2023
1 parent 994b8e1 commit 57010a7
Showing 1 changed file with 56 additions and 34 deletions.
90 changes: 56 additions & 34 deletions Lib/test/test_pprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,16 +648,21 @@ def test_set_of_sets_reprs(self):
import textwrap

# Single-line, always ordered:
data = frozenset((frozenset(), frozenset((1, 2, 3))))
self.assertEqual(
pprint.pformat(frozenset((frozenset(), frozenset((1, 2, 3))))),
pprint.pformat(data),
'frozenset({frozenset(), frozenset({1, 2, 3})})',
)
self.assertEqual(pprint.pformat(data), repr(data))

data = {
frozenset((1, 2)): frozenset((frozenset(), frozenset((1, 2, 3)))),
}
self.assertEqual(
pprint.pformat({
frozenset((1, 2)): frozenset((frozenset(), frozenset((1, 2, 3)))),
}),
pprint.pformat(data),
'{frozenset({1, 2}): frozenset({frozenset(), frozenset({1, 2, 3})})}',
)
self.assertEqual(pprint.pformat(data), repr(data))

# Single-line, unordered:
self.assertIn(
Expand All @@ -677,13 +682,60 @@ def test_set_of_sets_reprs(self):
"frozenset({frozenset({'spam', 'abcd'}), frozenset({'xyz', 'qwerty'})})",
"frozenset({frozenset({'abcd', 'spam'}), frozenset({'qwerty', 'xyz'})})",
"frozenset({frozenset({'abcd', 'spam'}), frozenset({'xyz', 'qwerty'})})",

],
)

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

# Inner-most frozensets are singleline, result is multiline, unordered:
check(
pprint.pformat(
frozenset((
frozenset(('regular string', 'other string')),
frozenset(('third string', 'one more string')),
))
),
[
"""
frozenset({frozenset({'regular string', 'other string'}),
frozenset({'third string', 'one more string'})})
""",
"""
frozenset({frozenset({'regular string', 'other string'}),
frozenset({'one more string', 'third string'})})
""",
"""
frozenset({frozenset({'other string', 'regular string'}),
frozenset({'third string', 'one more string'})})
""",
"""
frozenset({frozenset({'other string', 'regular string'}),
frozenset({'one more string', 'third string'})})
""",
# -
"""
frozenset({frozenset({'third string', 'one more string'}),
frozenset({'regular string', 'other string'})})
""",
"""
frozenset({frozenset({'third string', 'one more string'}),
frozenset({'other string', 'regular string'})})
""",
"""
frozenset({frozenset({'one more string', 'third string'}),
frozenset({'regular string', 'other string'})})
""",
"""
frozenset({frozenset({'one more string', 'third string'}),
frozenset({'other string', 'regular string'})})
""",
],
)

# Everything is multiline, unordered:
check(
pprint.pformat(
frozenset((
Expand Down Expand Up @@ -712,22 +764,6 @@ def check(res, invariants):
'qwerty is also absurdly long'})})
""",

"""
frozenset({frozenset({'spam is not so long',
'abcd is even longer that before'}),
frozenset({'qwerty is also absurdly long',
'xyz very-very long string'})})
""",

"""
frozenset({frozenset({'spam is not so long',
'abcd is even longer that before'}),
frozenset({'xyz very-very long string',
'qwerty is also absurdly long'})})
""",

# -

"""
frozenset({frozenset({'qwerty is also absurdly long',
'xyz very-very long string'}),
Expand All @@ -741,20 +777,6 @@ def check(res, invariants):
frozenset({'spam is not so long',
'abcd is even longer that before'})})
""",

"""
frozenset({frozenset({'xyz very-very long string',
'qwerty is also absurdly long'}),
frozenset({'abcd is even longer that before',
'spam is not so long'})})
""",

"""
frozenset({frozenset({'xyz very-very long string',
'qwerty is also absurdly long'}),
frozenset({'spam is not so long',
'abcd is even longer that before'})})
""",
],
)

Expand Down

0 comments on commit 57010a7

Please sign in to comment.