Skip to content

Commit b9af0e1

Browse files
committed
test: update cli test for coregistration
1 parent b6a5e14 commit b9af0e1

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from setuptools import find_packages, setup
44

5-
65
setup(
76
name="xdem",
87
use_scm_version=True, # Enable versioning with setuptools_scm

tests/test_cli.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,55 @@
11
"""Function to test the CLI"""
22

3+
import os
34
import subprocess
45

6+
import rasterio
7+
58
import xdem
9+
from xdem import dem_coregistration
610

711

812
class TestCLI:
913
# Define paths to the DEM files using xDEM examples
1014
ref_dem_path = xdem.examples.get_path("longyearbyen_ref_dem")
1115
tba_dem_path = xdem.examples.get_path("longyearbyen_tba_dem")
16+
aligned_dem_path = "aligned_dem.tiff"
17+
inlier_mask_path = "inlier_mask.tiff"
1218

13-
def test_xdem_cli(self) -> None:
19+
def test_xdem_cli_coreg(self) -> None:
1420
try:
1521
# Run the xDEM CLI command with the reference and secondary DEM files
1622
result = subprocess.run(
17-
["xdem", self.ref_dem_path, self.tba_dem_path],
23+
["xdem", "coregister", self.ref_dem_path, self.tba_dem_path],
1824
capture_output=True,
1925
text=True,
2026
)
21-
assert "hello world" in result.stdout
27+
28+
# Assert ClI ran successfully
2229
assert result.returncode == 0
2330

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

0 commit comments

Comments
 (0)