From eb4dbb35f1ffa670a2ae0dd69c8be458105166f1 Mon Sep 17 00:00:00 2001 From: vschaffn Date: Wed, 30 Oct 2024 14:09:51 +0100 Subject: [PATCH] test: add a cli test --- tests/test_cli.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/test_cli.py diff --git a/tests/test_cli.py b/tests/test_cli.py new file mode 100644 index 00000000..34bbf960 --- /dev/null +++ b/tests/test_cli.py @@ -0,0 +1,30 @@ +"""Function to test the CLI""" + +import subprocess + +import xdem + + +class TestCLI: + # Define paths to the DEM files using xDEM examples + ref_dem_path = xdem.examples.get_path("longyearbyen_ref_dem") + tba_dem_path = xdem.examples.get_path("longyearbyen_tba_dem") + + def test_xdem_cli(self) -> None: + try: + # Run the xDEM CLI command with the reference and secondary DEM files + result = subprocess.run( + ["xdem", self.ref_dem_path, self.tba_dem_path], + capture_output=True, + text=True, + ) + assert "hello world" in result.stdout + assert result.returncode == 0 + + except FileNotFoundError as e: + # In case 'xdem' is not found + raise AssertionError(f"CLI command 'xdem' not found : {e}") + + except Exception as e: + # Any other errors during subprocess run + raise AssertionError(f"An error occurred while running the CLI: {e}")