new-features (#5)
* refactoring and rework: runner now has setups / tests / cleanups as lists * add nextcloud runner * add email testing prototype with imap fixture * add dependency resolution (sort env files in input so that test order is correct) Reviewed-on: local-it-infrastructure/e2e_tests#5 Co-authored-by: Daniel <d.brummerloh@gmail.com> Co-committed-by: Daniel <d.brummerloh@gmail.com>
This commit is contained in:
parent
2e33f8f014
commit
d3dc0f942a
32 changed files with 573 additions and 247 deletions
52
src/env_file_helper.py
Normal file
52
src/env_file_helper.py
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
from pathlib import Path
|
||||
from typing import NamedTuple
|
||||
|
||||
from loguru import logger
|
||||
|
||||
|
||||
class EnvFile(NamedTuple):
|
||||
env_path: Path
|
||||
config: dict[str, str]
|
||||
env_type: str
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"EnvFile(type={self.env_type})"
|
||||
|
||||
|
||||
class DependencyRule(NamedTuple):
|
||||
child: str
|
||||
dependency: str
|
||||
|
||||
|
||||
def _is_rule_satisfied(in_list: list, rule: DependencyRule) -> tuple[bool, int]:
|
||||
child_indices = [index for index, element in enumerate(in_list) if element.env_type == rule.child]
|
||||
child_index = min(child_indices)
|
||||
# child_index = in_list.index(rule.child)
|
||||
parent_indices = [index for index, element in enumerate(in_list) if element.env_type == rule.dependency]
|
||||
parent_index = max(parent_indices)
|
||||
# parent_index = in_list.index(rule.dependency)
|
||||
return parent_index < child_index, parent_index
|
||||
|
||||
|
||||
def sort_env_files_by_rule(env_list: list[EnvFile], rules: list[DependencyRule]) -> list:
|
||||
in_list = env_list.copy()
|
||||
|
||||
def swap_item_with_previous(in_list: list[EnvFile], index: int):
|
||||
"""swaps item at index N with item at index N-1"""
|
||||
assert index > 0, "cannot swap with negative index"
|
||||
in_list[index], in_list[index - 1] = in_list[index - 1], in_list[index]
|
||||
|
||||
for _ in range(10_000):
|
||||
rule_satisfied: list[bool] = []
|
||||
for rule in rules:
|
||||
is_rule_satisfied, parent_index = _is_rule_satisfied(in_list, rule)
|
||||
if is_rule_satisfied:
|
||||
rule_satisfied.append(True)
|
||||
else:
|
||||
rule_satisfied.append(False)
|
||||
# parent_index = in_list.index(rule.dependency)
|
||||
swap_item_with_previous(in_list, parent_index)
|
||||
if all(rule_satisfied):
|
||||
return in_list
|
||||
logger.error("could not find order that satisfys all rules")
|
||||
raise ValueError
|
||||
Loading…
Add table
Add a link
Reference in a new issue