Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1c9c556

Browse files
committedNov 18, 2024·
test: add a cli test
1 parent 2af566b commit 1c9c556

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
 

‎tests/test_cli.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""Function to test the CLI"""
2+
3+
import subprocess
4+
5+
import xdem
6+
7+
8+
class TestCLI:
9+
# Define paths to the DEM files using xDEM examples
10+
ref_dem_path = xdem.examples.get_path("longyearbyen_ref_dem")
11+
tba_dem_path = xdem.examples.get_path("longyearbyen_tba_dem")
12+
13+
def test_xdem_cli(self) -> None:
14+
try:
15+
# Run the xDEM CLI command with the reference and secondary DEM files
16+
result = subprocess.run(
17+
["xdem", self.ref_dem_path, self.tba_dem_path],
18+
capture_output=True,
19+
text=True,
20+
)
21+
assert "hello world" in result.stdout
22+
assert result.returncode == 0
23+
24+
except FileNotFoundError as e:
25+
# In case 'xdem' is not found
26+
raise AssertionError(f"CLI command 'xdem' not found : {e}")
27+
28+
except Exception as e:
29+
# Any other errors during subprocess run
30+
raise AssertionError(f"An error occurred while running the CLI: {e}")

0 commit comments

Comments
 (0)
Please sign in to comment.