Skip to content

refactor(geotiff): extract GeoTIFF fixture builder#2912

Open
Melissari1997 wants to merge 1 commit into
xarray-contrib:mainfrom
Melissari1997:2423-extract-geotiff-fixtures
Open

refactor(geotiff): extract GeoTIFF fixture builder#2912
Melissari1997 wants to merge 1 commit into
xarray-contrib:mainfrom
Melissari1997:2423-extract-geotiff-fixtures

Conversation

@Melissari1997
Copy link
Copy Markdown
Contributor

Summary

Closes #2423.
Extracts the duplicated hand-built TIFF helper logic that existed in two test modules into a single shared xrspatial/geotiff/tests/_geotiff_fixtures.py module.

Changes

  • New: xrspatial/geotiff/tests/_geotiff_fixtures.py — exposes write_minimal_tiff(path, *, geokeys=None, geo_ascii=None) that builds a 4x4 float32 TIFF with optional GeoKeyDirectory (tag 34735) and/or GeoAsciiParams (tag 34737) payloads.
  • Refactored: unit/test_geotags.py::_write_tiff_with_geokeys — now delegates to write_minimal_tiff; the wrapper still builds the GeoKeyDirectory values from the model_type/projected_cs_type/geographic_type parameters so callers are unchanged.
  • Refactored: unit/test_metadata.py::_write_minimal_tiff_with_wkt — now delegates to write_minimal_tiff; the wrapper remains for the GTCitationGeoKey construction.
  • Cleanup: Removed unused from pathlib import Path from test_geotags.py.

Scope notes

The grep for "II.*42.*ifd_start" across the geotiff test suite found other inline TIFF builders, but all of them differ in dimensions, dtype, tag set, or structure (e.g. palette TIFFs, sub-byte bit depths, multi-band planar layouts, transformation-matrix geo models). None shared the 4x4/float32/GeoKey pattern, so they are left in place.

Consolidate duplicated hand-built TIFF helper functions into a single
parameterised `write_minimal_tiff` utility in `_geotiff_fixtures.py`.

This replaces the redundant implementations in `test_geotags.py` and
`test_metadata.py`, reducing code duplication and improving
maintainability of the GeoTIFF test suite.
@Melissari1997
Copy link
Copy Markdown
Contributor Author

PR Review: Extract shared hand-built TIFF helper to tests/_geotiff_fixtures.py

Blockers (must fix before merge)

None.

Suggestions (should fix, not blocking)

None.

Nits (optional improvements)

None.

What looks good

  • Clean extraction: the two inline TIFF builders (_write_tiff_with_geokeys in test_geotags.py and _write_minimal_tiff_with_wkt in test_metadata.py) both now delegate to the single write_minimal_tiff in _geotiff_fixtures.py.
  • Parameterised API (geokeys=None, geo_ascii=None) covers both use cases without coupling callers to shared internals.
  • The wrapper _write_tiff_with_geokeys in test_geotags.py remains as a thin convenience layer so the existing test call sites require no changes — zero behaviour modification.
  • No dead code left behind: unused from pathlib import Path was removed from test_geotags.py.
  • All 3357 tests pass (1015 skipped due to missing dependencies, which is pre-existing).

Checklist

  • No behaviour change to either existing test; both keep their current assertions
  • Reviewed other inline TIFF builders across the test suite — none share the same 4x4/float32/GeoKey structure, so they remain in place
  • No unused imports remain
  • All geotiff tests pass

@github-actions github-actions Bot added the performance PR touches performance-sensitive code label Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance PR touches performance-sensitive code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tests: extract shared hand-built TIFF helper to tests/_geotiff_fixtures.py

1 participant