From b4684998fda46af14dd333b19833ed7989f37706 Mon Sep 17 00:00:00 2001 From: ldericher <40151420+ldericher@users.noreply.github.com> Date: Wed, 3 Nov 2021 17:35:36 +0100 Subject: [PATCH] pytest --- tests/test_instance.py | 12 +++++------- tests/test_project.py | 31 +++++++++++++++++++++++++++++++ tests/test_service.py | 8 ++++---- tests/test_services.py | 14 ++++++++++++++ 4 files changed, 54 insertions(+), 11 deletions(-) create mode 100644 tests/test_project.py create mode 100644 tests/test_services.py diff --git a/tests/test_instance.py b/tests/test_instance.py index 81d8d1b..2f3f627 100644 --- a/tests/test_instance.py +++ b/tests/test_instance.py @@ -10,17 +10,15 @@ class TestDefault: assert i.config is not None assert len(i.config.projects) == 1 - p = i.config.projects[0] + pc = i.config.projects[0] - assert p.name == "hello-world.project" + assert pc.name == "hello-world.project" - ss = i.get_services(p.name) + p = i.get_project("hello-world.project") - assert len(ss.content) == 5 + assert p.directory == Path("example/hello-world.project") - s = ss.content[0] - - assert s.name == "greeter" + assert i.get_project("nonexistent") is None def test_empty(self): i = Instance() diff --git a/tests/test_project.py b/tests/test_project.py new file mode 100644 index 0000000..917c2db --- /dev/null +++ b/tests/test_project.py @@ -0,0 +1,31 @@ +from pathlib import Path + +import pytest + +from kiwi_scp._constants import COMPOSE_FILE_NAME +from kiwi_scp.instance import Project + + +class TestDefault: + def test_example(self): + p = Project(Path("example/hello-world.project")) + + ss = p.get_services() + + assert len(ss.content) == 5 + + s = ss.content[0] + + assert s.name == "greeter" + + ss2 = p.get_services(["nonexistent"]) + + assert len(ss2.content) == 0 + + def test_empty(self): + p = Project(Path("nonexistent")) + + with pytest.raises(FileNotFoundError) as exc_info: + p.get_services() + + assert exc_info.value.filename == f"nonexistent/{COMPOSE_FILE_NAME}" diff --git a/tests/test_service.py b/tests/test_service.py index 42244c8..1eb9e0a 100644 --- a/tests/test_service.py +++ b/tests/test_service.py @@ -9,7 +9,7 @@ class TestDefault: def test_empty(self): s = Service( name="s", - description=CommentedMap(), + content=CommentedMap(), ) assert s.name == "s" @@ -18,7 +18,7 @@ class TestDefault: def test_no_configs(self): s = Service( name="s", - description=CommentedMap({ + content=CommentedMap({ "image": "repo/image:tag", }), ) @@ -29,7 +29,7 @@ class TestDefault: def test_no_configs_in_volumes(self): s = Service( name="s", - description=CommentedMap({ + content=CommentedMap({ "image": "repo/image:tag", "volumes": [ "docker_volume/third/dir:/path/to/third/mountpoint", @@ -45,7 +45,7 @@ class TestDefault: def test_with_configs(self): s = Service( name="s", - description=CommentedMap({ + content=CommentedMap({ "image": "repo/image:tag", "volumes": [ "${CONFDIR}/some/config:/path/to/some/config", diff --git a/tests/test_services.py b/tests/test_services.py new file mode 100644 index 0000000..ff349ef --- /dev/null +++ b/tests/test_services.py @@ -0,0 +1,14 @@ +from ruamel.yaml import CommentedMap + +from kiwi_scp.instance import Service, Services + + +class TestServices: + def test_empty(self): + s = Service( + name="s", + content=CommentedMap(), + ) + ss = Services([s]) + + assert str(ss) == "services:\n s: {}"