fix: wrong typing in tests

This commit is contained in:
Xyphuz 2024-04-27 17:29:14 +08:00
parent aa4d3b70ed
commit 7b0466885a
2 changed files with 13 additions and 14 deletions

View file

@ -1,7 +1,6 @@
import re import re
from typing import Any, Dict, List, Optional, Union from typing import Any, Dict, List, Optional, Union
from pydantic import ValidationError
from pydantic_yaml import parse_yaml_raw_as from pydantic_yaml import parse_yaml_raw_as
import compose_viz.spec.compose_spec as spec import compose_viz.spec.compose_spec as spec
@ -44,7 +43,7 @@ class Parser:
with open(file_path, "r") as file: with open(file_path, "r") as file:
file_content = file.read() file_content = file.read()
compose_data = parse_yaml_raw_as(spec.ComposeSpecification, file_content) 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}") raise RuntimeError(f"Error parsing file '{file_path}': {e}")
services: List[Service] = [] services: List[Service] = []
@ -128,11 +127,8 @@ class Parser:
elif type(port_data) is spec.Ports: elif type(port_data) is spec.Ports:
assert port_data.target is not None, "Invalid port format, aborting." assert port_data.target is not None, "Invalid port format, aborting."
# ruamel.yaml does not parse port as int if type(port_data.published) is str or type(port_data.published) is int:
assert type(port_data.published) is not int host_port = str(port_data.published)
if type(port_data.published) is str:
host_port = port_data.published
if type(port_data.target) is int: if type(port_data.target) is int:
container_port = str(port_data.target) container_port = str(port_data.target)
@ -215,11 +211,16 @@ class Parser:
env_file: List[str] = [] env_file: List[str] = []
if service_data.env_file is not None: 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 str:
if type(service_data.env_file.root) is spec.ListOfStrings: env_file = [service_data.env_file.root]
env_file = service_data.env_file.root.root elif type(service_data.env_file.root) is list:
elif type(service_data.env_file.root) is str: for env_file_data in service_data.env_file.root:
env_file.append(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] = [] expose: List[str] = []
if service_data.expose is not None: if service_data.expose is not None:

View file

@ -26,5 +26,3 @@ networks:
front-tier: front-tier:
back-tier: back-tier:
admin: admin:
traefik-public:
external: true