Skip to content

Test: cover gil_friendly kwarg behaviour in geotiff writer/compression #1830

@brendancol

Description

@brendancol

Coverage gap

PR #1826 added a gil_friendly: bool = False parameter to:

  • xrspatial.geotiff._compression.deflate_compress
  • xrspatial.geotiff._compression.compress
  • xrspatial.geotiff._writer._prepare_strip
  • xrspatial.geotiff._writer._prepare_tile
  • xrspatial.geotiff._writer._compress_block

The flag gates a documented optimisation: when True, deflate is forced through stdlib zlib.compress (which releases the GIL) even if the optional deflate (libdeflate) PyPI binding is installed. The libdeflate binding does not release the GIL, so the writer's parallel strip/tile paths pass gil_friendly=True to keep thread-pool scaling (measured 5x vs 1.2x with 8 threads in the PR description).

The PR also added a one-shot UserWarning in deflate_compress when libdeflate is missing.

Behaviour with no direct test coverage

  1. deflate_compress(data, gil_friendly=True) with libdeflate installed must bypass the libdeflate binding and call zlib.compress instead. A regression dropping the and not gil_friendly clause in _compression.py:137 would silently re-route the parallel writer through the GIL-holding binding and ship the documented thread-pool scaling regression.
  2. deflate_compress(data, gil_friendly=False) with libdeflate installed must call deflate.zlib_compress (output stays wire-compatible but the call path differs).
  3. compress(compression=DEFLATE, gil_friendly=True/False) must forward the flag to deflate_compress. Other codec branches (LZW/PackBits/zstd/lz4) must ignore the flag since their bindings already release the GIL.
  4. The one-shot fallback UserWarning must fire exactly once when libdeflate is missing (existing test in test_parallel_writer_1800.py::test_deflate_compress_fallback_when_libdeflate_missing suppresses the warning rather than asserting it; the latch behaviour is uncovered).
  5. The parallel strip path in _write_stripped must invoke _prepare_strip with gil_friendly=True; the sequential strip path must invoke it with the default (False). Same matrix for _write_tiled -> _prepare_tile and the write_streaming parallel-tile branch through _compress_block.

These are all Cat 4 HIGH parameter-coverage gaps under the test-coverage sweep rubric: a documented bool flag with multiple meaningful branches, none of which is directly exercised. Existing tests (test_parallel_writer_1800.py, test_compression_level.py) cover round-trip correctness and the thread-pool dispatch but never observe which deflate backend ran.

Fix scope

Tests only. No source changes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions