diff --git a/tests/test_command_line.py b/tests/test_command_line.py index b3e0b09..10784d5 100644 --- a/tests/test_command_line.py +++ b/tests/test_command_line.py @@ -21,22 +21,23 @@ LOG: bytes = ( b"INFO Drawing extra icons...\n" b"INFO Drawing texts...\n" ) +OUTPUT_PATH: Path = Path("out") def error_run(arguments: list[str], message: bytes) -> None: """Run command that should fail and check error message.""" with Popen(["map-machine"] + arguments, stderr=PIPE) as pipe: - _, error = pipe.communicate() + _, output = pipe.communicate() + assert output == message assert pipe.returncode != 0 - assert error == message def run(arguments: list[str], message: bytes) -> None: - """Run command that should fail and check error message.""" + """Run command that should not fail and check output.""" with Popen(["map-machine"] + arguments, stderr=PIPE) as pipe: - _, error = pipe.communicate() + _, output = pipe.communicate() + assert output == message assert pipe.returncode == 0 - assert error == message def test_wrong_render_arguments() -> None: @@ -54,10 +55,10 @@ def test_render() -> None: COMMAND_LINES["render"] + ["--cache", "tests/data"], LOG + b"INFO Writing output SVG to out/map.svg...\n", ) - with Path("out/map.svg").open(encoding="utf-8") as output_file: + with (OUTPUT_PATH / "map.svg").open(encoding="utf-8") as output_file: root: Element = ElementTree.parse(output_file).getroot() - # 4 expected elements: `defs`, `rect` (background), `g` (outline), + # 8 expected elements: `defs`, `rect` (background), `g` (outline), # `g` (icon), 4 `text` elements (credits). assert len(root) == 8 assert len(root[3][0]) == 0 @@ -71,10 +72,10 @@ def test_render_with_tooltips() -> None: COMMAND_LINES["render_with_tooltips"] + ["--cache", "tests/data"], LOG + b"INFO Writing output SVG to out/map.svg...\n", ) - with Path("out/map.svg").open(encoding="utf-8") as output_file: + with (OUTPUT_PATH / "map.svg").open(encoding="utf-8") as output_file: root: Element = ElementTree.parse(output_file).getroot() - # 4 expected elements: `defs`, `rect` (background), `g` (outline), + # 8 expected elements: `defs`, `rect` (background), `g` (outline), # `g` (icon), 4 `text` elements (credits). assert len(root) == 8 assert len(root[3][0]) == 1 @@ -91,12 +92,11 @@ def test_icons() -> None: b"INFO Icon grid is written to out/icon_grid.svg.\n" b"INFO Icon grid is written to doc/grid.svg.\n", ) - - assert (Path("out") / "icon_grid.svg").is_file() - assert (Path("out") / "icons_by_name").is_dir() - assert (Path("out") / "icons_by_id").is_dir() - assert (Path("out") / "icons_by_name" / "Röntgen apple.svg").is_file() - assert (Path("out") / "icons_by_id" / "apple.svg").is_file() + assert (OUTPUT_PATH / "icon_grid.svg").is_file() + assert (OUTPUT_PATH / "icons_by_name").is_dir() + assert (OUTPUT_PATH / "icons_by_id").is_dir() + assert (OUTPUT_PATH / "icons_by_name" / "Röntgen apple.svg").is_file() + assert (OUTPUT_PATH / "icons_by_id" / "apple.svg").is_file() def test_mapcss() -> None: @@ -105,9 +105,8 @@ def test_mapcss() -> None: COMMAND_LINES["mapcss"], b"INFO MapCSS 0.2 scheme is written to out/map_machine_mapcss.\n", ) - out_path: Path = Path("out") / "map_machine_mapcss" + out_path: Path = OUTPUT_PATH / "map_machine_mapcss" - assert out_path.is_dir() assert out_path.is_dir() assert (out_path / "icons" / "apple.svg").is_file() assert (out_path / "map_machine.mapcss").is_file() @@ -120,7 +119,7 @@ def test_element() -> None: COMMAND_LINES["element"], b"INFO Element is written to out/element.svg.\n", ) - assert (Path("out") / "element.svg").is_file() + assert (OUTPUT_PATH / "element.svg").is_file() def test_unwrapped_element() -> None: @@ -140,5 +139,5 @@ def test_tile() -> None: b"INFO SVG file is rasterized to out/tiles/tile_18_160199_88904.png.\n", ) - assert (Path("out") / "tiles" / "tile_18_160199_88904.svg").is_file() - assert (Path("out") / "tiles" / "tile_18_160199_88904.png").is_file() + assert (OUTPUT_PATH / "tiles" / "tile_18_160199_88904.svg").is_file() + assert (OUTPUT_PATH / "tiles" / "tile_18_160199_88904.png").is_file()