refactoring

This commit is contained in:
Daniel 2023-11-21 22:09:39 +01:00
parent fa4c840374
commit 1faaf4700a

View file

@ -7,31 +7,30 @@ from tests_wordpress.runner_wordpress import RunnerWordpress
class TestRunner(Protocol): class TestRunner(Protocol):
def __init__(self, dotenv_path: Path):
...
def run_tests(): def run_tests():
pass ...
RUNNER_DICT: dict[str, type[TestRunner]] = {"wordpress": RunnerWordpress} RUNNER_DICT: dict[str, type[TestRunner]] = {"wordpress": RunnerWordpress}
class TestWrapper: class Wrapper:
def __init__(self, dotenv_path: Path): def __init__(self, dotenv_path: Path):
self.dotenv_path = dotenv_path assert dotenv_path.is_file()
self.config = self.load_config_from_dotenv(dotenv_path) config = dotenv_values(dotenv_path)
runner = self.load_runner() runner = self.load_runner(config, dotenv_path)
runner.run_tests() runner.run_tests()
def load_config_from_dotenv(self, dotenv_path: Path): def load_runner(self, config, dotenv_path):
assert dotenv_path.is_file() config_type = config["TYPE"]
return dotenv_values(self.dotenv_path)
def load_runner(self):
config_type = self.config["TYPE"]
ic(config_type) ic(config_type)
RunnerClass = RUNNER_DICT[config_type] RunnerClass = RUNNER_DICT[config_type]
return RunnerClass(self.dotenv_path) return RunnerClass(dotenv_path)
if __name__ == "__main__": if __name__ == "__main__":
dotenv_path = Path(__file__).parent / "./blog.dev.local-it.cloud.env" dotenv_path = Path(__file__).parent / "./blog.dev.local-it.cloud.env"
t = TestWrapper(dotenv_path) t = Wrapper(dotenv_path)