Skip to content

Commit 9e0ec10

Browse files
committed
refactor: rename and refactor resource functions
Renamed `_get_resources_from_paths` to `get_resources_from_path` and refactored the function to use a helper function `_get_res` for better readability and maintainability.
1 parent 490db84 commit 9e0ec10

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

cardano_node_tests/cluster_management/cluster_getter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,14 +440,14 @@ def _update_marked_tests(
440440

441441
def _resolve_resources_availability(self, cget_status: _ClusterGetStatus) -> bool:
442442
"""Resolve availability of required "use" and "lock" resources."""
443-
resources_locked = common._get_resources_from_paths(
443+
resources_locked = common.get_resources_from_path(
444444
paths=cget_status.instance_dir.glob(f"{common.RESOURCE_LOCKED_GLOB}_*")
445445
)
446446

447447
# This test wants to lock some resources, check if these are not in use
448448
res_lockable = []
449449
if cget_status.lock_resources:
450-
resources_used = common._get_resources_from_paths(
450+
resources_used = common.get_resources_from_path(
451451
paths=cget_status.instance_dir.glob(f"{common.RESOURCE_IN_USE_GLOB}_*")
452452
)
453453
unlockable_resources = {*resources_locked, *resources_used}

cardano_node_tests/cluster_management/common.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,18 @@
2424

2525
ADDRS_DATA_DIRNAME = "addrs_data"
2626

27+
RE_RESNAME = re.compile("_@@(.+)@@_")
2728

28-
def _get_resources_from_paths(paths: tp.Iterator[pl.Path]) -> tp.List[str]:
29+
30+
def _get_res(path: pl.Path) -> str:
31+
out = RE_RESNAME.search(str(path))
32+
if out is None:
33+
err = f"Resource name not found in path: {path}"
34+
raise ValueError(err)
35+
return out.group(1)
36+
37+
38+
def get_resources_from_path(paths: tp.Iterator[pl.Path]) -> tp.List[str]:
2939
"""Get resources names from status files path."""
30-
resources = [re.search("_@@(.+)@@_", str(r)).group(1) for r in paths] # type: ignore
40+
resources = [_get_res(p) for p in paths]
3141
return resources

cardano_node_tests/cluster_management/manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def _get_resources_by_glob(
296296
msg = "`from_set` cannot be a string"
297297
raise AssertionError(msg)
298298

299-
resources_locked = set(common._get_resources_from_paths(paths=self.instance_dir.glob(glob)))
299+
resources_locked = set(common.get_resources_from_path(paths=self.instance_dir.glob(glob)))
300300

301301
if from_set is not None:
302302
return list(resources_locked.intersection(from_set))

0 commit comments

Comments
 (0)