UPDATE
This commit is contained in:
@@ -2,7 +2,11 @@ from datetime import date
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
from location_data.data_driven_subdivision import sync_block_subdivision_with_result
|
||||
from location_data.data_driven_subdivision import (
|
||||
EmptyObservationDatasetError,
|
||||
build_clustering_dataset,
|
||||
sync_block_subdivision_with_result,
|
||||
)
|
||||
from location_data.models import (
|
||||
AnalysisGridCell,
|
||||
AnalysisGridObservation,
|
||||
@@ -133,3 +137,39 @@ class DataDrivenSubdivisionSyncTests(TestCase):
|
||||
self.subdivision.metadata["data_driven_subdivision"]["cluster_count"],
|
||||
2,
|
||||
)
|
||||
|
||||
def test_build_clustering_dataset_raises_clear_error_when_all_selected_features_are_null(self):
|
||||
cell = AnalysisGridCell.objects.create(
|
||||
soil_location=self.location,
|
||||
block_subdivision=self.subdivision,
|
||||
block_code="block-1",
|
||||
cell_code="cell-null",
|
||||
chunk_size_sqm=900,
|
||||
geometry=self.boundary,
|
||||
centroid_lat="35.689200",
|
||||
centroid_lon="51.389200",
|
||||
)
|
||||
observation = AnalysisGridObservation.objects.create(
|
||||
cell=cell,
|
||||
run=self.run,
|
||||
temporal_start=date(2025, 1, 1),
|
||||
temporal_end=date(2025, 1, 31),
|
||||
metadata={"job_refs": {"ndvi": "job-1"}},
|
||||
)
|
||||
|
||||
with self.assertLogs("location_data.data_driven_subdivision", level="ERROR") as captured:
|
||||
with self.assertRaisesRegex(
|
||||
EmptyObservationDatasetError,
|
||||
"Upstream processing completed but no usable feature values were persisted.",
|
||||
):
|
||||
build_clustering_dataset(
|
||||
observations=[observation],
|
||||
selected_features=["ndvi", "ndwi", "lst_c", "soil_vv_db"],
|
||||
run=self.run,
|
||||
location=self.location,
|
||||
)
|
||||
|
||||
joined = "\n".join(captured.output)
|
||||
self.assertIn("No usable observations available for clustering", joined)
|
||||
self.assertIn('"run_id": {}'.format(self.run.id), joined)
|
||||
self.assertIn('"region_id": {}'.format(self.location.id), joined)
|
||||
|
||||
Reference in New Issue
Block a user