|
1 | 1 | import filecmp |
| 2 | +import shutil |
2 | 3 | from importlib.metadata import version |
3 | | -from shutil import copy2 |
| 4 | +from pathlib import Path |
4 | 5 |
|
5 | 6 | import pytest |
| 7 | +from pytest import CaptureFixture, MonkeyPatch |
6 | 8 |
|
7 | 9 | from format_ipy_cells.main import main |
8 | 10 |
|
9 | 11 |
|
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 |
11 | 17 | clean_nb = "tests/fixtures/clean_nb.py" |
| 18 | + shutil.copy2(clean_nb, clean_tmp := str(tmp_path / "clean_nb.py")) |
12 | 19 |
|
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)) |
18 | 21 |
|
19 | 22 | 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" |
22 | 25 |
|
23 | 26 | out, err = capsys.readouterr() |
24 | | - assert out == f"Rewriting {raw_file}\n" |
| 27 | + assert out == f"Rewriting {raw_tmp}\n" |
25 | 28 | assert err == "" |
26 | 29 |
|
27 | | - ret = main([clean_file]) |
| 30 | + ret = main([clean_tmp]) |
28 | 31 | assert ret == 0, "expected exit code 0 when no files were changed" |
29 | 32 | out, err = capsys.readouterr() |
30 | 33 | assert out == err == "" |
31 | 34 |
|
32 | 35 |
|
33 | | -def test_main_print_version(capsys): |
| 36 | +def test_main_print_version(capsys: CaptureFixture[str]) -> None: |
34 | 37 |
|
35 | 38 | with pytest.raises(SystemExit): |
36 | 39 | ret_val = main(["-v"]) |
|
0 commit comments