mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 10:48:32 +00:00
Update Black tests (#13375)
This commit is contained in:
parent
bb12fe9d0c
commit
d86e5ad031
46 changed files with 2653 additions and 24 deletions
|
@ -0,0 +1 @@
|
|||
{"target_version": "py310"}
|
10
crates/ruff_python_formatter/resources/test/fixtures/black/cases/backslash_before_indent.py
vendored
Normal file
10
crates/ruff_python_formatter/resources/test/fixtures/black/cases/backslash_before_indent.py
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
class Plotter:
|
||||
\
|
||||
pass
|
||||
|
||||
class AnotherCase:
|
||||
\
|
||||
"""Some
|
||||
\
|
||||
Docstring
|
||||
"""
|
|
@ -0,0 +1,10 @@
|
|||
class Plotter:
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class AnotherCase:
|
||||
"""Some
|
||||
\
|
||||
Docstring
|
||||
"""
|
|
@ -2,5 +2,7 @@ def bob(): # pylint: disable=W9016
|
|||
pass
|
||||
|
||||
|
||||
def bobtwo(): # some comment here
|
||||
def bobtwo():
|
||||
|
||||
# some comment here
|
||||
pass
|
||||
|
|
|
@ -67,3 +67,63 @@ async def async_function(self):
|
|||
@decorated
|
||||
async def async_function(self):
|
||||
...
|
||||
|
||||
class ClassA:
|
||||
def f(self):
|
||||
|
||||
...
|
||||
|
||||
|
||||
class ClassB:
|
||||
def f(self):
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
...
|
||||
|
||||
|
||||
class ClassC:
|
||||
def f(self):
|
||||
|
||||
...
|
||||
# Comment
|
||||
|
||||
|
||||
class ClassD:
|
||||
def f(self):# Comment 1
|
||||
|
||||
...# Comment 2
|
||||
# Comment 3
|
||||
|
||||
|
||||
class ClassE:
|
||||
def f(self):
|
||||
|
||||
...
|
||||
def f2(self):
|
||||
print(10)
|
||||
|
||||
|
||||
class ClassF:
|
||||
def f(self):
|
||||
|
||||
...# Comment 2
|
||||
|
||||
|
||||
class ClassG:
|
||||
def f(self):#Comment 1
|
||||
|
||||
...# Comment 2
|
||||
|
||||
|
||||
class ClassH:
|
||||
def f(self):
|
||||
#Comment
|
||||
|
||||
...
|
||||
|
|
|
@ -70,3 +70,47 @@ async def async_function(self): ...
|
|||
|
||||
@decorated
|
||||
async def async_function(self): ...
|
||||
|
||||
|
||||
class ClassA:
|
||||
def f(self): ...
|
||||
|
||||
|
||||
class ClassB:
|
||||
def f(self): ...
|
||||
|
||||
|
||||
class ClassC:
|
||||
def f(self):
|
||||
|
||||
...
|
||||
# Comment
|
||||
|
||||
|
||||
class ClassD:
|
||||
def f(self): # Comment 1
|
||||
|
||||
... # Comment 2
|
||||
# Comment 3
|
||||
|
||||
|
||||
class ClassE:
|
||||
def f(self): ...
|
||||
def f2(self):
|
||||
print(10)
|
||||
|
||||
|
||||
class ClassF:
|
||||
def f(self): ... # Comment 2
|
||||
|
||||
|
||||
class ClassG:
|
||||
def f(self): # Comment 1
|
||||
... # Comment 2
|
||||
|
||||
|
||||
class ClassH:
|
||||
def f(self):
|
||||
# Comment
|
||||
|
||||
...
|
||||
|
|
13
crates/ruff_python_formatter/resources/test/fixtures/black/cases/fmtonoff6.py
vendored
Normal file
13
crates/ruff_python_formatter/resources/test/fixtures/black/cases/fmtonoff6.py
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
# Regression test for https://github.com/psf/black/issues/2478.
|
||||
def foo():
|
||||
arr = (
|
||||
(3833567325051000, 5, 1, 2, 4229.25, 6, 0),
|
||||
# fmt: off
|
||||
)
|
||||
|
||||
|
||||
# Regression test for https://github.com/psf/black/issues/3458.
|
||||
dependencies = {
|
||||
a: b,
|
||||
# fmt: off
|
||||
}
|
13
crates/ruff_python_formatter/resources/test/fixtures/black/cases/fmtonoff6.py.expect
vendored
Normal file
13
crates/ruff_python_formatter/resources/test/fixtures/black/cases/fmtonoff6.py.expect
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
# Regression test for https://github.com/psf/black/issues/2478.
|
||||
def foo():
|
||||
arr = (
|
||||
(3833567325051000, 5, 1, 2, 4229.25, 6, 0),
|
||||
# fmt: off
|
||||
)
|
||||
|
||||
|
||||
# Regression test for https://github.com/psf/black/issues/3458.
|
||||
dependencies = {
|
||||
a: b,
|
||||
# fmt: off
|
||||
}
|
|
@ -33,6 +33,7 @@
|
|||
|
||||
#
|
||||
|
||||
|
||||
#
|
||||
pass
|
||||
|
||||
|
|
|
@ -59,3 +59,61 @@ some_module.some_function(
|
|||
some_module.some_function(
|
||||
argument1, (one, two,), argument4, argument5, argument6
|
||||
)
|
||||
|
||||
def foo() -> (
|
||||
# comment inside parenthesised return type
|
||||
int
|
||||
):
|
||||
...
|
||||
|
||||
def foo() -> (
|
||||
# comment inside parenthesised return type
|
||||
# more
|
||||
int
|
||||
# another
|
||||
):
|
||||
...
|
||||
|
||||
def foo() -> (
|
||||
# comment inside parenthesised new union return type
|
||||
int | str | bytes
|
||||
):
|
||||
...
|
||||
|
||||
def foo() -> (
|
||||
# comment inside plain tuple
|
||||
):
|
||||
pass
|
||||
|
||||
def foo(arg: (# comment with non-return annotation
|
||||
int
|
||||
# comment with non-return annotation
|
||||
)):
|
||||
pass
|
||||
|
||||
def foo(arg: (# comment with non-return annotation
|
||||
int | range | memoryview
|
||||
# comment with non-return annotation
|
||||
)):
|
||||
pass
|
||||
|
||||
def foo(arg: (# only before
|
||||
int
|
||||
)):
|
||||
pass
|
||||
|
||||
def foo(arg: (
|
||||
int
|
||||
# only after
|
||||
)):
|
||||
pass
|
||||
|
||||
variable: ( # annotation
|
||||
because
|
||||
# why not
|
||||
)
|
||||
|
||||
variable: (
|
||||
because
|
||||
# why not
|
||||
)
|
||||
|
|
|
@ -112,3 +112,75 @@ some_module.some_function(
|
|||
argument5,
|
||||
argument6,
|
||||
)
|
||||
|
||||
|
||||
def foo() -> (
|
||||
# comment inside parenthesised return type
|
||||
int
|
||||
): ...
|
||||
|
||||
|
||||
def foo() -> (
|
||||
# comment inside parenthesised return type
|
||||
# more
|
||||
int
|
||||
# another
|
||||
): ...
|
||||
|
||||
|
||||
def foo() -> (
|
||||
# comment inside parenthesised new union return type
|
||||
int
|
||||
| str
|
||||
| bytes
|
||||
): ...
|
||||
|
||||
|
||||
def foo() -> (
|
||||
# comment inside plain tuple
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
def foo(
|
||||
arg: ( # comment with non-return annotation
|
||||
int
|
||||
# comment with non-return annotation
|
||||
),
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
def foo(
|
||||
arg: ( # comment with non-return annotation
|
||||
int
|
||||
| range
|
||||
| memoryview
|
||||
# comment with non-return annotation
|
||||
),
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
def foo(arg: int): # only before
|
||||
pass
|
||||
|
||||
|
||||
def foo(
|
||||
arg: (
|
||||
int
|
||||
# only after
|
||||
),
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
variable: ( # annotation
|
||||
because
|
||||
# why not
|
||||
)
|
||||
|
||||
variable: (
|
||||
because
|
||||
# why not
|
||||
)
|
||||
|
|
|
@ -6,7 +6,7 @@ def foo2(parameter_1, parameter_2, parameter_3, parameter_4, parameter_5, parame
|
|||
def foo3(parameter_1, parameter_2, parameter_3, parameter_4, parameter_5, parameter_6, parameter_7): pass
|
||||
def foo4(parameter_1, parameter_2, parameter_3, parameter_4, parameter_5, parameter_6, parameter_7): pass
|
||||
|
||||
# Adding some unformatted code covering a wide range of syntaxes.
|
||||
# Adding some unformated code covering a wide range of syntaxes.
|
||||
|
||||
if True:
|
||||
# Incorrectly indented prefix comments.
|
||||
|
|
|
@ -28,7 +28,7 @@ def foo3(
|
|||
|
||||
def foo4(parameter_1, parameter_2, parameter_3, parameter_4, parameter_5, parameter_6, parameter_7): pass
|
||||
|
||||
# Adding some unformatted code covering a wide range of syntaxes.
|
||||
# Adding some unformated code covering a wide range of syntaxes.
|
||||
|
||||
if True:
|
||||
# Incorrectly indented prefix comments.
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
# flags: --line-ranges=6-1000
|
||||
# NOTE: If you need to modify this file, pay special attention to the --line-ranges=
|
||||
# flag above as it's formatting specifically these lines.
|
||||
def foo1(parameter_1, parameter_2, parameter_3, parameter_4, parameter_5, parameter_6, parameter_7): pass
|
||||
def foo2(parameter_1, parameter_2, parameter_3, parameter_4, parameter_5, parameter_6, parameter_7): pass
|
||||
def foo3(parameter_1, parameter_2, parameter_3, parameter_4, parameter_5, parameter_6, parameter_7): pass
|
||||
def foo4(parameter_1, parameter_2, parameter_3, parameter_4, parameter_5, parameter_6, parameter_7): pass
|
|
@ -0,0 +1,27 @@
|
|||
# flags: --line-ranges=6-1000
|
||||
# NOTE: If you need to modify this file, pay special attention to the --line-ranges=
|
||||
# flag above as it's formatting specifically these lines.
|
||||
def foo1(parameter_1, parameter_2, parameter_3, parameter_4, parameter_5, parameter_6, parameter_7): pass
|
||||
def foo2(parameter_1, parameter_2, parameter_3, parameter_4, parameter_5, parameter_6, parameter_7): pass
|
||||
def foo3(
|
||||
parameter_1,
|
||||
parameter_2,
|
||||
parameter_3,
|
||||
parameter_4,
|
||||
parameter_5,
|
||||
parameter_6,
|
||||
parameter_7,
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
def foo4(
|
||||
parameter_1,
|
||||
parameter_2,
|
||||
parameter_3,
|
||||
parameter_4,
|
||||
parameter_5,
|
||||
parameter_6,
|
||||
parameter_7,
|
||||
):
|
||||
pass
|
|
@ -82,7 +82,7 @@ match (0, 1, 2):
|
|||
match x:
|
||||
case [0]:
|
||||
y = 0
|
||||
case [1, 0] if (x := x[:0]):
|
||||
case [1, 0] if x := x[:0]:
|
||||
y = 1
|
||||
case [1, 0]:
|
||||
y = 2
|
||||
|
|
|
@ -82,7 +82,7 @@ match (0, 1, 2):
|
|||
match x:
|
||||
case [0]:
|
||||
y = 0
|
||||
case [1, 0] if (x := x[:0]):
|
||||
case [1, 0] if x := x[:0]:
|
||||
y = 1
|
||||
case [1, 0]:
|
||||
y = 2
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
{"preview": "enabled", "target_version": "py310"}
|
|
@ -0,0 +1,32 @@
|
|||
match match:
|
||||
case "test" if case != "not very loooooooooooooog condition": # comment
|
||||
pass
|
||||
|
||||
match smth:
|
||||
case "test" if "any long condition" != "another long condition" and "this is a long condition":
|
||||
pass
|
||||
case test if "any long condition" != "another long condition" and "this is a looooong condition":
|
||||
pass
|
||||
case test if "any long condition" != "another long condition" and "this is a looooong condition": # some additional comments
|
||||
pass
|
||||
case test if (True): # some comment
|
||||
pass
|
||||
case test if (False
|
||||
): # some comment
|
||||
pass
|
||||
case test if (True # some comment
|
||||
):
|
||||
pass # some comment
|
||||
case cases if (True # some comment
|
||||
): # some other comment
|
||||
pass # some comment
|
||||
case match if (True # some comment
|
||||
):
|
||||
pass # some comment
|
||||
|
||||
# case black_test_patma_052 (originally in the pattern_matching_complex test case)
|
||||
match x:
|
||||
case [1, 0] if x := x[:0]:
|
||||
y = 1
|
||||
case [1, 0] if (x := x[:0]):
|
||||
y = 1
|
|
@ -0,0 +1,36 @@
|
|||
match match:
|
||||
case "test" if case != "not very loooooooooooooog condition": # comment
|
||||
pass
|
||||
|
||||
match smth:
|
||||
case "test" if (
|
||||
"any long condition" != "another long condition" and "this is a long condition"
|
||||
):
|
||||
pass
|
||||
case test if (
|
||||
"any long condition" != "another long condition"
|
||||
and "this is a looooong condition"
|
||||
):
|
||||
pass
|
||||
case test if (
|
||||
"any long condition" != "another long condition"
|
||||
and "this is a looooong condition"
|
||||
): # some additional comments
|
||||
pass
|
||||
case test if True: # some comment
|
||||
pass
|
||||
case test if False: # some comment
|
||||
pass
|
||||
case test if True: # some comment
|
||||
pass # some comment
|
||||
case cases if True: # some comment # some other comment
|
||||
pass # some comment
|
||||
case match if True: # some comment
|
||||
pass # some comment
|
||||
|
||||
# case black_test_patma_052 (originally in the pattern_matching_complex test case)
|
||||
match x:
|
||||
case [1, 0] if x := x[:0]:
|
||||
y = 1
|
||||
case [1, 0] if x := x[:0]:
|
||||
y = 1
|
|
@ -19,7 +19,7 @@ z: (Short
|
|||
z: (int) = 2.3
|
||||
z: ((int)) = foo()
|
||||
|
||||
# In case I go for not enforcing parentheses, this might get improved at the same time
|
||||
# In case I go for not enforcing parantheses, this might get improved at the same time
|
||||
x = (
|
||||
z
|
||||
== 9999999999999999999999999999999999999999
|
||||
|
|
|
@ -28,7 +28,7 @@ z: Short | Short2 | Short3 | Short4 = 8
|
|||
z: int = 2.3
|
||||
z: int = foo()
|
||||
|
||||
# In case I go for not enforcing parentheses, this might get improved at the same time
|
||||
# In case I go for not enforcing parantheses, this might get improved at the same time
|
||||
x = (
|
||||
z
|
||||
== 9999999999999999999999999999999999999999
|
||||
|
|
1
crates/ruff_python_formatter/resources/test/fixtures/black/cases/pep_701.options.json
vendored
Normal file
1
crates/ruff_python_formatter/resources/test/fixtures/black/cases/pep_701.options.json
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
{"target_version": "py312"}
|
136
crates/ruff_python_formatter/resources/test/fixtures/black/cases/pep_701.py
vendored
Normal file
136
crates/ruff_python_formatter/resources/test/fixtures/black/cases/pep_701.py
vendored
Normal file
|
@ -0,0 +1,136 @@
|
|||
x = f"foo"
|
||||
x = f'foo'
|
||||
x = f"""foo"""
|
||||
x = f'''foo'''
|
||||
x = f"foo {{ bar {{ baz"
|
||||
x = f"foo {{ {2 + 2}bar {{ baz"
|
||||
x = f'foo {{ {2 + 2}bar {{ baz'
|
||||
x = f"""foo {{ {2 + 2}bar {{ baz"""
|
||||
x = f'''foo {{ {2 + 2}bar {{ baz'''
|
||||
|
||||
# edge case: FSTRING_MIDDLE containing only whitespace should not be stripped
|
||||
x = f"{a} {b}"
|
||||
|
||||
x = f"foo {
|
||||
2 + 2
|
||||
} bar baz"
|
||||
|
||||
x = f"foo {{ {"a {2 + 2} b"}bar {{ baz"
|
||||
x = f"foo {{ {f'a {2 + 2} b'}bar {{ baz"
|
||||
x = f"foo {{ {f"a {2 + 2} b"}bar {{ baz"
|
||||
|
||||
x = f"foo {{ {f'a {f"a {2 + 2} b"} b'}bar {{ baz"
|
||||
x = f"foo {{ {f"a {f"a {2 + 2} b"} b"}bar {{ baz"
|
||||
|
||||
x = """foo {{ {2 + 2}bar
|
||||
baz"""
|
||||
|
||||
|
||||
x = f"""foo {{ {2 + 2}bar {{ baz"""
|
||||
|
||||
x = f"""foo {{ {
|
||||
2 + 2
|
||||
}bar {{ baz"""
|
||||
|
||||
|
||||
x = f"""foo {{ {
|
||||
2 + 2
|
||||
}bar
|
||||
baz"""
|
||||
|
||||
x = f"""foo {{ a
|
||||
foo {2 + 2}bar {{ baz
|
||||
|
||||
x = f"foo {{ {
|
||||
2 + 2 # comment
|
||||
}bar"
|
||||
|
||||
{{ baz
|
||||
|
||||
}} buzz
|
||||
|
||||
{print("abc" + "def"
|
||||
)}
|
||||
abc"""
|
||||
|
||||
# edge case: end triple quotes at index zero
|
||||
f"""foo {2+2} bar
|
||||
"""
|
||||
|
||||
f' \' {f"'"} \' '
|
||||
f" \" {f'"'} \" "
|
||||
|
||||
x = f"a{2+2:=^72}b"
|
||||
x = f"a{2+2:x}b"
|
||||
|
||||
rf'foo'
|
||||
rf'{foo}'
|
||||
|
||||
f"{x:{y}d}"
|
||||
|
||||
x = f"a{2+2:=^{x}}b"
|
||||
x = f"a{2+2:=^{foo(x+y**2):something else}}b"
|
||||
x = f"a{2+2:=^{foo(x+y**2):something else}one more}b"
|
||||
f'{(abc:=10)}'
|
||||
|
||||
f"This is a really long string, but just make sure that you reflow fstrings {
|
||||
2+2:d
|
||||
}"
|
||||
f"This is a really long string, but just make sure that you reflow fstrings correctly {2+2:d}"
|
||||
|
||||
f"{2+2=}"
|
||||
f"{2+2 = }"
|
||||
f"{ 2 + 2 = }"
|
||||
|
||||
f"""foo {
|
||||
datetime.datetime.now():%Y
|
||||
%m
|
||||
%d
|
||||
}"""
|
||||
|
||||
f"{
|
||||
X
|
||||
!r
|
||||
}"
|
||||
|
||||
raise ValueError(
|
||||
"xxxxxxxxxxxIncorrect --line-ranges format, expect START-END, found"
|
||||
f" {lines_str!r}"
|
||||
)
|
||||
|
||||
f"`escape` only permitted in {{'html', 'latex', 'latex-math'}}, \
|
||||
got {escape}"
|
||||
|
||||
x = f'\N{GREEK CAPITAL LETTER DELTA} \N{SNOWMAN} {x}'
|
||||
fr'\{{\}}'
|
||||
|
||||
f"""
|
||||
WITH {f'''
|
||||
{1}_cte AS ()'''}
|
||||
"""
|
||||
|
||||
value: str = f'''foo
|
||||
'''
|
||||
|
||||
log(
|
||||
f"Received operation {server_operation.name} from "
|
||||
f"{self.writer._transport.get_extra_info('peername')}", # type: ignore[attr-defined]
|
||||
level=0,
|
||||
)
|
||||
|
||||
f"{1:{f'{2}'}}"
|
||||
f'{1:{f'{2}'}}'
|
||||
f'{1:{2}d}'
|
||||
|
||||
f'{{\\"kind\\":\\"ConfigMap\\",\\"metadata\\":{{\\"annotations\\":{{}},\\"name\\":\\"cluster-info\\",\\"namespace\\":\\"amazon-cloudwatch\\"}}}}'
|
||||
|
||||
f"""{'''
|
||||
'''}"""
|
||||
|
||||
f"{'\''}"
|
||||
f"{f'\''}"
|
||||
|
||||
f'{1}\{{'
|
||||
f'{2} foo \{{[\}}'
|
||||
f'\{3}'
|
||||
rf"\{"a"}"
|
136
crates/ruff_python_formatter/resources/test/fixtures/black/cases/pep_701.py.expect
vendored
Normal file
136
crates/ruff_python_formatter/resources/test/fixtures/black/cases/pep_701.py.expect
vendored
Normal file
|
@ -0,0 +1,136 @@
|
|||
x = f"foo"
|
||||
x = f"foo"
|
||||
x = f"""foo"""
|
||||
x = f"""foo"""
|
||||
x = f"foo {{ bar {{ baz"
|
||||
x = f"foo {{ {2 + 2}bar {{ baz"
|
||||
x = f"foo {{ {2 + 2}bar {{ baz"
|
||||
x = f"""foo {{ {2 + 2}bar {{ baz"""
|
||||
x = f"""foo {{ {2 + 2}bar {{ baz"""
|
||||
|
||||
# edge case: FSTRING_MIDDLE containing only whitespace should not be stripped
|
||||
x = f"{a} {b}"
|
||||
|
||||
x = f"foo {
|
||||
2 + 2
|
||||
} bar baz"
|
||||
|
||||
x = f"foo {{ {"a {2 + 2} b"}bar {{ baz"
|
||||
x = f"foo {{ {f'a {2 + 2} b'}bar {{ baz"
|
||||
x = f"foo {{ {f"a {2 + 2} b"}bar {{ baz"
|
||||
|
||||
x = f"foo {{ {f'a {f"a {2 + 2} b"} b'}bar {{ baz"
|
||||
x = f"foo {{ {f"a {f"a {2 + 2} b"} b"}bar {{ baz"
|
||||
|
||||
x = """foo {{ {2 + 2}bar
|
||||
baz"""
|
||||
|
||||
|
||||
x = f"""foo {{ {2 + 2}bar {{ baz"""
|
||||
|
||||
x = f"""foo {{ {
|
||||
2 + 2
|
||||
}bar {{ baz"""
|
||||
|
||||
|
||||
x = f"""foo {{ {
|
||||
2 + 2
|
||||
}bar
|
||||
baz"""
|
||||
|
||||
x = f"""foo {{ a
|
||||
foo {2 + 2}bar {{ baz
|
||||
|
||||
x = f"foo {{ {
|
||||
2 + 2 # comment
|
||||
}bar"
|
||||
|
||||
{{ baz
|
||||
|
||||
}} buzz
|
||||
|
||||
{print("abc" + "def"
|
||||
)}
|
||||
abc"""
|
||||
|
||||
# edge case: end triple quotes at index zero
|
||||
f"""foo {2+2} bar
|
||||
"""
|
||||
|
||||
f' \' {f"'"} \' '
|
||||
f" \" {f'"'} \" "
|
||||
|
||||
x = f"a{2+2:=^72}b"
|
||||
x = f"a{2+2:x}b"
|
||||
|
||||
rf"foo"
|
||||
rf"{foo}"
|
||||
|
||||
f"{x:{y}d}"
|
||||
|
||||
x = f"a{2+2:=^{x}}b"
|
||||
x = f"a{2+2:=^{foo(x+y**2):something else}}b"
|
||||
x = f"a{2+2:=^{foo(x+y**2):something else}one more}b"
|
||||
f"{(abc:=10)}"
|
||||
|
||||
f"This is a really long string, but just make sure that you reflow fstrings {
|
||||
2+2:d
|
||||
}"
|
||||
f"This is a really long string, but just make sure that you reflow fstrings correctly {2+2:d}"
|
||||
|
||||
f"{2+2=}"
|
||||
f"{2+2 = }"
|
||||
f"{ 2 + 2 = }"
|
||||
|
||||
f"""foo {
|
||||
datetime.datetime.now():%Y
|
||||
%m
|
||||
%d
|
||||
}"""
|
||||
|
||||
f"{
|
||||
X
|
||||
!r
|
||||
}"
|
||||
|
||||
raise ValueError(
|
||||
"xxxxxxxxxxxIncorrect --line-ranges format, expect START-END, found"
|
||||
f" {lines_str!r}"
|
||||
)
|
||||
|
||||
f"`escape` only permitted in {{'html', 'latex', 'latex-math'}}, \
|
||||
got {escape}"
|
||||
|
||||
x = f"\N{GREEK CAPITAL LETTER DELTA} \N{SNOWMAN} {x}"
|
||||
rf"\{{\}}"
|
||||
|
||||
f"""
|
||||
WITH {f'''
|
||||
{1}_cte AS ()'''}
|
||||
"""
|
||||
|
||||
value: str = f"""foo
|
||||
"""
|
||||
|
||||
log(
|
||||
f"Received operation {server_operation.name} from "
|
||||
f"{self.writer._transport.get_extra_info('peername')}", # type: ignore[attr-defined]
|
||||
level=0,
|
||||
)
|
||||
|
||||
f"{1:{f'{2}'}}"
|
||||
f"{1:{f'{2}'}}"
|
||||
f"{1:{2}d}"
|
||||
|
||||
f'{{\\"kind\\":\\"ConfigMap\\",\\"metadata\\":{{\\"annotations\\":{{}},\\"name\\":\\"cluster-info\\",\\"namespace\\":\\"amazon-cloudwatch\\"}}}}'
|
||||
|
||||
f"""{'''
|
||||
'''}"""
|
||||
|
||||
f"{'\''}"
|
||||
f"{f'\''}"
|
||||
|
||||
f"{1}\{{"
|
||||
f"{2} foo \{{[\}}"
|
||||
f"\{3}"
|
||||
rf"\{"a"}"
|
|
@ -173,3 +173,10 @@ this_will_also_become_one_line = ( # comment
|
|||
"b"
|
||||
"c"
|
||||
)
|
||||
|
||||
assert some_var == expected_result, """
|
||||
test
|
||||
"""
|
||||
assert some_var == expected_result, f"""
|
||||
expected: {expected_result}
|
||||
actual: {some_var}"""
|
||||
|
|
|
@ -207,3 +207,10 @@ this_will_stay_on_three_lines = (
|
|||
)
|
||||
|
||||
this_will_also_become_one_line = "abc" # comment
|
||||
|
||||
assert some_var == expected_result, """
|
||||
test
|
||||
"""
|
||||
assert some_var == expected_result, f"""
|
||||
expected: {expected_result}
|
||||
actual: {some_var}"""
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
{"preview": "enabled", "target_version": "py311"}
|
|
@ -0,0 +1,5 @@
|
|||
def fn(*args: *tuple[*A, B]) -> None:
|
||||
pass
|
||||
|
||||
|
||||
fn.__annotations__
|
|
@ -0,0 +1,5 @@
|
|||
def fn(*args: *tuple[*A, B]) -> None:
|
||||
pass
|
||||
|
||||
|
||||
fn.__annotations__
|
23
crates/ruff_python_formatter/resources/test/fixtures/black/cases/split_delimiter_comments.py
vendored
Normal file
23
crates/ruff_python_formatter/resources/test/fixtures/black/cases/split_delimiter_comments.py
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
a = (
|
||||
1 + # type: ignore
|
||||
2 # type: ignore
|
||||
)
|
||||
a = (
|
||||
1 # type: ignore
|
||||
+ 2 # type: ignore
|
||||
)
|
||||
bad_split3 = (
|
||||
"What if we have inline comments on " # First Comment
|
||||
"each line of a bad split? In that " # Second Comment
|
||||
"case, we should just leave it alone." # Third Comment
|
||||
)
|
||||
parametrize(
|
||||
(
|
||||
{},
|
||||
{},
|
||||
),
|
||||
( # foobar
|
||||
{},
|
||||
{},
|
||||
),
|
||||
)
|
|
@ -0,0 +1,23 @@
|
|||
a = (
|
||||
1 # type: ignore
|
||||
+ 2 # type: ignore
|
||||
)
|
||||
a = (
|
||||
1 # type: ignore
|
||||
+ 2 # type: ignore
|
||||
)
|
||||
bad_split3 = (
|
||||
"What if we have inline comments on " # First Comment
|
||||
"each line of a bad split? In that " # Second Comment
|
||||
"case, we should just leave it alone." # Third Comment
|
||||
)
|
||||
parametrize(
|
||||
(
|
||||
{},
|
||||
{},
|
||||
),
|
||||
( # foobar
|
||||
{},
|
||||
{},
|
||||
),
|
||||
)
|
|
@ -0,0 +1 @@
|
|||
{"target_version": "py313"}
|
19
crates/ruff_python_formatter/resources/test/fixtures/black/cases/type_param_defaults.py
vendored
Normal file
19
crates/ruff_python_formatter/resources/test/fixtures/black/cases/type_param_defaults.py
vendored
Normal file
|
@ -0,0 +1,19 @@
|
|||
type A[T=int] = float
|
||||
type B[*P=int] = float
|
||||
type C[*Ts=int] = float
|
||||
type D[*Ts=*int] = float
|
||||
type D[something_that_is_very_very_very_long=something_that_is_very_very_very_long] = float
|
||||
type D[*something_that_is_very_very_very_long=*something_that_is_very_very_very_long] = float
|
||||
type something_that_is_long[something_that_is_long=something_that_is_long] = something_that_is_long
|
||||
|
||||
def simple[T=something_that_is_long](short1: int, short2: str, short3: bytes) -> float:
|
||||
pass
|
||||
|
||||
def longer[something_that_is_long=something_that_is_long](something_that_is_long: something_that_is_long) -> something_that_is_long:
|
||||
pass
|
||||
|
||||
def trailing_comma1[T=int,](a: str):
|
||||
pass
|
||||
|
||||
def trailing_comma2[T=int](a: str,):
|
||||
pass
|
37
crates/ruff_python_formatter/resources/test/fixtures/black/cases/type_param_defaults.py.expect
vendored
Normal file
37
crates/ruff_python_formatter/resources/test/fixtures/black/cases/type_param_defaults.py.expect
vendored
Normal file
|
@ -0,0 +1,37 @@
|
|||
type A[T = int] = float
|
||||
type B[*P = int] = float
|
||||
type C[*Ts = int] = float
|
||||
type D[*Ts = *int] = float
|
||||
type D[
|
||||
something_that_is_very_very_very_long = something_that_is_very_very_very_long
|
||||
] = float
|
||||
type D[
|
||||
*something_that_is_very_very_very_long = *something_that_is_very_very_very_long
|
||||
] = float
|
||||
type something_that_is_long[
|
||||
something_that_is_long = something_that_is_long
|
||||
] = something_that_is_long
|
||||
|
||||
|
||||
def simple[
|
||||
T = something_that_is_long
|
||||
](short1: int, short2: str, short3: bytes) -> float:
|
||||
pass
|
||||
|
||||
|
||||
def longer[
|
||||
something_that_is_long = something_that_is_long
|
||||
](something_that_is_long: something_that_is_long) -> something_that_is_long:
|
||||
pass
|
||||
|
||||
|
||||
def trailing_comma1[
|
||||
T = int,
|
||||
](a: str):
|
||||
pass
|
||||
|
||||
|
||||
def trailing_comma2[
|
||||
T = int
|
||||
](a: str,):
|
||||
pass
|
|
@ -104,6 +104,9 @@ IGNORE_LIST = [
|
|||
|
||||
# Uses a different output format
|
||||
"decorators.py",
|
||||
|
||||
# Tests line ranges that fall outside the source range. This is a CLI test case and not a formatting test case.
|
||||
"line_ranges_outside_source.py",
|
||||
]
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue