From 7388b3f8eac6608c6a204a28fcd636ac49a3d24c Mon Sep 17 00:00:00 2001 From: ldericher <40151420+ldericher@users.noreply.github.com> Date: Mon, 25 Oct 2021 13:00:11 +0200 Subject: [PATCH] pytest Instance --- kiwi_scp/instance.py | 9 ++++++--- tests/test_instance.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 tests/test_instance.py diff --git a/kiwi_scp/instance.py b/kiwi_scp/instance.py index 41facbe..12b1052 100644 --- a/kiwi_scp/instance.py +++ b/kiwi_scp/instance.py @@ -1,7 +1,7 @@ import functools import re from pathlib import Path -from typing import Iterable, List, Dict, Any +from typing import List, Dict, Any, Generator import attr import yaml @@ -68,5 +68,8 @@ class Instance: return Config.from_instance(self.directory) @property - def projects(self) -> Iterable[Project]: - return [] + def projects(self) -> Generator[Project, None, None]: + return ( + Project.from_directory(self.directory.joinpath(project.name)) + for project in self.config.projects + ) diff --git a/tests/test_instance.py b/tests/test_instance.py new file mode 100644 index 0000000..60dd462 --- /dev/null +++ b/tests/test_instance.py @@ -0,0 +1,31 @@ +from pathlib import Path + +from kiwi_scp.instance import Instance + + +def test_example(): + i = Instance(Path("example")) + + assert i.config is not None + assert len(list(i.projects)) == 1 + + p = next(i.projects) + + assert p.directory == Path("example/hello-world.project") + + +def test_empty(): + i = Instance() + + assert i.directory == Path(".") + assert i.config is not None + assert len(list(i.projects)) == 0 + + +def test_no_such_dir(): + nonexistent_path = Path("nonexistent") + i = Instance(nonexistent_path) + + assert i.directory == nonexistent_path + assert i.config is not None + assert len(list(i.projects)) == 0