test: parser exceptions
This commit is contained in:
parent
431e540d5d
commit
650fc9dc46
7 changed files with 42 additions and 14 deletions
|
@ -1,7 +1,8 @@
|
|||
exclude: |
|
||||
(?x)^(
|
||||
README.md|
|
||||
LICENSE
|
||||
LICENSE|
|
||||
tests/in/invalid.yaml
|
||||
)
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
|
|
0
tests/in/000000.yaml
Normal file
0
tests/in/000000.yaml
Normal file
3
tests/in/invalid.yaml
Normal file
3
tests/in/invalid.yaml
Normal file
|
@ -0,0 +1,3 @@
|
|||
what-is-this:
|
||||
"an invalid yaml"
|
||||
"test purpose"
|
3
tests/in/no-services.yaml
Normal file
3
tests/in/no-services.yaml
Normal file
|
@ -0,0 +1,3 @@
|
|||
what-is-this:
|
||||
- "a yaml file without services"
|
||||
- "test purpose"
|
|
@ -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")
|
||||
)
|
||||
|
|
18
tests/test_parser.py
Normal file
18
tests/test_parser.py
Normal file
|
@ -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")
|
16
tests/test_service.py
Normal file
16
tests/test_service.py
Normal file
|
@ -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")
|
||||
)
|
Loading…
Reference in a new issue