Skip to content

Commit f0bf488

Browse files
committed
Simulator: make _fetch_{metadata,target} public
Make _fetch_metadata and _fetch_taget public by renaming them to fetch_metadata and fetch_target. This will allow the removal of multiple pylint disables because of "accessing private members". Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
1 parent 49c077e commit f0bf488

File tree

3 files changed

+12
-18
lines changed

3 files changed

+12
-18
lines changed

tests/repository_simulator.py

+8-10
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def fetch(self, url: str) -> Iterator[bytes]:
206206
role = ver_and_name
207207
version = None
208208

209-
yield self._fetch_metadata(role, version)
209+
yield self.fetch_metadata(role, version)
210210
elif path.startswith("/targets/"):
211211
# figure out target path and hash prefix
212212
target_path = path[len("/targets/") :]
@@ -218,11 +218,11 @@ def fetch(self, url: str) -> Iterator[bytes]:
218218
prefix, _, filename = prefixed_filename.partition(".")
219219
target_path = f"{dir_parts}{sep}{filename}"
220220

221-
yield self._fetch_target(target_path, prefix)
221+
yield self.fetch_target(target_path, prefix)
222222
else:
223223
raise FetcherHTTPError(f"Unknown path '{path}'", 404)
224224

225-
def _fetch_target(
225+
def fetch_target(
226226
self, target_path: str, target_hash: Optional[str]
227227
) -> bytes:
228228
"""Return data for 'target_path', checking 'target_hash' if it is given.
@@ -241,9 +241,7 @@ def _fetch_target(
241241
logger.debug("fetched target %s", target_path)
242242
return repo_target.data
243243

244-
def _fetch_metadata(
245-
self, role: str, version: Optional[int] = None
246-
) -> bytes:
244+
def fetch_metadata(self, role: str, version: Optional[int] = None) -> bytes:
247245
"""Return signed metadata for 'role', using 'version' if it is given.
248246
249247
If version is None, non-versioned metadata is being requested.
@@ -284,7 +282,7 @@ def _fetch_metadata(
284282
def _compute_hashes_and_length(
285283
self, role: str
286284
) -> Tuple[Dict[str, str], int]:
287-
data = self._fetch_metadata(role)
285+
data = self.fetch_metadata(role)
288286
digest_object = sslib_hash.digest(sslib_hash.DEFAULT_HASH_ALGORITHM)
289287
digest_object.update(data)
290288
hashes = {sslib_hash.DEFAULT_HASH_ALGORITHM: digest_object.hexdigest()}
@@ -375,12 +373,12 @@ def write(self) -> None:
375373

376374
for ver in range(1, len(self.signed_roots) + 1):
377375
with open(os.path.join(dest_dir, f"{ver}.root.json"), "wb") as f:
378-
f.write(self._fetch_metadata(Root.type, ver))
376+
f.write(self.fetch_metadata(Root.type, ver))
379377

380378
for role in [Timestamp.type, Snapshot.type, Targets.type]:
381379
with open(os.path.join(dest_dir, f"{role}.json"), "wb") as f:
382-
f.write(self._fetch_metadata(role))
380+
f.write(self.fetch_metadata(role))
383381

384382
for role in self.md_delegates:
385383
with open(os.path.join(dest_dir, f"{role}.json"), "wb") as f:
386-
f.write(self._fetch_metadata(role))
384+
f.write(self.fetch_metadata(role))

tests/test_updater_consistent_snapshot.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,8 @@ def test_top_level_roles_update(
121121
sim = self._init_repo(consistent_snapshot)
122122
updater = self._init_updater(sim)
123123

124-
# pylint: disable=protected-access
125124
with patch.object(
126-
sim, "_fetch_metadata", wraps=sim._fetch_metadata
125+
sim, "fetch_metadata", wraps=sim.fetch_metadata
127126
) as wrapped_fetch:
128127
updater.refresh()
129128

@@ -166,9 +165,8 @@ def test_delegated_roles_update(
166165
updater = self._init_updater(sim)
167166
updater.refresh()
168167

169-
# pylint: disable=protected-access
170168
with patch.object(
171-
sim, "_fetch_metadata", wraps=sim._fetch_metadata
169+
sim, "fetch_metadata", wraps=sim.fetch_metadata
172170
) as wrapped_fetch:
173171
# trigger updater to fetch the delegated metadata
174172
updater.get_targetinfo("anything")
@@ -218,9 +216,8 @@ def test_download_targets(self, test_case_data: Dict[str, Any]) -> None:
218216
updater.config.prefix_targets_with_hash = prefix_targets_with_hash
219217
updater.refresh()
220218

221-
# pylint: disable=protected-access
222219
with patch.object(
223-
sim, "_fetch_target", wraps=sim._fetch_target
220+
sim, "fetch_target", wraps=sim.fetch_target
224221
) as wrapped_fetch_target:
225222

226223
for targetpath in targetpaths:

tests/test_updater_top_level_update.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ def _assert_content_equals(
9090
self, role: str, version: Optional[int] = None
9191
) -> None:
9292
"""Assert that local file content is the expected"""
93-
# pylint: disable=protected-access
94-
expected_content = self.sim._fetch_metadata(role, version)
93+
expected_content = self.sim.fetch_metadata(role, version)
9594
with open(os.path.join(self.metadata_dir, f"{role}.json"), "rb") as f:
9695
self.assertEqual(f.read(), expected_content)
9796

0 commit comments

Comments
 (0)