@@ -1465,3 +1465,48 @@ def test_cohort_data(fixture, api):
14651465 df_cohorts = api .cohorts (cohort_name )
14661466 # Check output.
14671467 validate_cohort_data (df_cohorts , cohort_data_expected_columns ())
1468+
1469+
1470+ # ------------------------------------------------------------------
1471+ # Tests for cohort_geometries()
1472+ # ------------------------------------------------------------------
1473+
1474+
1475+ @parametrize_with_cases ("fixture,api" , cases = case_ag3_sim )
1476+ def test_cohort_geometries (fixture , api ):
1477+ """Test that GeoJSON geometry can be loaded for a valid cohort set."""
1478+ geojson = api .cohort_geometries ("admin1_month" )
1479+ assert isinstance (geojson , dict )
1480+ assert geojson ["type" ] == "FeatureCollection"
1481+ assert "features" in geojson
1482+ assert len (geojson ["features" ]) > 0
1483+ for feature in geojson ["features" ]:
1484+ assert feature ["type" ] == "Feature"
1485+ assert "geometry" in feature
1486+ assert "properties" in feature
1487+ assert "coordinates" in feature ["geometry" ]
1488+
1489+
1490+ @parametrize_with_cases ("fixture,api" , cases = case_ag3_sim )
1491+ def test_cohort_geometries_admin1_year (fixture , api ):
1492+ """Test that GeoJSON geometry can be loaded for admin1_year."""
1493+ geojson = api .cohort_geometries ("admin1_year" )
1494+ assert isinstance (geojson , dict )
1495+ assert geojson ["type" ] == "FeatureCollection"
1496+ assert len (geojson ["features" ]) > 0
1497+
1498+
1499+ @parametrize_with_cases ("fixture,api" , cases = case_ag3_sim )
1500+ def test_cohort_geometries_invalid_cohort_set (fixture , api ):
1501+ """Test that an invalid cohort_set raises ValueError."""
1502+ with suppress_type_checks ():
1503+ with pytest .raises (ValueError , match = "not a valid cohort set" ):
1504+ api .cohort_geometries ("invalid_set" )
1505+
1506+
1507+ @parametrize_with_cases ("fixture,api" , cases = case_ag3_sim )
1508+ def test_cohort_geometries_cached (fixture , api ):
1509+ """Test that the second call returns the same cached object."""
1510+ g1 = api .cohort_geometries ("admin1_month" )
1511+ g2 = api .cohort_geometries ("admin1_month" )
1512+ assert g1 is g2
0 commit comments