cleanup #18
2 changed files with 29 additions and 1 deletions
|
|
@ -112,6 +112,11 @@ class Coordinator:
|
||||||
|
|
||||||
load_json_to_environ(test_credentials_path)
|
load_json_to_environ(test_credentials_path)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def add_to_sys(path: Path):
|
||||||
|
# this is a function so that it can be monkeypatched
|
||||||
|
sys.path.append(path.as_posix())
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def create_runner_dict(recipes_dir: Path) -> dict[str, type[Runner]]:
|
def create_runner_dict(recipes_dir: Path) -> dict[str, type[Runner]]:
|
||||||
"""Creates a dictionary holding all the RunnerClasses that can be discovered in recipes_dir
|
"""Creates a dictionary holding all the RunnerClasses that can be discovered in recipes_dir
|
||||||
|
|
@ -131,7 +136,7 @@ class Coordinator:
|
||||||
runner_discovery_pattern = re.compile("Runner.+")
|
runner_discovery_pattern = re.compile("Runner.+")
|
||||||
|
|
||||||
# make it possible to import modules from recipes_dir
|
# make it possible to import modules from recipes_dir
|
||||||
sys.path.append(recipes_dir.as_posix())
|
Coordinator.add_to_sys(recipes_dir)
|
||||||
|
|
||||||
for module_path in recipes_dir.rglob("*/runner_*.py"):
|
for module_path in recipes_dir.rglob("*/runner_*.py"):
|
||||||
rel_path = module_path.relative_to(recipes_dir).as_posix().replace("/", ".").replace(".py", "")
|
rel_path = module_path.relative_to(recipes_dir).as_posix().replace("/", ".").replace(".py", "")
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
@ -41,3 +42,25 @@ def test_runner_runner_dict_import(tmp_recipes: Path):
|
||||||
|
|
||||||
RUNNER_DICT = Coordinator.create_runner_dict(tmp_recipes)
|
RUNNER_DICT = Coordinator.create_runner_dict(tmp_recipes)
|
||||||
assert len(RUNNER_DICT.keys()) > 0
|
assert len(RUNNER_DICT.keys()) > 0
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def clear_sys_path():
|
||||||
|
"""clear sys.path before test, restore after"""
|
||||||
|
syspath_copy = sys.path.copy()
|
||||||
|
sys.path.clear()
|
||||||
|
yield
|
||||||
|
sys.path.extend(syspath_copy)
|
||||||
|
|
||||||
|
|
||||||
|
def test_runner_runner_dict_import_failing(tmp_recipes: Path, clear_sys_path, monkeypatch):
|
||||||
|
"""import from recipes dict should work, because create_runner_dict has sys.path.append"""
|
||||||
|
|
||||||
|
monkeypatch.setattr(
|
||||||
|
Coordinator,
|
||||||
|
"add_to_sys",
|
||||||
|
lambda x: x,
|
||||||
|
)
|
||||||
|
|
||||||
|
with pytest.raises(ModuleNotFoundError):
|
||||||
|
Coordinator.create_runner_dict(tmp_recipes)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue