From cd8e1bad6430f495e47b9c07f5de0cd31369fd8a Mon Sep 17 00:00:00 2001 From: konsti Date: Fri, 27 Oct 2023 12:44:19 +0200 Subject: [PATCH] Update black tests (#8278) Update black tests to https://github.com/psf/black/commit/c369e446f9dbff313ebb555bf461b4e7778ca78d --- .../fixtures/black/miscellaneous/force_pyi.py | 1 + .../black/miscellaneous/string_quotes.py | 1 + .../miscellaneous/string_quotes.py.expect | 1 + .../test/fixtures/black/raw_docstring.py | 16 ++++ .../fixtures/black/raw_docstring.py.expect | 14 +++ ...atibility@miscellaneous__force_pyi.py.snap | 13 ++- ...ility@miscellaneous__string_quotes.py.snap | 5 +- .../black_compatibility@raw_docstring.py.snap | 92 +++++++++++++++++++ 8 files changed, 137 insertions(+), 6 deletions(-) create mode 100644 crates/ruff_python_formatter/resources/test/fixtures/black/raw_docstring.py create mode 100644 crates/ruff_python_formatter/resources/test/fixtures/black/raw_docstring.py.expect create mode 100644 crates/ruff_python_formatter/tests/snapshots/black_compatibility@raw_docstring.py.snap diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/miscellaneous/force_pyi.py b/crates/ruff_python_formatter/resources/test/fixtures/black/miscellaneous/force_pyi.py index 9c8c40cc96..edc7495e66 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/miscellaneous/force_pyi.py +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/miscellaneous/force_pyi.py @@ -1,3 +1,4 @@ +# flags: --pyi from typing import Union @bird diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/miscellaneous/string_quotes.py b/crates/ruff_python_formatter/resources/test/fixtures/black/miscellaneous/string_quotes.py index 86c68e531a..9e6b78b05b 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/miscellaneous/string_quotes.py +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/miscellaneous/string_quotes.py @@ -1,4 +1,5 @@ '''''' + '\'' '"' "'" diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/miscellaneous/string_quotes.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/miscellaneous/string_quotes.py.expect index dce6105acf..641b20c8e4 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/miscellaneous/string_quotes.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/miscellaneous/string_quotes.py.expect @@ -1,4 +1,5 @@ """""" + "'" '"' "'" diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/raw_docstring.py b/crates/ruff_python_formatter/resources/test/fixtures/black/raw_docstring.py new file mode 100644 index 0000000000..bfde79202a --- /dev/null +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/raw_docstring.py @@ -0,0 +1,16 @@ +# flags: --preview --skip-string-normalization +class C: + + r"""Raw""" + +def f(): + + r"""Raw""" + +class SingleQuotes: + + + r'''Raw''' + +class UpperCaseR: + R"""Raw""" diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/raw_docstring.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/raw_docstring.py.expect new file mode 100644 index 0000000000..5be480f7f0 --- /dev/null +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/raw_docstring.py.expect @@ -0,0 +1,14 @@ +class C: + r"""Raw""" + + +def f(): + r"""Raw""" + + +class SingleQuotes: + r'''Raw''' + + +class UpperCaseR: + R"""Raw""" diff --git a/crates/ruff_python_formatter/tests/snapshots/black_compatibility@miscellaneous__force_pyi.py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@miscellaneous__force_pyi.py.snap index b2ea142296..678606a9ed 100644 --- a/crates/ruff_python_formatter/tests/snapshots/black_compatibility@miscellaneous__force_pyi.py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@miscellaneous__force_pyi.py.snap @@ -5,6 +5,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/miscellan ## Input ```py +# flags: --pyi from typing import Union @bird @@ -42,7 +43,8 @@ def eggs() -> Union[str, int]: ... ```diff --- Black +++ Ruff -@@ -1,32 +1,58 @@ +@@ -1,32 +1,59 @@ ++# flags: --pyi from typing import Union + @@ -67,13 +69,13 @@ def eggs() -> Union[str, int]: ... - def BMethod(self, arg: List[str]) -> None: ... + def BMethod(self, arg: List[str]) -> None: + ... -+ -+ -+class C: -+ ... -class C: ... ++class C: ++ ... ++ ++ @hmm -class D: ... +class D: @@ -118,6 +120,7 @@ def eggs() -> Union[str, int]: ... ## Ruff Output ```py +# flags: --pyi from typing import Union diff --git a/crates/ruff_python_formatter/tests/snapshots/black_compatibility@miscellaneous__string_quotes.py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@miscellaneous__string_quotes.py.snap index 022b30a5a3..4600e1fd20 100644 --- a/crates/ruff_python_formatter/tests/snapshots/black_compatibility@miscellaneous__string_quotes.py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@miscellaneous__string_quotes.py.snap @@ -6,6 +6,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/miscellan ```py '''''' + '\'' '"' "'" @@ -69,7 +70,7 @@ f"\"{a}\"{'hello' * b}\"{c}\"" ```diff --- Black +++ Ruff -@@ -24,7 +24,12 @@ +@@ -25,7 +25,12 @@ r'Tricky "quote' r"Not-so-tricky \"quote" rf"{yay}" @@ -89,6 +90,7 @@ f"\"{a}\"{'hello' * b}\"{c}\"" ```py """""" + "'" '"' "'" @@ -151,6 +153,7 @@ f"\"{a}\"{'hello' * b}\"{c}\"" ```py """""" + "'" '"' "'" diff --git a/crates/ruff_python_formatter/tests/snapshots/black_compatibility@raw_docstring.py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@raw_docstring.py.snap new file mode 100644 index 0000000000..8177e7d37f --- /dev/null +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@raw_docstring.py.snap @@ -0,0 +1,92 @@ +--- +source: crates/ruff_python_formatter/tests/fixtures.rs +input_file: crates/ruff_python_formatter/resources/test/fixtures/black/raw_docstring.py +--- +## Input + +```py +# flags: --preview --skip-string-normalization +class C: + + r"""Raw""" + +def f(): + + r"""Raw""" + +class SingleQuotes: + + + r'''Raw''' + +class UpperCaseR: + R"""Raw""" +``` + +## Black Differences + +```diff +--- Black ++++ Ruff +@@ -1,4 +1,6 @@ ++# flags: --preview --skip-string-normalization + class C: ++ + r"""Raw""" + + +@@ -7,8 +9,9 @@ + + + class SingleQuotes: +- r'''Raw''' + ++ r"""Raw""" ++ + + class UpperCaseR: + R"""Raw""" +``` + +## Ruff Output + +```py +# flags: --preview --skip-string-normalization +class C: + + r"""Raw""" + + +def f(): + r"""Raw""" + + +class SingleQuotes: + + r"""Raw""" + + +class UpperCaseR: + R"""Raw""" +``` + +## Black Output + +```py +class C: + r"""Raw""" + + +def f(): + r"""Raw""" + + +class SingleQuotes: + r'''Raw''' + + +class UpperCaseR: + R"""Raw""" +``` + +