chore: add type annotations in tests

This commit is contained in:
Xyphuz 2022-05-19 00:41:08 +08:00
parent ecdc76a2a1
commit 5349155622
6 changed files with 10 additions and 10 deletions

View file

@ -76,7 +76,7 @@ runner = CliRunner()
"111111", "111111",
], ],
) )
def test_cli(file_number: str): def test_cli(file_number: str) -> None:
input_path = f"tests/in/{file_number}.yaml" input_path = f"tests/in/{file_number}.yaml"
output_path = f"{file_number}.png" output_path = f"{file_number}.png"
result = runner.invoke(cli.app, ["-o", output_path, input_path]) result = runner.invoke(cli.app, ["-o", output_path, input_path])

View file

@ -3,7 +3,7 @@ import pytest
from compose_viz.extends import Extends from compose_viz.extends import Extends
def test_extend_init_normal(): def test_extend_init_normal() -> None:
try: try:
Extends(service_name="frontend", from_file="tests/in/000001.yaml") Extends(service_name="frontend", from_file="tests/in/000001.yaml")
@ -12,7 +12,7 @@ def test_extend_init_normal():
assert False, e assert False, e
def test_extend_init_without_from_file(): def test_extend_init_without_from_file() -> None:
try: try:
Extends(service_name="frontend") Extends(service_name="frontend")
@ -21,6 +21,6 @@ def test_extend_init_without_from_file():
assert False, e assert False, e
def test_extend_init_without_service_name(): def test_extend_init_without_service_name() -> None:
with pytest.raises(TypeError): with pytest.raises(TypeError):
Extends(from_file="tests/in/000001.yaml") # type: ignore Extends(from_file="tests/in/000001.yaml") # type: ignore

View file

@ -1537,7 +1537,7 @@ from compose_viz.service import Service
), ),
], ],
) )
def test_parse_file(test_input, expected): def test_parse_file(test_input: str, expected: Compose) -> None:
parser = Parser() parser = Parser()
actual = parser.parse(test_input) actual = parser.parse(test_input)

View file

@ -3,16 +3,16 @@ import pytest
from compose_viz.parser import Parser from compose_viz.parser import Parser
def test_parser_error_parsing_file(): def test_parser_error_parsing_file() -> None:
with pytest.raises(RuntimeError, match=r"Error parsing file 'tests/in/invalid.yaml'.*"): with pytest.raises(RuntimeError, match=r"Error parsing file 'tests/in/invalid.yaml'.*"):
Parser().parse("tests/in/invalid.yaml") Parser().parse("tests/in/invalid.yaml")
def test_parser_invalid_yaml(): def test_parser_invalid_yaml() -> None:
with pytest.raises(RuntimeError, match=r"Empty yaml file, aborting."): with pytest.raises(RuntimeError, match=r"Empty yaml file, aborting."):
Parser().parse("tests/in/000000.yaml") Parser().parse("tests/in/000000.yaml")
def test_parser_no_services_found(): def test_parser_no_services_found() -> None:
with pytest.raises(RuntimeError, match=r"No services found, aborting."): with pytest.raises(RuntimeError, match=r"No services found, aborting."):
Parser().parse("tests/in/no-services.yaml") Parser().parse("tests/in/no-services.yaml")

View file

@ -4,7 +4,7 @@ from compose_viz.extends import Extends
from compose_viz.service import Service from compose_viz.service import Service
def test_service_init(): def test_service_init() -> None:
with pytest.raises(ValueError, match=r"Both image and extends are not defined in service 'frontend', aborting."): with pytest.raises(ValueError, match=r"Both image and extends are not defined in service 'frontend', aborting."):
Service(name="frontend") Service(name="frontend")

View file

@ -5,7 +5,7 @@ from compose_viz import __app_name__, __version__, cli
runner = CliRunner() runner = CliRunner()
def test_version(): def test_version() -> None:
result = runner.invoke(cli.app, ["--version"]) result = runner.invoke(cli.app, ["--version"])
assert result.exit_code == 0 assert result.exit_code == 0