-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* map blacken-docs * add test * add tests
- Loading branch information
1 parent
5bef009
commit 0fc3679
Showing
6 changed files
with
126 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
autoflake | ||
autopep8 | ||
black | ||
blacken-docs | ||
coverage[toml] | ||
flake8 | ||
isort>=5.4.2 | ||
|
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
"""Check blacken-docs runs.""" | ||
import os | ||
from typing import TYPE_CHECKING | ||
|
||
from nbqa.__main__ import main | ||
|
||
if TYPE_CHECKING: | ||
from _pytest.capture import CaptureFixture | ||
|
||
|
||
def test_blacken_docs(capsys: "CaptureFixture") -> None: | ||
""" | ||
Check blacken-docs. | ||
Parameters | ||
---------- | ||
capsys | ||
Pytest fixture to capture stdout and stderr. | ||
""" | ||
path = os.path.join("tests", "data", "notebook_for_testing.ipynb") | ||
main(["blacken-docs", path, "--nbqa-diff", "--nbqa-md"]) | ||
out, err = capsys.readouterr() | ||
expected_out = ( | ||
"\x1b[1mCell 2\x1b[0m\n" | ||
"------\n" | ||
f"\x1b[1;37m--- {path}\n" | ||
f"\x1b[0m\x1b[1;37m+++ {path}\n" | ||
"\x1b[0m\x1b[36m@@ -1 +1 @@\n" | ||
"\x1b[0m\x1b[31m-set(())\n" | ||
"\x1b[0m\x1b[32m+set()\n" | ||
"\x1b[0m\n" | ||
"To apply these changes, remove the `--nbqa-diff` flag\n" | ||
) | ||
expected_out = ( | ||
"\x1b[1mCell 3\x1b[0m\n" | ||
"------\n" | ||
f"\x1b[1;37m--- {path}\n" | ||
f"\x1b[0m\x1b[1;37m+++ {path}\n" | ||
"\x1b[0m\x1b[36m@@ -1,3 +1,3 @@\n" | ||
"\x1b[0m\x1b[31m-2 +2\n" | ||
"\x1b[0m\x1b[32m+2 + 2\n" | ||
"\x1b[0m\n" | ||
f"{path}: Rewriting...\n" | ||
"To apply these changes, remove the `--nbqa-diff` flag\n" | ||
) | ||
expected_err = "" | ||
assert out == expected_out | ||
assert err == expected_err |
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,56 @@ | ||
"""Check mdformat works.""" | ||
|
||
import difflib | ||
import os | ||
from pathlib import Path | ||
from typing import TYPE_CHECKING | ||
|
||
from nbqa.__main__ import main | ||
|
||
if TYPE_CHECKING: | ||
|
||
from _pytest.capture import CaptureFixture | ||
|
||
|
||
def test_mdformat(tmp_notebook_for_testing: Path) -> None: | ||
""" | ||
Check pyupgrade works. Should only reformat code cells. | ||
Parameters | ||
---------- | ||
tmp_notebook_for_testing | ||
Temporary copy of :code:`tmp_notebook_for_testing.ipynb`. | ||
""" | ||
# check diff | ||
with open(tmp_notebook_for_testing, encoding="utf-8") as handle: | ||
before = handle.readlines() | ||
path = os.path.join("tests", "data", "notebook_for_testing.ipynb") | ||
|
||
main(["mdformat", os.path.abspath(path), "--nbqa-md"]) | ||
with open(tmp_notebook_for_testing, encoding="utf-8") as handle: | ||
after = handle.readlines() | ||
|
||
diff = difflib.unified_diff(before, after) | ||
result = "".join(i for i in diff if any([i.startswith("+ "), i.startswith("- ")])) | ||
expected = ( | ||
'- "First level heading\\n",\n- "==="\n+ "# First level heading"\n' | ||
) | ||
assert result == expected | ||
|
||
|
||
def test_mdformat_works_with_empty_file(capsys: "CaptureFixture") -> None: | ||
""" | ||
Check mdformat works with empty notebook. | ||
Parameters | ||
---------- | ||
capsys | ||
Pytest fixture to capture stdout and stderr. | ||
""" | ||
path = os.path.abspath(os.path.join("tests", "data", "footer.ipynb")) | ||
|
||
main(["mdformat", path, "--nbqa-diff", "--nbqa-md"]) | ||
|
||
out, err = capsys.readouterr() | ||
assert out == "" | ||
assert err == "" |