diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2fa471a..29b731d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,8 @@ exclude: | (?x)^( README.md| - LICENSE + LICENSE| + tests/in/invalid.yaml ) repos: - repo: https://github.com/pre-commit/pre-commit-hooks diff --git a/tests/in/000000.yaml b/tests/in/000000.yaml new file mode 100644 index 0000000..e69de29 diff --git a/tests/in/invalid.yaml b/tests/in/invalid.yaml new file mode 100644 index 0000000..8e7a231 --- /dev/null +++ b/tests/in/invalid.yaml @@ -0,0 +1,3 @@ +what-is-this: + "an invalid yaml" + "test purpose" diff --git a/tests/in/no-services.yaml b/tests/in/no-services.yaml new file mode 100644 index 0000000..a0bf4a1 --- /dev/null +++ b/tests/in/no-services.yaml @@ -0,0 +1,3 @@ +what-is-this: + - "a yaml file without services" + - "test purpose" diff --git a/tests/test_extends.py b/tests/test_extends.py index ffbe6f7..8b28cd1 100644 --- a/tests/test_extends.py +++ b/tests/test_extends.py @@ -1,7 +1,6 @@ import pytest from compose_viz.extends import Extends -from compose_viz.service import Service def test_extend_init(): @@ -15,15 +14,3 @@ def test_extend_init(): with pytest.raises(TypeError): Extends(from_file="tests/in/000001.yaml") # type: ignore - - -def test_service_init(): - with pytest.raises(ValueError, match=r"Both image and extends are not defined in service 'frontend', aborting."): - Service(name="frontend") - - with pytest.raises( - ValueError, match=r"Only one of image and extends can be defined in service 'frontend', aborting." - ): - Service( - name="frontend", image="image", extends=Extends(service_name="frontend", from_file="tests/in/000001.yaml") - ) diff --git a/tests/test_parser.py b/tests/test_parser.py new file mode 100644 index 0000000..e28a9f9 --- /dev/null +++ b/tests/test_parser.py @@ -0,0 +1,18 @@ +import pytest + +from compose_viz.parser import Parser + + +def test_parser_error_parsing_file(): + with pytest.raises(RuntimeError, match=r"Error parsing file 'tests/in/invalid.yaml'.*"): + Parser().parse("tests/in/invalid.yaml") + + +def test_parser_invalid_yaml(): + with pytest.raises(RuntimeError, match=r"Empty yaml file, aborting."): + Parser().parse("tests/in/000000.yaml") + + +def test_parser_no_services_found(): + with pytest.raises(RuntimeError, match=r"No services found, aborting."): + Parser().parse("tests/in/no-services.yaml") diff --git a/tests/test_service.py b/tests/test_service.py new file mode 100644 index 0000000..4006e2d --- /dev/null +++ b/tests/test_service.py @@ -0,0 +1,16 @@ +import pytest + +from compose_viz.extends import Extends +from compose_viz.service import Service + + +def test_service_init(): + with pytest.raises(ValueError, match=r"Both image and extends are not defined in service 'frontend', aborting."): + Service(name="frontend") + + with pytest.raises( + ValueError, match=r"Only one of image and extends can be defined in service 'frontend', aborting." + ): + Service( + name="frontend", image="image", extends=Extends(service_name="frontend", from_file="tests/in/000001.yaml") + )