Skip to content

Commit

Permalink
Add magics to import sorting tests for Jupyter Notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvmanila committed Jul 26, 2023
1 parent 023d1dc commit 0bcbc95
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
17 changes: 17 additions & 0 deletions crates/ruff/resources/test/fixtures/jupyter/isort.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@
"def foo():\n",
" pass"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "16214f6f-bb32-4594-81be-79fb27c6ec92",
"metadata": {},
"outputs": [],
"source": [
"from pathlib import Path\n",
"import sys\n",
"\n",
"%matplotlib \\\n",
" --inline\n",
"\n",
"import math\n",
"import abc"
]
}
],
"metadata": {
Expand Down
17 changes: 17 additions & 0 deletions crates/ruff/resources/test/fixtures/jupyter/isort_expected.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,23 @@
"def foo():\n",
" pass"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6d6c55c6-4a34-4662-914b-4ee11c9c24a5",
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
"from pathlib import Path\n",
"\n",
"%matplotlib \\\n",
" --inline\n",
"\n",
"import abc\n",
"import math"
]
}
],
"metadata": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,45 @@ isort.ipynb:cell 2:1:1: I001 [*] Import block is un-sorted or un-formatted
7 9 | def foo():
8 10 | pass

isort.ipynb:cell 2:6:1: I001 [*] Import block is un-sorted or un-formatted
|
4 | def foo():
5 | pass
6 | / from pathlib import Path
7 | | import sys
8 | |
9 | | %matplotlib \
| |_^ I001
10 | --inline
|
= help: Organize imports

Fix
6 6 | # Newline should be added here
7 7 | def foo():
8 8 | pass
9 |+import sys
9 10 | from pathlib import Path
10 |-import sys
11 11 |
12 12 | %matplotlib \
13 13 | --inline

isort.ipynb:cell 3:5:1: I001 [*] Import block is un-sorted or un-formatted
|
3 | --inline
4 |
5 | / import math
6 | | import abc
|
= help: Organize imports

Fix
12 12 | %matplotlib \
13 13 | --inline
14 14 |
15 |+import abc
15 16 | import math
16 |-import abc


0 comments on commit 0bcbc95

Please sign in to comment.