Update Black tests (#6618)

## Summary

Pulls in some tests that we previously couldn't support

## Test Plan

`cargo test`
This commit is contained in:
Charlie Marsh 2023-08-16 11:05:51 -04:00 committed by GitHub
parent 12f3c4c931
commit d0b8e4f701
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 778 additions and 5 deletions

View file

@ -1,3 +1,3 @@
# The input source must not contain any Py36-specific syntax (e.g. argument type # The input source must not contain any Py36-specific syntax (e.g. argument type
# annotations, trailing comma after *rest) or this test becomes invalid. # annotations, trailing comma after *rest) or this test becomes invalid.
def long_function_name(argument_one, argument_two, argument_three, argument_four, argument_five, argument_six, *rest): ... def long_function_name(argument_one, argument_two, argument_three, argument_four, argument_five, argument_six, *rest): pass

View file

@ -9,4 +9,4 @@ def long_function_name(
argument_six, argument_six,
*rest, *rest,
): ):
... pass

View file

@ -0,0 +1,194 @@
A[*b]
A[*b] = 1
A
del A[*b]
A
A[*b, *b]
A[*b, *b] = 1
A
del A[*b, *b]
A
A[b, *b]
A[b, *b] = 1
A
del A[b, *b]
A
A[*b, b]
A[*b, b] = 1
A
del A[*b, b]
A
A[b, b, *b]
A[b, b, *b] = 1
A
del A[b, b, *b]
A
A[*b, b, b]
A[*b, b, b] = 1
A
del A[*b, b, b]
A
A[b, *b, b]
A[b, *b, b] = 1
A
del A[b, *b, b]
A
A[b, b, *b, b]
A[b, b, *b, b] = 1
A
del A[b, b, *b, b]
A
A[b, *b, b, b]
A[b, *b, b, b] = 1
A
del A[b, *b, b, b]
A
A[A[b, *b, b]]
A[A[b, *b, b]] = 1
A
del A[A[b, *b, b]]
A
A[*A[b, *b, b]]
A[*A[b, *b, b]] = 1
A
del A[*A[b, *b, b]]
A
A[b, ...]
A[b, ...] = 1
A
del A[b, ...]
A
A[*A[b, ...]]
A[*A[b, ...]] = 1
A
del A[*A[b, ...]]
A
l = [1, 2, 3]
A[*l]
A[*l] = 1
A
del A[*l]
A
A[*l, 4]
A[*l, 4] = 1
A
del A[*l, 4]
A
A[0, *l]
A[0, *l] = 1
A
del A[0, *l]
A
A[1:2, *l]
A[1:2, *l] = 1
A
del A[1:2, *l]
A
repr(A[1:2, *l]) == repr(A[1:2, 1, 2, 3])
t = (1, 2, 3)
A[*t]
A[*t] = 1
A
del A[*t]
A
A[*t, 4]
A[*t, 4] = 1
A
del A[*t, 4]
A
A[0, *t]
A[0, *t] = 1
A
del A[0, *t]
A
A[1:2, *t]
A[1:2, *t] = 1
A
del A[1:2, *t]
A
repr(A[1:2, *t]) == repr(A[1:2, 1, 2, 3])
def returns_list():
return [1, 2, 3]
A[returns_list()]
A[returns_list()] = 1
A
del A[returns_list()]
A
A[returns_list(), 4]
A[returns_list(), 4] = 1
A
del A[returns_list(), 4]
A
A[*returns_list()]
A[*returns_list()] = 1
A
del A[*returns_list()]
A
A[*returns_list(), 4]
A[*returns_list(), 4] = 1
A
del A[*returns_list(), 4]
A
A[0, *returns_list()]
A[0, *returns_list()] = 1
A
del A[0, *returns_list()]
A
A[*returns_list(), *returns_list()]
A[*returns_list(), *returns_list()] = 1
A
del A[*returns_list(), *returns_list()]
A
A[1:2, *b]
A[*b, 1:2]
A[1:2, *b, 1:2]
A[*b, 1:2, *b]
A[1:, *b]
A[*b, 1:]
A[1:, *b, 1:]
A[*b, 1:, *b]
A[:1, *b]
A[*b, :1]
A[:1, *b, :1]
A[*b, :1, *b]
A[:, *b]
A[*b, :]
A[:, *b, :]
A[*b, :, *b]
A[a * b()]
A[a * b(), *c, *d(), e * f(g * h)]
A[a * b(), :]
A[a * b(), *c, *d(), e * f(g * h) :]
A[[b] * len(c), :]
def f1(*args: *b):
pass
f1.__annotations__
def f2(*args: *b, arg1):
pass
f2.__annotations__
def f3(*args: *b, arg1: int):
pass
f3.__annotations__
def f4(*args: *b, arg1: int = 2):
pass
f4.__annotations__

View file

@ -0,0 +1,194 @@
A[*b]
A[*b] = 1
A
del A[*b]
A
A[*b, *b]
A[*b, *b] = 1
A
del A[*b, *b]
A
A[b, *b]
A[b, *b] = 1
A
del A[b, *b]
A
A[*b, b]
A[*b, b] = 1
A
del A[*b, b]
A
A[b, b, *b]
A[b, b, *b] = 1
A
del A[b, b, *b]
A
A[*b, b, b]
A[*b, b, b] = 1
A
del A[*b, b, b]
A
A[b, *b, b]
A[b, *b, b] = 1
A
del A[b, *b, b]
A
A[b, b, *b, b]
A[b, b, *b, b] = 1
A
del A[b, b, *b, b]
A
A[b, *b, b, b]
A[b, *b, b, b] = 1
A
del A[b, *b, b, b]
A
A[A[b, *b, b]]
A[A[b, *b, b]] = 1
A
del A[A[b, *b, b]]
A
A[*A[b, *b, b]]
A[*A[b, *b, b]] = 1
A
del A[*A[b, *b, b]]
A
A[b, ...]
A[b, ...] = 1
A
del A[b, ...]
A
A[*A[b, ...]]
A[*A[b, ...]] = 1
A
del A[*A[b, ...]]
A
l = [1, 2, 3]
A[*l]
A[*l] = 1
A
del A[*l]
A
A[*l, 4]
A[*l, 4] = 1
A
del A[*l, 4]
A
A[0, *l]
A[0, *l] = 1
A
del A[0, *l]
A
A[1:2, *l]
A[1:2, *l] = 1
A
del A[1:2, *l]
A
repr(A[1:2, *l]) == repr(A[1:2, 1, 2, 3])
t = (1, 2, 3)
A[*t]
A[*t] = 1
A
del A[*t]
A
A[*t, 4]
A[*t, 4] = 1
A
del A[*t, 4]
A
A[0, *t]
A[0, *t] = 1
A
del A[0, *t]
A
A[1:2, *t]
A[1:2, *t] = 1
A
del A[1:2, *t]
A
repr(A[1:2, *t]) == repr(A[1:2, 1, 2, 3])
def returns_list():
return [1, 2, 3]
A[returns_list()]
A[returns_list()] = 1
A
del A[returns_list()]
A
A[returns_list(), 4]
A[returns_list(), 4] = 1
A
del A[returns_list(), 4]
A
A[*returns_list()]
A[*returns_list()] = 1
A
del A[*returns_list()]
A
A[*returns_list(), 4]
A[*returns_list(), 4] = 1
A
del A[*returns_list(), 4]
A
A[0, *returns_list()]
A[0, *returns_list()] = 1
A
del A[0, *returns_list()]
A
A[*returns_list(), *returns_list()]
A[*returns_list(), *returns_list()] = 1
A
del A[*returns_list(), *returns_list()]
A
A[1:2, *b]
A[*b, 1:2]
A[1:2, *b, 1:2]
A[*b, 1:2, *b]
A[1:, *b]
A[*b, 1:]
A[1:, *b, 1:]
A[*b, 1:, *b]
A[:1, *b]
A[*b, :1]
A[:1, *b, :1]
A[*b, :1, *b]
A[:, *b]
A[*b, :]
A[:, *b, :]
A[*b, :, *b]
A[a * b()]
A[a * b(), *c, *d(), e * f(g * h)]
A[a * b(), :]
A[a * b(), *c, *d(), e * f(g * h) :]
A[[b] * len(c), :]
def f1(*args: *b):
pass
f1.__annotations__
def f2(*args: *b, arg1):
pass
f2.__annotations__
def f3(*args: *b, arg1: int):
pass
f3.__annotations__
def f4(*args: *b, arg1: int = 2):
pass
f4.__annotations__

View file

@ -0,0 +1,69 @@
if (foo := 0):
pass
if (foo := 1):
pass
if (y := 5 + 5):
pass
y = (x := 0)
y += (x := 0)
(y := 5 + 5)
test: int = (test2 := 2)
a, b = (test := (1, 2))
# see also https://github.com/psf/black/issues/2139
assert (foo := 42 - 12)
foo(x=(y := f(x)))
def foo(answer=(p := 42)):
...
def foo2(answer: (p := 42) = 5):
...
lambda: (x := 1)
a[(x := 12)]
a[:(x := 13)]
# we don't touch expressions in f-strings but if we do one day, don't break 'em
f'{(x:=10)}'
def a():
return (x := 3)
await (b := 1)
yield (a := 2)
raise (c := 3)
def this_is_so_dumb() -> (please := no):
pass
async def await_the_walrus():
with (x := y):
pass
with (x := y) as z, (a := b) as c:
pass
with (x := await y):
pass
with (x := await a, y := await b):
pass
with ((x := await a, y := await b)):
pass
with (x := await a), (y := await b):
pass

View file

@ -0,0 +1,71 @@
if foo := 0:
pass
if foo := 1:
pass
if y := 5 + 5:
pass
y = (x := 0)
y += (x := 0)
(y := 5 + 5)
test: int = (test2 := 2)
a, b = (test := (1, 2))
# see also https://github.com/psf/black/issues/2139
assert (foo := 42 - 12)
foo(x=(y := f(x)))
def foo(answer=(p := 42)):
...
def foo2(answer: (p := 42) = 5):
...
lambda: (x := 1)
a[(x := 12)]
a[:(x := 13)]
# we don't touch expressions in f-strings but if we do one day, don't break 'em
f"{(x:=10)}"
def a():
return (x := 3)
await (b := 1)
yield (a := 2)
raise (c := 3)
def this_is_so_dumb() -> (please := no):
pass
async def await_the_walrus():
with (x := y):
pass
with (x := y) as z, (a := b) as c:
pass
with (x := await y):
pass
with (x := await a, y := await b):
pass
with (x := await a, y := await b):
pass
with (x := await a), (y := await b):
pass

View file

@ -43,6 +43,7 @@ def import_fixture(fixture: Path, fixture_set: str):
# The name of the folders in the `data` for which the tests should be imported # The name of the folders in the `data` for which the tests should be imported
FIXTURE_SETS = [ FIXTURE_SETS = [
"fast",
"py_36", "py_36",
"py_37", "py_37",
"py_38", "py_38",
@ -58,9 +59,6 @@ FIXTURE_SETS = [
# Tests that ruff doesn't fully support yet and, therefore, should not be imported # Tests that ruff doesn't fully support yet and, therefore, should not be imported
IGNORE_LIST = [ IGNORE_LIST = [
"pep_572_remove_parens.py", # Reformatting bugs
"pep_646.py", # Rust Python parser bug
# Contain syntax errors # Contain syntax errors
"async_as_identifier.py", "async_as_identifier.py",
"invalid_header.py", "invalid_header.py",

View file

@ -0,0 +1,247 @@
---
source: crates/ruff_python_formatter/tests/fixtures.rs
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/py_38/pep_572_remove_parens.py
---
## Input
```py
if (foo := 0):
pass
if (foo := 1):
pass
if (y := 5 + 5):
pass
y = (x := 0)
y += (x := 0)
(y := 5 + 5)
test: int = (test2 := 2)
a, b = (test := (1, 2))
# see also https://github.com/psf/black/issues/2139
assert (foo := 42 - 12)
foo(x=(y := f(x)))
def foo(answer=(p := 42)):
...
def foo2(answer: (p := 42) = 5):
...
lambda: (x := 1)
a[(x := 12)]
a[:(x := 13)]
# we don't touch expressions in f-strings but if we do one day, don't break 'em
f'{(x:=10)}'
def a():
return (x := 3)
await (b := 1)
yield (a := 2)
raise (c := 3)
def this_is_so_dumb() -> (please := no):
pass
async def await_the_walrus():
with (x := y):
pass
with (x := y) as z, (a := b) as c:
pass
with (x := await y):
pass
with (x := await a, y := await b):
pass
with ((x := await a, y := await b)):
pass
with (x := await a), (y := await b):
pass
```
## Black Differences
```diff
--- Black
+++ Ruff
@@ -34,7 +34,7 @@
lambda: (x := 1)
a[(x := 12)]
-a[:(x := 13)]
+a[: (x := 13)]
# we don't touch expressions in f-strings but if we do one day, don't break 'em
f"{(x:=10)}"
```
## Ruff Output
```py
if foo := 0:
pass
if foo := 1:
pass
if y := 5 + 5:
pass
y = (x := 0)
y += (x := 0)
(y := 5 + 5)
test: int = (test2 := 2)
a, b = (test := (1, 2))
# see also https://github.com/psf/black/issues/2139
assert (foo := 42 - 12)
foo(x=(y := f(x)))
def foo(answer=(p := 42)):
...
def foo2(answer: (p := 42) = 5):
...
lambda: (x := 1)
a[(x := 12)]
a[: (x := 13)]
# we don't touch expressions in f-strings but if we do one day, don't break 'em
f"{(x:=10)}"
def a():
return (x := 3)
await (b := 1)
yield (a := 2)
raise (c := 3)
def this_is_so_dumb() -> (please := no):
pass
async def await_the_walrus():
with (x := y):
pass
with (x := y) as z, (a := b) as c:
pass
with (x := await y):
pass
with (x := await a, y := await b):
pass
with (x := await a, y := await b):
pass
with (x := await a), (y := await b):
pass
```
## Black Output
```py
if foo := 0:
pass
if foo := 1:
pass
if y := 5 + 5:
pass
y = (x := 0)
y += (x := 0)
(y := 5 + 5)
test: int = (test2 := 2)
a, b = (test := (1, 2))
# see also https://github.com/psf/black/issues/2139
assert (foo := 42 - 12)
foo(x=(y := f(x)))
def foo(answer=(p := 42)):
...
def foo2(answer: (p := 42) = 5):
...
lambda: (x := 1)
a[(x := 12)]
a[:(x := 13)]
# we don't touch expressions in f-strings but if we do one day, don't break 'em
f"{(x:=10)}"
def a():
return (x := 3)
await (b := 1)
yield (a := 2)
raise (c := 3)
def this_is_so_dumb() -> (please := no):
pass
async def await_the_walrus():
with (x := y):
pass
with (x := y) as z, (a := b) as c:
pass
with (x := await y):
pass
with (x := await a, y := await b):
pass
with (x := await a, y := await b):
pass
with (x := await a), (y := await b):
pass
```