From 4e6f2d1a0d9237e672008efebf6ac3ea4f3e8c82 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Thu, 27 Jan 2022 20:58:01 -0800 Subject: [PATCH 1/3] torture test Fixes #2651. Fixes #2754. Fixes #2518. This adds a test that lists a number of cases of unstable formatting that we have seen in the issue tracker. Checking it in will ensure that we don't regress on these cases. --- tests/data/torture.py | 64 +++++++++++++++++++++++++++++++++++++++++++ tests/test_format.py | 1 + 2 files changed, 65 insertions(+) create mode 100644 tests/data/torture.py diff --git a/tests/data/torture.py b/tests/data/torture.py new file mode 100644 index 00000000000..99229ea6466 --- /dev/null +++ b/tests/data/torture.py @@ -0,0 +1,64 @@ +importA;() << 0 ** 101234234242352525425252352352525234890264906820496920680926538059059209922523523525 # + +assert sort_by_dependency( + { + "1": {"2", "3"}, "2": {"2a", "2b"}, "3": {"3a", "3b"}, + "2a": set(), "2b": set(), "3a": set(), "3b": set() + } +) == ["2a", "2b", "2", "3a", "3b", "3", "1"] + +importA +0;0^0# + +class A: + def foo(self): + for _ in range(10): + aaaaaaaaaaaaaaaaaaa = bbbbbbbbbbbbbbb.cccccccccc( # pylint: disable=no-member + xxxxxxxxxxxx + ) + +assert ( + a_function(very_long_arguments_that_surpass_the_limit, which_is_eighty_eight_in_this_case_plus_a_bit_more) + == {"x": "this need to pass the line limit as well", "b": "but only by a little bit"} +) + +# output + +importA +( + () + << 0 + ** 101234234242352525425252352352525234890264906820496920680926538059059209922523523525 +) # + +assert ( + sort_by_dependency( + { + "1": {"2", "3"}, + "2": {"2a", "2b"}, + "3": {"3a", "3b"}, + "2a": set(), + "2b": set(), + "3a": set(), + "3b": set(), + } + ) + == ["2a", "2b", "2", "3a", "3b", "3", "1"] +) + +importA +0 +0 ^ 0 # + + +class A: + def foo(self): + for _ in range(10): + aaaaaaaaaaaaaaaaaaa = bbbbbbbbbbbbbbb.cccccccccc( + xxxxxxxxxxxx + ) # pylint: disable=no-member + +assert ( + a_function(very_long_arguments_that_surpass_the_limit, which_is_eighty_eight_in_this_case_plus_a_bit_more) + == {"x": "this need to pass the line limit as well", "b": "but only by a little bit"} +) diff --git a/tests/test_format.py b/tests/test_format.py index 88f084ea478..5a5d06ca49b 100644 --- a/tests/test_format.py +++ b/tests/test_format.py @@ -52,6 +52,7 @@ "remove_parens", "slices", "string_prefixes", + "torture", "trailing_comma_optional_parens1", "trailing_comma_optional_parens2", "trailing_comma_optional_parens3", From 9adcd80153ea08a62bb52af6ec1d335252a7ef22 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Thu, 27 Jan 2022 21:07:37 -0800 Subject: [PATCH 2/3] remove case that is still broken --- tests/data/torture.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/tests/data/torture.py b/tests/data/torture.py index 99229ea6466..b4e6666b328 100644 --- a/tests/data/torture.py +++ b/tests/data/torture.py @@ -17,11 +17,6 @@ def foo(self): xxxxxxxxxxxx ) -assert ( - a_function(very_long_arguments_that_surpass_the_limit, which_is_eighty_eight_in_this_case_plus_a_bit_more) - == {"x": "this need to pass the line limit as well", "b": "but only by a little bit"} -) - # output importA @@ -57,8 +52,3 @@ def foo(self): aaaaaaaaaaaaaaaaaaa = bbbbbbbbbbbbbbb.cccccccccc( xxxxxxxxxxxx ) # pylint: disable=no-member - -assert ( - a_function(very_long_arguments_that_surpass_the_limit, which_is_eighty_eight_in_this_case_plus_a_bit_more) - == {"x": "this need to pass the line limit as well", "b": "but only by a little bit"} -) From 21cb584b804f3dd3f95c694dddb8a43f3b3f6bfc Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Thu, 27 Jan 2022 21:08:48 -0800 Subject: [PATCH 3/3] case from #2321 --- tests/data/torture.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/data/torture.py b/tests/data/torture.py index b4e6666b328..79a44c2e34c 100644 --- a/tests/data/torture.py +++ b/tests/data/torture.py @@ -17,6 +17,11 @@ def foo(self): xxxxxxxxxxxx ) +def test(self, othr): + return (1 == 2 and + (name, description, self.default, self.selected, self.auto_generated, self.parameters, self.meta_data, self.schedule) == + (name, description, othr.default, othr.selected, othr.auto_generated, othr.parameters, othr.meta_data, othr.schedule)) + # output importA @@ -52,3 +57,25 @@ def foo(self): aaaaaaaaaaaaaaaaaaa = bbbbbbbbbbbbbbb.cccccccccc( xxxxxxxxxxxx ) # pylint: disable=no-member + + +def test(self, othr): + return 1 == 2 and ( + name, + description, + self.default, + self.selected, + self.auto_generated, + self.parameters, + self.meta_data, + self.schedule, + ) == ( + name, + description, + othr.default, + othr.selected, + othr.auto_generated, + othr.parameters, + othr.meta_data, + othr.schedule, + )