Skip to content

Commit f050c91

Browse files
committed
test: update cli test for coregistration
1 parent 58ed8fb commit f050c91

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

tests/test_cli.py

+32-4
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,54 @@
11
"""Function to test the CLI"""
2-
2+
import os
33
import subprocess
44

5+
import rasterio
6+
57
import xdem
8+
from xdem import dem_coregistration
69

710

811
class TestCLI:
912
# Define paths to the DEM files using xDEM examples
1013
ref_dem_path = xdem.examples.get_path("longyearbyen_ref_dem")
1114
tba_dem_path = xdem.examples.get_path("longyearbyen_tba_dem")
15+
aligned_dem_path = "aligned_dem.tiff"
16+
inlier_mask_path = "inlier_mask.tiff"
1217

13-
def test_xdem_cli(self) -> None:
18+
def test_xdem_cli_coreg(self) -> None:
1419
try:
1520
# Run the xDEM CLI command with the reference and secondary DEM files
1621
result = subprocess.run(
17-
["xdem", self.ref_dem_path, self.tba_dem_path],
22+
["xdem", "coregister", self.ref_dem_path, self.tba_dem_path],
1823
capture_output=True,
1924
text=True,
2025
)
21-
assert "hello world" in result.stdout
26+
27+
# Assert ClI ran successfully
2228
assert result.returncode == 0
2329

30+
# Verify the existence of the output files
31+
assert os.path.exists(self.aligned_dem_path), f"Aligned DEM not found: {self.aligned_dem_path}"
32+
assert os.path.exists(self.inlier_mask_path), f"Inlier mask not found: {self.inlier_mask_path}"
33+
34+
# Retrieve ground truth
35+
true_coreg_dem, coreg_method, out_stats, true_inlier_mask = dem_coregistration(
36+
xdem.DEM(self.tba_dem_path), xdem.DEM(self.ref_dem_path), self.aligned_dem_path
37+
)
38+
39+
# Load elements processed by the xDEM CLI command
40+
aligned_dem = xdem.DEM(self.aligned_dem_path)
41+
with rasterio.open(self.inlier_mask_path) as src:
42+
inlier_mask = src.read(1)
43+
44+
# Verify match with ground truth
45+
assert aligned_dem == true_coreg_dem, "Aligned DEM does not match the ground truth."
46+
assert inlier_mask.all() == true_inlier_mask.all(), "Inlier mask does not match the ground truth."
47+
48+
# Erase files
49+
os.remove(self.aligned_dem_path)
50+
os.remove(self.inlier_mask_path)
51+
2452
except FileNotFoundError as e:
2553
# In case 'xdem' is not found
2654
raise AssertionError(f"CLI command 'xdem' not found : {e}")

0 commit comments

Comments
 (0)