From 5fa2201e9618b9b9b64f60927319834e3167f343 Mon Sep 17 00:00:00 2001 From: Dhruv Manilawala Date: Wed, 26 Jul 2023 17:59:44 +0530 Subject: [PATCH] Add magics to import sorting tests for Jupyter Notebook --- .../test/fixtures/jupyter/isort.ipynb | 17 ++++++++ .../fixtures/jupyter/isort_expected.ipynb | 17 ++++++++ ...yter__notebook__tests__import_sorting.snap | 41 +++++++++++++++++++ 3 files changed, 75 insertions(+) diff --git a/crates/ruff/resources/test/fixtures/jupyter/isort.ipynb b/crates/ruff/resources/test/fixtures/jupyter/isort.ipynb index aef5ff2e8b8aa..9572f7b25e8ad 100644 --- a/crates/ruff/resources/test/fixtures/jupyter/isort.ipynb +++ b/crates/ruff/resources/test/fixtures/jupyter/isort.ipynb @@ -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": { diff --git a/crates/ruff/resources/test/fixtures/jupyter/isort_expected.ipynb b/crates/ruff/resources/test/fixtures/jupyter/isort_expected.ipynb index 009c598e71672..5118aa36615e2 100644 --- a/crates/ruff/resources/test/fixtures/jupyter/isort_expected.ipynb +++ b/crates/ruff/resources/test/fixtures/jupyter/isort_expected.ipynb @@ -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": { diff --git a/crates/ruff/src/jupyter/snapshots/ruff__jupyter__notebook__tests__import_sorting.snap b/crates/ruff/src/jupyter/snapshots/ruff__jupyter__notebook__tests__import_sorting.snap index 240556c37576f..a1e4c636f0ca6 100644 --- a/crates/ruff/src/jupyter/snapshots/ruff__jupyter__notebook__tests__import_sorting.snap +++ b/crates/ruff/src/jupyter/snapshots/ruff__jupyter__notebook__tests__import_sorting.snap @@ -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 +