diff --git a/compose_viz/models/service.py b/compose_viz/models/service.py index dba1fd3..abd94f6 100644 --- a/compose_viz/models/service.py +++ b/compose_viz/models/service.py @@ -16,8 +16,8 @@ class Service: depends_on: List[str] = [], links: List[str] = [], extends: Optional[Extends] = None, - cgroup_parent: str = None, - container_name: str = None, + cgroup_parent: Optional[str] = None, + container_name: Optional[str] = None, devices: List[str] = [], env_file: List[str] = [], expose: List[str] = [], diff --git a/compose_viz/parser.py b/compose_viz/parser.py index 4d631fc..6f296d4 100644 --- a/compose_viz/parser.py +++ b/compose_viz/parser.py @@ -176,35 +176,32 @@ class Parser: if service_data.links is not None: service_links = service_data.links - cgroup_parent: Optional[str] = None if service_data.cgroup_parent is not None: cgroup_parent = service_data.cgroup_parent - + container_name: Optional[str] = None if service_data.container_name is not None: container_name = service_data.container_name - - + env_file: List[str] = [] if service_data.env_file is not None: if type(service_data.env_file) is spec.StringOrList: - if(type(service_data.env_file.__root__) is spec.ListOfStrings): + if type(service_data.env_file.__root__) is spec.ListOfStrings: env_file = service_data.env_file.__root__.__root__ - elif(type(service_data.env_file.__root__) is str): + elif type(service_data.env_file.__root__) is str: env_file.append(service_data.env_file.__root__) - expose: List[str] = [] if service_data.expose is not None: - expose = service_data.expose - + for port in service_data.expose: + expose.append(str(port)) + profiles: List[str] = [] if service_data.profiles is not None: if type(service_data.profiles) is spec.ListOfStrings: profiles = service_data.profiles.__root__ - services.append( Service( name=service_name, diff --git a/tests/test_parse_file.py b/tests/test_parse_file.py index 54a8c86..226d755 100644 --- a/tests/test_parse_file.py +++ b/tests/test_parse_file.py @@ -248,7 +248,7 @@ from compose_viz.parser import Parser Service( name="frontend", image="awesome/frontend", - cgroup_parent="system", + cgroup_parent="system", ), ], ), @@ -260,7 +260,7 @@ from compose_viz.parser import Parser Service( name="frontend", image="awesome/frontend", - container_name="myfrontend", + container_name="myfrontend", ), ], ), @@ -272,24 +272,17 @@ from compose_viz.parser import Parser Service( name="frontend", image="awesome/frontend", - env_file=[ - "a.env" - ], + env_file=["a.env"], ), Service( name="backend", image="awesome/backend", - env_file=[ - "b.env" - ], + env_file=["b.env"], ), Service( name="db", image="awesome/db", - env_file=[ - "c.env", - "d.env" - ], + env_file=["c.env", "d.env"], ), ], ), @@ -301,46 +294,34 @@ from compose_viz.parser import Parser Service( name="frontend", image="awesome/frontend", - expose=[ - "27118" - ], + expose=["27118"], ), Service( name="backend", image="awesome/backend", - expose=[ - "27017", - "27018" - ], + expose=["27017", "27018"], ), ], ), ), - ( + ( "profiles/docker-compose", Compose( services=[ Service( name="frontend", image="awesome/frontend", - profiles=[ - "frontend" - ], + profiles=["frontend"], ), Service( name="phpmyadmin", image="phpmyadmin", - profiles=[ - "debug" - ], + profiles=["debug"], ), Service( name="db", image="awesome/db", - profiles=[ - "db", - "sql" - ], + profiles=["db", "sql"], ), ], ), @@ -380,10 +361,9 @@ def test_parse_file(test_file_path: str, expected: Compose) -> None: assert actual_service.extends.service_name == expected_service.extends.service_name assert actual_service.extends.from_file == expected_service.extends.from_file - assert actual_service.cgroup_parent == expected_service.cgroup_parent assert actual_service.container_name == expected_service.container_name assert actual_service.expose == expected_service.expose assert actual_service.env_file == expected_service.env_file - assert actual_service.profiles == expected_service.profiles \ No newline at end of file + assert actual_service.profiles == expected_service.profiles diff --git a/tests/ymls/cgroup_parent/docker-compose.yml b/tests/ymls/cgroup_parent/docker-compose.yml index bc22662..6d41ad4 100644 --- a/tests/ymls/cgroup_parent/docker-compose.yml +++ b/tests/ymls/cgroup_parent/docker-compose.yml @@ -3,4 +3,4 @@ version: "3.9" services: frontend: image: awesome/frontend - cgroup_parent: "system" \ No newline at end of file + cgroup_parent: "system" diff --git a/tests/ymls/container_name/docker-compose.yml b/tests/ymls/container_name/docker-compose.yml index f3e6794..08047c2 100644 --- a/tests/ymls/container_name/docker-compose.yml +++ b/tests/ymls/container_name/docker-compose.yml @@ -3,4 +3,4 @@ version: "3.9" services: frontend: image: awesome/frontend - container_name: "myfrontend" \ No newline at end of file + container_name: "myfrontend" diff --git a/tests/ymls/devices/docker-compose.yml b/tests/ymls/devices/docker-compose.yml index 474d385..f3fa6f8 100644 --- a/tests/ymls/devices/docker-compose.yml +++ b/tests/ymls/devices/docker-compose.yml @@ -9,4 +9,4 @@ services: image: awesome/backend devices: - "/dev/ttyUSB1:/dev/ttyUSB1" - - "/dev/ttyUSB2:/dev/ttyUSB2" \ No newline at end of file + - "/dev/ttyUSB2:/dev/ttyUSB2" diff --git a/tests/ymls/expose/docker-compose.yml b/tests/ymls/expose/docker-compose.yml index 473be64..1e1bdee 100644 --- a/tests/ymls/expose/docker-compose.yml +++ b/tests/ymls/expose/docker-compose.yml @@ -9,4 +9,4 @@ services: image: awesome/backend expose: - "27017" - - "27018" \ No newline at end of file + - "27018" diff --git a/tests/ymls/profiles/docker-compose.yml b/tests/ymls/profiles/docker-compose.yml index 64d755f..39282af 100644 --- a/tests/ymls/profiles/docker-compose.yml +++ b/tests/ymls/profiles/docker-compose.yml @@ -11,4 +11,4 @@ services: image: awesome/db profiles: - db - - sql \ No newline at end of file + - sql