-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable more non-panicking formatter tests (#3262)
- Loading branch information
1 parent
2700158
commit 16be691
Showing
9 changed files
with
3,282 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
213 changes: 213 additions & 0 deletions
213
...ython_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments3_py.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,213 @@ | ||
--- | ||
source: crates/ruff_python_formatter/src/lib.rs | ||
expression: snapshot | ||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments3.py | ||
--- | ||
## Input | ||
|
||
```py | ||
# The percent-percent comments are Spyder IDE cells. | ||
# %% | ||
def func(): | ||
x = """ | ||
a really long string | ||
""" | ||
lcomp3 = [ | ||
# This one is actually too long to fit in a single line. | ||
element.split("\n", 1)[0] | ||
# yup | ||
for element in collection.select_elements() | ||
# right | ||
if element is not None | ||
] | ||
# Capture each of the exceptions in the MultiError along with each of their causes and contexts | ||
if isinstance(exc_value, MultiError): | ||
embedded = [] | ||
for exc in exc_value.exceptions: | ||
if exc not in _seen: | ||
embedded.append( | ||
# This should be left alone (before) | ||
traceback.TracebackException.from_exception( | ||
exc, | ||
limit=limit, | ||
lookup_lines=lookup_lines, | ||
capture_locals=capture_locals, | ||
# copy the set of _seen exceptions so that duplicates | ||
# shared between sub-exceptions are not omitted | ||
_seen=set(_seen), | ||
) | ||
# This should be left alone (after) | ||
) | ||
# everything is fine if the expression isn't nested | ||
traceback.TracebackException.from_exception( | ||
exc, | ||
limit=limit, | ||
lookup_lines=lookup_lines, | ||
capture_locals=capture_locals, | ||
# copy the set of _seen exceptions so that duplicates | ||
# shared between sub-exceptions are not omitted | ||
_seen=set(_seen), | ||
) | ||
# %% | ||
``` | ||
|
||
## Black Differences | ||
|
||
```diff | ||
--- Black | ||
+++ Ruff | ||
@@ -9,10 +9,11 @@ | ||
lcomp3 = [ | ||
# This one is actually too long to fit in a single line. | ||
element.split("\n", 1)[0] | ||
- # yup | ||
- for element in collection.select_elements() | ||
- # right | ||
- if element is not None | ||
+ for # yup | ||
+ element in collection.select_elements() | ||
+ if # right | ||
+ element | ||
+ is not None | ||
] | ||
# Capture each of the exceptions in the MultiError along with each of their causes and contexts | ||
if isinstance(exc_value, MultiError): | ||
@@ -26,9 +27,9 @@ | ||
limit=limit, | ||
lookup_lines=lookup_lines, | ||
capture_locals=capture_locals, | ||
- # copy the set of _seen exceptions so that duplicates | ||
+ _seen=# copy the set of _seen exceptions so that duplicates | ||
# shared between sub-exceptions are not omitted | ||
- _seen=set(_seen), | ||
+ set(_seen), | ||
) | ||
# This should be left alone (after) | ||
) | ||
@@ -39,9 +40,9 @@ | ||
limit=limit, | ||
lookup_lines=lookup_lines, | ||
capture_locals=capture_locals, | ||
- # copy the set of _seen exceptions so that duplicates | ||
+ _seen=# copy the set of _seen exceptions so that duplicates | ||
# shared between sub-exceptions are not omitted | ||
- _seen=set(_seen), | ||
+ set(_seen), | ||
) | ||
``` | ||
|
||
## Ruff Output | ||
|
||
```py | ||
# The percent-percent comments are Spyder IDE cells. | ||
# %% | ||
def func(): | ||
x = """ | ||
a really long string | ||
""" | ||
lcomp3 = [ | ||
# This one is actually too long to fit in a single line. | ||
element.split("\n", 1)[0] | ||
for # yup | ||
element in collection.select_elements() | ||
if # right | ||
element | ||
is not None | ||
] | ||
# Capture each of the exceptions in the MultiError along with each of their causes and contexts | ||
if isinstance(exc_value, MultiError): | ||
embedded = [] | ||
for exc in exc_value.exceptions: | ||
if exc not in _seen: | ||
embedded.append( | ||
# This should be left alone (before) | ||
traceback.TracebackException.from_exception( | ||
exc, | ||
limit=limit, | ||
lookup_lines=lookup_lines, | ||
capture_locals=capture_locals, | ||
_seen=# copy the set of _seen exceptions so that duplicates | ||
# shared between sub-exceptions are not omitted | ||
set(_seen), | ||
) | ||
# This should be left alone (after) | ||
) | ||
# everything is fine if the expression isn't nested | ||
traceback.TracebackException.from_exception( | ||
exc, | ||
limit=limit, | ||
lookup_lines=lookup_lines, | ||
capture_locals=capture_locals, | ||
_seen=# copy the set of _seen exceptions so that duplicates | ||
# shared between sub-exceptions are not omitted | ||
set(_seen), | ||
) | ||
# %% | ||
``` | ||
|
||
## Black Output | ||
|
||
```py | ||
# The percent-percent comments are Spyder IDE cells. | ||
# %% | ||
def func(): | ||
x = """ | ||
a really long string | ||
""" | ||
lcomp3 = [ | ||
# This one is actually too long to fit in a single line. | ||
element.split("\n", 1)[0] | ||
# yup | ||
for element in collection.select_elements() | ||
# right | ||
if element is not None | ||
] | ||
# Capture each of the exceptions in the MultiError along with each of their causes and contexts | ||
if isinstance(exc_value, MultiError): | ||
embedded = [] | ||
for exc in exc_value.exceptions: | ||
if exc not in _seen: | ||
embedded.append( | ||
# This should be left alone (before) | ||
traceback.TracebackException.from_exception( | ||
exc, | ||
limit=limit, | ||
lookup_lines=lookup_lines, | ||
capture_locals=capture_locals, | ||
# copy the set of _seen exceptions so that duplicates | ||
# shared between sub-exceptions are not omitted | ||
_seen=set(_seen), | ||
) | ||
# This should be left alone (after) | ||
) | ||
# everything is fine if the expression isn't nested | ||
traceback.TracebackException.from_exception( | ||
exc, | ||
limit=limit, | ||
lookup_lines=lookup_lines, | ||
capture_locals=capture_locals, | ||
# copy the set of _seen exceptions so that duplicates | ||
# shared between sub-exceptions are not omitted | ||
_seen=set(_seen), | ||
) | ||
# %% | ||
``` | ||
|
||
|
Oops, something went wrong.