Skip to content

Fix broken doctests in geotensor module#48

Open
toadlyBroodle wants to merge 1 commit into
spaceml-org:feature/geotensor_npapifrom
toadlyBroodle:fix/doctest-fixes-on-feature
Open

Fix broken doctests in geotensor module#48
toadlyBroodle wants to merge 1 commit into
spaceml-org:feature/geotensor_npapifrom
toadlyBroodle:fix/doctest-fixes-on-feature

Conversation

@toadlyBroodle

Copy link
Copy Markdown

Fix broken doctests in geotensor module

Refs #40. Re-targets the doctest-fix portion of #45 against feature/geotensor_npapi per maintainer request.

Summary

Running pytest --doctest-modules georeader/geotensor.py on feature/geotensor_npapi fails on 17 of 18 examples. This PR fixes the breakages, adds make test-doctest, and configures default doctest flags.

Before: 17 failed, 1 passed
After: 17 passed, 1 skipped (resize, depends on optional skimage)

Changes

Import path

  • 9 doctest examples used from georeader import GeoTensor, but GeoTensor is not exposed at the package level. Changed to from georeader.geotensor import GeoTensor to match the canonical import used everywhere else in the codebase (abstract_reader.py, save.py, mosaic.py, read.py, etc.).

Missing setup

  • 6 examples (expand_dims, pad_array, resize, transpose, write_from_window, concatenate) referenced transform and crs without defining them, raising NameError. Added explicit setup using rasterio.Affine(...) and an EPSG string.

Mismatched expected output

  • GeoTensor.__add__: print(gt_offset.shape) had no expected output line. Added (3, 100, 100).
  • GeoTensor.isel: expected (500000, 4650000) but actual repr is (500000.0, 4650000.0). Updated.

Aspirational examples

  • GeoTensor.footprint had 6 examples; some used fake load_file('image1.tif') paths or wrote files. Reworked: examples 1, 2, 5, 6 now use real checked output; file-dependent lines in examples 3 and 4 marked # doctest: +SKIP.
  • GeoTensor.resize requires skimage (optional dependency). Marked example +SKIP.

Other fixes

  • GeoTensor.concatenate example called bare concatenate(...) instead of the classmethod GeoTensor.concatenate(...). Fixed.
  • GeoTensor.pad_array example asserted on gt.shape instead of the returned padded tensor. Fixed.

Tooling

  • pyproject.toml: added doctest_optionflags = ["ELLIPSIS", "NORMALIZE_WHITESPACE"] so future doctests tolerate whitespace and truncated reprs.
  • Makefile: added make test-doctest target.

Scope

Only georeader/geotensor.py is touched. rasterio_reader.py and io.py also have failing doctests (file-path dependent), but most of their examples would need per-line +SKIP markers that obscure the docs. Happy to address them in a follow-up if you'd prefer.

Test results

$ make test-doctest
17 passed, 1 skipped in 0.46s

Existing test suite unaffected.

Several doctests in geotensor.py were failing:
- 9 examples used `from georeader import GeoTensor` but GeoTensor is
  not exposed at the package level. Changed to the canonical
  `from georeader.geotensor import GeoTensor` (matches the rest of the
  codebase).
- 6 examples referenced `transform` and `crs` without defining them.
  Added explicit setup with `rasterio.Affine` and an EPSG string.
- `__add__` and `isel` print examples lacked or had wrong expected output.
  Updated to match actual repr (float coords, etc).
- `footprint` had several aspirational examples (load_file with fake
  paths, writing files). Reworked to use checked output for runnable
  examples and marked file-dependent lines with +SKIP.
- `resize` examples are marked +SKIP because skimage is an optional dep.
- `concatenate` example was calling a bare `concatenate(...)` function
  instead of the classmethod `GeoTensor.concatenate(...)`.

Also:
- Add `doctest_optionflags = ["ELLIPSIS", "NORMALIZE_WHITESPACE"]` to
  pyproject.toml so doctest output comparisons tolerate whitespace and
  truncated reprs.
- Add `make test-doctest` target to run doctests on geotensor.py.

After: 17 passed, 1 skipped (resize, optional skimage dep).
Before: 17 failed, 1 passed.

Refs spaceml-org#40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant