Skip to content

Commit 2f7d24a

Browse files
committed
tests: lint fixes
Signed-off-by: Jussi Kukkonen <[email protected]>
1 parent 80de350 commit 2f7d24a

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

tests/test_updater_ng.py

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
from __future__ import annotations
77

8-
from collections.abc import Iterable
98
import logging
109
import os
1110
import shutil

tests/test_updater_top_level_update.py

+23-14
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,7 +84,7 @@ 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:
@@ -702,9 +701,10 @@ def test_load_metadata_from_cache(self, wrapped_open: MagicMock) -> None:
702701
updater.get_targetinfo("non_existent_target")
703702

704703
# Test that metadata is loaded from cache and not downloaded
704+
root_dir = os.path.join(self.metadata_dir, "root_history")
705705
wrapped_open.assert_has_calls(
706706
[
707-
call(os.path.join(self.metadata_dir, "root_history/2.root.json"), "rb"),
707+
call(os.path.join(root_dir, "2.root.json"), "rb"),
708708
call(os.path.join(self.metadata_dir, "timestamp.json"), "rb"),
709709
call(os.path.join(self.metadata_dir, "snapshot.json"), "rb"),
710710
call(os.path.join(self.metadata_dir, "targets.json"), "rb"),
@@ -715,7 +715,6 @@ def test_load_metadata_from_cache(self, wrapped_open: MagicMock) -> None:
715715
expected_calls = [("root", 2), ("timestamp", None)]
716716
self.assertListEqual(self.sim.fetch_tracker.metadata, expected_calls)
717717

718-
719718
@patch.object(builtins, "open", wraps=builtins.open)
720719
def test_intermediate_root_cache(self, wrapped_open: MagicMock) -> None:
721720
"""Test that refresh uses the intermediate roots from cache"""
@@ -729,17 +728,25 @@ def test_intermediate_root_cache(self, wrapped_open: MagicMock) -> None:
729728
self._run_refresh()
730729

731730
# assert that cache lookups happened but data was downloaded from remote
731+
root_dir = os.path.join(self.metadata_dir, "root_history")
732732
wrapped_open.assert_has_calls(
733733
[
734-
call(os.path.join(self.metadata_dir, "root_history/2.root.json"), "rb"),
735-
call(os.path.join(self.metadata_dir, "root_history/3.root.json"), "rb"),
736-
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"),
737737
call(os.path.join(self.metadata_dir, "timestamp.json"), "rb"),
738738
call(os.path.join(self.metadata_dir, "snapshot.json"), "rb"),
739739
call(os.path.join(self.metadata_dir, "targets.json"), "rb"),
740740
]
741741
)
742-
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+
]
743750
self.assertListEqual(self.sim.fetch_tracker.metadata, expected_calls)
744751

745752
# Clear statistics for open() calls and metadata requests
@@ -750,9 +757,9 @@ def test_intermediate_root_cache(self, wrapped_open: MagicMock) -> None:
750757
self._run_refresh()
751758
wrapped_open.assert_has_calls(
752759
[
753-
call(os.path.join(self.metadata_dir, "root_history/2.root.json"), "rb"),
754-
call(os.path.join(self.metadata_dir, "root_history/3.root.json"), "rb"),
755-
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"),
756763
call(os.path.join(self.metadata_dir, "timestamp.json"), "rb"),
757764
call(os.path.join(self.metadata_dir, "snapshot.json"), "rb"),
758765
call(os.path.join(self.metadata_dir, "targets.json"), "rb"),
@@ -773,7 +780,9 @@ def test_intermediate_root_cache_poisoning(self) -> None:
773780
self._run_refresh()
774781

775782
# Modify cached intermediate root v2 so that it's no longer signed correctly
776-
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+
)
777786
md = Metadata.from_file(root_path)
778787
md.signatures.clear()
779788
md.to_file(root_path)

0 commit comments

Comments
 (0)