Skip to content

Commit 926e264

Browse files
committed
type annotate tests, swap older pytest tmpdir fixture for tmp_path
1 parent 24fd7e7 commit 926e264

File tree

3 files changed

+21
-21
lines changed

3 files changed

+21
-21
lines changed

setup.cfg

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,3 @@ disallow_any_generics = true
5050
disallow_incomplete_defs = true
5151
warn_redundant_casts = true
5252
warn_unused_ignores = true
53-
54-
[mypy-tests.*]
55-
disallow_untyped_defs = false

tests/test_helpers.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@
1111

1212

1313
@pytest.mark.parametrize("raw_delim", ["# %%", "#%%"])
14-
def test_format_cell_delimiters(raw_delim):
14+
def test_format_cell_delimiters(raw_delim: str) -> None:
1515

1616
assert format_cell_delimiters(raw_delim) == "# %%"
1717

1818

1919
@pytest.mark.parametrize("input", ["# %%some comment", "# %% some comment"])
20-
def test_format_comments_after_cell_delimiters(input):
20+
def test_format_comments_after_cell_delimiters(input: str) -> None:
2121

2222
assert format_comments_after_cell_delimiters(input) == "# %% some comment"
2323

2424

25-
def test_remove_empty_cells():
25+
def test_remove_empty_cells() -> None:
2626
# single empty cell
2727
out = remove_empty_cells("# %%\n\n# %%")
2828
assert out == "# %%"
@@ -51,12 +51,12 @@ def test_remove_empty_cells():
5151
"# %%\n\t\t\n \n \nfoo = 'bar'",
5252
],
5353
)
54-
def test_remove_empty_lines_starting_cell(input):
54+
def test_remove_empty_lines_starting_cell(input: str) -> None:
5555

5656
assert remove_empty_lines_starting_cell(input) == "# %%\nfoo = 'bar'"
5757

5858

59-
def test_ensure_two_blank_lines_preceding_cell():
59+
def test_ensure_two_blank_lines_preceding_cell() -> None:
6060
# single preceding blank line
6161
out = ensure_two_blank_lines_preceding_cell("\n# %%\n")
6262
assert out == "\n\n\n# %%\n"
@@ -81,6 +81,6 @@ def test_ensure_two_blank_lines_preceding_cell():
8181
"\n# %%\na = 5\n\n\n# %%\n\t \n\n \n",
8282
],
8383
)
84-
def test_delete_last_cell_if_empty(input):
84+
def test_delete_last_cell_if_empty(input: str) -> None:
8585

8686
assert delete_last_cell_if_empty(input) == "\n# %%\na = 5\n"

tests/test_main.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,39 @@
11
import filecmp
2+
import shutil
23
from importlib.metadata import version
3-
from shutil import copy2
4+
from pathlib import Path
45

56
import pytest
7+
from pytest import CaptureFixture, MonkeyPatch
68

79
from format_ipy_cells.main import main
810

911

10-
def test_main_format_cells(capsys, tmpdir):
12+
def test_main_format_cells(
13+
tmp_path: Path, capsys: CaptureFixture[str], monkeypatch: MonkeyPatch
14+
) -> None:
15+
shutil.copy2("tests/fixtures/raw_nb.py", raw_tmp := str(tmp_path / "raw_nb.py"))
16+
# test we leave clean file as is and don't print logs about it
1117
clean_nb = "tests/fixtures/clean_nb.py"
18+
shutil.copy2(clean_nb, clean_tmp := str(tmp_path / "clean_nb.py"))
1219

13-
raw_file = copy2("tests/fixtures/raw_nb.py", tmpdir)
14-
# test we leave clean file as is and don't write logs about it
15-
clean_file = copy2(clean_nb, tmpdir)
16-
17-
ret = main((raw_file, clean_file))
20+
ret = main((raw_tmp, clean_tmp))
1821

1922
assert ret == 1
20-
assert filecmp.cmp(raw_file, clean_nb), "Formatted file has unexpected content"
21-
assert filecmp.cmp(clean_file, clean_nb), "clean file should not have changed"
23+
assert filecmp.cmp(raw_tmp, clean_nb), "Formatted file has unexpected content"
24+
assert filecmp.cmp(clean_tmp, clean_nb), "clean file should not have changed"
2225

2326
out, err = capsys.readouterr()
24-
assert out == f"Rewriting {raw_file}\n"
27+
assert out == f"Rewriting {raw_tmp}\n"
2528
assert err == ""
2629

27-
ret = main([clean_file])
30+
ret = main([clean_tmp])
2831
assert ret == 0, "expected exit code 0 when no files were changed"
2932
out, err = capsys.readouterr()
3033
assert out == err == ""
3134

3235

33-
def test_main_print_version(capsys):
36+
def test_main_print_version(capsys: CaptureFixture[str]) -> None:
3437

3538
with pytest.raises(SystemExit):
3639
ret_val = main(["-v"])

0 commit comments

Comments
 (0)