e2e_tests/src/dirmanager.py
2023-11-27 14:21:39 +01:00

65 lines
1.7 KiB
Python

from pathlib import Path
class DirManager:
"""Manages directories for the tests and should be used to create and find
and use the correct directories.
The structures is as follows:
tests dir/
session_dir-1/
progress
records
results
states
session_dir-2/
records
...
"""
def __init__(self, output_dir: Path | str, session_id: str):
# root test dir
if isinstance(output_dir, str):
output_dir = Path(output_dir)
self._output_dir = output_dir.resolve()
self.session_id = session_id
def create_all_dirs(self):
self.create_dirs(self._output_dir, exist_ok=True)
self.create_dirs([self.SESSION, self.RECORDS, self.STATES, self.RESULTS, self.PROGRESS], exist_ok=True)
@property
def OUTPUT(self):
return self._output_dir
@property
def SESSION(self):
return self._output_dir / f"test-{self.session_id}"
@property
def RECORDS(self):
return self.SESSION / Path("records")
@property
def STATES(self):
return self.SESSION / Path("states")
@property
def RESULTS(self):
return self.SESSION / Path("results")
@property
def PROGRESS(self):
return self.SESSION / Path("progress")
@staticmethod
def create_dirs(dirs: Path | list[Path] | dict[str, Path], exist_ok=False):
match dirs:
case Path():
dirs.mkdir(exist_ok=exist_ok)
case list():
for d in dirs:
d.mkdir(exist_ok=exist_ok)
case dict():
for d in dirs.values():
d.mkdir(exist_ok=exist_ok)