-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add ruff tool to pre-commit hooks * added missing field language * added test * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * added example * added link * added ruff to toolchain requirements * Update tests/tools/test_ruff_works.py Co-authored-by: Marco Edward Gorelli <[email protected]> * [pre-commit-hook] ruff invoked with --quiet * no quiet * fixup Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Marco Edward Gorelli <[email protected]> Co-authored-by: MarcoGorelli <>
- Loading branch information
1 parent
1cfb6ea
commit 0b44015
Showing
6 changed files
with
118 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,5 @@ pytest | |
pytest-cov | ||
pytest-randomly | ||
pyupgrade | ||
ruff | ||
yapf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,7 @@ toolchain = | |
mypy | ||
pylint | ||
pyupgrade | ||
ruff | ||
|
||
[flake8] | ||
extend-ignore = E203,E503 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
"""Check :code:`ruff` works as intended.""" | ||
|
||
import os | ||
from typing import TYPE_CHECKING | ||
|
||
import pytest | ||
|
||
from nbqa.__main__ import main | ||
|
||
if TYPE_CHECKING: | ||
from _pytest.capture import CaptureFixture | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"path_0, path_1, path_2", | ||
( | ||
( | ||
os.path.abspath( | ||
os.path.join("tests", "data", "notebook_for_testing.ipynb") | ||
), | ||
os.path.abspath( | ||
os.path.join("tests", "data", "notebook_for_testing_copy.ipynb") | ||
), | ||
os.path.abspath( | ||
os.path.join("tests", "data", "notebook_starting_with_md.ipynb") | ||
), | ||
), | ||
( | ||
os.path.join("tests", "data", "notebook_for_testing.ipynb"), | ||
os.path.join("tests", "data", "notebook_for_testing_copy.ipynb"), | ||
os.path.join("tests", "data", "notebook_starting_with_md.ipynb"), | ||
), | ||
), | ||
) | ||
def test_ruff_works( | ||
path_0: str, path_1: str, path_2: str, capsys: "CaptureFixture" | ||
) -> None: | ||
""" | ||
Check flake8 works. Shouldn't alter the notebook content. | ||
Parameters | ||
---------- | ||
capsys | ||
Pytest fixture to capture stdout and stderr. | ||
""" | ||
# check passing both absolute and relative paths | ||
|
||
main(["ruff", path_0, path_1, path_2]) | ||
|
||
expected_path_0 = os.path.join("tests", "data", "notebook_for_testing.ipynb") | ||
expected_path_1 = os.path.join("tests", "data", "notebook_for_testing_copy.ipynb") | ||
expected_path_2 = os.path.join("tests", "data", "notebook_starting_with_md.ipynb") | ||
|
||
out, err = capsys.readouterr() | ||
expected_out = ( | ||
"Found 13 error(s).\n" | ||
f"{expected_path_1}:cell_1:1:8: F401 `os` imported but unused\n" | ||
f"{expected_path_1}:cell_1:3:8: F401 `glob` imported but unused\n" | ||
f"{expected_path_1}:cell_1:5:8: F401 `nbqa` imported but unused\n" | ||
f"{expected_path_0}:cell_1:1:8: F401 `os` imported but unused\n" | ||
f"{expected_path_0}:cell_1:3:8: F401 `glob` imported but unused\n" | ||
f"{expected_path_0}:cell_1:5:8: F401 `nbqa` imported but unused\n" | ||
f"{expected_path_0}:cell_4:1:1: E402 Module level import not at top of file\n" | ||
f"{expected_path_0}:cell_4:1:20: F401 `random.randint` imported but unused\n" | ||
f"{expected_path_0}:cell_5:1:1: E402 Module level import not at top of file\n" | ||
f"{expected_path_0}:cell_5:2:1: E402 Module level import not at top of file\n" | ||
f"{expected_path_2}:cell_1:1:8: F401 `os` imported but unused\n" | ||
f"{expected_path_2}:cell_1:3:8: F401 `glob` imported but unused\n" | ||
f"{expected_path_2}:cell_1:5:8: F401 `nbqa` imported but unused\n" | ||
"10 potentially fixable with the --fix option.\n" | ||
) | ||
assert "\n".join(sorted(out.replace("\r\n", "\n").splitlines())) == "\n".join( | ||
sorted(expected_out.splitlines()) | ||
) | ||
assert err == "" | ||
|
||
|
||
def test_cell_with_all_magics(capsys: "CaptureFixture") -> None: | ||
""" | ||
Should ignore cell with all magics. | ||
Parameters | ||
---------- | ||
capsys | ||
Pytest fixture to capture stdout and stderr. | ||
""" | ||
|
||
path = os.path.join("tests", "data", "all_magic_cell.ipynb") | ||
main(["ruff", path]) | ||
|
||
out, err = capsys.readouterr() | ||
assert out == "" | ||
assert err == "" |