implement env manager (#6)

* add EnvManager class

* holds all functions that are env file related

* integrates runner dependency resolution

* add integration and unit tests for EnvManager

Reviewed-on: local-it-infrastructure/e2e_tests#6
Co-authored-by: Daniel <d.brummerloh@gmail.com>
Co-committed-by: Daniel <d.brummerloh@gmail.com>
This commit is contained in:
Daniel 2023-12-04 17:09:01 +01:00 committed by dan
parent d3dc0f942a
commit 3fa10aaa69
18 changed files with 264 additions and 198 deletions

View file

@ -1,70 +0,0 @@
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/
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.HTML, self.STATES, self.ENV_FILES, self.RESULTS], exist_ok=True
)
@property
def OUTPUT_DIR(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 / "records"
@property
def HTML(self):
return self.RECORDS / "html"
@property
def STATES(self):
return self.SESSION / "states"
@property
def ENV_FILES(self):
return self.STATES / "env_files"
@property
def RESULTS(self):
return self.SESSION / "results"
@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)