Skip to content

Commit b122d14

Browse files
committed
Return both original and updated SourceKind in tests
1 parent 4ce5c28 commit b122d14

File tree

4 files changed

+23
-22
lines changed

4 files changed

+23
-22
lines changed

crates/ruff/src/jupyter/notebook.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ print("after empty cells")
541541
#[test]
542542
fn test_import_sorting() -> Result<()> {
543543
let path = "isort.ipynb".to_string();
544-
let (diagnostics, source_kind) = test_notebook_path(
544+
let (diagnostics, source_kind, _) = test_notebook_path(
545545
&path,
546546
Path::new("isort_expected.ipynb"),
547547
&settings::Settings::for_rule(Rule::UnsortedImports),
@@ -553,7 +553,7 @@ print("after empty cells")
553553
#[test]
554554
fn test_line_magics() -> Result<()> {
555555
let path = "line_magics.ipynb".to_string();
556-
let (diagnostics, source_kind) = test_notebook_path(
556+
let (diagnostics, source_kind, _) = test_notebook_path(
557557
&path,
558558
Path::new("line_magics_expected.ipynb"),
559559
&settings::Settings::for_rule(Rule::UnusedImport),
@@ -565,7 +565,7 @@ print("after empty cells")
565565
#[test]
566566
fn test_json_consistency() -> Result<()> {
567567
let path = "before_fix.ipynb".to_string();
568-
let (_, source_kind) = test_notebook_path(
568+
let (_, _, source_kind) = test_notebook_path(
569569
path,
570570
Path::new("after_fix.ipynb"),
571571
&settings::Settings::for_rule(Rule::UnusedImport),

crates/ruff/src/jupyter/snapshots/ruff__jupyter__notebook__tests__import_sorting.snap

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,16 @@ isort.ipynb:cell 2:1:1: I001 [*] Import block is un-sorted or un-formatted
4747
7 9 | def foo():
4848
8 10 | pass
4949

50-
isort.ipynb:cell 2:6:1: I001 [*] Import block is un-sorted or un-formatted
51-
|
52-
4 | def foo():
53-
5 | pass
54-
6 | / from pathlib import Path
55-
7 | | import sys
56-
8 | |
57-
9 | | %matplotlib \
58-
| |_^ I001
59-
10 | --inline
60-
|
61-
= help: Organize imports
50+
isort.ipynb:cell 3:1:1: I001 [*] Import block is un-sorted or un-formatted
51+
|
52+
1 | / from pathlib import Path
53+
2 | | import sys
54+
3 | |
55+
4 | | %matplotlib \
56+
| |_^ I001
57+
5 | --inline
58+
|
59+
= help: Organize imports
6260

6361
Fix
6462
6 6 | # Newline should be added here
@@ -71,12 +69,12 @@ isort.ipynb:cell 2:6:1: I001 [*] Import block is un-sorted or un-formatted
7169
12 12 | %matplotlib \
7270
13 13 | --inline
7371

74-
isort.ipynb:cell 3:5:1: I001 [*] Import block is un-sorted or un-formatted
72+
isort.ipynb:cell 3:7:1: I001 [*] Import block is un-sorted or un-formatted
7573
|
76-
3 | --inline
77-
4 |
78-
5 | / import math
79-
6 | | import abc
74+
5 | --inline
75+
6 |
76+
7 | / import math
77+
8 | | import abc
8078
|
8179
= help: Organize imports
8280

crates/ruff/src/jupyter/snapshots/ruff__jupyter__notebook__tests__line_magics.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ line_magics.ipynb:cell 1:5:8: F401 [*] `os` imported but unused
77
4 |
88
5 | import os
99
| ^^ F401
10+
6 |
11+
7 | _ = math.pi
1012
|
1113
= help: Remove unused import: `os`
1214

crates/ruff/src/test.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,17 @@ pub(crate) fn test_notebook_path(
6262
path: impl AsRef<Path>,
6363
expected: impl AsRef<Path>,
6464
settings: &Settings,
65-
) -> Result<(Vec<Message>, SourceKind)> {
65+
) -> Result<(Vec<Message>, SourceKind, SourceKind)> {
6666
let mut source_kind = SourceKind::Jupyter(read_jupyter_notebook(path.as_ref())?);
67+
let original_source_kind = source_kind.clone();
6768
let messages = test_contents(&mut source_kind, path.as_ref(), settings);
6869
let expected_notebook = read_jupyter_notebook(expected.as_ref())?;
6970
if let SourceKind::Jupyter(notebook) = &source_kind {
7071
assert_eq!(notebook.cell_offsets(), expected_notebook.cell_offsets());
7172
assert_eq!(notebook.index(), expected_notebook.index());
7273
assert_eq!(notebook.content(), expected_notebook.content());
7374
};
74-
Ok((messages, source_kind))
75+
Ok((messages, original_source_kind, source_kind))
7576
}
7677

7778
/// Run [`check_path`] on a snippet of Python code.

0 commit comments

Comments
 (0)