1
- import os
2
1
import logging
2
+ import os
3
+ import traceback
3
4
4
5
import pytest
5
6
from click .testing import CliRunner
6
-
7
7
from osmox import cli
8
8
9
9
logging .basicConfig (level = logging .INFO )
10
10
11
+
11
12
@pytest .fixture
12
13
def fixtures_root ():
13
14
return os .path .abspath (os .path .join (os .path .dirname (__file__ ), "fixtures" ))
14
15
16
+
15
17
@pytest .fixture
16
18
def config_path (fixtures_root ):
17
19
return os .path .join (fixtures_root , "test_config.json" )
18
20
21
+
19
22
@pytest .fixture
20
23
def toy_osm_path (fixtures_root ):
21
24
return os .path .join (fixtures_root , "park.osm" )
22
25
26
+
23
27
@pytest .fixture
24
28
def runner ():
25
29
return CliRunner ()
26
30
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
+
27
39
def test_cli_with_default_args (runner , config_path , toy_osm_path ):
28
40
# 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 )
39
44
assert "geopackage" in result .exit_code
40
45
assert "epsg:4326" in result .exit_code
41
46
@@ -44,13 +49,6 @@ def test_cli_output_formats(runner, config_path, toy_osm_path):
44
49
for output_format in ["geojson" , "geopackage" , "geoparquet" ]:
45
50
result = runner .invoke (
46
51
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" ],
54
53
)
55
- print (result .output )
56
- assert result .exit_code == 0
54
+ check_exit_code (result )
0 commit comments