contour: test coverage for all-equal auto-levels and empty explicit levels#3353
Conversation
Melissari1997
left a comment
There was a problem hiding this comment.
PR Review: Test coverage for all-equal auto-levels and empty explicit levels
Changed file: xrspatial/tests/test_contour.py
Blockers (must fix before merge)
None. All tests are logically correct and target real coverage gaps not exercised by existing tests.
Suggestions (should fix, not blocking)
S1 — Use create_test_raster instead of raw xr.DataArray
All three new tests construct the raster with raw xr.DataArray(...) rather than the project's create_test_raster helper. Every other test in this file that exercises contour behavior uses create_test_raster, which sets up dims, coords, units, and CRS attrs consistently. Using the raw constructor means:
- No coords are set
- The CRS attribute is absent
At minimum the geopandas test should test with a CRS-bearing raster to exercise the CRS-propagation path (consistent with other empty-result geopandas tests at test_geopandas_empty_result_keeps_crs and test_geopandas_all_nan_keeps_crs).
xrspatial/tests/test_contour.py:1515, 1527, 1537
S2 — Class naming doesn't follow project convention
The class is named TestIssue3352Coverage. The existing convention is descriptive class names like TestEdgeCases, TestNaNBackendParity, TestGeoDataFrame, etc. A descriptive name would be more maintainable.
xrspatial/tests/test_contour.py:1507
S3 — test_contours_empty_explicit_levels_geopandas misses column assertions
The existing test test_geopandas_empty_result_keeps_crs asserts 'level' in gdf.columns and 'geometry' in gdf.columns on an empty GeoDataFrame. The new geopandas test checks isinstance and len == 0 but does not verify the expected schema.
xrspatial/tests/test_contour.py:1540-1542
Nits (optional improvements)
N1 — Double-quote style for dims strings
The rest of the file consistently uses single quotes for string literals (dims=['y', 'x']). All three new tests use double quotes (dims=["y", "x"]).
xrspatial/tests/test_contour.py:1515-1516, 1528, 1538
N2 — assert result == [] vs explicit type + length checks
assert result == [] works for the numpy return case. However, other tests in this file (e.g. test_no_contours_flat) use assert isinstance(result, list) separately. An object of the wrong type (e.g. a tuple ()) would slip past == [].
xrspatial/tests/test_contour.py:1519, 1531
What looks good
- Tests target genuine coverage gaps —
test_no_contours_flattests flat rasters with explicit levels, so thelevels=Noneauto-level path was not exercised withvmin == vmax. - Both return types (numpy and geopandas) are covered for the empty-levels case.
pytest.importorskip("geopandas")is used for the geopandas test, consistent with the rest of the file.- Docstrings are clear and explain why these cases matter.
- Minimal and focused — each test does exactly one thing.
Checklist
- Covers stated gap: all-equal auto-levels, empty explicit levels
- Correct assertions
- Follows file conventions (see S1, S2, N1)
-
pytest.importorskipused appropriately
Melissari1997
left a comment
There was a problem hiding this comment.
Follow-up review (after fix commits)
Disposition of previous findings
| Finding | Status | Notes |
|---|---|---|
S1 — use create_test_raster |
Fixed | All three tests now use create_test_raster |
| S2 — class naming convention | Fixed | Renamed to TestFlatAutoLevelsAndEmptyLevels |
| S3 — geopandas column assertions | Fixed | level and geometry columns now asserted |
| N1 — double-quote style | Fixed | Switched to single quotes throughout |
N2 — bare == [] assert style |
Fixed | Both numpy tests now use isinstance + len |
No new issues found. All previous findings are resolved.
brendancol
left a comment
There was a problem hiding this comment.
@Melissari1997 LGTM...thanks again
Closes #3352
Summary
test_contours_flat_auto_levels— asserts an all-equal raster withlevels=Nonereturns[](covers thevmin == vmaxbranch in auto-level generation)test_contours_empty_explicit_levels_numpy— assertslevels=[]with numpy return type returns[]test_contours_empty_explicit_levels_geopandas— assertslevels=[]with geopandas return type returns an empty GeoDataFrameBackend coverage
Numpy only (both edge cases hit the early-return path before backend dispatch).