Skip to content

Commit fe7b2c2

Browse files
committed
Initial test :)
1 parent 928ffc1 commit fe7b2c2

File tree

4 files changed

+114
-0
lines changed

4 files changed

+114
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "eab4754a-d6df-4b41-8ee8-7e23aef440f9",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"import math\n",
11+
"\n",
12+
"%matplotlib inline\n",
13+
"\n",
14+
"import os\n",
15+
"\n",
16+
"_ = math.pi"
17+
]
18+
}
19+
],
20+
"metadata": {
21+
"kernelspec": {
22+
"display_name": "Python (ruff)",
23+
"language": "python",
24+
"name": "ruff"
25+
},
26+
"language_info": {
27+
"codemirror_mode": {
28+
"name": "ipython",
29+
"version": 3
30+
},
31+
"file_extension": ".py",
32+
"mimetype": "text/x-python",
33+
"name": "python",
34+
"nbconvert_exporter": "python",
35+
"pygments_lexer": "ipython3",
36+
"version": "3.11.3"
37+
}
38+
},
39+
"nbformat": 4,
40+
"nbformat_minor": 5
41+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "cad32845-44f9-4a53-8b8c-a6b1bb3f3378",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"import math\n",
11+
"\n",
12+
"%matplotlib inline\n",
13+
"\n",
14+
"\n",
15+
"_ = math.pi"
16+
]
17+
}
18+
],
19+
"metadata": {
20+
"kernelspec": {
21+
"display_name": "Python (ruff)",
22+
"language": "python",
23+
"name": "ruff"
24+
},
25+
"language_info": {
26+
"codemirror_mode": {
27+
"name": "ipython",
28+
"version": 3
29+
},
30+
"file_extension": ".py",
31+
"mimetype": "text/x-python",
32+
"name": "python",
33+
"nbconvert_exporter": "python",
34+
"pygments_lexer": "ipython3",
35+
"version": "3.11.3"
36+
}
37+
},
38+
"nbformat": 4,
39+
"nbformat_minor": 5
40+
}

crates/ruff/src/jupyter/notebook.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,18 @@ print("after empty cells")
552552
Ok(())
553553
}
554554

555+
#[test]
556+
fn test_line_magics() -> Result<()> {
557+
let path = "line_magics.ipynb".to_string();
558+
let (diagnostics, source_kind) = test_notebook_path(
559+
&path,
560+
Path::new("line_magics_expected.ipynb"),
561+
&settings::Settings::for_rule(Rule::UnusedImport),
562+
)?;
563+
assert_messages!(diagnostics, path, source_kind);
564+
Ok(())
565+
}
566+
555567
#[test]
556568
fn test_json_consistency() -> Result<()> {
557569
let path = "before_fix.ipynb".to_string();
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
source: crates/ruff/src/jupyter/notebook.rs
3+
---
4+
line_magics.ipynb:cell 1:5:8: F401 [*] `os` imported but unused
5+
|
6+
3 | %matplotlib inline
7+
4 |
8+
5 | import os
9+
| ^^ F401
10+
|
11+
= help: Remove unused import: `os`
12+
13+
Fix
14+
2 2 |
15+
3 3 | %matplotlib inline
16+
4 4 |
17+
5 |-import os
18+
6 5 |
19+
7 6 | _ = math.pi
20+
21+

0 commit comments

Comments
 (0)