Skip to content

Commit 33c1446

Browse files
committed
Address more mypy warnings on tests files
All of the changes are made manual. The target files are only those who test the new code. Signed-off-by: Martin Vrachev <[email protected]>
1 parent 8bc049d commit 33c1446

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

tests/test_examples.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import tempfile
1111
import unittest
1212
from pathlib import Path
13+
from typing import ClassVar, List
1314

1415

1516
class TestRepoExamples(unittest.TestCase):
@@ -20,26 +21,30 @@ class TestRepoExamples(unittest.TestCase):
2021
2122
"""
2223

24+
repo_examples_dir: ClassVar[Path]
25+
2326
@classmethod
24-
def setUpClass(cls):
27+
def setUpClass(cls) -> None:
2528
"""Locate and cache 'repo_example' dir."""
2629
base = Path(__file__).resolve().parents[1]
2730
cls.repo_examples_dir = base / "examples" / "repo_example"
2831

29-
def setUp(self):
32+
def setUp(self) -> None:
3033
"""Create and change into test dir.
3134
NOTE: Test scripts are expected to create dirs/files in new CWD."""
3235
self.original_cwd = os.getcwd()
3336
self.base_test_dir = os.path.realpath(tempfile.mkdtemp())
3437
os.chdir(self.base_test_dir)
3538

36-
def tearDown(self):
39+
def tearDown(self) -> None:
3740
"""Change back to original dir and remove test dir, which may contain
3841
dirs/files the test created at test-time CWD."""
3942
os.chdir(self.original_cwd)
4043
shutil.rmtree(self.base_test_dir)
4144

42-
def _run_script_and_assert_files(self, script_name, filenames_created):
45+
def _run_script_and_assert_files(
46+
self, script_name: str, filenames_created: List[str]
47+
) -> None:
4348
"""Run script in 'repo_example' dir and assert that it created the
4449
files corresponding to the passed filenames inside a 'tmp*' test dir at
4550
CWD."""
@@ -63,7 +68,7 @@ def _run_script_and_assert_files(self, script_name, filenames_created):
6368
metadata_path.exists(), f"missing '{metadata_path}' file"
6469
)
6570

66-
def test_basic_repo(self):
71+
def test_basic_repo(self) -> None:
6772
"""Run 'basic_repo.py' and assert creation of metadata files."""
6873
self._run_script_and_assert_files(
6974
"basic_repo.py",

tests/test_updater_consistent_snapshot.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from tuf.api.metadata import (
1818
SPECIFICATION_VERSION,
1919
TOP_LEVEL_ROLE_NAMES,
20+
TargetFile,
2021
Targets,
2122
)
2223
from tuf.ngclient import Updater
@@ -109,7 +110,9 @@ def _assert_targets_files_exist(self, filenames: Iterable[str]) -> None:
109110
}
110111

111112
@utils.run_sub_tests_with_dataset(top_level_roles_data)
112-
def test_top_level_roles_update(self, test_case_data: Dict[str, Any]):
113+
def test_top_level_roles_update(
114+
self, test_case_data: Dict[str, Any]
115+
) -> None:
113116
# Test if the client fetches and stores metadata files with the
114117
# correct version prefix, depending on 'consistent_snapshot' config
115118
consistent_snapshot: bool = test_case_data["consistent_snapshot"]
@@ -143,7 +146,9 @@ def test_top_level_roles_update(self, test_case_data: Dict[str, Any]):
143146
}
144147

145148
@utils.run_sub_tests_with_dataset(delegated_roles_data)
146-
def test_delegated_roles_update(self, test_case_data: Dict[str, Any]):
149+
def test_delegated_roles_update(
150+
self, test_case_data: Dict[str, Any]
151+
) -> None:
147152
# Test if the client fetches and stores delegated metadata files with
148153
# the correct version prefix, depending on 'consistent_snapshot' config
149154
consistent_snapshot: bool = test_case_data["consistent_snapshot"]
@@ -193,7 +198,7 @@ def test_delegated_roles_update(self, test_case_data: Dict[str, Any]):
193198
}
194199

195200
@utils.run_sub_tests_with_dataset(targets_download_data)
196-
def test_download_targets(self, test_case_data: Dict[str, Any]):
201+
def test_download_targets(self, test_case_data: Dict[str, Any]) -> None:
197202
# Test if the client fetches and stores target files with
198203
# the correct hash prefix, depending on 'consistent_snapshot'
199204
# and 'prefix_targets_with_hash' config
@@ -220,6 +225,7 @@ def test_download_targets(self, test_case_data: Dict[str, Any]):
220225

221226
for targetpath in targetpaths:
222227
info = updater.get_targetinfo(targetpath)
228+
assert isinstance(info, TargetFile)
223229
updater.download_target(info)
224230
expected_prefix = (
225231
None if not hash_algo else info.hashes[hash_algo]

0 commit comments

Comments
 (0)