Skip to content

Commit 6ae5329

Browse files
committed
Fix more black warnings on test files
The changes are automatic linting fixes from black. The target files are only those who test the new code. Signed-off-by: Martin Vrachev <[email protected]>
1 parent 2a07526 commit 6ae5329

5 files changed

+68
-16
lines changed

tests/test_api.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,12 @@ def test_compact_json(self) -> None:
136136
)
137137

138138
def test_read_write_read_compare(self) -> None:
139-
for metadata in [Root.type, Snapshot.type, Timestamp.type, Targets.type]:
139+
for metadata in [
140+
Root.type,
141+
Snapshot.type,
142+
Timestamp.type,
143+
Targets.type,
144+
]:
140145
path = os.path.join(self.repo_dir, "metadata", metadata + ".json")
141146
md_obj = Metadata.from_file(path)
142147

@@ -148,7 +153,12 @@ def test_read_write_read_compare(self) -> None:
148153
os.remove(path_2)
149154

150155
def test_to_from_bytes(self) -> None:
151-
for metadata in [Root.type, Snapshot.type, Timestamp.type, Targets.type]:
156+
for metadata in [
157+
Root.type,
158+
Snapshot.type,
159+
Timestamp.type,
160+
Targets.type,
161+
]:
152162
path = os.path.join(self.repo_dir, "metadata", metadata + ".json")
153163
with open(path, "rb") as f:
154164
metadata_bytes = f.read()
@@ -710,7 +720,9 @@ def test_targetfile_from_file(self) -> None:
710720

711721
def test_targetfile_from_data(self) -> None:
712722
data = b"Inline test content"
713-
target_file_path = os.path.join(self.repo_dir, Targets.type, "file1.txt")
723+
target_file_path = os.path.join(
724+
self.repo_dir, Targets.type, "file1.txt"
725+
)
714726

715727
# Test with a valid hash algorithm
716728
targetfile_from_data = TargetFile.from_data(

tests/test_trusted_metadata_set.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,9 @@ def snapshot_expired_modifier(snapshot: Snapshot) -> None:
364364
snapshot.expires = datetime(1970, 1, 1)
365365

366366
# expired intermediate snapshot is loaded but will raise
367-
snapshot = self.modify_metadata(Snapshot.type, snapshot_expired_modifier)
367+
snapshot = self.modify_metadata(
368+
Snapshot.type, snapshot_expired_modifier
369+
)
368370
with self.assertRaises(exceptions.ExpiredMetadataError):
369371
self.trusted_set.update_snapshot(snapshot)
370372

@@ -399,7 +401,9 @@ def no_meta_modifier(snapshot: Snapshot) -> None:
399401
snapshot.meta = {}
400402

401403
snapshot = self.modify_metadata(Snapshot.type, no_meta_modifier)
402-
self._update_all_besides_targets(self.metadata[Timestamp.type], snapshot)
404+
self._update_all_besides_targets(
405+
self.metadata[Timestamp.type], snapshot
406+
)
403407
# remove meta information with information about targets from snapshot
404408
with self.assertRaises(exceptions.RepositoryError):
405409
self.trusted_set.update_targets(self.metadata[Targets.type])
@@ -410,7 +414,9 @@ def meta_length_modifier(snapshot: Snapshot) -> None:
410414
snapshot.meta[metafile_path] = MetaFile(version=1, length=1)
411415

412416
snapshot = self.modify_metadata(Snapshot.type, meta_length_modifier)
413-
self._update_all_besides_targets(self.metadata[Timestamp.type], snapshot)
417+
self._update_all_besides_targets(
418+
self.metadata[Timestamp.type], snapshot
419+
)
414420
# observed_hash != stored hash in snapshot meta for targets
415421
with self.assertRaises(exceptions.RepositoryError):
416422
self.trusted_set.update_targets(self.metadata[Targets.type])
@@ -421,7 +427,9 @@ def meta_modifier(snapshot: Snapshot) -> None:
421427
snapshot.meta[metafile_path] = MetaFile(version=2)
422428

423429
snapshot = self.modify_metadata(Snapshot.type, meta_modifier)
424-
self._update_all_besides_targets(self.metadata[Timestamp.type], snapshot)
430+
self._update_all_besides_targets(
431+
self.metadata[Timestamp.type], snapshot
432+
)
425433
# new_delegate.signed.version != meta.version stored in snapshot
426434
with self.assertRaises(exceptions.BadVersionNumberError):
427435
self.trusted_set.update_targets(self.metadata[Targets.type])

tests/test_updater_consistent_snapshot.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def test_download_targets(self, test_case_data: Dict[str, Any]):
212212

213213
with patch.object(
214214
sim, "_fetch_target", wraps=sim._fetch_target
215-
) as wrapped_fetch_target:
215+
) as wrapped_fetch_target:
216216

217217
for targetpath in targetpaths:
218218
info = updater.get_targetinfo(targetpath)

tests/test_updater_ng.py

+32-7
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,14 @@
1919

2020
from tests import utils
2121
from tuf import exceptions, ngclient, unittest_toolbox
22-
from tuf.api.metadata import Metadata, Root, Snapshot, TargetFile, Targets, Timestamp
22+
from tuf.api.metadata import (
23+
Metadata,
24+
Root,
25+
Snapshot,
26+
TargetFile,
27+
Targets,
28+
Timestamp,
29+
)
2330

2431
logger = logging.getLogger(__name__)
2532

@@ -112,7 +119,7 @@ def setUp(self) -> None:
112119
+ utils.TEST_HOST_ADDRESS
113120
+ ":"
114121
+ str(self.server_process_handler.port)
115-
+ repository_basepath.replace("\\","/")
122+
+ repository_basepath.replace("\\", "/")
116123
)
117124

118125
self.metadata_url = f"{url_prefix}/metadata/"
@@ -180,17 +187,27 @@ def test_refresh_and_download(self) -> None:
180187

181188
# top-level metadata is in local directory already
182189
self.updater.refresh()
183-
self._assert_files([Root.type, Snapshot.type, Targets.type, Timestamp.type])
190+
self._assert_files(
191+
[Root.type, Snapshot.type, Targets.type, Timestamp.type]
192+
)
184193

185194
# Get targetinfos, assert that cache does not contain files
186195
info1 = self.updater.get_targetinfo("file1.txt")
187196
assert isinstance(info1, TargetFile)
188-
self._assert_files([Root.type, Snapshot.type, Targets.type, Timestamp.type])
197+
self._assert_files(
198+
[Root.type, Snapshot.type, Targets.type, Timestamp.type]
199+
)
189200

190201
# Get targetinfo for 'file3.txt' listed in the delegated role1
191202
info3 = self.updater.get_targetinfo("file3.txt")
192203
assert isinstance(info3, TargetFile)
193-
expected_files = ["role1", Root.type, Snapshot.type, Targets.type, Timestamp.type]
204+
expected_files = [
205+
"role1",
206+
Root.type,
207+
Snapshot.type,
208+
Targets.type,
209+
Timestamp.type,
210+
]
194211
self._assert_files(expected_files)
195212
self.assertIsNone(self.updater.find_cached_target(info1))
196213
self.assertIsNone(self.updater.find_cached_target(info3))
@@ -217,11 +234,19 @@ def test_refresh_with_only_local_root(self) -> None:
217234
self._assert_files([Root.type])
218235

219236
self.updater.refresh()
220-
self._assert_files([Root.type, Snapshot.type, Targets.type, Timestamp.type])
237+
self._assert_files(
238+
[Root.type, Snapshot.type, Targets.type, Timestamp.type]
239+
)
221240

222241
# Get targetinfo for 'file3.txt' listed in the delegated role1
223242
self.updater.get_targetinfo("file3.txt")
224-
expected_files = ["role1", Root.type, Snapshot.type, Targets.type, Timestamp.type]
243+
expected_files = [
244+
"role1",
245+
Root.type,
246+
Snapshot.type,
247+
Targets.type,
248+
Timestamp.type,
249+
]
225250
self._assert_files(expected_files)
226251

227252
def test_implicit_refresh_with_only_local_root(self) -> None:

tests/test_updater_top_level_update.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@
1414

1515
from tests import utils
1616
from tests.repository_simulator import RepositorySimulator
17-
from tuf.api.metadata import TOP_LEVEL_ROLE_NAMES, Metadata, Root, Snapshot, Targets, Timestamp
17+
from tuf.api.metadata import (
18+
TOP_LEVEL_ROLE_NAMES,
19+
Metadata,
20+
Root,
21+
Snapshot,
22+
Targets,
23+
Timestamp,
24+
)
1825
from tuf.exceptions import (
1926
BadVersionNumberError,
2027
ExpiredMetadataError,

0 commit comments

Comments
 (0)