Skip to content

Commit

Permalink
add black compatibility snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
takaya0 committed Nov 10, 2024
1 parent 4cdd196 commit 41b4426
Show file tree
Hide file tree
Showing 3 changed files with 378 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
---
source: crates/ruff_python_formatter/tests/fixtures.rs
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/cases/context_managers_38.py
snapshot_kind: text
---
## Input

```python
with \
make_context_manager1() as cm1, \
make_context_manager2() as cm2, \
make_context_manager3() as cm3, \
make_context_manager4() as cm4 \
:
pass
with \
make_context_manager1() as cm1, \
make_context_manager2(), \
make_context_manager3() as cm3, \
make_context_manager4() \
:
pass
with \
new_new_new1() as cm1, \
new_new_new2() \
:
pass
with mock.patch.object(
self.my_runner, "first_method", autospec=True
) as mock_run_adb, mock.patch.object(
self.my_runner, "second_method", autospec=True, return_value="foo"
):
pass
```

## Black Differences

```diff
--- Black
+++ Ruff
@@ -1,8 +1,18 @@
-with make_context_manager1() as cm1, make_context_manager2() as cm2, make_context_manager3() as cm3, make_context_manager4() as cm4:
+with (
+ make_context_manager1() as cm1,
+ make_context_manager2() as cm2,
+ make_context_manager3() as cm3,
+ make_context_manager4() as cm4,
+):
pass
-with make_context_manager1() as cm1, make_context_manager2(), make_context_manager3() as cm3, make_context_manager4():
+with (
+ make_context_manager1() as cm1,
+ make_context_manager2(),
+ make_context_manager3() as cm3,
+ make_context_manager4(),
+):
pass
@@ -10,9 +20,10 @@
pass
-with mock.patch.object(
- self.my_runner, "first_method", autospec=True
-) as mock_run_adb, mock.patch.object(
- self.my_runner, "second_method", autospec=True, return_value="foo"
+with (
+ mock.patch.object(self.my_runner, "first_method", autospec=True) as mock_run_adb,
+ mock.patch.object(
+ self.my_runner, "second_method", autospec=True, return_value="foo"
+ ),
):
pass
```

## Ruff Output

```python
with (
make_context_manager1() as cm1,
make_context_manager2() as cm2,
make_context_manager3() as cm3,
make_context_manager4() as cm4,
):
pass
with (
make_context_manager1() as cm1,
make_context_manager2(),
make_context_manager3() as cm3,
make_context_manager4(),
):
pass
with new_new_new1() as cm1, new_new_new2():
pass
with (
mock.patch.object(self.my_runner, "first_method", autospec=True) as mock_run_adb,
mock.patch.object(
self.my_runner, "second_method", autospec=True, return_value="foo"
),
):
pass
```

## Black Output

```python
with make_context_manager1() as cm1, make_context_manager2() as cm2, make_context_manager3() as cm3, make_context_manager4() as cm4:
pass
with make_context_manager1() as cm1, make_context_manager2(), make_context_manager3() as cm3, make_context_manager4():
pass
with new_new_new1() as cm1, new_new_new2():
pass
with mock.patch.object(
self.my_runner, "first_method", autospec=True
) as mock_run_adb, mock.patch.object(
self.my_runner, "second_method", autospec=True, return_value="foo"
):
pass
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
---
source: crates/ruff_python_formatter/tests/fixtures.rs
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/cases/context_managers_autodetect_38.py
snapshot_kind: text
---
## Input

```python
# This file doesn't use any Python 3.9+ only grammars.
# Make sure parens around a single context manager don't get autodetected as
# Python 3.9+.
with (a):
pass
with \
make_context_manager1() as cm1, \
make_context_manager2() as cm2, \
make_context_manager3() as cm3, \
make_context_manager4() as cm4 \
:
pass
with mock.patch.object(
self.my_runner, "first_method", autospec=True
) as mock_run_adb, mock.patch.object(
self.my_runner, "second_method", autospec=True, return_value="foo"
):
pass
```

## Black Differences

```diff
--- Black
+++ Ruff
@@ -7,13 +7,19 @@
pass
-with make_context_manager1() as cm1, make_context_manager2() as cm2, make_context_manager3() as cm3, make_context_manager4() as cm4:
+with (
+ make_context_manager1() as cm1,
+ make_context_manager2() as cm2,
+ make_context_manager3() as cm3,
+ make_context_manager4() as cm4,
+):
pass
-with mock.patch.object(
- self.my_runner, "first_method", autospec=True
-) as mock_run_adb, mock.patch.object(
- self.my_runner, "second_method", autospec=True, return_value="foo"
+with (
+ mock.patch.object(self.my_runner, "first_method", autospec=True) as mock_run_adb,
+ mock.patch.object(
+ self.my_runner, "second_method", autospec=True, return_value="foo"
+ ),
):
pass
```

## Ruff Output

```python
# This file doesn't use any Python 3.9+ only grammars.
# Make sure parens around a single context manager don't get autodetected as
# Python 3.9+.
with a:
pass
with (
make_context_manager1() as cm1,
make_context_manager2() as cm2,
make_context_manager3() as cm3,
make_context_manager4() as cm4,
):
pass
with (
mock.patch.object(self.my_runner, "first_method", autospec=True) as mock_run_adb,
mock.patch.object(
self.my_runner, "second_method", autospec=True, return_value="foo"
),
):
pass
```

## Black Output

```python
# This file doesn't use any Python 3.9+ only grammars.
# Make sure parens around a single context manager don't get autodetected as
# Python 3.9+.
with a:
pass
with make_context_manager1() as cm1, make_context_manager2() as cm2, make_context_manager3() as cm3, make_context_manager4() as cm4:
pass
with mock.patch.object(
self.my_runner, "first_method", autospec=True
) as mock_run_adb, mock.patch.object(
self.my_runner, "second_method", autospec=True, return_value="foo"
):
pass
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
---
source: crates/ruff_python_formatter/tests/fixtures.rs
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/cases/preview_context_managers_autodetect_38.py
snapshot_kind: text
---
## Input

```python
# This file doesn't use any Python 3.9+ only grammars.
# Make sure parens around a single context manager don't get autodetected as
# Python 3.9+.
with (a):
pass
with \
make_context_manager1() as cm1, \
make_context_manager2() as cm2, \
make_context_manager3() as cm3, \
make_context_manager4() as cm4 \
:
pass
with mock.patch.object(
self.my_runner, "first_method", autospec=True
) as mock_run_adb, mock.patch.object(
self.my_runner, "second_method", autospec=True, return_value="foo"
):
pass
```

## Black Differences

```diff
--- Black
+++ Ruff
@@ -7,13 +7,19 @@
pass
-with make_context_manager1() as cm1, make_context_manager2() as cm2, make_context_manager3() as cm3, make_context_manager4() as cm4:
+with (
+ make_context_manager1() as cm1,
+ make_context_manager2() as cm2,
+ make_context_manager3() as cm3,
+ make_context_manager4() as cm4,
+):
pass
-with mock.patch.object(
- self.my_runner, "first_method", autospec=True
-) as mock_run_adb, mock.patch.object(
- self.my_runner, "second_method", autospec=True, return_value="foo"
+with (
+ mock.patch.object(self.my_runner, "first_method", autospec=True) as mock_run_adb,
+ mock.patch.object(
+ self.my_runner, "second_method", autospec=True, return_value="foo"
+ ),
):
pass
```

## Ruff Output

```python
# This file doesn't use any Python 3.9+ only grammars.
# Make sure parens around a single context manager don't get autodetected as
# Python 3.9+.
with a:
pass
with (
make_context_manager1() as cm1,
make_context_manager2() as cm2,
make_context_manager3() as cm3,
make_context_manager4() as cm4,
):
pass
with (
mock.patch.object(self.my_runner, "first_method", autospec=True) as mock_run_adb,
mock.patch.object(
self.my_runner, "second_method", autospec=True, return_value="foo"
),
):
pass
```

## Black Output

```python
# This file doesn't use any Python 3.9+ only grammars.
# Make sure parens around a single context manager don't get autodetected as
# Python 3.9+.
with a:
pass
with make_context_manager1() as cm1, make_context_manager2() as cm2, make_context_manager3() as cm3, make_context_manager4() as cm4:
pass
with mock.patch.object(
self.my_runner, "first_method", autospec=True
) as mock_run_adb, mock.patch.object(
self.my_runner, "second_method", autospec=True, return_value="foo"
):
pass
```

0 comments on commit 41b4426

Please sign in to comment.