Skip to content

Commit ce92bf2

Browse files
committed
type check tests
1 parent 0cdc85a commit ce92bf2

15 files changed

+148
-119
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ module = [
6363
"matplotlib.*",
6464
"mpl_toolkits.*",
6565
"pandas.*",
66+
"pytest.*",
6667
"scipy.*",
6768
]
6869
ignore_missing_imports = true

tests/conftest.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
import pytest
1+
from pathlib import Path
22

3+
from pytest import FixtureRequest, fixture
34

4-
@pytest.fixture(scope="session")
5-
def repo_dir():
6-
import pathlib
5+
from stagpy.stagyydata import StagyyData, Step
76

8-
return pathlib.Path(__file__).parent.parent.resolve()
97

8+
@fixture(scope="session")
9+
def repo_dir() -> Path:
10+
return Path(__file__).parent.parent.resolve()
1011

11-
@pytest.fixture(scope="session", params=["ra-100000", "annulus"])
12-
def example_dir(request, repo_dir):
13-
return repo_dir / "Examples" / request.param
1412

13+
@fixture(scope="session", params=["ra-100000", "annulus"])
14+
def example_dir(request: FixtureRequest, repo_dir: Path) -> Path:
15+
return repo_dir / "Examples" / request.param
1516

16-
@pytest.fixture(scope="module")
17-
def sdat(example_dir):
18-
import stagpy.stagyydata
1917

20-
return stagpy.stagyydata.StagyyData(example_dir)
18+
@fixture(scope="module")
19+
def sdat(example_dir: Path) -> StagyyData:
20+
return StagyyData(example_dir)
2121

2222

23-
@pytest.fixture(scope="module")
24-
def step(sdat):
23+
@fixture(scope="module")
24+
def step(sdat: StagyyData) -> Step:
2525
return sdat.snaps[-1]

tests/test_args.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import re
22

33
import pytest
4+
from pytest import CaptureFixture
45

56
import stagpy.args
67

78

8-
def test_no_args(capsys):
9+
def test_no_args(capsys: CaptureFixture) -> None:
910
stagpy.args.parse_args([])()
1011
output = capsys.readouterr()
1112
expected = re.compile(
@@ -14,7 +15,7 @@ def test_no_args(capsys):
1415
assert expected.fullmatch(output.out)
1516

1617

17-
def test_help(capsys):
18+
def test_help(capsys: CaptureFixture) -> None:
1819
with pytest.raises(SystemExit):
1920
stagpy.args.parse_args(["-h"])
2021
output = capsys.readouterr()
@@ -27,7 +28,7 @@ def test_help(capsys):
2728
assert expected.fullmatch(output.out)
2829

2930

30-
def test_invalid_argument(capsys):
31+
def test_invalid_argument(capsys: CaptureFixture) -> None:
3132
with pytest.raises(SystemExit):
3233
stagpy.args.parse_args(["-dummyinvalidarg"])
3334
output = capsys.readouterr()
@@ -37,49 +38,49 @@ def test_invalid_argument(capsys):
3738
assert expected.fullmatch(output.err)
3839

3940

40-
def test_invalid_subcmd(capsys):
41+
def test_invalid_subcmd(capsys: CaptureFixture) -> None:
4142
with pytest.raises(SystemExit):
4243
stagpy.args.parse_args(["dummyinvalidcmd"])
4344
output = capsys.readouterr()
4445
expected = re.compile(r"^usage: .*error:.*invalid choice:.*\n$", flags=re.DOTALL)
4546
assert expected.fullmatch(output.err)
4647

4748

48-
def test_field_subcmd():
49+
def test_field_subcmd() -> None:
4950
func = stagpy.args.parse_args(["field"])
5051
assert func is stagpy.field.cmd
5152

5253

53-
def test_rprof_subcmd():
54+
def test_rprof_subcmd() -> None:
5455
func = stagpy.args.parse_args(["rprof"])
5556
assert func is stagpy.rprof.cmd
5657

5758

58-
def test_time_cmd():
59+
def test_time_cmd() -> None:
5960
func = stagpy.args.parse_args(["time"])
6061
assert func is stagpy.time_series.cmd
6162

6263

63-
def test_plates_subcmd():
64+
def test_plates_subcmd() -> None:
6465
func = stagpy.args.parse_args(["plates"])
6566
assert func is stagpy.plates.cmd
6667

6768

68-
def test_info_subcmd():
69+
def test_info_subcmd() -> None:
6970
func = stagpy.args.parse_args(["info"])
7071
assert func is stagpy.commands.info_cmd
7172

7273

73-
def test_var_subcmd():
74+
def test_var_subcmd() -> None:
7475
func = stagpy.args.parse_args(["var"])
7576
assert func is stagpy.commands.var_cmd
7677

7778

78-
def test_version_subcmd():
79+
def test_version_subcmd() -> None:
7980
func = stagpy.args.parse_args(["version"])
8081
assert func is stagpy.commands.version_cmd
8182

8283

83-
def test_config_subcmd():
84+
def test_config_subcmd() -> None:
8485
func = stagpy.args.parse_args(["config"])
8586
assert func is stagpy.commands.config_cmd

tests/test_cli.py

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
1+
from __future__ import annotations
2+
13
import re
24
import subprocess
5+
from pathlib import Path
36

4-
import pytest
7+
from pytest import FixtureRequest, fixture
58

69

7-
@pytest.fixture(params=[("ra-100000", 5, 1000), ("annulus", 100, 3000)])
8-
def dir_isnap(request, repo_dir):
10+
@fixture(params=[("ra-100000", 5, 1000), ("annulus", 100, 3000)])
11+
def dir_isnap(request: FixtureRequest, repo_dir: Path) -> tuple[Path, int, int]:
912
return (
1013
repo_dir / "Examples" / request.param[0],
1114
request.param[1],
1215
request.param[2],
1316
)
1417

1518

16-
@pytest.fixture(
19+
@fixture(
1720
params=[
1821
("stagpy field", ["stagpy_T_stream{:05d}.pdf"]),
1922
("stagpy field -o=T.v3", ["stagpy_T_v3{:05d}.pdf"]),
2023
("stagpy field -o=T-v3", ["stagpy_T{:05d}.pdf", "stagpy_v3{:05d}.pdf"]),
2124
]
2225
)
23-
def all_cmd_field(request, dir_isnap):
26+
def all_cmd_field(
27+
request: FixtureRequest, dir_isnap: tuple[Path, int, int]
28+
) -> tuple[str, list[str]]:
2429
cmd = request.param[0]
2530
cmd += " -p={}".format(dir_isnap[0])
2631
expected_files = []
@@ -29,13 +34,15 @@ def all_cmd_field(request, dir_isnap):
2934
return cmd, expected_files
3035

3136

32-
@pytest.fixture(
37+
@fixture(
3338
params=[
3439
("stagpy rprof", ["stagpy_rprof_Tmean_{}.pdf"]),
3540
("stagpy rprof -o=Tmean,vzabs", ["stagpy_rprof_Tmean_vzabs_{}.pdf"]),
3641
]
3742
)
38-
def all_cmd_rprof(request, dir_isnap):
43+
def all_cmd_rprof(
44+
request: FixtureRequest, dir_isnap: tuple[Path, int, int]
45+
) -> tuple[str, list[str]]:
3946
cmd = request.param[0]
4047
cmd += " -p={}".format(dir_isnap[0])
4148
expected_files = []
@@ -44,18 +51,20 @@ def all_cmd_rprof(request, dir_isnap):
4451
return cmd, expected_files
4552

4653

47-
@pytest.fixture(
54+
@fixture(
4855
params=[
4956
("stagpy time -o Tmean.Nutop", ["stagpy_time_Tmean_Nutop.pdf"]),
5057
]
5158
)
52-
def all_cmd_time(request, dir_isnap):
59+
def all_cmd_time(
60+
request: FixtureRequest, dir_isnap: tuple[str, int, int]
61+
) -> tuple[str, list[str]]:
5362
cmd = request.param[0]
5463
cmd += " -p={}".format(dir_isnap[0])
5564
return cmd, request.param[1]
5665

5766

58-
@pytest.fixture(
67+
@fixture(
5968
params=[
6069
(
6170
"stagpy plates -o v2.dv2 -continents --field T",
@@ -67,7 +76,9 @@ def all_cmd_time(request, dir_isnap):
6776
),
6877
]
6978
)
70-
def all_cmd_plates(request, dir_isnap):
79+
def all_cmd_plates(
80+
request: FixtureRequest, dir_isnap: tuple[str, int, int]
81+
) -> tuple[str, list[str]]:
7182
cmd = request.param[0]
7283
cmd += " -p={}".format(dir_isnap[0])
7384
expected_files = []
@@ -76,30 +87,30 @@ def all_cmd_plates(request, dir_isnap):
7687
return cmd, expected_files
7788

7889

79-
def helper_test_cli(all_cmd, tmp):
90+
def helper_test_cli(all_cmd: tuple[str, list[str]], tmp: Path) -> None:
8091
subprocess.run(all_cmd[0] + " -n={}/stagpy".format(tmp), shell=True)
8192
produced_files = sorted(tmp.iterdir())
8293
expected_files = [tmp / expfile for expfile in sorted(all_cmd[1])]
8394
assert produced_files == expected_files
8495

8596

86-
def test_field_cli(all_cmd_field, tmp_path):
97+
def test_field_cli(all_cmd_field: tuple[str, list[str]], tmp_path: Path) -> None:
8798
helper_test_cli(all_cmd_field, tmp_path)
8899

89100

90-
def test_rprof_cli(all_cmd_rprof, tmp_path):
101+
def test_rprof_cli(all_cmd_rprof: tuple[str, list[str]], tmp_path: Path) -> None:
91102
helper_test_cli(all_cmd_rprof, tmp_path)
92103

93104

94-
def test_time_cli(all_cmd_time, tmp_path):
105+
def test_time_cli(all_cmd_time: tuple[str, list[str]], tmp_path: Path) -> None:
95106
helper_test_cli(all_cmd_time, tmp_path)
96107

97108

98-
def test_plates_cli(all_cmd_plates, tmp_path):
109+
def test_plates_cli(all_cmd_plates: tuple[str, list[str]], tmp_path: Path) -> None:
99110
helper_test_cli(all_cmd_plates, tmp_path)
100111

101112

102-
def test_err_cli():
113+
def test_err_cli() -> None:
103114
subp = subprocess.run("stagpy field", shell=True, stderr=subprocess.PIPE)
104115
reg = re.compile(rb"^Oops!.*\nPlease.*\n\nNoParFileError.*$")
105116
assert reg.match(subp.stderr)

tests/test_commands.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import re
2+
from pathlib import Path
3+
4+
from pytest import CaptureFixture
25

36
import stagpy.commands
47

58

6-
def test_info_cmd(capsys, example_dir):
9+
def test_info_cmd(capsys: CaptureFixture, example_dir: Path) -> None:
710
stagpy.conf.core.path = example_dir
811
stagpy.commands.info_cmd()
912
output = capsys.readouterr()
@@ -14,21 +17,21 @@ def test_info_cmd(capsys, example_dir):
1417
del stagpy.conf.core.path
1518

1619

17-
def test_var_cmd(capsys):
20+
def test_var_cmd(capsys: CaptureFixture) -> None:
1821
stagpy.commands.var_cmd()
1922
output = capsys.readouterr()
2023
expected = re.compile(r"field:\n.*\nrprof:\n.*\ntime:\n.*\n.*$", flags=re.DOTALL)
2124
assert expected.fullmatch(output.out)
2225

2326

24-
def test_version_cmd(capsys):
27+
def test_version_cmd(capsys: CaptureFixture) -> None:
2528
stagpy.commands.version_cmd()
2629
output = capsys.readouterr()
2730
expected = "stagpy version: {}\n".format(stagpy.__version__)
2831
assert output.out == expected
2932

3033

31-
def test_config_cmd(capsys):
34+
def test_config_cmd(capsys: CaptureFixture) -> None:
3235
stagpy.commands.config_cmd()
3336
output = capsys.readouterr()
3437
expected = "(c|f): available only as CLI argument/in the config file"

tests/test_field.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,49 @@
33
import stagpy.error
44
import stagpy.field
55
import stagpy.phyvars
6+
from stagpy.stagyydata import Step
67

78

8-
def test_field_unknown(step):
9+
def test_field_unknown(step: Step) -> None:
910
with pytest.raises(stagpy.error.UnknownFieldVarError):
1011
step.fields["InvalidField"]
1112
assert "InvalidField" in step.fields
1213

1314

14-
def test_field_missing(step):
15+
def test_field_missing(step: Step) -> None:
1516
with pytest.raises(stagpy.error.MissingDataError):
1617
step.fields["rsc"]
1718
assert "rsc" not in step.fields
1819

1920

20-
def test_valid_field_var():
21+
def test_valid_field_var() -> None:
2122
for var in stagpy.phyvars.FIELD:
2223
assert stagpy.field.valid_field_var(var)
2324
for var in stagpy.phyvars.FIELD_EXTRA:
2425
assert stagpy.field.valid_field_var(var)
2526

2627

27-
def test_valid_field_var_invalid():
28+
def test_valid_field_var_invalid() -> None:
2829
assert not stagpy.field.valid_field_var("dummyfieldvar")
2930

3031

31-
def test_get_meshes_fld_no_walls(step):
32+
def test_get_meshes_fld_no_walls(step: Step) -> None:
3233
xmesh, ymesh, fld, meta = stagpy.field.get_meshes_fld(step, "T", walls=False)
3334
assert len(fld.shape) == 2
3435
assert xmesh.shape[0] == ymesh.shape[0] == fld.shape[0]
3536
assert xmesh.shape[1] == ymesh.shape[1] == fld.shape[1]
3637
assert meta.description == "Temperature"
3738

3839

39-
def test_get_meshes_fld_walls(step):
40+
def test_get_meshes_fld_walls(step: Step) -> None:
4041
xmesh, ymesh, fld, meta = stagpy.field.get_meshes_fld(step, "T", walls=True)
4142
assert len(fld.shape) == 2
4243
assert xmesh.shape[0] == ymesh.shape[0] == fld.shape[0] + 1
4344
assert xmesh.shape[1] == ymesh.shape[1] == fld.shape[1] + 1
4445
assert meta.description == "Temperature"
4546

4647

47-
def test_get_meshes_vec(step):
48+
def test_get_meshes_vec(step: Step) -> None:
4849
xmesh, ymesh, vec1, vec2 = stagpy.field.get_meshes_vec(step, "v")
4950
assert len(vec1.shape) == 2
5051
assert xmesh.shape[0] == ymesh.shape[0] == vec1.shape[0] == vec2.shape[0]

tests/test_helpers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
import stagpy._helpers
33

44

5-
def test_out_name_conf():
5+
def test_out_name_conf() -> None:
66
oname = "something_fancy"
77
stagpy.conf.core.outname = oname
88
stem = "teapot"
99
assert stagpy._helpers.out_name(stem) == oname + "_" + stem
1010
del stagpy.conf.core.outname
1111

1212

13-
def test_out_name_number():
13+
def test_out_name_number() -> None:
1414
assert stagpy._helpers.out_name("T", 123) == "stagpy_T00123"
1515

1616

17-
def test_baredoc():
17+
def test_baredoc() -> None:
1818
"""
1919
Badly formatted docstring .. .
2020

0 commit comments

Comments
 (0)