diff --git a/compose_viz/extends.py b/compose_viz/extends.py new file mode 100644 index 0000000..0ec2903 --- /dev/null +++ b/compose_viz/extends.py @@ -0,0 +1,12 @@ +class Extends: + def __init__(self, from_file: str, service_name: str): + self._from_file = from_file + self._service_name = service_name + + @property + def from_file(self): + return self._from_file + + @property + def service_name(self): + return self._service_name \ No newline at end of file diff --git a/compose_viz/service.py b/compose_viz/service.py index b61ccff..acf28aa 100644 --- a/compose_viz/service.py +++ b/compose_viz/service.py @@ -1,8 +1,10 @@ from typing import List +from compose_viz.extends import Extends + class Service: - def __init__(self, name: str, image: str, ports: List[str] = [], networks: List[str] = [], volumes: List[str] = [], depends_on: List[str] = [], links: List[str] = [], extends: List[str] = []) -> None: + def __init__(self, name: str, image: str = None, ports: List[str] = [], networks: List[str] = [], volumes: List[str] = [], depends_on: List[str] = [], links: List[str] = [], extends: Extends = None) -> None: self._name = name self._image = image self._ports = ports diff --git a/tests/test_extends.py b/tests/test_extends.py new file mode 100644 index 0000000..3cf9c2f --- /dev/null +++ b/tests/test_extends.py @@ -0,0 +1,6 @@ +import pytest +from compose_viz.service import Service + +def test_parse_file(): + with pytest.raises(ValueError, match=r"Both image and extends are not defined in service 'frontend', aborting."): + Service(name='frontend')