Skip to content

Commit a728717

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 d3b877b commit a728717

File tree

5 files changed

+59
-15
lines changed

5 files changed

+59
-15
lines changed

tests/test_api.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from tests import utils
2929
from tuf import exceptions
3030
from tuf.api.metadata import (
31+
TOP_LEVEL_ROLE_NAMES,
3132
DelegatedRole,
3233
Delegations,
3334
Key,
@@ -136,7 +137,7 @@ def test_compact_json(self) -> None:
136137
)
137138

138139
def test_read_write_read_compare(self) -> None:
139-
for metadata in [Root.type, Snapshot.type, Timestamp.type, Targets.type]:
140+
for metadata in TOP_LEVEL_ROLE_NAMES:
140141
path = os.path.join(self.repo_dir, "metadata", metadata + ".json")
141142
md_obj = Metadata.from_file(path)
142143

@@ -148,7 +149,7 @@ def test_read_write_read_compare(self) -> None:
148149
os.remove(path_2)
149150

150151
def test_to_from_bytes(self) -> None:
151-
for metadata in [Root.type, Snapshot.type, Timestamp.type, Targets.type]:
152+
for metadata in TOP_LEVEL_ROLE_NAMES:
152153
path = os.path.join(self.repo_dir, "metadata", metadata + ".json")
153154
with open(path, "rb") as f:
154155
metadata_bytes = f.read()
@@ -710,7 +711,9 @@ def test_targetfile_from_file(self) -> None:
710711

711712
def test_targetfile_from_data(self) -> None:
712713
data = b"Inline test content"
713-
target_file_path = os.path.join(self.repo_dir, Targets.type, "file1.txt")
714+
target_file_path = os.path.join(
715+
self.repo_dir, Targets.type, "file1.txt"
716+
)
714717

715718
# Test with a valid hash algorithm
716719
targetfile_from_data = TargetFile.from_data(

tests/test_trusted_metadata_set.py

Lines changed: 12 additions & 4 deletions
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_key_rotations.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ def test_non_root_rotations(self, md_version: MdVersion) -> None:
275275
with self.assertRaises(expected_error):
276276
self._run_refresh()
277277

278+
278279
if __name__ == "__main__":
279280
if "--dump" in sys.argv:
280281
TestUpdaterKeyRotations.dump_dir = tempfile.mkdtemp()

tests/test_updater_ng.py

Lines changed: 32 additions & 7 deletions
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

Lines changed: 8 additions & 1 deletion
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)