mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-01 12:25:10 +00:00
Show preview changes for tests with options (#9223)
This commit is contained in:
parent
1e7bc1dffe
commit
d835b28d01
5 changed files with 236 additions and 0 deletions
|
|
@ -157,6 +157,39 @@ fn format() {
|
||||||
CodeFrame::new("python", &formatted_code)
|
CodeFrame::new("python", &formatted_code)
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
if options.preview().is_enabled() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We want to capture the differences in the preview style in our fixtures
|
||||||
|
let options_preview = options.with_preview(PreviewMode::Enabled);
|
||||||
|
let printed_preview = format_module_source(&content, options_preview.clone())
|
||||||
|
.expect("Formatting to succeed");
|
||||||
|
let formatted_preview = printed_preview.as_code();
|
||||||
|
|
||||||
|
ensure_unchanged_ast(&content, formatted_preview, &options_preview, input_path);
|
||||||
|
ensure_stability_when_formatting_twice(
|
||||||
|
formatted_preview,
|
||||||
|
&options_preview,
|
||||||
|
input_path,
|
||||||
|
);
|
||||||
|
|
||||||
|
if formatted_code != formatted_preview {
|
||||||
|
// Having both snapshots makes it hard to see the difference, so we're keeping only
|
||||||
|
// diff.
|
||||||
|
writeln!(
|
||||||
|
snapshot,
|
||||||
|
"#### Preview changes\n{}",
|
||||||
|
CodeFrame::new(
|
||||||
|
"diff",
|
||||||
|
TextDiff::from_lines(formatted_code, formatted_preview)
|
||||||
|
.unified_diff()
|
||||||
|
.header("Stable", "Preview")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// We want to capture the differences in the preview style in our fixtures
|
// We want to capture the differences in the preview style in our fixtures
|
||||||
|
|
|
||||||
|
|
@ -535,6 +535,28 @@ def doctest_extra_indent3():
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
#### Preview changes
|
||||||
|
```diff
|
||||||
|
--- Stable
|
||||||
|
+++ Preview
|
||||||
|
@@ -270,9 +270,11 @@
|
||||||
|
|
||||||
|
Examples
|
||||||
|
--------
|
||||||
|
- >>> df = pl.DataFrame(
|
||||||
|
- ... {"foo": [1, 2, 3], "bar": [6, 7, 8], "ham": ["a", "b", "c"]}
|
||||||
|
- ... )
|
||||||
|
+ >>> df = pl.DataFrame({
|
||||||
|
+ ... "foo": [1, 2, 3],
|
||||||
|
+ ... "bar": [6, 7, 8],
|
||||||
|
+ ... "ham": ["a", "b", "c"],
|
||||||
|
+ ... })
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
### Output 2
|
### Output 2
|
||||||
```
|
```
|
||||||
indent-style = space
|
indent-style = space
|
||||||
|
|
@ -1139,6 +1161,28 @@ def doctest_extra_indent3():
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
#### Preview changes
|
||||||
|
```diff
|
||||||
|
--- Stable
|
||||||
|
+++ Preview
|
||||||
|
@@ -270,9 +270,11 @@
|
||||||
|
|
||||||
|
Examples
|
||||||
|
--------
|
||||||
|
- >>> df = pl.DataFrame(
|
||||||
|
- ... {"foo": [1, 2, 3], "bar": [6, 7, 8], "ham": ["a", "b", "c"]}
|
||||||
|
- ... )
|
||||||
|
+ >>> df = pl.DataFrame({
|
||||||
|
+ ... "foo": [1, 2, 3],
|
||||||
|
+ ... "bar": [6, 7, 8],
|
||||||
|
+ ... "ham": ["a", "b", "c"],
|
||||||
|
+ ... })
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
### Output 4
|
### Output 4
|
||||||
```
|
```
|
||||||
indent-style = tab
|
indent-style = tab
|
||||||
|
|
@ -1876,4 +1920,26 @@ def doctest_extra_indent3():
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
#### Preview changes
|
||||||
|
```diff
|
||||||
|
--- Stable
|
||||||
|
+++ Preview
|
||||||
|
@@ -700,9 +700,11 @@
|
||||||
|
|
||||||
|
Examples
|
||||||
|
--------
|
||||||
|
- >>> df = pl.DataFrame(
|
||||||
|
- ... {"foo": [1, 2, 3], "bar": [6, 7, 8], "ham": ["a", "b", "c"]}
|
||||||
|
- ... )
|
||||||
|
+ >>> df = pl.DataFrame({
|
||||||
|
+ ... "foo": [1, 2, 3],
|
||||||
|
+ ... "bar": [6, 7, 8],
|
||||||
|
+ ... "ham": ["a", "b", "c"],
|
||||||
|
+ ... })
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -319,6 +319,19 @@ trailing_preferred_quote_texts = [''' "''', ''' ""''', ''' """''', ''' """"''']
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
#### Preview changes
|
||||||
|
```diff
|
||||||
|
--- Stable
|
||||||
|
+++ Preview
|
||||||
|
@@ -1,4 +1,5 @@
|
||||||
|
"' test"
|
||||||
|
+
|
||||||
|
'" test'
|
||||||
|
|
||||||
|
'" test'
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
### Output 2
|
### Output 2
|
||||||
```
|
```
|
||||||
indent-style = space
|
indent-style = space
|
||||||
|
|
@ -496,4 +509,17 @@ trailing_preferred_quote_texts = [''' "''', ''' ""''', ''' """''', ''' """"''']
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
#### Preview changes
|
||||||
|
```diff
|
||||||
|
--- Stable
|
||||||
|
+++ Preview
|
||||||
|
@@ -1,4 +1,5 @@
|
||||||
|
"' test"
|
||||||
|
+
|
||||||
|
'" test'
|
||||||
|
|
||||||
|
'" test'
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -156,6 +156,78 @@ def f():
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
#### Preview changes
|
||||||
|
```diff
|
||||||
|
--- Stable
|
||||||
|
+++ Preview
|
||||||
|
@@ -1,13 +1,13 @@
|
||||||
|
"""
|
||||||
|
Black's `Preview.module_docstring_newlines`
|
||||||
|
"""
|
||||||
|
+
|
||||||
|
first_stmt_after_module_level_docstring = 1
|
||||||
|
|
||||||
|
|
||||||
|
class CachedRepository:
|
||||||
|
# Black's `Preview.dummy_implementations`
|
||||||
|
- def get_release_info(self):
|
||||||
|
- ...
|
||||||
|
+ def get_release_info(self): ...
|
||||||
|
|
||||||
|
|
||||||
|
def raw_docstring():
|
||||||
|
@@ -27,23 +27,22 @@
|
||||||
|
|
||||||
|
|
||||||
|
class RemoveNewlineBeforeClassDocstring:
|
||||||
|
-
|
||||||
|
"""Black's `Preview.no_blank_line_before_class_docstring`"""
|
||||||
|
|
||||||
|
|
||||||
|
def f():
|
||||||
|
"""Black's `Preview.prefer_splitting_right_hand_side_of_assignments`"""
|
||||||
|
- aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[
|
||||||
|
- bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
|
- ] = cccccccc.ccccccccccccc.cccccccc
|
||||||
|
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb] = (
|
||||||
|
+ cccccccc.ccccccccccccc.cccccccc
|
||||||
|
+ )
|
||||||
|
|
||||||
|
- aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[
|
||||||
|
- bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
|
- ] = cccccccc.ccccccccccccc().cccccccc
|
||||||
|
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb] = (
|
||||||
|
+ cccccccc.ccccccccccccc().cccccccc
|
||||||
|
+ )
|
||||||
|
|
||||||
|
- aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[
|
||||||
|
- bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
|
- ] = cccccccc.ccccccccccccc(d).cccccccc
|
||||||
|
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb] = (
|
||||||
|
+ cccccccc.ccccccccccccc(d).cccccccc
|
||||||
|
+ )
|
||||||
|
|
||||||
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb] = (
|
||||||
|
cccccccc.ccccccccccccc(d).cccccccc + e
|
||||||
|
@@ -57,9 +56,9 @@
|
||||||
|
+ eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
|
||||||
|
)
|
||||||
|
|
||||||
|
- self._cache: dict[
|
||||||
|
- DependencyCacheKey, list[list[DependencyPackage]]
|
||||||
|
- ] = collections.defaultdict(list)
|
||||||
|
- self._cached_dependencies_by_level: dict[
|
||||||
|
- int, list[DependencyCacheKey]
|
||||||
|
- ] = collections.defaultdict(list)
|
||||||
|
+ self._cache: dict[DependencyCacheKey, list[list[DependencyPackage]]] = (
|
||||||
|
+ collections.defaultdict(list)
|
||||||
|
+ )
|
||||||
|
+ self._cached_dependencies_by_level: dict[int, list[DependencyCacheKey]] = (
|
||||||
|
+ collections.defaultdict(list)
|
||||||
|
+ )
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
### Output 2
|
### Output 2
|
||||||
```
|
```
|
||||||
indent-style = space
|
indent-style = space
|
||||||
|
|
|
||||||
|
|
@ -129,6 +129,19 @@ def docstring_single():
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
#### Preview changes
|
||||||
|
```diff
|
||||||
|
--- Stable
|
||||||
|
+++ Preview
|
||||||
|
@@ -1,4 +1,5 @@
|
||||||
|
'single'
|
||||||
|
+
|
||||||
|
'double'
|
||||||
|
r'r single'
|
||||||
|
r'r double'
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
### Output 2
|
### Output 2
|
||||||
```
|
```
|
||||||
indent-style = space
|
indent-style = space
|
||||||
|
|
@ -201,6 +214,19 @@ def docstring_single():
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
#### Preview changes
|
||||||
|
```diff
|
||||||
|
--- Stable
|
||||||
|
+++ Preview
|
||||||
|
@@ -1,4 +1,5 @@
|
||||||
|
"single"
|
||||||
|
+
|
||||||
|
"double"
|
||||||
|
r"r single"
|
||||||
|
r"r double"
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
### Output 3
|
### Output 3
|
||||||
```
|
```
|
||||||
indent-style = space
|
indent-style = space
|
||||||
|
|
@ -273,4 +299,17 @@ def docstring_single():
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
#### Preview changes
|
||||||
|
```diff
|
||||||
|
--- Stable
|
||||||
|
+++ Preview
|
||||||
|
@@ -1,4 +1,5 @@
|
||||||
|
'single'
|
||||||
|
+
|
||||||
|
"double"
|
||||||
|
r'r single'
|
||||||
|
r"r double"
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue