Skip to content

Commit 46e6837

Browse files
committed
Update Black tests
This is currently stacked on #20777 to remove the panic from introducing the new syntax error tracked in #20774. I also still need to go through the other new deviations to make sure they look reasonable. Summary -- ```shell git clone git@github.com:psf/black.git ../other/black crates/ruff_python_formatter/resources/test/fixtures/import_black_tests.py ../other/black ``` Then ran our tests and accepted the snapshots I had to make a small fix to our tuple normalization logic for `del` statements in the second commit, otherwise the tests were panicking at a changed AST. I think the new implementation is closer to the intention described in the nearby comment anyway, though. The first commit adds the new files, the next three commits make some small fixes to help get the tests running, and then the last commit accepts all of the new snapshots, including the new unsupported syntax error for one f-string example, tracked in #20774. Test Plan -- Newly imported tests
1 parent d912f13 commit 46e6837

File tree

99 files changed

+2660
-65
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+2660
-65
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# regression test for #1765
2+
class Foo:
3+
def foo(self):
4+
if True:
5+
content_ids: Mapping[
6+
str, Optional[ContentId]
7+
] = self.publisher_content_store.store_config_contents(files)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# regression test for #1765
2+
class Foo:
3+
def foo(self):
4+
if True:
5+
content_ids: Mapping[str, Optional[ContentId]] = (
6+
self.publisher_content_store.store_config_contents(files)
7+
)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"target_version": "3.10"}
1+
{"target_version": "3.10"}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# long variable name
2+
this_is_a_ridiculously_long_name_and_nobody_in_their_right_mind_would_use_one_like_it = 0
3+
this_is_a_ridiculously_long_name_and_nobody_in_their_right_mind_would_use_one_like_it = 1 # with a comment
4+
this_is_a_ridiculously_long_name_and_nobody_in_their_right_mind_would_use_one_like_it = [
5+
1, 2, 3
6+
]
7+
this_is_a_ridiculously_long_name_and_nobody_in_their_right_mind_would_use_one_like_it = function()
8+
this_is_a_ridiculously_long_name_and_nobody_in_their_right_mind_would_use_one_like_it = function(
9+
arg1, arg2, arg3
10+
)
11+
this_is_a_ridiculously_long_name_and_nobody_in_their_right_mind_would_use_one_like_it = function(
12+
[1, 2, 3], arg1, [1, 2, 3], arg2, [1, 2, 3], arg3
13+
)
14+
# long function name
15+
normal_name = but_the_function_name_is_now_ridiculously_long_and_it_is_still_super_annoying()
16+
normal_name = but_the_function_name_is_now_ridiculously_long_and_it_is_still_super_annoying(
17+
arg1, arg2, arg3
18+
)
19+
normal_name = but_the_function_name_is_now_ridiculously_long_and_it_is_still_super_annoying(
20+
[1, 2, 3], arg1, [1, 2, 3], arg2, [1, 2, 3], arg3
21+
)
22+
string_variable_name = (
23+
"a string that is waaaaaaaayyyyyyyy too long, even in parens, there's nothing you can do" # noqa
24+
)
25+
for key in """
26+
hostname
27+
port
28+
username
29+
""".split():
30+
if key in self.connect_kwargs:
31+
raise ValueError(err.format(key))
32+
concatenated_strings = "some strings that are " "concatenated implicitly, so if you put them on separate " "lines it will fit"
33+
del concatenated_strings, string_variable_name, normal_function_name, normal_name, need_more_to_make_the_line_long_enough
34+
del ([], name_1, name_2), [(), [], name_4, name_3], name_1[[name_2 for name_1 in name_0]]
35+
del (),
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# long variable name
2+
this_is_a_ridiculously_long_name_and_nobody_in_their_right_mind_would_use_one_like_it = (
3+
0
4+
)
5+
this_is_a_ridiculously_long_name_and_nobody_in_their_right_mind_would_use_one_like_it = (
6+
1 # with a comment
7+
)
8+
this_is_a_ridiculously_long_name_and_nobody_in_their_right_mind_would_use_one_like_it = [
9+
1,
10+
2,
11+
3,
12+
]
13+
this_is_a_ridiculously_long_name_and_nobody_in_their_right_mind_would_use_one_like_it = (
14+
function()
15+
)
16+
this_is_a_ridiculously_long_name_and_nobody_in_their_right_mind_would_use_one_like_it = function(
17+
arg1, arg2, arg3
18+
)
19+
this_is_a_ridiculously_long_name_and_nobody_in_their_right_mind_would_use_one_like_it = function(
20+
[1, 2, 3], arg1, [1, 2, 3], arg2, [1, 2, 3], arg3
21+
)
22+
# long function name
23+
normal_name = (
24+
but_the_function_name_is_now_ridiculously_long_and_it_is_still_super_annoying()
25+
)
26+
normal_name = (
27+
but_the_function_name_is_now_ridiculously_long_and_it_is_still_super_annoying(
28+
arg1, arg2, arg3
29+
)
30+
)
31+
normal_name = (
32+
but_the_function_name_is_now_ridiculously_long_and_it_is_still_super_annoying(
33+
[1, 2, 3], arg1, [1, 2, 3], arg2, [1, 2, 3], arg3
34+
)
35+
)
36+
string_variable_name = "a string that is waaaaaaaayyyyyyyy too long, even in parens, there's nothing you can do" # noqa
37+
for key in """
38+
hostname
39+
port
40+
username
41+
""".split():
42+
if key in self.connect_kwargs:
43+
raise ValueError(err.format(key))
44+
concatenated_strings = (
45+
"some strings that are "
46+
"concatenated implicitly, so if you put them on separate "
47+
"lines it will fit"
48+
)
49+
del (
50+
concatenated_strings,
51+
string_variable_name,
52+
normal_function_name,
53+
normal_name,
54+
need_more_to_make_the_line_long_enough,
55+
)
56+
del (
57+
([], name_1, name_2),
58+
[(), [], name_4, name_3],
59+
name_1[[name_2 for name_1 in name_0]],
60+
)
61+
del ((),)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"target_version": "3.8"}
1+
{"target_version": "3.8"}

crates/ruff_python_formatter/resources/test/fixtures/black/cases/context_managers_39.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,9 @@ async def func():
8282
argument1, argument2, argument3="some_value"
8383
):
8484
pass
85+
86+
87+
88+
# don't remove the brackets here, it changes the meaning of the code.
89+
with (x, y) as z:
90+
pass

crates/ruff_python_formatter/resources/test/fixtures/black/cases/context_managers_39.py.expect

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,8 @@ async def func():
8383
some_other_function(argument1, argument2, argument3="some_value"),
8484
):
8585
pass
86+
87+
88+
# don't remove the brackets here, it changes the meaning of the code.
89+
with (x, y) as z:
90+
pass
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"""
2+
87 characters ............................................................................
3+
"""
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"""
2+
87 characters ............................................................................
3+
"""

0 commit comments

Comments
 (0)