Skip to content

Commit 002c828

Browse files
author
lukpueh
authored
Merge pull request #1710 from MVrachev/start-linting
Start linting the test
2 parents d3b877b + 28602e4 commit 002c828

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+178
-102
lines changed

docs/CONTRIBUTORS.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ Individual tests can also be executed. Optional '-v' flags can be added to
139139
increase log level up to DEBUG ('-vvvv').
140140
::
141141

142-
$ python3 test_updater.py # run a specific test file
143-
$ python3 test_updater.py TestUpdater.test_4_refresh # run a specific test
144-
$ python3 test_updater.py -vvvv TestUpdater.test_4_refresh # run test with DEBUG log level
142+
$ python3 test_updater_ng.py # run a specific test file
143+
$ python3 test_updater_ng.py TestUpdater.test_refresh_and_download # run a specific test
144+
$ python3 test_updater_ng.py -vvvv TestUpdater.test_refresh_and_download # run test with DEBUG log level
145145

146146

147147
All of the log levels and the corresponding options that could be used for testing are:

pyproject.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@ build-backend = "setuptools.build_meta"
77
# Read more here: https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html#configuration-via-a-file
88
[tool.black]
99
line-length=80
10+
# TODO: remove "excludes" after deleting old test files
11+
exclude="tests/.*old.py"
1012

1113
# Isort section
1214
# Read more here: https://pycqa.github.io/isort/docs/configuration/config_files.html
1315
[tool.isort]
1416
profile="black"
1517
line_length=80
1618
known_first_party = ["tuf"]
19+
# TODO: remove "skip_glob" after deleting old test files
20+
skip_glob="*old.py"
1721

1822
# Pylint section
1923

@@ -55,6 +59,8 @@ module-rgx="^(_?[a-z][a-z0-9_]*|__init__)$"
5559
no-docstring-rgx="(__.*__|main|test.*|.*test|.*Test)$"
5660
variable-rgx="^[a-z][a-z0-9_]*$"
5761
docstring-min-length=10
62+
# TODO: remove "ignore-patterns" after deleting old test files
63+
ignore-patterns=".*_old.py"
5864

5965
[tool.pylint.logging]
6066
logging-format-style="old"
@@ -76,6 +82,9 @@ strict_equality = "True"
7682
disallow_untyped_defs = "True"
7783
disallow_untyped_calls = "True"
7884
show_error_codes = "True"
85+
disable_error_code = ["attr-defined"]
86+
# TODO: remove "exclude" after deleting old test files
87+
exclude=".*_old.py"
7988

8089
[[tool.mypy.overrides]]
8190
module = [

requirements-test.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ pylint
1414
mypy
1515
bandit
1616
types-requests
17+
types-python-dateutil

tests/repository_data/generate_project_data.py renamed to tests/repository_data/generate_project_data_old.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
See LICENSE-MIT.txt OR LICENSE-APACHE.txt for licensing information.
1818
1919
<Purpose>
20-
Generate a pre-fabricated set of metadata files for 'test_developer_tool.py'
21-
test cases.
20+
Generate a pre-fabricated set of metadata files for
21+
'test_developer_tool_old.py' test cases.
2222
"""
2323

2424
import shutil

tests/repository_simulator.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def fetch(self, url: str) -> Iterator[bytes]:
216216
role = ver_and_name
217217
version = None
218218

219-
yield self._fetch_metadata(role, version)
219+
yield self.fetch_metadata(role, version)
220220
elif path.startswith("/targets/"):
221221
# figure out target path and hash prefix
222222
target_path = path[len("/targets/") :]
@@ -228,11 +228,11 @@ def fetch(self, url: str) -> Iterator[bytes]:
228228
prefix, _, filename = prefixed_filename.partition(".")
229229
target_path = f"{dir_parts}{sep}{filename}"
230230

231-
yield self._fetch_target(target_path, prefix)
231+
yield self.fetch_target(target_path, prefix)
232232
else:
233233
raise FetcherHTTPError(f"Unknown path '{path}'", 404)
234234

235-
def _fetch_target(
235+
def fetch_target(
236236
self, target_path: str, target_hash: Optional[str]
237237
) -> bytes:
238238
"""Return data for 'target_path', checking 'target_hash' if it is given.
@@ -253,9 +253,7 @@ def _fetch_target(
253253
logger.debug("fetched target %s", target_path)
254254
return repo_target.data
255255

256-
def _fetch_metadata(
257-
self, role: str, version: Optional[int] = None
258-
) -> bytes:
256+
def fetch_metadata(self, role: str, version: Optional[int] = None) -> bytes:
259257
"""Return signed metadata for 'role', using 'version' if it is given.
260258
261259
If version is None, non-versioned metadata is being requested.
@@ -298,7 +296,7 @@ def _fetch_metadata(
298296
def _compute_hashes_and_length(
299297
self, role: str
300298
) -> Tuple[Dict[str, str], int]:
301-
data = self._fetch_metadata(role)
299+
data = self.fetch_metadata(role)
302300
digest_object = sslib_hash.digest(sslib_hash.DEFAULT_HASH_ALGORITHM)
303301
digest_object.update(data)
304302
hashes = {sslib_hash.DEFAULT_HASH_ALGORITHM: digest_object.hexdigest()}
@@ -392,12 +390,12 @@ def write(self) -> None:
392390

393391
for ver in range(1, len(self.signed_roots) + 1):
394392
with open(os.path.join(dest_dir, f"{ver}.root.json"), "wb") as f:
395-
f.write(self._fetch_metadata(Root.type, ver))
393+
f.write(self.fetch_metadata(Root.type, ver))
396394

397395
for role in [Timestamp.type, Snapshot.type, Targets.type]:
398396
with open(os.path.join(dest_dir, f"{role}.json"), "wb") as f:
399-
f.write(self._fetch_metadata(role))
397+
f.write(self.fetch_metadata(role))
400398

401399
for role in self.md_delegates:
402400
with open(os.path.join(dest_dir, f"{role}.json"), "wb") as f:
403-
f.write(self._fetch_metadata(role))
401+
f.write(self.fetch_metadata(role))
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
"""
77
<Program>
8-
simple_https_server.py
8+
simple_https_server_old.py
99
1010
<Author>
1111
Vladimir Diaz.
@@ -53,7 +53,7 @@
5353
print(port_message)
5454

5555
if len(sys.argv) > 1 and certfile != sys.argv[1]:
56-
print('simple_https_server: cert file was not found: ' + sys.argv[1] +
56+
print('simple_https_server_old: cert file was not found: ' + sys.argv[1] +
5757
'; using default: ' + certfile + " certfile")
5858

5959
httpd.serve_forever()
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
"""
77
<Program Name>
8-
slow_retrieval_server.py
8+
slow_retrieval_server_old.py
99
1010
<Author>
1111
Konstantin Andrianov.
@@ -18,7 +18,7 @@
1818
1919
<Purpose>
2020
Server that throttles data by sending one byte at a time (specified time
21-
interval 'DELAY'). The server is used in 'test_slow_retrieval_attack.py'.
21+
interval 'DELAY'). The server is used in 'test_slow_retrieval_attack_old.py'.
2222
"""
2323

2424
import os

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(

0 commit comments

Comments
 (0)