Skip to content

Commit f35b237

Browse files
committed
tests: Make tests cope with root history in local cache
Signed-off-by: Jussi Kukkonen <[email protected]>
1 parent 72bb243 commit f35b237

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

tests/test_updater_consistent_snapshot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def teardown_subtest(self) -> None:
6262
if self.dump_dir is not None:
6363
self.sim.write()
6464

65-
utils.cleanup_dir(self.metadata_dir)
65+
utils.cleanup_metadata_dir(self.metadata_dir)
6666

6767
def _init_repo(
6868
self, consistent_snapshot: bool, prefix_targets: bool = True

tests/test_updater_delegation_graphs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def setup_subtest(self) -> None:
9292
self.sim.write()
9393

9494
def teardown_subtest(self) -> None:
95-
utils.cleanup_dir(self.metadata_dir)
95+
utils.cleanup_metadata_dir(self.metadata_dir)
9696

9797
def _init_repo(self, test_case: DelegationsTestCase) -> None:
9898
"""Create a new RepositorySimulator instance and

tests/test_updater_ng.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from __future__ import annotations
77

8+
from collections.abc import Iterable
89
import logging
910
import os
1011
import shutil

tests/utils.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,16 @@ def configure_test_logging(argv: list[str]) -> None:
155155
logging.basicConfig(level=loglevel)
156156

157157

158-
def cleanup_dir(path: str) -> None:
159-
"""Delete all files inside a directory"""
160-
for filepath in [
161-
os.path.join(path, filename) for filename in os.listdir(path)
162-
]:
163-
os.remove(filepath)
158+
def cleanup_metadata_dir(path: str) -> None:
159+
"""Delete the local metadata dir"""
160+
with os.scandir(path) as it:
161+
for entry in it:
162+
if entry.name == "root_history":
163+
cleanup_metadata_dir(entry.path)
164+
elif entry.name.endswith(".json"):
165+
os.remove(entry.path)
166+
else:
167+
raise ValueError(f"Unexpected local metadata file {entry.path}")
164168

165169

166170
class TestServerProcess:

0 commit comments

Comments
 (0)