From c0605a155fae1a9e792516fa63a874ec9f0b0430 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 4 Dec 2023 13:32:56 +0100 Subject: [PATCH] add second test, cleanup --- tests/test_env_resolution.py | 70 ++++++++++++------------------------ 1 file changed, 22 insertions(+), 48 deletions(-) diff --git a/tests/test_env_resolution.py b/tests/test_env_resolution.py index 6bbb67b..e192de7 100644 --- a/tests/test_env_resolution.py +++ b/tests/test_env_resolution.py @@ -1,61 +1,35 @@ -import sys from pathlib import Path -from icecream import ic - -# sys.path.append(Path(__file__).parent.parent.resolve().__str__()) -# import pytest -# from prototyping.sorting_algo import Rule, is_rule_satisfied, sort_by_rules from src.coordinator import Coordinator from src.env_file_helper import DependencyRule, EnvFile, sort_env_files_by_rule -# @pytest.fixture -# def in_list(): -# return ["a", "b", "c", "d", "e", "f", "g"] + +def test_complex_sorting() -> None: + demo_rules = [ # X depends on Y + DependencyRule("a", "e"), + DependencyRule("b", "e"), + DependencyRule("b", "f"), + DependencyRule("c", "e"), + DependencyRule("d", "e"), + DependencyRule("f", "e"), + ] + + demo_types = ["a", "b", "c", "d", "e", "f", "g"] + env_files = [EnvFile(env_type=t, env_path=Path(), config=dict()) for t in demo_types] + + sorted_env_files = sort_env_files_by_rule(env_files, demo_rules) + + assert sorted_env_files[0].env_type == "e" -# @pytest.fixture -# def rules() -> list[Rule]: -# return [ # X depends on Y -# Rule("a", "e"), -# Rule("b", "e"), -# Rule("b", "f"), -# Rule("c", "e"), -# Rule("d", "e"), -# Rule("f", "e"), -# ] - - -# def has_rules_satisfied(in_list, rules): -# rule_satisfied: list[bool] = [] -# for rule in rules: -# if is_rule_satisfied(in_list, rule): -# rule_satisfied.append(True) -# else: -# rule_satisfied.append(False) -# return all(rule_satisfied) - - -# def test_stuff(in_list, rules): -# sort_by_rules(in_list, rules) -# assert has_unique_elements(in_list) -# assert has_rules_satisfied(in_list, rules) - - -ENV_FILES = [ - Path("envfiles/blog.test.dev.local-it.cloud.env"), # wordpress - Path("envfiles/login.test.dev.local-it.cloud.env"), # authentik -] - - -def test_real_env_files(): +def test_real_env_files() -> None: """authentik should be first""" + ENV_FILES = [ + Path("envfiles/blog.test.dev.local-it.cloud.env"), # wordpress + Path("envfiles/login.test.dev.local-it.cloud.env"), # authentik + ] env_files: list[EnvFile] = Coordinator._getn_env_files_list(ENV_FILES) dependency_rules: list[DependencyRule] = Coordinator._get_dependency_rules(env_files) - - ic(env_files) sorted_env_files = sort_env_files_by_rule(env_files, dependency_rules) - ic(env_files) - ic(sorted_env_files) assert sorted_env_files[0].env_type == "authentik"