Skip to content

Commit b718517

Browse files
committed
Add type more hints to tests.
1 parent e03942f commit b718517

File tree

5 files changed

+19
-20
lines changed

5 files changed

+19
-20
lines changed

tests/test_dates.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# stdlib
1010
import re
1111
from datetime import date, datetime, timedelta
12+
from typing import Union
1213

1314
# 3rd party
1415
import pytest
@@ -177,7 +178,7 @@ def test_parse_month():
177178

178179

179180
@pytest.mark.parametrize("month_idx, month", enumerate(month_full_names))
180-
def test_get_month_number_from_name(month_idx, month):
181+
def test_get_month_number_from_name(month_idx: int, month: str):
181182
month_idx += 1 # to make 1-indexed
182183

183184
for i in range(3, len(month)):
@@ -189,7 +190,7 @@ def test_get_month_number_from_name(month_idx, month):
189190

190191

191192
@count(13, 1)
192-
def test_get_month_number_from_no(count):
193+
def test_get_month_number_from_no(count: int):
193194
assert dates.get_month_number(count) == count
194195

195196

@@ -205,7 +206,7 @@ def test_get_month_number_from_no(count):
205206
("13", "The given month ('13') is not recognised."),
206207
]
207208
)
208-
def test_get_month_number_errors(value, match):
209+
def test_get_month_number_errors(value: Union[str, int], match: str):
209210
with pytest.raises(ValueError, match=re.escape(match)):
210211
dates.get_month_number(value)
211212

tests/test_paths.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ def test_load_json(tmpdir):
612612
assert tmp_file.load_json() == {"key": "value", "int": 1234, "float": 12.34}
613613

614614

615-
def test_in_directory(tmp_pathplus):
615+
def test_in_directory(tmp_pathplus: PathPlus):
616616
cwd = os.getcwd()
617617

618618
with in_directory(tmp_pathplus):
@@ -638,7 +638,7 @@ def test_in_directory(tmp_pathplus):
638638
("foo/bar/baz/foo.yml", "foo/bar/baz"),
639639
]
640640
)
641-
def test_traverse_to_file(tmp_pathplus, location, expected):
641+
def test_traverse_to_file(tmp_pathplus: PathPlus, location: str, expected: str):
642642
(tmp_pathplus / location).parent.maybe_make(parents=True)
643643
(tmp_pathplus / location).touch()
644644
assert traverse_to_file(tmp_pathplus / "foo" / "bar" / "baz", "foo.yml") == tmp_pathplus / expected
@@ -647,7 +647,7 @@ def test_traverse_to_file(tmp_pathplus, location, expected):
647647
# TODO: height
648648

649649

650-
def test_traverse_to_file_errors(tmp_pathplus):
650+
def test_traverse_to_file_errors(tmp_pathplus: PathPlus):
651651
(tmp_pathplus / "foo/bar/baz").parent.maybe_make(parents=True)
652652
if os.sep == '/':
653653
with pytest.raises(FileNotFoundError, match="'foo.yml' not found in .*/foo/bar/baz"):
@@ -702,7 +702,7 @@ def test_iterchildren_match(data_regression: DataRegressionFixture):
702702
data_regression.check(child_paths)
703703

704704

705-
def test_iterchildren_no_exclusions(tmp_pathplus):
705+
def test_iterchildren_no_exclusions(tmp_pathplus: PathPlus):
706706
(tmp_pathplus / ".git").mkdir()
707707
(tmp_pathplus / "venv").mkdir()
708708
(tmp_pathplus / ".venv").mkdir()
@@ -800,5 +800,5 @@ def test_iterchildren_no_exclusions(tmp_pathplus):
800800
("domdf_python_tools/**/*.py", "domdf_python_tools/domdf_python_tools/pagesizes/units.py", True),
801801
]
802802
)
803-
def test_globpath(pattern, filename, match: bool):
803+
def test_globpath(pattern: str, filename: str, match: bool):
804804
assert matchglob(filename, pattern) is match

tests/test_paths_stdlib.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def symlink_skip_reason():
6969

7070

7171
@pytest.fixture()
72-
def BASE(tmp_pathplus):
72+
def BASE(tmp_pathplus: PathPlus):
7373
top_dir = tmp_pathplus
7474
tmp_pathplus = top_dir / "a/b/c/d"
7575
tmp_pathplus.maybe_make(parents=True)
@@ -276,7 +276,7 @@ def test_link_to_not_implemented(BASE):
276276
p.link_to(q)
277277

278278

279-
def test_rename(BASE, tmp_pathplus):
279+
def test_rename(BASE, tmp_pathplus: PathPlus):
280280
P = PathPlus(BASE)
281281
p = P / "fileA"
282282
size = p.stat().st_size
@@ -558,15 +558,15 @@ def test_is_socket_false(BASE):
558558
assert not (P / "fileA" / "bah").is_socket()
559559

560560

561-
def test_is_block_device_false(tmp_pathplus):
561+
def test_is_block_device_false(tmp_pathplus: PathPlus):
562562
P = tmp_pathplus.resolve() / TESTFN
563563
assert not (P / "fileA").is_block_device()
564564
assert not (P / "dirA").is_block_device()
565565
assert not (P / "non-existing").is_block_device()
566566
assert not (P / "fileA" / "bah").is_block_device()
567567

568568

569-
def test_is_char_device_false(tmp_pathplus):
569+
def test_is_char_device_false(tmp_pathplus: PathPlus):
570570
P = tmp_pathplus.resolve() / TESTFN
571571
assert not (P / "fileA").is_char_device()
572572
assert not (P / "dirA").is_char_device()
@@ -609,7 +609,7 @@ def test_unsupported_flavour():
609609
pathlib.WindowsPath()
610610

611611

612-
def test_glob_empty_pattern(tmp_pathplus):
612+
def test_glob_empty_pattern(tmp_pathplus: PathPlus):
613613
p = tmp_pathplus
614614
with pytest.raises(ValueError, match="Unacceptable pattern"):
615615
list(p.glob(''))

tests/test_testing.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,15 +210,12 @@ def test_only_macos():
210210
assert False # noqa: PT015
211211

212212

213-
pytest_plugins = ("domdf_python_tools.testing", )
214-
215-
216-
def test_tmp_pathplus(tmp_pathplus):
213+
def test_tmp_pathplus(tmp_pathplus: PathPlus):
217214
assert isinstance(tmp_pathplus, PathPlus)
218215
assert tmp_pathplus.exists()
219216

220217

221-
def test_check_file_output(tmp_pathplus, file_regression: FileRegressionFixture):
218+
def test_check_file_output(tmp_pathplus: PathPlus, file_regression: FileRegressionFixture):
222219
with pytest.raises(FileNotFoundError, match="No such file or directory: '.*'"):
223220
check_file_output(tmp_pathplus / "file.txt", file_regression)
224221

@@ -248,7 +245,7 @@ def test_fixed_datetime(fixed_datetime):
248245
pytest.param(datetime.datetime(2020, 7, 4, 10, 00), datetime.datetime(2020, 7, 4), id='1'),
249246
]
250247
)
251-
def test_with_fixed_datetime(fake_datetime, expected_date):
248+
def test_with_fixed_datetime(fake_datetime, expected_date: datetime.datetime):
252249

253250
with with_fixed_datetime(fake_datetime):
254251
assert datetime.datetime.today() == expected_date

tests/test_words.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import pathlib
44
import random
55
import string
6+
from typing import List
67

78
# 3rd party
89
import pytest
@@ -24,7 +25,7 @@
2425
(500, ["tuning", "knowledgestorm", "backing", "motivation", "calculated"]),
2526
],
2627
)
27-
def test_get_random_word(seed, expected_values):
28+
def test_get_random_word(seed: int, expected_values: List[str]):
2829
random.seed(seed)
2930

3031
for i in range(5):

0 commit comments

Comments
 (0)