1
0
Fork 0
mirror of https://github.com/yavook/kiwi-scp.git synced 2024-11-21 20:33:00 +00:00

pytest Instance

This commit is contained in:
Jörn-Michael Miehe 2021-10-25 13:00:11 +02:00
parent df55aa69d2
commit 7388b3f8ea
2 changed files with 37 additions and 3 deletions

View file

@ -1,7 +1,7 @@
import functools import functools
import re import re
from pathlib import Path from pathlib import Path
from typing import Iterable, List, Dict, Any from typing import List, Dict, Any, Generator
import attr import attr
import yaml import yaml
@ -68,5 +68,8 @@ class Instance:
return Config.from_instance(self.directory) return Config.from_instance(self.directory)
@property @property
def projects(self) -> Iterable[Project]: def projects(self) -> Generator[Project, None, None]:
return [] return (
Project.from_directory(self.directory.joinpath(project.name))
for project in self.config.projects
)

31
tests/test_instance.py Normal file
View file

@ -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