Skip to content

Commit

Permalink
fix: wrong typing in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wst24365888 committed Apr 27, 2024
1 parent aa4d3b7 commit 7b04668
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
25 changes: 13 additions & 12 deletions compose_viz/parser.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import re
from typing import Any, Dict, List, Optional, Union

from pydantic import ValidationError
from pydantic_yaml import parse_yaml_raw_as

import compose_viz.spec.compose_spec as spec
Expand Down Expand Up @@ -44,7 +43,7 @@ def parse(self, file_path: str, root_service: Optional[str] = None) -> Compose:
with open(file_path, "r") as file:
file_content = file.read()
compose_data = parse_yaml_raw_as(spec.ComposeSpecification, file_content)
except ValidationError as e:
except Exception as e:
raise RuntimeError(f"Error parsing file '{file_path}': {e}")

services: List[Service] = []
Expand Down Expand Up @@ -128,11 +127,8 @@ def parse(self, file_path: str, root_service: Optional[str] = None) -> Compose:
elif type(port_data) is spec.Ports:
assert port_data.target is not None, "Invalid port format, aborting."

# ruamel.yaml does not parse port as int
assert type(port_data.published) is not int

if type(port_data.published) is str:
host_port = port_data.published
if type(port_data.published) is str or type(port_data.published) is int:
host_port = str(port_data.published)

if type(port_data.target) is int:
container_port = str(port_data.target)
Expand Down Expand Up @@ -215,11 +211,16 @@ def parse(self, file_path: str, root_service: Optional[str] = None) -> Compose:

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:
env_file = service_data.env_file.root.root
elif type(service_data.env_file.root) is str:
env_file.append(service_data.env_file.root)
if type(service_data.env_file.root) is str:
env_file = [service_data.env_file.root]
elif type(service_data.env_file.root) is list:
for env_file_data in service_data.env_file.root:
if type(env_file_data) is str:
env_file.append(env_file_data)
elif type(env_file_data) is spec.EnvFilePath:
env_file.append(env_file_data.path)
else:
print(f"Invalid env_file data: {service_data.env_file.root}")

expose: List[str] = []
if service_data.expose is not None:
Expand Down
2 changes: 0 additions & 2 deletions tests/ymls/networks/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,3 @@ networks:
front-tier:
back-tier:
admin:
traefik-public:
external: true

0 comments on commit 7b04668

Please sign in to comment.