Skip to content

Commit 0bcbc95

Browse files
committed
Add magics to import sorting tests for Jupyter Notebook
1 parent 023d1dc commit 0bcbc95

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

crates/ruff/resources/test/fixtures/jupyter/isort.ipynb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,23 @@
2525
"def foo():\n",
2626
" pass"
2727
]
28+
},
29+
{
30+
"cell_type": "code",
31+
"execution_count": null,
32+
"id": "16214f6f-bb32-4594-81be-79fb27c6ec92",
33+
"metadata": {},
34+
"outputs": [],
35+
"source": [
36+
"from pathlib import Path\n",
37+
"import sys\n",
38+
"\n",
39+
"%matplotlib \\\n",
40+
" --inline\n",
41+
"\n",
42+
"import math\n",
43+
"import abc"
44+
]
2845
}
2946
],
3047
"metadata": {

crates/ruff/resources/test/fixtures/jupyter/isort_expected.ipynb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,23 @@
2727
"def foo():\n",
2828
" pass"
2929
]
30+
},
31+
{
32+
"cell_type": "code",
33+
"execution_count": null,
34+
"id": "6d6c55c6-4a34-4662-914b-4ee11c9c24a5",
35+
"metadata": {},
36+
"outputs": [],
37+
"source": [
38+
"import sys\n",
39+
"from pathlib import Path\n",
40+
"\n",
41+
"%matplotlib \\\n",
42+
" --inline\n",
43+
"\n",
44+
"import abc\n",
45+
"import math"
46+
]
3047
}
3148
],
3249
"metadata": {

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,45 @@ 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
62+
63+
Fix
64+
6 6 | # Newline should be added here
65+
7 7 | def foo():
66+
8 8 | pass
67+
9 |+import sys
68+
9 10 | from pathlib import Path
69+
10 |-import sys
70+
11 11 |
71+
12 12 | %matplotlib \
72+
13 13 | --inline
73+
74+
isort.ipynb:cell 3:5:1: I001 [*] Import block is un-sorted or un-formatted
75+
|
76+
3 | --inline
77+
4 |
78+
5 | / import math
79+
6 | | import abc
80+
|
81+
= help: Organize imports
82+
83+
Fix
84+
12 12 | %matplotlib \
85+
13 13 | --inline
86+
14 14 |
87+
15 |+import abc
88+
15 16 | import math
89+
16 |-import abc
90+
5091

0 commit comments

Comments
 (0)