From fd7fd84fe38a761ff2143c4bf965a6db8989a92d Mon Sep 17 00:00:00 2001 From: sobolevn Date: Sat, 21 Oct 2023 08:56:16 +0300 Subject: [PATCH 1/5] gh-111147: Fix `test_set_of_sets_reprs` in `test_pprint` --- Lib/test/test_pprint.py | 292 +++++++++++----------------------------- 1 file changed, 82 insertions(+), 210 deletions(-) diff --git a/Lib/test/test_pprint.py b/Lib/test/test_pprint.py index 6ea7e7db2ce113..6c86a0a09abb65 100644 --- a/Lib/test/test_pprint.py +++ b/Lib/test/test_pprint.py @@ -8,7 +8,6 @@ import pprint import random import test.support -import test.test_set import types import unittest @@ -619,217 +618,90 @@ def test_set_reprs(self): self.assertEqual(pprint.pformat(frozenset3(range(7)), width=20), 'frozenset3({0, 1, 2, 3, 4, 5, 6})') - @unittest.expectedFailure - #See http://bugs.python.org/issue13907 @test.support.cpython_only def test_set_of_sets_reprs(self): - # This test creates a complex arrangement of frozensets and - # compares the pretty-printed repr against a string hard-coded in - # the test. The hard-coded repr depends on the sort order of - # frozensets. - # - # However, as the docs point out: "Since sets only define - # partial ordering (subset relationships), the output of the - # list.sort() method is undefined for lists of sets." - # - # In a nutshell, the test assumes frozenset({0}) will always - # sort before frozenset({1}), but: - # - # >>> frozenset({0}) < frozenset({1}) - # False - # >>> frozenset({1}) < frozenset({0}) - # False - # - # Consequently, this test is fragile and - # implementation-dependent. Small changes to Python's sort - # algorithm cause the test to fail when it should pass. - # XXX Or changes to the dictionary implementation... - - 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) + # This test has a long history, see: + # - https://github.com/python/cpython/commit/969fe57baa0eb80332990f9cda936a33e13fabef + # - https://bugs.python.org/issue13907 + # - https://github.com/python/cpython/issues/111147 + + import textwrap + + # Single-line: + self.assertEqual( + pprint.pformat(frozenset((frozenset(), frozenset((1,))))), + 'frozenset({frozenset(), frozenset({1})})', + ) + self.assertEqual( + pprint.pformat(frozenset((frozenset(), frozenset((1, 2))))), + 'frozenset({frozenset(), frozenset({1, 2})})', + ) + self.assertEqual( + pprint.pformat(frozenset((frozenset(), frozenset((1, 2, 3))))), + 'frozenset({frozenset(), frozenset({1, 2, 3})})', + ) + + # Multiline: + expected_format = textwrap.dedent(""" + frozenset({frozenset(), + frozenset({0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 20, + 21, + 22, + 23, + 24})})""") + self.assertEqual( + pprint.pformat( + frozenset(( + frozenset(), + frozenset(range(25)), + )), + # len(str(frozenset(range(25)))) is longer than 80 + width=80, + ), + expected_format[1:], # strip first newline + ) + + # And also `frozenset`s with `dict`: + self.assertEqual( + pprint.pformat({ + frozenset((1, 2)): frozenset((frozenset(), frozenset((1, 2, 3)))), + }), + '{frozenset({1, 2}): frozenset({frozenset(), frozenset({1, 2, 3})})}', + ) + + # and multiline: + expected_format = textwrap.dedent(""" + {frozenset({frozenset(), frozenset({1, 2, 3})}): frozenset({frozenset(), + frozenset({1, + 2, + 3})})}""") + self.assertEqual( + pprint.pformat({ + frozenset((frozenset(), frozenset((1, 2, 3)))): + frozenset((frozenset(), frozenset((1, 2, 3)))), + }), + expected_format[1:], # strip first newline + ) def test_depth(self): nested_tuple = (1, (2, (3, (4, (5, 6))))) From 994b8e1daffe1894e84170b96b80780ff547e6cd Mon Sep 17 00:00:00 2001 From: sobolevn Date: Wed, 15 Nov 2023 22:26:20 +0300 Subject: [PATCH 2/5] Address review --- Lib/test/test_pprint.py | 181 +++++++++++++++++++++++++--------------- 1 file changed, 116 insertions(+), 65 deletions(-) diff --git a/Lib/test/test_pprint.py b/Lib/test/test_pprint.py index beeef2329279d2..efe0f0f03f5342 100644 --- a/Lib/test/test_pprint.py +++ b/Lib/test/test_pprint.py @@ -622,70 +622,36 @@ def test_set_reprs(self): self.assertEqual(pprint.pformat(frozenset3(range(7)), width=20), 'frozenset3({0, 1, 2, 3, 4, 5, 6})') - @test.support.cpython_only def test_set_of_sets_reprs(self): + # This test creates a complex arrangement of frozensets and + # compares the pretty-printed repr against a string hard-coded in + # the test. The hard-coded repr depends on the sort order of + # frozensets. + # + # However, as the docs point out: "Since sets only define + # partial ordering (subset relationships), the output of the + # list.sort() method is undefined for lists of sets." + # + # >>> frozenset({0}) < frozenset({1}) + # False + # >>> frozenset({1}) < frozenset({0}) + # False + # + # In this test we list all possible invariants of the result + # for unordered frozensets. + # # This test has a long history, see: # - https://github.com/python/cpython/commit/969fe57baa0eb80332990f9cda936a33e13fabef - # - https://bugs.python.org/issue13907 + # - https://github.com/python/cpython/issues/58115 # - https://github.com/python/cpython/issues/111147 import textwrap - # Single-line: - self.assertEqual( - pprint.pformat(frozenset((frozenset(), frozenset((1,))))), - 'frozenset({frozenset(), frozenset({1})})', - ) - self.assertEqual( - pprint.pformat(frozenset((frozenset(), frozenset((1, 2))))), - 'frozenset({frozenset(), frozenset({1, 2})})', - ) + # Single-line, always ordered: self.assertEqual( pprint.pformat(frozenset((frozenset(), frozenset((1, 2, 3))))), 'frozenset({frozenset(), frozenset({1, 2, 3})})', ) - - # Multiline: - expected_format = textwrap.dedent(""" - frozenset({frozenset(), - frozenset({0, - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 12, - 13, - 14, - 15, - 16, - 17, - 18, - 19, - 20, - 21, - 22, - 23, - 24})})""") - self.assertEqual( - pprint.pformat( - frozenset(( - frozenset(), - frozenset(range(25)), - )), - # len(str(frozenset(range(25)))) is longer than 80 - width=80, - ), - expected_format[1:], # strip first newline - ) - - # And also `frozenset`s with `dict`: self.assertEqual( pprint.pformat({ frozenset((1, 2)): frozenset((frozenset(), frozenset((1, 2, 3)))), @@ -693,18 +659,103 @@ def test_set_of_sets_reprs(self): '{frozenset({1, 2}): frozenset({frozenset(), frozenset({1, 2, 3})})}', ) - # and multiline: - expected_format = textwrap.dedent(""" - {frozenset({frozenset(), frozenset({1, 2, 3})}): frozenset({frozenset(), - frozenset({1, - 2, - 3})})}""") - self.assertEqual( - pprint.pformat({ - frozenset((frozenset(), frozenset((1, 2, 3)))): - frozenset((frozenset(), frozenset((1, 2, 3)))), - }), - expected_format[1:], # strip first newline + # Single-line, unordered: + self.assertIn( + pprint.pformat( + frozenset(( + frozenset(("xyz", "qwerty")), + frozenset(("abcd", "spam"))), + ), + ), + [ + "frozenset({frozenset({'qwerty', 'xyz'}), frozenset({'spam', 'abcd'})})", + "frozenset({frozenset({'xyz', 'qwerty'}), frozenset({'spam', 'abcd'})})", + "frozenset({frozenset({'qwerty', 'xyz'}), frozenset({'abcd', 'spam'})})", + "frozenset({frozenset({'xyz', 'qwerty'}), frozenset({'abcd', 'spam'})})", + + "frozenset({frozenset({'spam', 'abcd'}), frozenset({'qwerty', 'xyz'})})", + "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]) + + check( + pprint.pformat( + 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({'abcd is even longer that before', + 'spam is not so long'}), + frozenset({'qwerty is also absurdly long', + 'xyz very-very long string'})}) + """, + + """ + frozenset({frozenset({'abcd is even longer that before', + 'spam is not so long'}), + frozenset({'xyz very-very long string', + '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'}), + frozenset({'abcd is even longer that before', + 'spam is not so long'})}) + """, + + """ + frozenset({frozenset({'qwerty is also absurdly long', + 'xyz very-very long string'}), + 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'})}) + """, + ], ) def test_depth(self): From 57010a7196ceb93d0043987c81c312825f75a299 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Thu, 16 Nov 2023 14:42:43 +0300 Subject: [PATCH 3/5] Address review --- Lib/test/test_pprint.py | 90 +++++++++++++++++++++++++---------------- 1 file changed, 56 insertions(+), 34 deletions(-) diff --git a/Lib/test/test_pprint.py b/Lib/test/test_pprint.py index efe0f0f03f5342..3f4df4909b111b 100644 --- a/Lib/test/test_pprint.py +++ b/Lib/test/test_pprint.py @@ -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( @@ -677,6 +682,7 @@ 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'})})", + ], ) @@ -684,6 +690,52 @@ def test_set_of_sets_reprs(self): 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(( @@ -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'}), @@ -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'})}) - """, ], ) From bcc2e7764bce3c5cb6397aa1b0ebd8e5a628e37e Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Thu, 16 Nov 2023 15:24:22 +0300 Subject: [PATCH 4/5] Apply suggestions from code review Co-authored-by: Serhiy Storchaka --- Lib/test/test_pprint.py | 70 ++++++++--------------------------------- 1 file changed, 13 insertions(+), 57 deletions(-) diff --git a/Lib/test/test_pprint.py b/Lib/test/test_pprint.py index 3f4df4909b111b..67e441fa00cf22 100644 --- a/Lib/test/test_pprint.py +++ b/Lib/test/test_pprint.py @@ -665,73 +665,29 @@ def test_set_of_sets_reprs(self): self.assertEqual(pprint.pformat(data), repr(data)) # Single-line, unordered: - self.assertIn( - pprint.pformat( - frozenset(( - frozenset(("xyz", "qwerty")), - frozenset(("abcd", "spam"))), - ), - ), - [ - "frozenset({frozenset({'qwerty', 'xyz'}), frozenset({'spam', 'abcd'})})", - "frozenset({frozenset({'xyz', 'qwerty'}), frozenset({'spam', 'abcd'})})", - "frozenset({frozenset({'qwerty', 'xyz'}), frozenset({'abcd', 'spam'})})", - "frozenset({frozenset({'xyz', 'qwerty'}), frozenset({'abcd', 'spam'})})", - - "frozenset({frozenset({'spam', 'abcd'}), frozenset({'qwerty', 'xyz'})})", - "frozenset({frozenset({'spam', 'abcd'}), frozenset({'xyz', 'qwerty'})})", - "frozenset({frozenset({'abcd', 'spam'}), frozenset({'qwerty', 'xyz'})})", - "frozenset({frozenset({'abcd', 'spam'}), frozenset({'xyz', 'qwerty'})})", - - ], - ) + fs1 = frozenset(("xyz", "qwerty")) + fs2 = frozenset(("abcd", "spam")) + fs = frozenset((fs1, fs2))) + self.assertEqual(pprint.pformat(fs, repr(fs)) # 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: + fs1 = frozenset(('regular string', 'other string')) + fs2 = frozenset(('third string', 'one more string')) check( - pprint.pformat( - frozenset(( - frozenset(('regular string', 'other string')), - frozenset(('third string', 'one more string')), - )) - ), + pprint.pformat(frozenset((fs1, fs2))), [ """ - 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({%r, + %r}) + """ % (fs1, fs2), """ - frozenset({frozenset({'one more string', 'third string'}), - frozenset({'other string', 'regular string'})}) - """, + frozenset({%r, + %r}) + """ % (fs2, fs1), ], ) From 6f8ca31761f577e0b37d00519185d10fa45f1b07 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Thu, 16 Nov 2023 16:03:53 +0300 Subject: [PATCH 5/5] Address review --- Lib/test/test_pprint.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/Lib/test/test_pprint.py b/Lib/test/test_pprint.py index 67e441fa00cf22..4e6fed1ab969ac 100644 --- a/Lib/test/test_pprint.py +++ b/Lib/test/test_pprint.py @@ -648,27 +648,24 @@ def test_set_of_sets_reprs(self): import textwrap # Single-line, always ordered: - data = frozenset((frozenset(), frozenset((1, 2, 3)))) - self.assertEqual( - pprint.pformat(data), - 'frozenset({frozenset(), frozenset({1, 2, 3})})', - ) + fs0 = frozenset() + fs1 = frozenset(('abc', 'xyz')) + data = frozenset((fs0, fs1)) + self.assertEqual(pprint.pformat(data), + 'frozenset({%r, %r})' % (fs0, fs1)) self.assertEqual(pprint.pformat(data), repr(data)) - data = { - frozenset((1, 2)): frozenset((frozenset(), frozenset((1, 2, 3)))), - } - self.assertEqual( - pprint.pformat(data), - '{frozenset({1, 2}): frozenset({frozenset(), frozenset({1, 2, 3})})}', - ) + fs2 = frozenset(('one', 'two')) + data = {fs2: frozenset((fs0, fs1))} + self.assertEqual(pprint.pformat(data), + "{%r: frozenset({%r, %r})}" % (fs2, fs0, fs1)) self.assertEqual(pprint.pformat(data), repr(data)) # Single-line, unordered: fs1 = frozenset(("xyz", "qwerty")) fs2 = frozenset(("abcd", "spam")) - fs = frozenset((fs1, fs2))) - self.assertEqual(pprint.pformat(fs, repr(fs)) + fs = frozenset((fs1, fs2)) + self.assertEqual(pprint.pformat(fs), repr(fs)) # Multiline, unordered: def check(res, invariants):