Skip to content

test: cover utils helpers and xsg accessor; fix deprecations#124

Open
Divyateja2709 wants to merge 1 commit intoioos:mainfrom
Divyateja2709:tests/utils-and-accessor-coverage
Open

test: cover utils helpers and xsg accessor; fix deprecations#124
Divyateja2709 wants to merge 1 commit intoioos:mainfrom
Divyateja2709:tests/utils-and-accessor-coverage

Conversation

@Divyateja2709
Copy link
Copy Markdown

This PR improves test coverage and reliability by adding unit tests for utility functions and accessor behavior, along with small fixes to ensure correct warnings and robust handling of inputs.

Changes

Tests

  • Added tests/test_utils.py:

    • Covers format_bytes
    • Covers asdatetime (None, datetime, cftime, ISO string)
    • Covers compute_2d_subset_mask (full vs partial coverage)
    • Tests utils.assign_ugrid_topology (deprecation + delegation)
  • Added tests/test_accessor.py:

    • Tests ds.xsg behavior when no grid is recognized:

      • Emits warning
      • subset_polygon and subset_bbox return None
      • subset_vars passthrough
      • has_vertical_levels behavior
  • Updated tests/test_grids/test_sgrid.py:

    • Defines default zarr__version__ = 0 when optional dependencies are missing
    • Prevents test collection failures (NameError)

Fixes / Improvements

  • Deprecation handling

    • Correct use of warnings.warn(...) with proper signature and stacklevel=2
    • Fixed deprecation message to reference assign_ugrid_topology correctly
  • Input robustness

    • normalize_polygon_x_coords now coerces inputs using np.asarray(poly)
    • Ensures consistent behavior for list/tuple polygon inputs

Why this matters

  • Improves coverage of previously untested core utilities
  • Ensures consistent and predictable accessor behavior in edge cases
  • Fixes incorrect deprecation warnings so users receive proper guidance
  • Prevents CI/test failures when optional dependencies are unavailable
  • Strengthens overall reliability and maintainability of the package

Notes

  • This PR focuses on tests and small reliability fixes only
  • Independent of README/documentation PR (docs/readme-quickstart-fixes)

- Add tests for format_bytes, asdatetime, compute_2d_subset_mask, and
  utils.assign_ugrid_topology forwarding with DeprecationWarning
- Add accessor tests for unknown-grid warning and None subset behavior
- Fix warnings.warn argument order in assign_ugrid_topology; correct message
- Coerce polygon coords via np.asarray in normalize_polygon_x_coords
- Define zarr__version__ when fsspec/zarr import fails (test collection)

Made-with: Cursor
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