Skip to content

Commit d5f1eea

Browse files
committed
tests: lint fixes
Signed-off-by: Jussi Kukkonen <[email protected]>
1 parent b7cbe43 commit d5f1eea

File tree

3 files changed

+36
-19
lines changed

3 files changed

+36
-19
lines changed

tests/test_updater_delegation_graphs.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ def _init_updater(self) -> Updater:
135135
def _assert_files_exist(self, roles: Iterable[str]) -> None:
136136
"""Assert that local metadata files match 'roles'"""
137137
expected_files = [f"{role}.json" for role in roles]
138-
found_files = [e.name for e in os.scandir(self.metadata_dir) if e.is_file()]
138+
found_files = [
139+
e.name for e in os.scandir(self.metadata_dir) if e.is_file()
140+
]
139141

140142
self.assertListEqual(sorted(found_files), sorted(expected_files))
141143

tests/test_updater_ng.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55

66
from __future__ import annotations
77

8-
from collections.abc import Iterable
98
import logging
109
import os
1110
import shutil
1211
import sys
1312
import tempfile
1413
import unittest
15-
from typing import Callable, ClassVar
14+
from typing import TYPE_CHECKING, Callable, ClassVar
1615
from unittest.mock import MagicMock, patch
1716

1817
from securesystemslib.signer import Signer
@@ -29,6 +28,9 @@
2928
)
3029
from tuf.ngclient import Updater, UpdaterConfig
3130

31+
if TYPE_CHECKING:
32+
from collections.abc import Iterable
33+
3234
logger = logging.getLogger(__name__)
3335

3436

@@ -153,7 +155,9 @@ def _modify_repository_root(
153155
def _assert_files_exist(self, roles: Iterable[str]) -> None:
154156
"""Assert that local metadata files match 'roles'"""
155157
expected_files = [f"{role}.json" for role in roles]
156-
found_files = [e.name for e in os.scandir(self.client_directory) if e.is_file()]
158+
found_files = [
159+
e.name for e in os.scandir(self.client_directory) if e.is_file()
160+
]
157161

158162
self.assertListEqual(sorted(found_files), sorted(expected_files))
159163

tests/test_updater_top_level_update.py

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import builtins
77
import datetime
8-
import logging
98
import os
109
import sys
1110
import tempfile
@@ -68,13 +67,13 @@ def setUp(self) -> None:
6867
def tearDown(self) -> None:
6968
self.temp_dir.cleanup()
7069

71-
def _run_refresh(self, skip_bootstrap:bool=False) -> Updater:
70+
def _run_refresh(self, skip_bootstrap: bool = False) -> Updater:
7271
"""Create a new Updater instance and refresh"""
7372
updater = self._init_updater(skip_bootstrap)
7473
updater.refresh()
7574
return updater
7675

77-
def _init_updater(self, skip_bootstrap:bool=False) -> Updater:
76+
def _init_updater(self, skip_bootstrap: bool = False) -> Updater:
7877
"""Create a new Updater instance"""
7978
if self.dump_dir is not None:
8079
self.sim.write()
@@ -85,13 +84,15 @@ def _init_updater(self, skip_bootstrap:bool=False) -> Updater:
8584
self.targets_dir,
8685
"https://example.com/targets/",
8786
self.sim,
88-
bootstrap=None if skip_bootstrap else self.sim.signed_roots[0]
87+
bootstrap=None if skip_bootstrap else self.sim.signed_roots[0],
8988
)
9089

9190
def _assert_files_exist(self, roles: Iterable[str]) -> None:
9291
"""Assert that local metadata files match 'roles'"""
9392
expected_files = [f"{role}.json" for role in roles]
94-
found_files = [e.name for e in os.scandir(self.metadata_dir) if e.is_file()]
93+
found_files = [
94+
e.name for e in os.scandir(self.metadata_dir) if e.is_file()
95+
]
9596

9697
self.assertListEqual(sorted(found_files), sorted(expected_files))
9798

@@ -700,9 +701,10 @@ def test_load_metadata_from_cache(self, wrapped_open: MagicMock) -> None:
700701
updater.get_targetinfo("non_existent_target")
701702

702703
# Test that metadata is loaded from cache and not downloaded
704+
root_dir = os.path.join(self.metadata_dir, "root_history")
703705
wrapped_open.assert_has_calls(
704706
[
705-
call(os.path.join(self.metadata_dir, "root_history/2.root.json"), "rb"),
707+
call(os.path.join(root_dir, "2.root.json"), "rb"),
706708
call(os.path.join(self.metadata_dir, "timestamp.json"), "rb"),
707709
call(os.path.join(self.metadata_dir, "snapshot.json"), "rb"),
708710
call(os.path.join(self.metadata_dir, "targets.json"), "rb"),
@@ -713,7 +715,6 @@ def test_load_metadata_from_cache(self, wrapped_open: MagicMock) -> None:
713715
expected_calls = [("root", 2), ("timestamp", None)]
714716
self.assertListEqual(self.sim.fetch_tracker.metadata, expected_calls)
715717

716-
717718
@patch.object(builtins, "open", wraps=builtins.open)
718719
def test_intermediate_root_cache(self, wrapped_open: MagicMock) -> None:
719720
"""Test that refresh uses the intermediate roots from cache"""
@@ -727,17 +728,25 @@ def test_intermediate_root_cache(self, wrapped_open: MagicMock) -> None:
727728
self._run_refresh()
728729

729730
# assert that cache lookups happened but data was downloaded from remote
731+
root_dir = os.path.join(self.metadata_dir, "root_history")
730732
wrapped_open.assert_has_calls(
731733
[
732-
call(os.path.join(self.metadata_dir, "root_history/2.root.json"), "rb"),
733-
call(os.path.join(self.metadata_dir, "root_history/3.root.json"), "rb"),
734-
call(os.path.join(self.metadata_dir, "root_history/4.root.json"), "rb"),
734+
call(os.path.join(root_dir, "2.root.json"), "rb"),
735+
call(os.path.join(root_dir, "3.root.json"), "rb"),
736+
call(os.path.join(root_dir, "4.root.json"), "rb"),
735737
call(os.path.join(self.metadata_dir, "timestamp.json"), "rb"),
736738
call(os.path.join(self.metadata_dir, "snapshot.json"), "rb"),
737739
call(os.path.join(self.metadata_dir, "targets.json"), "rb"),
738740
]
739741
)
740-
expected_calls = [("root", 2), ("root", 3), ("root", 4), ("timestamp", None), ("snapshot", 1), ("targets", 1)]
742+
expected_calls = [
743+
("root", 2),
744+
("root", 3),
745+
("root", 4),
746+
("timestamp", None),
747+
("snapshot", 1),
748+
("targets", 1),
749+
]
741750
self.assertListEqual(self.sim.fetch_tracker.metadata, expected_calls)
742751

743752
# Clear statistics for open() calls and metadata requests
@@ -748,9 +757,9 @@ def test_intermediate_root_cache(self, wrapped_open: MagicMock) -> None:
748757
self._run_refresh()
749758
wrapped_open.assert_has_calls(
750759
[
751-
call(os.path.join(self.metadata_dir, "root_history/2.root.json"), "rb"),
752-
call(os.path.join(self.metadata_dir, "root_history/3.root.json"), "rb"),
753-
call(os.path.join(self.metadata_dir, "root_history/4.root.json"), "rb"),
760+
call(os.path.join(root_dir, "2.root.json"), "rb"),
761+
call(os.path.join(root_dir, "3.root.json"), "rb"),
762+
call(os.path.join(root_dir, "4.root.json"), "rb"),
754763
call(os.path.join(self.metadata_dir, "timestamp.json"), "rb"),
755764
call(os.path.join(self.metadata_dir, "snapshot.json"), "rb"),
756765
call(os.path.join(self.metadata_dir, "targets.json"), "rb"),
@@ -771,7 +780,9 @@ def test_intermediate_root_cache_poisoning(self) -> None:
771780
self._run_refresh()
772781

773782
# Modify cached intermediate root v2 so that it's no longer signed correctly
774-
root_path = os.path.join(self.metadata_dir, "root_history", "2.root.json")
783+
root_path = os.path.join(
784+
self.metadata_dir, "root_history", "2.root.json"
785+
)
775786
md = Metadata.from_file(root_path)
776787
md.signatures.clear()
777788
md.to_file(root_path)

0 commit comments

Comments
 (0)