From 1ec80883f0f827eaa74cc5d81a822e74fe253601 Mon Sep 17 00:00:00 2001 From: Xyphuz Date: Wed, 18 May 2022 23:28:18 +0800 Subject: [PATCH] chore: apply pre-commit hooks --- .github/workflows/cd.yml | 4 +- .github/workflows/ci.yml | 8 +- .github/workflows/release-tagged-version.yml | 10 +- .gitignore | 2 +- compose_viz/__main__.py | 1 - compose_viz/cli.py | 8 +- compose_viz/compose.py | 1 + compose_viz/extends.py | 7 +- compose_viz/graph.py | 52 +- compose_viz/parser.py | 44 +- compose_viz/service.py | 14 +- tests/in/000001.yaml | 2 +- tests/in/000010.yaml | 2 +- tests/in/000011.yaml | 2 +- tests/in/000100.yaml | 2 +- tests/in/000101.yaml | 2 +- tests/in/000110.yaml | 2 +- tests/in/000111.yaml | 2 +- tests/in/001000.yaml | 2 +- tests/in/001001.yaml | 2 +- tests/in/001010.yaml | 2 +- tests/in/001011.yaml | 2 +- tests/in/001100.yaml | 2 +- tests/in/001101.yaml | 2 +- tests/in/001110.yaml | 2 +- tests/in/001111.yaml | 2 +- tests/in/010000.yaml | 2 +- tests/in/010001.yaml | 2 +- tests/in/010010.yaml | 2 +- tests/in/010011.yaml | 2 +- tests/in/010100.yaml | 2 +- tests/in/010101.yaml | 2 +- tests/in/010110.yaml | 2 +- tests/in/010111.yaml | 2 +- tests/in/011000.yaml | 2 +- tests/in/011001.yaml | 4 +- tests/in/011010.yaml | 4 +- tests/in/011011.yaml | 4 +- tests/in/011100.yaml | 2 +- tests/in/011101.yaml | 2 +- tests/in/011110.yaml | 4 +- tests/in/011111.yaml | 4 +- tests/in/100000.yaml | 2 +- tests/in/100001.yaml | 4 +- tests/in/100010.yaml | 2 +- tests/in/100011.yaml | 4 +- tests/in/100100.yaml | 2 +- tests/in/100101.yaml | 4 +- tests/in/100110.yaml | 2 +- tests/in/100111.yaml | 4 +- tests/in/101000.yaml | 2 +- tests/in/101001.yaml | 4 +- tests/in/101010.yaml | 2 +- tests/in/101011.yaml | 4 +- tests/in/101100.yaml | 2 +- tests/in/101101.yaml | 4 +- tests/in/101110.yaml | 2 +- tests/in/101111.yaml | 4 +- tests/in/110000.yaml | 2 +- tests/in/110001.yaml | 4 +- tests/in/110010.yaml | 4 +- tests/in/110011.yaml | 4 +- tests/in/110100.yaml | 4 +- tests/in/110101.yaml | 4 +- tests/in/110110.yaml | 4 +- tests/in/110111.yaml | 4 +- tests/in/111000.yaml | 2 +- tests/in/111001.yaml | 4 +- tests/in/111010.yaml | 4 +- tests/in/111011.yaml | 4 +- tests/in/111100.yaml | 4 +- tests/in/111101.yaml | 4 +- tests/in/111110.yaml | 4 +- tests/in/111111.yaml | 4 +- tests/in/docker-compose.yaml | 2 +- tests/test_cli.py | 138 +- tests/test_extends.py | 29 +- tests/test_parse_file.py | 2756 ++++++++++-------- tests/test_version.py | 2 +- 79 files changed, 1807 insertions(+), 1451 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 4377be7..d8ac70b 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -10,9 +10,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - + - name: Build and Publish to PyPi uses: JRubics/poetry-publish@v1.10 with: pypi_token: ${{ secrets.PYPI_TOKEN }} - extra_build_dependency_packages: "graphviz" \ No newline at end of file + extra_build_dependency_packages: "graphviz" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c7f38c1..411ceeb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,19 +12,19 @@ jobs: steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v3 - + - name: Switch to Current Branch run: git checkout ${{ env.BRANCH }} - run: | sudo apt-get update sudo apt-get install -y graphviz - + - name: Setup Python 3.10.4 uses: actions/setup-python@v3 with: python-version: '3.10.4' - + - name: Validate Test Files run: | docker-compose -f tests/in/000001.yaml config -q @@ -90,7 +90,7 @@ jobs: docker-compose -f tests/in/111101.yaml config -q docker-compose -f tests/in/111110.yaml config -q docker-compose -f tests/in/111111.yaml config -q - + - name: Setup Poetry uses: Gr1N/setup-poetry@v7 with: diff --git a/.github/workflows/release-tagged-version.yml b/.github/workflows/release-tagged-version.yml index d10f37c..f2ce249 100644 --- a/.github/workflows/release-tagged-version.yml +++ b/.github/workflows/release-tagged-version.yml @@ -18,19 +18,19 @@ jobs: steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v3 - + - name: Switch to Current Branch run: git checkout ${{ env.BRANCH }} - run: | sudo apt-get update sudo apt-get install -y graphviz - + - name: Setup Python 3.10.4 uses: actions/setup-python@v3 with: python-version: '3.10.4' - + - name: Setup Poetry uses: Gr1N/setup-poetry@v7 with: @@ -38,7 +38,7 @@ jobs: - run: | poetry install --no-root poetry build - + - name: "Release Tagged Version" uses: "marvinpinto/action-automatic-releases@latest" with: @@ -46,4 +46,4 @@ jobs: prerelease: false files: | LICENSE - dist/** \ No newline at end of file + dist/** diff --git a/.gitignore b/.gitignore index fa94aa8..5d7a886 100644 --- a/.gitignore +++ b/.gitignore @@ -158,4 +158,4 @@ cython_debug/ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. -#.idea/ \ No newline at end of file +#.idea/ diff --git a/compose_viz/__main__.py b/compose_viz/__main__.py index 4065f3b..8ade738 100644 --- a/compose_viz/__main__.py +++ b/compose_viz/__main__.py @@ -1,5 +1,4 @@ from compose_viz.cli import start_cli - if __name__ == "__main__": start_cli() diff --git a/compose_viz/cli.py b/compose_viz/cli.py index 8cac6f4..e028d70 100644 --- a/compose_viz/cli.py +++ b/compose_viz/cli.py @@ -1,9 +1,11 @@ from enum import Enum -import typer from typing import Optional + +import typer + from compose_viz import __app_name__, __version__ -from compose_viz.parser import Parser from compose_viz.graph import Graph +from compose_viz.parser import Parser class VisualizationFormats(str, Enum): @@ -47,7 +49,7 @@ def compose_viz( help="Show the version of compose-viz.", callback=_version_callback, is_eager=True, - ) + ), ) -> None: parser = Parser() compose = parser.parse(input_path) diff --git a/compose_viz/compose.py b/compose_viz/compose.py index 4cafca1..0734342 100644 --- a/compose_viz/compose.py +++ b/compose_viz/compose.py @@ -1,4 +1,5 @@ from typing import List + from compose_viz.service import Service diff --git a/compose_viz/extends.py b/compose_viz/extends.py index fb3af9f..9948aa0 100644 --- a/compose_viz/extends.py +++ b/compose_viz/extends.py @@ -1,5 +1,8 @@ +from typing import Optional + + class Extends: - def __init__(self, service_name: str, from_file: str = None): + def __init__(self, service_name: str, from_file: Optional[str] = None): self._service_name = service_name self._from_file = from_file @@ -9,4 +12,4 @@ class Extends: @property def from_file(self): - return self._from_file \ No newline at end of file + return self._from_file diff --git a/compose_viz/graph.py b/compose_viz/graph.py index 9f8a7fa..09761cf 100644 --- a/compose_viz/graph.py +++ b/compose_viz/graph.py @@ -5,17 +5,17 @@ from compose_viz.compose import Compose def apply_vertex_style(type) -> dict: style = { - 'service': { - 'shape': 'component', + "service": { + "shape": "component", }, - 'volume': { - 'shape': 'folder', + "volume": { + "shape": "folder", }, - 'network': { - 'shape': 'pentagon', + "network": { + "shape": "pentagon", }, - 'port': { - 'shape': 'circle', + "port": { + "shape": "circle", }, } @@ -24,18 +24,18 @@ def apply_vertex_style(type) -> dict: def apply_edge_style(type) -> dict: style = { - 'ports': { - 'style': 'solid', + "ports": { + "style": "solid", }, - 'links': { - 'style': 'solid', + "links": { + "style": "solid", }, - 'volumes': { - 'style': 'dashed', + "volumes": { + "style": "dashed", + }, + "depends_on": { + "style": "dotted", }, - 'depends_on': { - 'style': 'dotted', - } } return style[type] @@ -44,7 +44,7 @@ def apply_edge_style(type) -> dict: class Graph: def __init__(self, compose: Compose, filename: str) -> None: self.dot = graphviz.Digraph() - self.dot.attr('graph', background='#ffffff', pad='0.5', ratio='fill') + self.dot.attr("graph", background="#ffffff", pad="0.5", ratio="fill") self.compose = compose self.filename = filename @@ -56,17 +56,17 @@ class Graph: def render(self, format: str, cleanup: bool = True) -> None: for service in self.compose.services: - self.add_vertex(service.name, 'service') + self.add_vertex(service.name, "service") for network in service.networks: - self.add_vertex("net#" + network, 'network') - self.add_edge(service.name, "net#" + network, 'links') + self.add_vertex("net#" + network, "network") + self.add_edge(service.name, "net#" + network, "links") for volume in service.volumes: - self.add_vertex(volume, 'volume') - self.add_edge(service.name, volume, 'links') + self.add_vertex(volume, "volume") + self.add_edge(service.name, volume, "links") for port in service.ports: - self.add_vertex(port, 'port') - self.add_edge(service.name, port, 'ports') + self.add_vertex(port, "port") + self.add_edge(service.name, port, "ports") for depends_on in service.depends_on: - self.dot.edge(depends_on, service.name, 'depends_on') + self.dot.edge(depends_on, service.name, "depends_on") self.dot.render(outfile=self.filename, format=format, cleanup=cleanup) diff --git a/compose_viz/parser.py b/compose_viz/parser.py index 6d345fb..be545e8 100644 --- a/compose_viz/parser.py +++ b/compose_viz/parser.py @@ -1,48 +1,60 @@ -from re import S -from compose_viz.compose import Compose -from compose_viz.compose import Service +from typing import List, Optional + from ruamel.yaml import YAML +from compose_viz.compose import Compose, Service + class Parser: def __init__(self): pass def parse(self, file_path: str) -> Compose: - # validate input file using `docker-compose config -q sys.argv[1]` first # load the yaml file with open(file_path, "r") as f: try: - yaml = YAML(typ='safe', pure=True) + yaml = YAML(typ="safe", pure=True) yaml_data = yaml.load(f) - except YAML.YAMLError as exc: - raise YAML.YAMLError + except Exception as e: + raise Exception(f"Error parsing file {file_path}: {e}") + # validate the yaml file if not yaml_data: print("Error: empty yaml file") raise ValueError + if not yaml_data.get("services"): print("Error: no services found") raise ValueError + # parse services data into Service objects services_data = yaml_data["services"] services = [] + for service, service_name in zip(services_data.values(), services_data.keys()): - #print("name: {}".format(service_name)) + # print("name: {}".format(service_name)) + + service_image: Optional[str] = None if service.get("image"): service_image = service["image"] - #print("image: {}".format(service_image)) + # print("image: {}".format(service_image)) + + service_networks: List[str] = [] if service.get("networks"): - if(type(service["networks"]) is list): + if type(service["networks"]) is list: service_networks = service["networks"] else: service_networks = list(service["networks"].keys()) - #print("networks: {}".format(service_networks)) - services.append(Service( - name=service_name, - image=service_image, - networks=service_networks, - )) + # print("networks: {}".format(service_networks)) + + services.append( + Service( + name=service_name, + image=service_image, + networks=service_networks, + ) + ) + # create Compose object compose = Compose(services) diff --git a/compose_viz/service.py b/compose_viz/service.py index feaaf53..336bab9 100644 --- a/compose_viz/service.py +++ b/compose_viz/service.py @@ -1,10 +1,20 @@ -from typing import List +from typing import List, Optional from compose_viz.extends import Extends class Service: - 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: + def __init__( + self, + name: str, + image: Optional[str] = None, + ports: List[str] = [], + networks: List[str] = [], + volumes: List[str] = [], + depends_on: List[str] = [], + links: List[str] = [], + extends: Optional[Extends] = None, + ) -> None: self._name = name if image is None and extends is None: diff --git a/tests/in/000001.yaml b/tests/in/000001.yaml index 1683eba..b6e30ec 100644 --- a/tests/in/000001.yaml +++ b/tests/in/000001.yaml @@ -23,4 +23,4 @@ services: networks: front-tier: back-tier: - admin: \ No newline at end of file + admin: diff --git a/tests/in/000010.yaml b/tests/in/000010.yaml index 1d1084a..377b994 100644 --- a/tests/in/000010.yaml +++ b/tests/in/000010.yaml @@ -7,4 +7,4 @@ services: service: base cli: extends: - service: common \ No newline at end of file + service: common diff --git a/tests/in/000011.yaml b/tests/in/000011.yaml index 515f31f..d17efbe 100644 --- a/tests/in/000011.yaml +++ b/tests/in/000011.yaml @@ -25,4 +25,4 @@ services: networks: front-tier: back-tier: - admin: \ No newline at end of file + admin: diff --git a/tests/in/000100.yaml b/tests/in/000100.yaml index 34c09b1..c68c007 100644 --- a/tests/in/000100.yaml +++ b/tests/in/000100.yaml @@ -5,4 +5,4 @@ services: ports: - "8000:5000" redis: - image: "redis:alpine" \ No newline at end of file + image: "redis:alpine" diff --git a/tests/in/000101.yaml b/tests/in/000101.yaml index 6d1ce63..6eb5b7f 100644 --- a/tests/in/000101.yaml +++ b/tests/in/000101.yaml @@ -29,4 +29,4 @@ services: networks: front-tier: back-tier: - admin: \ No newline at end of file + admin: diff --git a/tests/in/000110.yaml b/tests/in/000110.yaml index 6eb8f19..d67632a 100644 --- a/tests/in/000110.yaml +++ b/tests/in/000110.yaml @@ -12,4 +12,4 @@ services: extends: service: frontend ports: - - "8000:5001" \ No newline at end of file + - "8000:5001" diff --git a/tests/in/000111.yaml b/tests/in/000111.yaml index 5195a82..c17fb18 100644 --- a/tests/in/000111.yaml +++ b/tests/in/000111.yaml @@ -29,4 +29,4 @@ services: networks: front-tier: back-tier: - admin: \ No newline at end of file + admin: diff --git a/tests/in/001000.yaml b/tests/in/001000.yaml index 51adbed..f64c323 100644 --- a/tests/in/001000.yaml +++ b/tests/in/001000.yaml @@ -7,4 +7,4 @@ services: redis: image: redis db: - image: postgres \ No newline at end of file + image: postgres diff --git a/tests/in/001001.yaml b/tests/in/001001.yaml index 37a10e0..1e176a6 100644 --- a/tests/in/001001.yaml +++ b/tests/in/001001.yaml @@ -26,4 +26,4 @@ services: networks: front-tier: back-tier: - admin: \ No newline at end of file + admin: diff --git a/tests/in/001010.yaml b/tests/in/001010.yaml index b65dbf3..62f96e4 100644 --- a/tests/in/001010.yaml +++ b/tests/in/001010.yaml @@ -8,4 +8,4 @@ services: redis: image: redis db: - image: postgres \ No newline at end of file + image: postgres diff --git a/tests/in/001011.yaml b/tests/in/001011.yaml index bd1b850..f91c6b5 100644 --- a/tests/in/001011.yaml +++ b/tests/in/001011.yaml @@ -27,4 +27,4 @@ services: networks: front-tier: back-tier: - admin: \ No newline at end of file + admin: diff --git a/tests/in/001100.yaml b/tests/in/001100.yaml index e3219c8..ef3d14c 100644 --- a/tests/in/001100.yaml +++ b/tests/in/001100.yaml @@ -14,4 +14,4 @@ services: backend: image: awesome/backend ports: - - "8000:5001" \ No newline at end of file + - "8000:5001" diff --git a/tests/in/001101.yaml b/tests/in/001101.yaml index 417fe7f..04483a2 100644 --- a/tests/in/001101.yaml +++ b/tests/in/001101.yaml @@ -27,4 +27,4 @@ services: networks: front-tier: back-tier: - admin: \ No newline at end of file + admin: diff --git a/tests/in/001110.yaml b/tests/in/001110.yaml index 3b83196..75981f6 100644 --- a/tests/in/001110.yaml +++ b/tests/in/001110.yaml @@ -16,4 +16,4 @@ services: extends: service: frontend ports: - - "8000:5001" \ No newline at end of file + - "8000:5001" diff --git a/tests/in/001111.yaml b/tests/in/001111.yaml index acd9932..e328460 100644 --- a/tests/in/001111.yaml +++ b/tests/in/001111.yaml @@ -28,4 +28,4 @@ services: networks: front-tier: back-tier: - admin: \ No newline at end of file + admin: diff --git a/tests/in/010000.yaml b/tests/in/010000.yaml index b1c39d7..2b61286 100644 --- a/tests/in/010000.yaml +++ b/tests/in/010000.yaml @@ -12,4 +12,4 @@ services: target: /var/run/postgres/postgres.sock volumes: - db-data: \ No newline at end of file + db-data: diff --git a/tests/in/010001.yaml b/tests/in/010001.yaml index 74bd2ea..4361504 100644 --- a/tests/in/010001.yaml +++ b/tests/in/010001.yaml @@ -34,4 +34,4 @@ networks: back-tier: admin: volumes: - db-data: \ No newline at end of file + db-data: diff --git a/tests/in/010010.yaml b/tests/in/010010.yaml index bd14c8f..9294993 100644 --- a/tests/in/010010.yaml +++ b/tests/in/010010.yaml @@ -10,4 +10,4 @@ services: - cli-volume:/var/lib/backup/data:ro volumes: common-volume: - cli-volume: \ No newline at end of file + cli-volume: diff --git a/tests/in/010011.yaml b/tests/in/010011.yaml index 0d36cf2..6337778 100644 --- a/tests/in/010011.yaml +++ b/tests/in/010011.yaml @@ -35,4 +35,4 @@ networks: back-tier: admin: volumes: - db-data: \ No newline at end of file + db-data: diff --git a/tests/in/010100.yaml b/tests/in/010100.yaml index de377ee..a601ccd 100644 --- a/tests/in/010100.yaml +++ b/tests/in/010100.yaml @@ -13,4 +13,4 @@ services: ports: - "8000:5000" volumes: - db-data: \ No newline at end of file + db-data: diff --git a/tests/in/010101.yaml b/tests/in/010101.yaml index 86a28b1..098a6a9 100644 --- a/tests/in/010101.yaml +++ b/tests/in/010101.yaml @@ -36,4 +36,4 @@ networks: back-tier: admin: volumes: - db-data: \ No newline at end of file + db-data: diff --git a/tests/in/010110.yaml b/tests/in/010110.yaml index bfbffd6..2727cf4 100644 --- a/tests/in/010110.yaml +++ b/tests/in/010110.yaml @@ -20,4 +20,4 @@ services: ports: - "8000:5000" volumes: - db-data: \ No newline at end of file + db-data: diff --git a/tests/in/010111.yaml b/tests/in/010111.yaml index 6cb7eb8..19fb865 100644 --- a/tests/in/010111.yaml +++ b/tests/in/010111.yaml @@ -37,4 +37,4 @@ networks: back-tier: admin: volumes: - db-data: \ No newline at end of file + db-data: diff --git a/tests/in/011000.yaml b/tests/in/011000.yaml index 4ef3c19..0e31582 100644 --- a/tests/in/011000.yaml +++ b/tests/in/011000.yaml @@ -19,4 +19,4 @@ services: backend: image: awesome/backend volumes: - db-data: \ No newline at end of file + db-data: diff --git a/tests/in/011001.yaml b/tests/in/011001.yaml index 023ab8c..495facc 100644 --- a/tests/in/011001.yaml +++ b/tests/in/011001.yaml @@ -9,7 +9,7 @@ services: image: awesome/monitoring networks: - admin - + backend: image: awesome/backend @@ -37,4 +37,4 @@ networks: back-tier: admin: volumes: - db-data: \ No newline at end of file + db-data: diff --git a/tests/in/011010.yaml b/tests/in/011010.yaml index 6d09ea6..4578dc1 100644 --- a/tests/in/011010.yaml +++ b/tests/in/011010.yaml @@ -4,7 +4,7 @@ services: monitoring: image: awesome/monitoring - + backend: volumes: @@ -22,4 +22,4 @@ services: service: frontend volumes: - db-data: \ No newline at end of file + db-data: diff --git a/tests/in/011011.yaml b/tests/in/011011.yaml index e98f01a..a263f0b 100644 --- a/tests/in/011011.yaml +++ b/tests/in/011011.yaml @@ -9,7 +9,7 @@ services: image: awesome/monitoring networks: - admin - + backend: networks: @@ -38,4 +38,4 @@ networks: back-tier: admin: volumes: - db-data: \ No newline at end of file + db-data: diff --git a/tests/in/011100.yaml b/tests/in/011100.yaml index dbebc65..2bb322e 100644 --- a/tests/in/011100.yaml +++ b/tests/in/011100.yaml @@ -25,4 +25,4 @@ services: ports: - "8000:5001" volumes: - db-data: \ No newline at end of file + db-data: diff --git a/tests/in/011101.yaml b/tests/in/011101.yaml index 6e24fad..8f366a2 100644 --- a/tests/in/011101.yaml +++ b/tests/in/011101.yaml @@ -9,7 +9,7 @@ services: image: awesome/monitoring networks: - admin - + backend: image: awesome/backend diff --git a/tests/in/011110.yaml b/tests/in/011110.yaml index 928200f..d0553d2 100644 --- a/tests/in/011110.yaml +++ b/tests/in/011110.yaml @@ -6,7 +6,7 @@ services: monitoring: image: awesome/monitoring - + backend: volumes: @@ -26,4 +26,4 @@ services: - "8000:5010" volumes: - db-data: \ No newline at end of file + db-data: diff --git a/tests/in/011111.yaml b/tests/in/011111.yaml index 1b0db20..34389f4 100644 --- a/tests/in/011111.yaml +++ b/tests/in/011111.yaml @@ -9,7 +9,7 @@ services: image: awesome/monitoring networks: - admin - + backend: networks: @@ -40,4 +40,4 @@ networks: back-tier: admin: volumes: - db-data: \ No newline at end of file + db-data: diff --git a/tests/in/100000.yaml b/tests/in/100000.yaml index c214153..7ea23ec 100644 --- a/tests/in/100000.yaml +++ b/tests/in/100000.yaml @@ -6,4 +6,4 @@ services: links: - "db:database" db: - image: postgres \ No newline at end of file + image: postgres diff --git a/tests/in/100001.yaml b/tests/in/100001.yaml index 82a5fa2..2c130d1 100644 --- a/tests/in/100001.yaml +++ b/tests/in/100001.yaml @@ -9,7 +9,7 @@ services: image: awesome/monitoring networks: - admin - + backend: image: awesome/backend @@ -28,4 +28,4 @@ services: networks: front-tier: back-tier: - admin: \ No newline at end of file + admin: diff --git a/tests/in/100010.yaml b/tests/in/100010.yaml index cbe9d92..b7d9de1 100644 --- a/tests/in/100010.yaml +++ b/tests/in/100010.yaml @@ -4,7 +4,7 @@ services: monitoring: image: awesome/monitoring - + backend: extends: diff --git a/tests/in/100011.yaml b/tests/in/100011.yaml index 8f0cd92..7c4be01 100644 --- a/tests/in/100011.yaml +++ b/tests/in/100011.yaml @@ -9,7 +9,7 @@ services: image: awesome/monitoring networks: - admin - + backend: networks: @@ -29,4 +29,4 @@ services: networks: front-tier: back-tier: - admin: \ No newline at end of file + admin: diff --git a/tests/in/100100.yaml b/tests/in/100100.yaml index 4640d65..e3b8a94 100644 --- a/tests/in/100100.yaml +++ b/tests/in/100100.yaml @@ -4,7 +4,7 @@ services: monitoring: image: awesome/monitoring - + backend: image: awesome/backend diff --git a/tests/in/100101.yaml b/tests/in/100101.yaml index bf6cac2..a576314 100644 --- a/tests/in/100101.yaml +++ b/tests/in/100101.yaml @@ -9,7 +9,7 @@ services: image: awesome/monitoring networks: - admin - + backend: image: awesome/backend @@ -30,4 +30,4 @@ services: networks: front-tier: back-tier: - admin: \ No newline at end of file + admin: diff --git a/tests/in/100110.yaml b/tests/in/100110.yaml index cfd53d9..612d73f 100644 --- a/tests/in/100110.yaml +++ b/tests/in/100110.yaml @@ -4,7 +4,7 @@ services: monitoring: image: awesome/monitoring - + backend: extends: diff --git a/tests/in/100111.yaml b/tests/in/100111.yaml index 25df8c8..4e1ca01 100644 --- a/tests/in/100111.yaml +++ b/tests/in/100111.yaml @@ -9,7 +9,7 @@ services: image: awesome/monitoring networks: - admin - + backend: networks: @@ -31,4 +31,4 @@ services: networks: front-tier: back-tier: - admin: \ No newline at end of file + admin: diff --git a/tests/in/101000.yaml b/tests/in/101000.yaml index 72d5f8c..8f52814 100644 --- a/tests/in/101000.yaml +++ b/tests/in/101000.yaml @@ -4,7 +4,7 @@ services: monitoring: image: awesome/monitoring - + backend: image: awesome/backend diff --git a/tests/in/101001.yaml b/tests/in/101001.yaml index a01f7ae..5fbf3d9 100644 --- a/tests/in/101001.yaml +++ b/tests/in/101001.yaml @@ -9,7 +9,7 @@ services: image: awesome/monitoring networks: - admin - + backend: image: awesome/backend @@ -30,4 +30,4 @@ services: networks: front-tier: back-tier: - admin: \ No newline at end of file + admin: diff --git a/tests/in/101010.yaml b/tests/in/101010.yaml index a99477d..1fe5809 100644 --- a/tests/in/101010.yaml +++ b/tests/in/101010.yaml @@ -4,7 +4,7 @@ services: monitoring: image: awesome/monitoring - + backend: depends_on: diff --git a/tests/in/101011.yaml b/tests/in/101011.yaml index 82e7c24..f882bcd 100644 --- a/tests/in/101011.yaml +++ b/tests/in/101011.yaml @@ -9,7 +9,7 @@ services: image: awesome/monitoring networks: - admin - + backend: networks: @@ -31,4 +31,4 @@ services: networks: front-tier: back-tier: - admin: \ No newline at end of file + admin: diff --git a/tests/in/101100.yaml b/tests/in/101100.yaml index b08993e..a7f17fe 100644 --- a/tests/in/101100.yaml +++ b/tests/in/101100.yaml @@ -4,7 +4,7 @@ services: monitoring: image: awesome/monitoring - + backend: image: awesome/backend diff --git a/tests/in/101101.yaml b/tests/in/101101.yaml index 8b521fe..dc00820 100644 --- a/tests/in/101101.yaml +++ b/tests/in/101101.yaml @@ -9,7 +9,7 @@ services: image: awesome/monitoring networks: - admin - + backend: image: awesome/backend @@ -32,4 +32,4 @@ services: networks: front-tier: back-tier: - admin: \ No newline at end of file + admin: diff --git a/tests/in/101110.yaml b/tests/in/101110.yaml index 6468f37..e6cb223 100644 --- a/tests/in/101110.yaml +++ b/tests/in/101110.yaml @@ -5,7 +5,7 @@ services: monitoring: image: awesome/monitoring - + backend: depends_on: diff --git a/tests/in/101111.yaml b/tests/in/101111.yaml index 81bd981..b17b0d4 100644 --- a/tests/in/101111.yaml +++ b/tests/in/101111.yaml @@ -9,7 +9,7 @@ services: image: awesome/monitoring networks: - admin - + backend: networks: @@ -33,4 +33,4 @@ services: networks: front-tier: back-tier: - admin: \ No newline at end of file + admin: diff --git a/tests/in/110000.yaml b/tests/in/110000.yaml index b07f8ff..f79c07a 100644 --- a/tests/in/110000.yaml +++ b/tests/in/110000.yaml @@ -21,4 +21,4 @@ services: db: image: postgres volumes: - db-data: \ No newline at end of file + db-data: diff --git a/tests/in/110001.yaml b/tests/in/110001.yaml index 6475de2..dab8541 100644 --- a/tests/in/110001.yaml +++ b/tests/in/110001.yaml @@ -9,7 +9,7 @@ services: image: awesome/monitoring networks: - admin - + backend: image: awesome/backend @@ -39,4 +39,4 @@ networks: back-tier: admin: volumes: - db-data: \ No newline at end of file + db-data: diff --git a/tests/in/110010.yaml b/tests/in/110010.yaml index 477467a..8dcf22e 100644 --- a/tests/in/110010.yaml +++ b/tests/in/110010.yaml @@ -4,7 +4,7 @@ services: monitoring: image: awesome/monitoring - + backend: volumes: @@ -24,4 +24,4 @@ services: image: postgres volumes: - db-data: \ No newline at end of file + db-data: diff --git a/tests/in/110011.yaml b/tests/in/110011.yaml index 412dba1..2725ee8 100644 --- a/tests/in/110011.yaml +++ b/tests/in/110011.yaml @@ -9,7 +9,7 @@ services: image: awesome/monitoring networks: - admin - + backend: networks: @@ -40,4 +40,4 @@ networks: back-tier: admin: volumes: - db-data: \ No newline at end of file + db-data: diff --git a/tests/in/110100.yaml b/tests/in/110100.yaml index 9ef067c..ac0fc6c 100644 --- a/tests/in/110100.yaml +++ b/tests/in/110100.yaml @@ -4,7 +4,7 @@ services: monitoring: image: awesome/monitoring - + backend: image: awesome/backend @@ -25,4 +25,4 @@ services: image: postgres volumes: - db-data: \ No newline at end of file + db-data: diff --git a/tests/in/110101.yaml b/tests/in/110101.yaml index 2a8000c..48b9d1d 100644 --- a/tests/in/110101.yaml +++ b/tests/in/110101.yaml @@ -9,7 +9,7 @@ services: image: awesome/monitoring networks: - admin - + backend: image: awesome/backend @@ -41,4 +41,4 @@ networks: back-tier: admin: volumes: - db-data: \ No newline at end of file + db-data: diff --git a/tests/in/110110.yaml b/tests/in/110110.yaml index 61b97d3..f9abebe 100644 --- a/tests/in/110110.yaml +++ b/tests/in/110110.yaml @@ -4,7 +4,7 @@ services: monitoring: image: awesome/monitoring - + backend: volumes: @@ -26,4 +26,4 @@ services: image: postgres volumes: - db-data: \ No newline at end of file + db-data: diff --git a/tests/in/110111.yaml b/tests/in/110111.yaml index 8b7017c..76e6a4f 100644 --- a/tests/in/110111.yaml +++ b/tests/in/110111.yaml @@ -9,7 +9,7 @@ services: image: awesome/monitoring networks: - admin - + backend: networks: @@ -42,4 +42,4 @@ networks: back-tier: admin: volumes: - db-data: \ No newline at end of file + db-data: diff --git a/tests/in/111000.yaml b/tests/in/111000.yaml index 24483e4..bdcd442 100644 --- a/tests/in/111000.yaml +++ b/tests/in/111000.yaml @@ -23,4 +23,4 @@ services: db: image: postgres volumes: - db-data: \ No newline at end of file + db-data: diff --git a/tests/in/111001.yaml b/tests/in/111001.yaml index b6acfed..7586730 100644 --- a/tests/in/111001.yaml +++ b/tests/in/111001.yaml @@ -9,7 +9,7 @@ services: image: awesome/monitoring networks: - admin - + backend: image: awesome/backend @@ -41,4 +41,4 @@ networks: back-tier: admin: volumes: - db-data: \ No newline at end of file + db-data: diff --git a/tests/in/111010.yaml b/tests/in/111010.yaml index 8126c95..7591564 100644 --- a/tests/in/111010.yaml +++ b/tests/in/111010.yaml @@ -4,7 +4,7 @@ services: monitoring: image: awesome/monitoring - + backend: volumes: @@ -26,4 +26,4 @@ services: image: postgres volumes: - db-data: \ No newline at end of file + db-data: diff --git a/tests/in/111011.yaml b/tests/in/111011.yaml index 596aa40..3714d62 100644 --- a/tests/in/111011.yaml +++ b/tests/in/111011.yaml @@ -9,7 +9,7 @@ services: image: awesome/monitoring networks: - admin - + backend: networks: @@ -42,4 +42,4 @@ networks: back-tier: admin: volumes: - db-data: \ No newline at end of file + db-data: diff --git a/tests/in/111100.yaml b/tests/in/111100.yaml index 23c650b..9a52b90 100644 --- a/tests/in/111100.yaml +++ b/tests/in/111100.yaml @@ -4,7 +4,7 @@ services: monitoring: image: awesome/monitoring - + backend: image: awesome/backend @@ -27,4 +27,4 @@ services: image: postgres volumes: - db-data: \ No newline at end of file + db-data: diff --git a/tests/in/111101.yaml b/tests/in/111101.yaml index 79ebf03..4d6bead 100644 --- a/tests/in/111101.yaml +++ b/tests/in/111101.yaml @@ -9,7 +9,7 @@ services: image: awesome/monitoring networks: - admin - + backend: image: awesome/backend @@ -43,4 +43,4 @@ networks: back-tier: admin: volumes: - db-data: \ No newline at end of file + db-data: diff --git a/tests/in/111110.yaml b/tests/in/111110.yaml index 41d68d3..540c9de 100644 --- a/tests/in/111110.yaml +++ b/tests/in/111110.yaml @@ -3,7 +3,7 @@ services: image: awesome/webapp monitoring: image: awesome/monitoring - + backend: volumes: @@ -27,4 +27,4 @@ services: image: postgres volumes: - db-data: \ No newline at end of file + db-data: diff --git a/tests/in/111111.yaml b/tests/in/111111.yaml index 25d25a2..2ed41b9 100644 --- a/tests/in/111111.yaml +++ b/tests/in/111111.yaml @@ -9,7 +9,7 @@ services: image: awesome/monitoring networks: - admin - + backend: networks: @@ -44,4 +44,4 @@ networks: back-tier: admin: volumes: - db-data: \ No newline at end of file + db-data: diff --git a/tests/in/docker-compose.yaml b/tests/in/docker-compose.yaml index 3f94ba7..68e98a8 100644 --- a/tests/in/docker-compose.yaml +++ b/tests/in/docker-compose.yaml @@ -9,7 +9,7 @@ services: image: awesome/monitoring networks: - admin - + backend: image: awesome/backend diff --git a/tests/test_cli.py b/tests/test_cli.py index 128fb3b..fea0981 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,77 +1,81 @@ import os + import pytest - from typer.testing import CliRunner -from compose_viz import cli +from compose_viz import cli runner = CliRunner() -@pytest.mark.parametrize("file_number", [ - "000001", - "000010", - "000011", - "000100", - "000101", - "000110", - "000111", - "001000", - "001001", - "001010", - "001011", - "001100", - "001101", - "001110", - "001111", - "010000", - "010001", - "010010", - "010011", - "010100", - "010101", - "010110", - "010111", - "011000", - "011001", - "011010", - "011011", - "011100", - "011101", - "011110", - "011111", - "100000", - "100001", - "100010", - "100011", - "100100", - "100101", - "100110", - "100111", - "101000", - "101001", - "101010", - "101011", - "101100", - "101101", - "101110", - "101111", - "110000", - "110001", - "110010", - "110011", - "110100", - "110101", - "110110", - "110111", - "111000", - "111001", - "111010", - "111011", - "111100", - "111101", - "111110", - "111111", -]) + +@pytest.mark.parametrize( + "file_number", + [ + "000001", + "000010", + "000011", + "000100", + "000101", + "000110", + "000111", + "001000", + "001001", + "001010", + "001011", + "001100", + "001101", + "001110", + "001111", + "010000", + "010001", + "010010", + "010011", + "010100", + "010101", + "010110", + "010111", + "011000", + "011001", + "011010", + "011011", + "011100", + "011101", + "011110", + "011111", + "100000", + "100001", + "100010", + "100011", + "100100", + "100101", + "100110", + "100111", + "101000", + "101001", + "101010", + "101011", + "101100", + "101101", + "101110", + "101111", + "110000", + "110001", + "110010", + "110011", + "110100", + "110101", + "110110", + "110111", + "111000", + "111001", + "111010", + "111011", + "111100", + "111101", + "111110", + "111111", + ], +) def test_cli(file_number: str): input_path = f"tests/in/{file_number}.yaml" output_path = f"{file_number}.png" diff --git a/tests/test_extends.py b/tests/test_extends.py index 4020277..ffbe6f7 100644 --- a/tests/test_extends.py +++ b/tests/test_extends.py @@ -1,22 +1,29 @@ import pytest + from compose_viz.extends import Extends from compose_viz.service import Service - + + def test_extend_init(): try: - Extends(service_name='frontend', from_file='tests/in/000001.yaml') - Extends(service_name='frontend') + Extends(service_name="frontend", from_file="tests/in/000001.yaml") + Extends(service_name="frontend") assert True - except: - assert False + except Exception as e: + assert False, e with pytest.raises(TypeError): - Extends(from_file='tests/in/000001.yaml') - + 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')) + 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_parse_file.py b/tests/test_parse_file.py index 15f2dcc..9272ffa 100644 --- a/tests/test_parse_file.py +++ b/tests/test_parse_file.py @@ -1,1224 +1,1542 @@ -from os import link import pytest -from compose_viz.parser import Parser -from compose_viz.compose import Compose -from compose_viz.service import Service -from compose_viz.extends import Extends -@pytest.mark.parametrize('test_input,expected',[ - ('tests/in/000001.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - networks=['front-tier', 'back-tier'], - ), - Service( - name='monitoring', - image='awesome/monitoring', - networks=['admin'], - ), - Service( - name='backend', - image='awesome/backend', - networks=['back-tier', 'admin'], - ), - ])), - ('tests/in/000010.yaml',Compose([ - Service( - name='base', - image='busybox', - ), - Service( - name='common', - extends=Extends(service_name='frontend'), - ), - Service( - name='cli', - extends=Extends(service_name='common'), - ), - ])), - ('tests/in/000011.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - networks=['front-tier', 'back-tier'], - ), - Service( - name='monitoring', - networks=['admin'], - extends=Extends(service_name='frontend'), - ), - Service( - name='backend', - networks=['back-tier', 'admin'], - extends=Extends(service_name='frontend'), - ), - ])), - ('tests/in/000100.yaml',Compose([ - Service( - name='web', - image='build from .', - ports=['8000:5000'], - ), - Service( - name='redis', - image='redis:alpine', - ), - ])), - ('tests/in/000101.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - ports=['8000:5000'], - networks=['front-tier', 'back-tier'], - ), - Service( - name='monitoring', - image='awesome/monitoring', - ports=['8000:5001'], - networks=['admin'], - ), - Service( - name='backend', - image='awesome/backend', - ports=['8000:5010'], - networks=['back-tier', 'admin'], - ), - ])), - ('tests/in/000110.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - ports=['8000:5000'], - ), - Service( - name='monitoring', - extends=Extends(service_name='frontend'), - ), - Service( - name='backend', - extends=Extends(service_name='frontend'), - ports=['8000:5001'], - ), - ])), - ('tests/in/000111.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - ports=['8000:5000'], - networks=['front-tier', 'back-tier'], - ), - Service( - name='monitoring', - networks=['admin'], - extends=Extends(service_name='frontend'), - ), - Service( - name='backend', - ports=['8000:5001'], - networks=['back-tier', 'admin'], - extends=Extends(service_name='frontend'), - ), - ])), - ('tests/in/001000.yaml',Compose([ - Service( - name='web', - image='build from .', - depends_on=['db','redis'], - ), - Service( - name='redis', - image='redis', - ), - Service( - name='db', - image='postgres', - ), - ])), - ('tests/in/001001.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - networks=['front-tier', 'back-tier'], - depends_on=['monitoring','backend'], - ), - Service( - name='monitoring', - image='awesome/monitoring', - networks=['admin'], - ), - Service( - name='backend', - image='awesome/backend', - networks=['back-tier', 'admin'], - ), - ])), - ('tests/in/001010.yaml',Compose([ - Service( - name='web', - depends_on=['db','redis'], - extends=Extends(service_name='redis'), - ), - Service( - name='redis', - image='redis', - ), - Service( - name='db', - image='postgres', - ), - ])), - ('tests/in/001011.yaml',Compose([ - Service( - name='frontend', - networks=['front-tier', 'back-tier'], - depends_on=['monitoring','backend'], - extends=Extends(service_name='backend'), - ), - Service( - name='monitoring', - image='awesome/monitoring', - networks=['admin'], - ), - Service( - name='backend', - image='awesome/backend', - networks=['back-tier', 'admin'], - ), - ])), - ('tests/in/001100.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - ports=['8000:5000'], - ), - Service( - name='monitoring', - image='awesome/monitoring', - depends_on=['backend'], - ports=['8000:5010'], - ), - Service( - name='backend', - image='awesome/backend', - ports=['8000:5001'], - ), - ])), - ('tests/in/001101.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - networks=['front-tier', 'back-tier'], - ), - Service( - name='monitoring', - image='awesome/monitoring', - networks=['admin'], - depends_on=['backend'], - ports=['8000:5010'], - ), - Service( - name='backend', - image='awesome/backend', - networks=['back-tier', 'admin'], - ), - ])), - ('tests/in/001110.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - ports=['8000:5000'], - ), - Service( - name='monitoring', - depends_on=['backend'], - extends=Extends(service_name='frontend'), - ports=['8000:5010'], - ), - Service( - name='backend', - image='awesome/backend', - ports=['8000:5001'], - ), - ])), - ('tests/in/001111.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - networks=['front-tier', 'back-tier'], - ), - Service( - name='monitoring', - networks=['admin'], - depends_on=['backend'], - extends=Extends(service_name='frontend'), - ports=['8000:5010'], - ), - Service( - name='backend', - image='awesome/backend', - networks=['back-tier', 'admin'], - ), - ])), - ('tests/in/010000.yaml',Compose([ - Service( - name='backend', - image='awesome/backend', - volumes=['db-data'], - ), - ])), - ('tests/in/010001.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - networks=['front-tier', 'back-tier'], - ), - Service( - name='monitoring', - image='awesome/monitoring', - networks=['admin'], - ), - Service( - name='backend', - image='awesome/backend', - networks=['back-tier', 'admin'], - volumes=['db-data'], - ), - ])), - ('tests/in/010010.yaml',Compose([ - Service( - name='common', - image='busybox', - volumes=['common-volume'], - ), - Service( - name='cli', - extends=Extends(service_name='common'), - volumes=['cli-volume'], - ), - ])), - ('tests/in/010011.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - networks=['front-tier', 'back-tier'], - ), - Service( - name='monitoring', - image='awesome/monitoring', - networks=['admin'], - ), - Service( - name='backend', - networks=['back-tier', 'admin'], - volumes=['db-data'], - extends=Extends(service_name='monitoring'), - ), - ])), - ('tests/in/010100.yaml',Compose([ - Service( - name='backend', - image='awesome/backend', - volumes=['db-data'], - ports=["8000:5000"], - ), - ])), - ('tests/in/010101.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - networks=['front-tier', 'back-tier'], - ), - Service( - name='monitoring', - image='awesome/monitoring', - networks=['admin'], - ), - Service( - name='backend', - image='awesome/backend', - networks=['back-tier', 'admin'], - volumes=['db-data'], - ports=['8000:5000'], - ), - ])), - ('tests/in/010110.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - ), - Service( - name='monitoring', - image='awesome/monitoring', - ), - Service( - name='backend', - volumes=['db-data'], - extends=Extends(service_name='monitoring'), - ports=['8000:5000'], - ), - ])), - ('tests/in/010111.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - networks=['front-tier', 'back-tier'], - ), - Service( - name='monitoring', - image='awesome/monitoring', - networks=['admin'], - ), - Service( - name='backend', - networks=['back-tier', 'admin'], - volumes=['db-data'], - extends=Extends(service_name='monitoring'), - ports=['8000:5000'], - ), - ])), - ('tests/in/011000.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - ), - Service( - name='monitoring', - image='awesome/monitoring', - depends_on=['backend'], - volumes=['db-data'], - ), - Service( - name='backend', - image='awesome/backend', - ), - ])), - ('tests/in/011001.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - networks=['front-tier', 'back-tier'], - ), - Service( - name='monitoring', - image='awesome/monitoring', - networks=['admin'], - ), - Service( - name='backend', - image='awesome/backend', - networks=['back-tier','admin'], - volumes=['db-data'], - depends_on=['monitoring'], - ), - ])), - ('tests/in/011010.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - ), - Service( - name='monitoring', - image='awesome/monitoring', - ), - Service( - name='backend', - volumes=['db-data'], - depends_on=['monitoring'], - extends=Extends(service_name='frontend'), - ), - ])), - ('tests/in/011011.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - networks=['front-tier','back-tier'], - ), - Service( - name='monitoring', - image='awesome/monitoring', - networks=['admin'], - ), - Service( - name='backend', - networks=['back-tier','admin'], - volumes=['db-data'], - depends_on=['monitoring'], - extends=Extends(service_name='frontend'), - ), - ])), - ('tests/in/011100.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - ), - Service( - name='monitoring', - image='awesome/monitoring', - ), - Service( - name='backend', - volumes=['db-data'], - depends_on=['monitoring'], - extends=Extends(service_name='frontend'), - ports=['8000:5010'], - ), - ])), - ('tests/in/011101.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - networks=['front-tier', 'back-tier'], - ), - Service( - name='monitoring', - image='awesome/monitoring', - networks=['admin'], - ), - Service( - name='backend', - image='awesome/backend', - networks=['back-tier', 'admin'], - volumes=['db-data'], - depends_on=['monitoring'], - ports=['8000:5010'], - ), - ])), - ('tests/in/011110.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - ), - Service( - name='monitoring', - image='awesome/monitoring', - ), - Service( - name='backend', - volumes=['db-data'], - depends_on=['monitoring'], - extends=Extends(service_name='frontend'), - ports=['8000:5010'], - ), - ])), - ('tests/in/011111.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - networks=['front-tier', 'back-tier'], - ), - Service( - name='monitoring', - image='awesome/monitoring', - networks=['admin'], - ), - Service( - name='backend', - networks=['back-tier', 'admin'], - volumes=['db-data'], - depends_on=['monitoring'], - extends=Extends(service_name='monitoring'), - ports=['8000:5010'], - ), - ])), - ('tests/in/100000.yaml',Compose([ - Service( - name='web', - image='build from .', - links=['db:database'], - ), - Service( - name='db', - image='postgres', - ), - ])), - ('tests/in/100001.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - networks=['front-tier', 'back-tier'], - ), - Service( - name='monitoring', - image='awesome/monitoring', - networks=['admin'], - ), - Service( - name='backend', - image='awesome/backend', - networks=['back-tier', 'admin'], - links=['db:database'], - ), - Service( - name='db', - image='postgres', - ), - ])), - ('tests/in/100010.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - ), - Service( - name='monitoring', - image='awesome/monitoring', - ), - Service( - name='backend', - extends=Extends(service_name='frontend'), - links=['db:database'], - ), - Service( - name='db', - image='postgres', - ), - ])), - ('tests/in/100011.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - networks=['front-tier', 'back-tier'], - ), - Service( - name='monitoring', - image='awesome/monitoring', - networks=['admin'], - ), - Service( - name='backend', - networks=['back-tier', 'admin'], - extends=Extends(service_name='frontend'), - links=['db:database'], - ), - Service( - name='db', - image='postgres', - ), - ])), - ('tests/in/100100.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - ), - Service( - name='monitoring', - image='awesome/monitoring', - ), - Service( - name='backend', - image='awesome/backend', - ports=['8000:5010'], - links=['db:database'], - ), - Service( - name='db', - image='postgres', - ), - ])), - ('tests/in/100101.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - networks=['front-tier', 'back-tier'], - ), - Service( - name='monitoring', - image='awesome/monitoring', - networks=['admin'], - ), - Service( - name='backend', - image='awesome/backend', - networks=['back-tier', 'admin'], - ports=['8000:5010'], - links=['db:database'], - ), - Service( - name='db', - image='postgres', - ), - ])), - ('tests/in/100110.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - ), - Service( - name='monitoring', - image='awesome/monitoring', - ), - Service( - name='backend', - extends=Extends(service_name='frontend'), - ports=['8000:5010'], - links=['db:database'], - ), - Service( - name='db', - image='postgres', - ), - ])), - ('tests/in/100111.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - networks=['front-tier', 'back-tier'], - ), - Service( - name='monitoring', - image='awesome/monitoring', - networks=['admin'], - ), - Service( - name='backend', - networks=['back-tier', 'admin'], - extends=Extends(service_name='frontend'), - ports=['8000:5010'], - links=['db:database'], - ), - Service( - name='db', - image='postgres', - ), - ])), - ('tests/in/101000.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - ), - Service( - name='monitoring', - image='awesome/monitoring', - ), - Service( - name='backend', - image='awesome/backend', - depends_on=['monitoring'], - links=['db:database'], - ), - Service( - name='db', - image='postgres', - ), - ])), - ('tests/in/101001.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - networks=['front-tier', 'back-tier'], - ), - Service( - name='monitoring', - image='awesome/monitoring', - networks=['admin'], - ), - Service( - name='backend', - image='awesome/backend', - networks=['back-tier', 'admin'], - depends_on=['monitoring'], - links=['db:database'], - ), - Service( - name='db', - image='postgres', - ), - ])), - ('tests/in/101010.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - ), - Service( - name='monitoring', - image='awesome/monitoring', - ), - Service( - name='backend', - depends_on=['monitoring'], - extends=Extends(service_name='frontend'), - links=['db:database'], - ), - Service( - name='db', - image='postgres', - ), - ])), - ('tests/in/101011.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - networks=['front-tier', 'back-tier'], - ), - Service( - name='monitoring', - image='awesome/monitoring', - networks=['admin'], - ), - Service( - name='backend', - networks=['back-tier', 'admin'], - depends_on=['monitoring'], - extends=Extends(service_name='frontend'), - links=['db:database'], - ), - Service( - name='db', - image='postgres', - ), - ])), - ('tests/in/101100.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - ), - Service( - name='monitoring', - image='awesome/monitoring', - ), - Service( - name='backend', - image='awesome/backend', - depends_on=['monitoring'], - ports=['8000:5010'], - links=['db:database'], - ), - Service( - name='db', - image='postgres', - ), - ])), - ('tests/in/101101.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - networks=['front-tier', 'back-tier'], - ), - Service( - name='monitoring', - image='awesome/monitoring', - networks=['admin'], - ), - Service( - name='backend', - image='awesome/backend', - networks=['back-tier', 'admin'], - depends_on=['monitoring'], - ports=['8000:5010'], - links=['db:database'], - ), - Service( - name='db', - image='postgres', - ), - ])), - ('tests/in/101110.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - ), - Service( - name='monitoring', - image='awesome/monitoring', - ), - Service( - name='backend', - depends_on=['monitoring'], - extends=Extends(service_name='frontend'), - ports=['8000:5010'], - links=['db:database'], - ), - Service( - name='db', - image='postgres', - ), - ])), - ('tests/in/101111.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - networks=['front-tier', 'back-tier'], - ), - Service( - name='monitoring', - image='awesome/monitoring', - networks=['admin'], - ), - Service( - name='backend', - networks=['back-tier', 'admin'], - depends_on=['monitoring'], - extends=Extends(service_name='frontend'), - ports=['8000:5010'], - links=['db:database'], - ), - Service( - name='db', - image='postgres', - ), - ])), - ('tests/in/110000.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - ), - Service( - name='monitoring', - image='awesome/monitoring', - volumes=['db-data'], - links=['db:database'], - ), - Service( - name='backend', - image='awesome/backend', - ), - Service( - name='db', - image='postgres', - ), - ])), - ('tests/in/110001.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - networks=['front-tier', 'back-tier'], - ), - Service( - name='monitoring', - image='awesome/monitoring', - networks=['admin'], - ), - Service( - name='backend', - image='awesome/backend', - networks=['back-tier', 'admin'], - volumes=['db-data'], - links=['db:database'], - ), - Service( - name='db', - image='postgres', - ), - ])), - ('tests/in/110010.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - ), - Service( - name='monitoring', - image='awesome/monitoring', - ), - Service( - name='backend', - volumes=['db-data'], - extends=Extends(service_name='frontend'), - links=['db:database'], - ), - Service( - name='db', - image='postgres', - ), - ])), - ('tests/in/110011.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - networks=['front-tier', 'back-tier'], - ), - Service( - name='monitoring', - image='awesome/monitoring', - networks=['admin'], - ), - Service( - name='backend', - networks=['back-tier', 'admin'], - volumes=['db-data'], - extends=Extends(service_name='frontend'), - links=['db:database'], - ), - Service( - name='db', - image='postgres', - ), - ])), - ('tests/in/110100.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - ), - Service( - name='monitoring', - image='awesome/monitoring', - ), - Service( - name='backend', - image='awesome/backend', - volumes=['db-data'], - ports=['8000:5010'], - links=['db:database'], - ), - Service( - name='db', - image='postgres', - ), - ])), - ('tests/in/110101.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - networks=['front-tier', 'back-tier'], - ), - Service( - name='monitoring', - image='awesome/monitoring', - networks=['admin'], - ), - Service( - name='backend', - image='awesome/backend', - networks=['back-tier', 'admin'], - volumes=['db-data'], - ports=['8000:5010'], - links=['db:database'], - ), - Service( - name='db', - image='postgres', - ), - ])), - ('tests/in/110110.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - ), - Service( - name='monitoring', - image='awesome/monitoring', - ), - Service( - name='backend', - volumes=['db-data'], - extends=Extends(service_name='frontend'), - ports=['8000:5010'], - links=['db:database'], - ), - Service( - name='db', - image='postgres', - ), - ])), - ('tests/in/110111.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - networks=['front-tier', 'back-tier'], - ), - Service( - name='monitoring', - image='awesome/monitoring', - networks=['admin'], - ), - Service( - name='backend', - networks=['back-tier', 'admin'], - volumes=['db-data'], - extends=Extends(service_name='frontend'), - ports=['8000:5010'], - links=['db:database'], - ), - Service( - name='db', - image='postgres', - ), - ])), - ('tests/in/111000.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - ), - Service( - name='monitoring', - image='awesome/monitoring', - depends_on=['backend'], - volumes=['db-data'], - links=['db:database'], - ), - Service( - name='backend', - image='awesome/backend', - ), - Service( - name='db', - image='postgres', - ), - ])), - ('tests/in/111001.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - networks=['front-tier', 'back-tier'], - ), - Service( - name='monitoring', - image='awesome/monitoring', - networks=['admin'], - ), - Service( - name='backend', - image='awesome/backend', - networks=['back-tier', 'admin'], - volumes=['db-data'], - depends_on=['monitoring'], - links=['db:database'], - ), - Service( - name='db', - image='postgres', - ), - ])), - ('tests/in/111010.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - ), - Service( - name='monitoring', - image='awesome/monitoring', - ), - Service( - name='backend', - volumes=['db-data'], - depends_on=['monitoring'], - extends=Extends(service_name='frontend'), - links=['db:database'], - ), - Service( - name='db', - image='postgres', - ), - ])), - ('tests/in/111011.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - networks=['front-tier', 'back-tier'], - ), - Service( - name='monitoring', - image='awesome/monitoring', - networks=['admin'], - ), - Service( - name='backend', - networks=['back-tier', 'admin'], - volumes=['db-data'], - depends_on=['monitoring'], - extends=Extends(service_name='frontend'), - links=['db:database'], - ), - Service( - name='db', - image='postgres', - ), - ])), - ('tests/in/111100.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - ), - Service( - name='monitoring', - image='awesome/monitoring', - ), - Service( - name='backend', - image='awesome/backend', - volumes=['db-data'], - depends_on=['monitoring'], - ports=['8000:5010'], - links=['db:database'], - ), - Service( - name='db', - image='postgres', - ), - ])), - ('tests/in/111101.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - networks=['front-tier', 'back-tier'], - ), - Service( - name='monitoring', - image='awesome/monitoring', - networks=['admin'], - ), - Service( - name='backend', - image='awesome/backend', - networks=['back-tier', 'admin'], - volumes=['db-data'], - depends_on=['monitoring'], - ports=['8000:5010'], - links=['db:database'], - ), - Service( - name='db', - image='postgres', - ), - ])), - ('tests/in/111110.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - ), - Service( - name='monitoring', - image='awesome/monitoring', - ), - Service( - name='backend', - volumes=['db-data'], - depends_on=['monitoring'], - extends=Extends(service_name='frontend'), - ports=['8000:5010'], - links=['db:database'], - ), - Service( - name='db', - image='postgres', - ), - ])), - ('tests/in/111111.yaml',Compose([ - Service( - name='frontend', - image='awesome/webapp', - networks=['front-tier', 'back-tier'], - ), - Service( - name='monitoring', - image='awesome/monitoring', - networks=['admin'], - ), - Service( - name='backend', - networks=['back-tier', 'admin'], - volumes=['db-data'], - depends_on=['monitoring'], - extends=Extends(service_name='frontend'), - ports=['8000:5010'], - links=['db:database'], - ), - Service( - name='db', - image='postgres', - ), - ])), -]) - +from compose_viz.compose import Compose +from compose_viz.extends import Extends +from compose_viz.parser import Parser +from compose_viz.service import Service + + +@pytest.mark.parametrize( + "test_input,expected", + [ + ( + "tests/in/000001.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + networks=["front-tier", "back-tier"], + ), + Service( + name="monitoring", + image="awesome/monitoring", + networks=["admin"], + ), + Service( + name="backend", + image="awesome/backend", + networks=["back-tier", "admin"], + ), + ] + ), + ), + ( + "tests/in/000010.yaml", + Compose( + [ + Service( + name="base", + image="busybox", + ), + Service( + name="common", + extends=Extends(service_name="frontend"), + ), + Service( + name="cli", + extends=Extends(service_name="common"), + ), + ] + ), + ), + ( + "tests/in/000011.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + networks=["front-tier", "back-tier"], + ), + Service( + name="monitoring", + networks=["admin"], + extends=Extends(service_name="frontend"), + ), + Service( + name="backend", + networks=["back-tier", "admin"], + extends=Extends(service_name="frontend"), + ), + ] + ), + ), + ( + "tests/in/000100.yaml", + Compose( + [ + Service( + name="web", + image="build from .", + ports=["8000:5000"], + ), + Service( + name="redis", + image="redis:alpine", + ), + ] + ), + ), + ( + "tests/in/000101.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + ports=["8000:5000"], + networks=["front-tier", "back-tier"], + ), + Service( + name="monitoring", + image="awesome/monitoring", + ports=["8000:5001"], + networks=["admin"], + ), + Service( + name="backend", + image="awesome/backend", + ports=["8000:5010"], + networks=["back-tier", "admin"], + ), + ] + ), + ), + ( + "tests/in/000110.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + ports=["8000:5000"], + ), + Service( + name="monitoring", + extends=Extends(service_name="frontend"), + ), + Service( + name="backend", + extends=Extends(service_name="frontend"), + ports=["8000:5001"], + ), + ] + ), + ), + ( + "tests/in/000111.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + ports=["8000:5000"], + networks=["front-tier", "back-tier"], + ), + Service( + name="monitoring", + networks=["admin"], + extends=Extends(service_name="frontend"), + ), + Service( + name="backend", + ports=["8000:5001"], + networks=["back-tier", "admin"], + extends=Extends(service_name="frontend"), + ), + ] + ), + ), + ( + "tests/in/001000.yaml", + Compose( + [ + Service( + name="web", + image="build from .", + depends_on=["db", "redis"], + ), + Service( + name="redis", + image="redis", + ), + Service( + name="db", + image="postgres", + ), + ] + ), + ), + ( + "tests/in/001001.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + networks=["front-tier", "back-tier"], + depends_on=["monitoring", "backend"], + ), + Service( + name="monitoring", + image="awesome/monitoring", + networks=["admin"], + ), + Service( + name="backend", + image="awesome/backend", + networks=["back-tier", "admin"], + ), + ] + ), + ), + ( + "tests/in/001010.yaml", + Compose( + [ + Service( + name="web", + depends_on=["db", "redis"], + extends=Extends(service_name="redis"), + ), + Service( + name="redis", + image="redis", + ), + Service( + name="db", + image="postgres", + ), + ] + ), + ), + ( + "tests/in/001011.yaml", + Compose( + [ + Service( + name="frontend", + networks=["front-tier", "back-tier"], + depends_on=["monitoring", "backend"], + extends=Extends(service_name="backend"), + ), + Service( + name="monitoring", + image="awesome/monitoring", + networks=["admin"], + ), + Service( + name="backend", + image="awesome/backend", + networks=["back-tier", "admin"], + ), + ] + ), + ), + ( + "tests/in/001100.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + ports=["8000:5000"], + ), + Service( + name="monitoring", + image="awesome/monitoring", + depends_on=["backend"], + ports=["8000:5010"], + ), + Service( + name="backend", + image="awesome/backend", + ports=["8000:5001"], + ), + ] + ), + ), + ( + "tests/in/001101.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + networks=["front-tier", "back-tier"], + ), + Service( + name="monitoring", + image="awesome/monitoring", + networks=["admin"], + depends_on=["backend"], + ports=["8000:5010"], + ), + Service( + name="backend", + image="awesome/backend", + networks=["back-tier", "admin"], + ), + ] + ), + ), + ( + "tests/in/001110.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + ports=["8000:5000"], + ), + Service( + name="monitoring", + depends_on=["backend"], + extends=Extends(service_name="frontend"), + ports=["8000:5010"], + ), + Service( + name="backend", + image="awesome/backend", + ports=["8000:5001"], + ), + ] + ), + ), + ( + "tests/in/001111.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + networks=["front-tier", "back-tier"], + ), + Service( + name="monitoring", + networks=["admin"], + depends_on=["backend"], + extends=Extends(service_name="frontend"), + ports=["8000:5010"], + ), + Service( + name="backend", + image="awesome/backend", + networks=["back-tier", "admin"], + ), + ] + ), + ), + ( + "tests/in/010000.yaml", + Compose( + [ + Service( + name="backend", + image="awesome/backend", + volumes=["db-data"], + ), + ] + ), + ), + ( + "tests/in/010001.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + networks=["front-tier", "back-tier"], + ), + Service( + name="monitoring", + image="awesome/monitoring", + networks=["admin"], + ), + Service( + name="backend", + image="awesome/backend", + networks=["back-tier", "admin"], + volumes=["db-data"], + ), + ] + ), + ), + ( + "tests/in/010010.yaml", + Compose( + [ + Service( + name="common", + image="busybox", + volumes=["common-volume"], + ), + Service( + name="cli", + extends=Extends(service_name="common"), + volumes=["cli-volume"], + ), + ] + ), + ), + ( + "tests/in/010011.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + networks=["front-tier", "back-tier"], + ), + Service( + name="monitoring", + image="awesome/monitoring", + networks=["admin"], + ), + Service( + name="backend", + networks=["back-tier", "admin"], + volumes=["db-data"], + extends=Extends(service_name="monitoring"), + ), + ] + ), + ), + ( + "tests/in/010100.yaml", + Compose( + [ + Service( + name="backend", + image="awesome/backend", + volumes=["db-data"], + ports=["8000:5000"], + ), + ] + ), + ), + ( + "tests/in/010101.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + networks=["front-tier", "back-tier"], + ), + Service( + name="monitoring", + image="awesome/monitoring", + networks=["admin"], + ), + Service( + name="backend", + image="awesome/backend", + networks=["back-tier", "admin"], + volumes=["db-data"], + ports=["8000:5000"], + ), + ] + ), + ), + ( + "tests/in/010110.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + ), + Service( + name="monitoring", + image="awesome/monitoring", + ), + Service( + name="backend", + volumes=["db-data"], + extends=Extends(service_name="monitoring"), + ports=["8000:5000"], + ), + ] + ), + ), + ( + "tests/in/010111.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + networks=["front-tier", "back-tier"], + ), + Service( + name="monitoring", + image="awesome/monitoring", + networks=["admin"], + ), + Service( + name="backend", + networks=["back-tier", "admin"], + volumes=["db-data"], + extends=Extends(service_name="monitoring"), + ports=["8000:5000"], + ), + ] + ), + ), + ( + "tests/in/011000.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + ), + Service( + name="monitoring", + image="awesome/monitoring", + depends_on=["backend"], + volumes=["db-data"], + ), + Service( + name="backend", + image="awesome/backend", + ), + ] + ), + ), + ( + "tests/in/011001.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + networks=["front-tier", "back-tier"], + ), + Service( + name="monitoring", + image="awesome/monitoring", + networks=["admin"], + ), + Service( + name="backend", + image="awesome/backend", + networks=["back-tier", "admin"], + volumes=["db-data"], + depends_on=["monitoring"], + ), + ] + ), + ), + ( + "tests/in/011010.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + ), + Service( + name="monitoring", + image="awesome/monitoring", + ), + Service( + name="backend", + volumes=["db-data"], + depends_on=["monitoring"], + extends=Extends(service_name="frontend"), + ), + ] + ), + ), + ( + "tests/in/011011.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + networks=["front-tier", "back-tier"], + ), + Service( + name="monitoring", + image="awesome/monitoring", + networks=["admin"], + ), + Service( + name="backend", + networks=["back-tier", "admin"], + volumes=["db-data"], + depends_on=["monitoring"], + extends=Extends(service_name="frontend"), + ), + ] + ), + ), + ( + "tests/in/011100.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + ), + Service( + name="monitoring", + image="awesome/monitoring", + ), + Service( + name="backend", + volumes=["db-data"], + depends_on=["monitoring"], + extends=Extends(service_name="frontend"), + ports=["8000:5010"], + ), + ] + ), + ), + ( + "tests/in/011101.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + networks=["front-tier", "back-tier"], + ), + Service( + name="monitoring", + image="awesome/monitoring", + networks=["admin"], + ), + Service( + name="backend", + image="awesome/backend", + networks=["back-tier", "admin"], + volumes=["db-data"], + depends_on=["monitoring"], + ports=["8000:5010"], + ), + ] + ), + ), + ( + "tests/in/011110.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + ), + Service( + name="monitoring", + image="awesome/monitoring", + ), + Service( + name="backend", + volumes=["db-data"], + depends_on=["monitoring"], + extends=Extends(service_name="frontend"), + ports=["8000:5010"], + ), + ] + ), + ), + ( + "tests/in/011111.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + networks=["front-tier", "back-tier"], + ), + Service( + name="monitoring", + image="awesome/monitoring", + networks=["admin"], + ), + Service( + name="backend", + networks=["back-tier", "admin"], + volumes=["db-data"], + depends_on=["monitoring"], + extends=Extends(service_name="monitoring"), + ports=["8000:5010"], + ), + ] + ), + ), + ( + "tests/in/100000.yaml", + Compose( + [ + Service( + name="web", + image="build from .", + links=["db:database"], + ), + Service( + name="db", + image="postgres", + ), + ] + ), + ), + ( + "tests/in/100001.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + networks=["front-tier", "back-tier"], + ), + Service( + name="monitoring", + image="awesome/monitoring", + networks=["admin"], + ), + Service( + name="backend", + image="awesome/backend", + networks=["back-tier", "admin"], + links=["db:database"], + ), + Service( + name="db", + image="postgres", + ), + ] + ), + ), + ( + "tests/in/100010.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + ), + Service( + name="monitoring", + image="awesome/monitoring", + ), + Service( + name="backend", + extends=Extends(service_name="frontend"), + links=["db:database"], + ), + Service( + name="db", + image="postgres", + ), + ] + ), + ), + ( + "tests/in/100011.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + networks=["front-tier", "back-tier"], + ), + Service( + name="monitoring", + image="awesome/monitoring", + networks=["admin"], + ), + Service( + name="backend", + networks=["back-tier", "admin"], + extends=Extends(service_name="frontend"), + links=["db:database"], + ), + Service( + name="db", + image="postgres", + ), + ] + ), + ), + ( + "tests/in/100100.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + ), + Service( + name="monitoring", + image="awesome/monitoring", + ), + Service( + name="backend", + image="awesome/backend", + ports=["8000:5010"], + links=["db:database"], + ), + Service( + name="db", + image="postgres", + ), + ] + ), + ), + ( + "tests/in/100101.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + networks=["front-tier", "back-tier"], + ), + Service( + name="monitoring", + image="awesome/monitoring", + networks=["admin"], + ), + Service( + name="backend", + image="awesome/backend", + networks=["back-tier", "admin"], + ports=["8000:5010"], + links=["db:database"], + ), + Service( + name="db", + image="postgres", + ), + ] + ), + ), + ( + "tests/in/100110.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + ), + Service( + name="monitoring", + image="awesome/monitoring", + ), + Service( + name="backend", + extends=Extends(service_name="frontend"), + ports=["8000:5010"], + links=["db:database"], + ), + Service( + name="db", + image="postgres", + ), + ] + ), + ), + ( + "tests/in/100111.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + networks=["front-tier", "back-tier"], + ), + Service( + name="monitoring", + image="awesome/monitoring", + networks=["admin"], + ), + Service( + name="backend", + networks=["back-tier", "admin"], + extends=Extends(service_name="frontend"), + ports=["8000:5010"], + links=["db:database"], + ), + Service( + name="db", + image="postgres", + ), + ] + ), + ), + ( + "tests/in/101000.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + ), + Service( + name="monitoring", + image="awesome/monitoring", + ), + Service( + name="backend", + image="awesome/backend", + depends_on=["monitoring"], + links=["db:database"], + ), + Service( + name="db", + image="postgres", + ), + ] + ), + ), + ( + "tests/in/101001.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + networks=["front-tier", "back-tier"], + ), + Service( + name="monitoring", + image="awesome/monitoring", + networks=["admin"], + ), + Service( + name="backend", + image="awesome/backend", + networks=["back-tier", "admin"], + depends_on=["monitoring"], + links=["db:database"], + ), + Service( + name="db", + image="postgres", + ), + ] + ), + ), + ( + "tests/in/101010.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + ), + Service( + name="monitoring", + image="awesome/monitoring", + ), + Service( + name="backend", + depends_on=["monitoring"], + extends=Extends(service_name="frontend"), + links=["db:database"], + ), + Service( + name="db", + image="postgres", + ), + ] + ), + ), + ( + "tests/in/101011.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + networks=["front-tier", "back-tier"], + ), + Service( + name="monitoring", + image="awesome/monitoring", + networks=["admin"], + ), + Service( + name="backend", + networks=["back-tier", "admin"], + depends_on=["monitoring"], + extends=Extends(service_name="frontend"), + links=["db:database"], + ), + Service( + name="db", + image="postgres", + ), + ] + ), + ), + ( + "tests/in/101100.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + ), + Service( + name="monitoring", + image="awesome/monitoring", + ), + Service( + name="backend", + image="awesome/backend", + depends_on=["monitoring"], + ports=["8000:5010"], + links=["db:database"], + ), + Service( + name="db", + image="postgres", + ), + ] + ), + ), + ( + "tests/in/101101.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + networks=["front-tier", "back-tier"], + ), + Service( + name="monitoring", + image="awesome/monitoring", + networks=["admin"], + ), + Service( + name="backend", + image="awesome/backend", + networks=["back-tier", "admin"], + depends_on=["monitoring"], + ports=["8000:5010"], + links=["db:database"], + ), + Service( + name="db", + image="postgres", + ), + ] + ), + ), + ( + "tests/in/101110.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + ), + Service( + name="monitoring", + image="awesome/monitoring", + ), + Service( + name="backend", + depends_on=["monitoring"], + extends=Extends(service_name="frontend"), + ports=["8000:5010"], + links=["db:database"], + ), + Service( + name="db", + image="postgres", + ), + ] + ), + ), + ( + "tests/in/101111.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + networks=["front-tier", "back-tier"], + ), + Service( + name="monitoring", + image="awesome/monitoring", + networks=["admin"], + ), + Service( + name="backend", + networks=["back-tier", "admin"], + depends_on=["monitoring"], + extends=Extends(service_name="frontend"), + ports=["8000:5010"], + links=["db:database"], + ), + Service( + name="db", + image="postgres", + ), + ] + ), + ), + ( + "tests/in/110000.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + ), + Service( + name="monitoring", + image="awesome/monitoring", + volumes=["db-data"], + links=["db:database"], + ), + Service( + name="backend", + image="awesome/backend", + ), + Service( + name="db", + image="postgres", + ), + ] + ), + ), + ( + "tests/in/110001.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + networks=["front-tier", "back-tier"], + ), + Service( + name="monitoring", + image="awesome/monitoring", + networks=["admin"], + ), + Service( + name="backend", + image="awesome/backend", + networks=["back-tier", "admin"], + volumes=["db-data"], + links=["db:database"], + ), + Service( + name="db", + image="postgres", + ), + ] + ), + ), + ( + "tests/in/110010.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + ), + Service( + name="monitoring", + image="awesome/monitoring", + ), + Service( + name="backend", + volumes=["db-data"], + extends=Extends(service_name="frontend"), + links=["db:database"], + ), + Service( + name="db", + image="postgres", + ), + ] + ), + ), + ( + "tests/in/110011.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + networks=["front-tier", "back-tier"], + ), + Service( + name="monitoring", + image="awesome/monitoring", + networks=["admin"], + ), + Service( + name="backend", + networks=["back-tier", "admin"], + volumes=["db-data"], + extends=Extends(service_name="frontend"), + links=["db:database"], + ), + Service( + name="db", + image="postgres", + ), + ] + ), + ), + ( + "tests/in/110100.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + ), + Service( + name="monitoring", + image="awesome/monitoring", + ), + Service( + name="backend", + image="awesome/backend", + volumes=["db-data"], + ports=["8000:5010"], + links=["db:database"], + ), + Service( + name="db", + image="postgres", + ), + ] + ), + ), + ( + "tests/in/110101.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + networks=["front-tier", "back-tier"], + ), + Service( + name="monitoring", + image="awesome/monitoring", + networks=["admin"], + ), + Service( + name="backend", + image="awesome/backend", + networks=["back-tier", "admin"], + volumes=["db-data"], + ports=["8000:5010"], + links=["db:database"], + ), + Service( + name="db", + image="postgres", + ), + ] + ), + ), + ( + "tests/in/110110.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + ), + Service( + name="monitoring", + image="awesome/monitoring", + ), + Service( + name="backend", + volumes=["db-data"], + extends=Extends(service_name="frontend"), + ports=["8000:5010"], + links=["db:database"], + ), + Service( + name="db", + image="postgres", + ), + ] + ), + ), + ( + "tests/in/110111.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + networks=["front-tier", "back-tier"], + ), + Service( + name="monitoring", + image="awesome/monitoring", + networks=["admin"], + ), + Service( + name="backend", + networks=["back-tier", "admin"], + volumes=["db-data"], + extends=Extends(service_name="frontend"), + ports=["8000:5010"], + links=["db:database"], + ), + Service( + name="db", + image="postgres", + ), + ] + ), + ), + ( + "tests/in/111000.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + ), + Service( + name="monitoring", + image="awesome/monitoring", + depends_on=["backend"], + volumes=["db-data"], + links=["db:database"], + ), + Service( + name="backend", + image="awesome/backend", + ), + Service( + name="db", + image="postgres", + ), + ] + ), + ), + ( + "tests/in/111001.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + networks=["front-tier", "back-tier"], + ), + Service( + name="monitoring", + image="awesome/monitoring", + networks=["admin"], + ), + Service( + name="backend", + image="awesome/backend", + networks=["back-tier", "admin"], + volumes=["db-data"], + depends_on=["monitoring"], + links=["db:database"], + ), + Service( + name="db", + image="postgres", + ), + ] + ), + ), + ( + "tests/in/111010.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + ), + Service( + name="monitoring", + image="awesome/monitoring", + ), + Service( + name="backend", + volumes=["db-data"], + depends_on=["monitoring"], + extends=Extends(service_name="frontend"), + links=["db:database"], + ), + Service( + name="db", + image="postgres", + ), + ] + ), + ), + ( + "tests/in/111011.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + networks=["front-tier", "back-tier"], + ), + Service( + name="monitoring", + image="awesome/monitoring", + networks=["admin"], + ), + Service( + name="backend", + networks=["back-tier", "admin"], + volumes=["db-data"], + depends_on=["monitoring"], + extends=Extends(service_name="frontend"), + links=["db:database"], + ), + Service( + name="db", + image="postgres", + ), + ] + ), + ), + ( + "tests/in/111100.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + ), + Service( + name="monitoring", + image="awesome/monitoring", + ), + Service( + name="backend", + image="awesome/backend", + volumes=["db-data"], + depends_on=["monitoring"], + ports=["8000:5010"], + links=["db:database"], + ), + Service( + name="db", + image="postgres", + ), + ] + ), + ), + ( + "tests/in/111101.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + networks=["front-tier", "back-tier"], + ), + Service( + name="monitoring", + image="awesome/monitoring", + networks=["admin"], + ), + Service( + name="backend", + image="awesome/backend", + networks=["back-tier", "admin"], + volumes=["db-data"], + depends_on=["monitoring"], + ports=["8000:5010"], + links=["db:database"], + ), + Service( + name="db", + image="postgres", + ), + ] + ), + ), + ( + "tests/in/111110.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + ), + Service( + name="monitoring", + image="awesome/monitoring", + ), + Service( + name="backend", + volumes=["db-data"], + depends_on=["monitoring"], + extends=Extends(service_name="frontend"), + ports=["8000:5010"], + links=["db:database"], + ), + Service( + name="db", + image="postgres", + ), + ] + ), + ), + ( + "tests/in/111111.yaml", + Compose( + [ + Service( + name="frontend", + image="awesome/webapp", + networks=["front-tier", "back-tier"], + ), + Service( + name="monitoring", + image="awesome/monitoring", + networks=["admin"], + ), + Service( + name="backend", + networks=["back-tier", "admin"], + volumes=["db-data"], + depends_on=["monitoring"], + extends=Extends(service_name="frontend"), + ports=["8000:5010"], + links=["db:database"], + ), + Service( + name="db", + image="postgres", + ), + ] + ), + ), + ], +) def test_parse_file(test_input, expected): parser = Parser() actual = parser.parse(test_input) diff --git a/tests/test_version.py b/tests/test_version.py index 1d2abd6..a3bd0eb 100644 --- a/tests/test_version.py +++ b/tests/test_version.py @@ -1,6 +1,6 @@ from typer.testing import CliRunner -from compose_viz import cli, __app_name__, __version__ +from compose_viz import __app_name__, __version__, cli runner = CliRunner()