Skip to content

Commit 9cfd585

Browse files
committed
Add CLI test traceback printer
1 parent 8294818 commit 9cfd585

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

tests/test_cli.py

+19-21
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,46 @@
1-
import os
21
import logging
2+
import os
3+
import traceback
34

45
import pytest
56
from click.testing import CliRunner
6-
77
from osmox import cli
88

99
logging.basicConfig(level=logging.INFO)
1010

11+
1112
@pytest.fixture
1213
def fixtures_root():
1314
return os.path.abspath(os.path.join(os.path.dirname(__file__), "fixtures"))
1415

16+
1517
@pytest.fixture
1618
def config_path(fixtures_root):
1719
return os.path.join(fixtures_root, "test_config.json")
1820

21+
1922
@pytest.fixture
2023
def toy_osm_path(fixtures_root):
2124
return os.path.join(fixtures_root, "park.osm")
2225

26+
2327
@pytest.fixture
2428
def runner():
2529
return CliRunner()
2630

31+
32+
def check_exit_code(result):
33+
"Print full traceback if the CLI runner failed"
34+
if result.exit_code != 0:
35+
traceback.print_tb(result.exc_info[-1])
36+
assert result.exit_code == 0
37+
38+
2739
def test_cli_with_default_args(runner, config_path, toy_osm_path):
2840
# Test the command with minimal arguments
29-
result = runner.invoke(
30-
cli.run,
31-
[
32-
config_path,
33-
toy_osm_path,
34-
'output_test'
35-
]
36-
)
37-
#print(result.output)
38-
assert result.exit_code == 0
41+
result = runner.invoke(cli.run, [config_path, toy_osm_path, "output_test"])
42+
43+
check_exit_code(result)
3944
assert "geopackage" in result.exit_code
4045
assert "epsg:4326" in result.exit_code
4146

@@ -44,13 +49,6 @@ def test_cli_output_formats(runner, config_path, toy_osm_path):
4449
for output_format in ["geojson", "geopackage", "geoparquet"]:
4550
result = runner.invoke(
4651
cli.run,
47-
[
48-
config_path,
49-
toy_osm_path,
50-
'output_test',
51-
"-f", output_format,
52-
"-crs", "epsg:4326"
53-
]
52+
[config_path, toy_osm_path, "output_test", "-f", output_format, "-crs", "epsg:4326"],
5453
)
55-
print(result.output)
56-
assert result.exit_code == 0
54+
check_exit_code(result)

0 commit comments

Comments
 (0)