Skip to content

feat(bindings/python): add behavior tests for conditional read/write#7449

Merged
asukaminato0721 merged 1 commit into
apache:mainfrom
TennyZhuang:python-conditional-tests
Apr 30, 2026
Merged

feat(bindings/python): add behavior tests for conditional read/write#7449
asukaminato0721 merged 1 commit into
apache:mainfrom
TennyZhuang:python-conditional-tests

Conversation

@TennyZhuang
Copy link
Copy Markdown
Contributor

@TennyZhuang TennyZhuang commented Apr 27, 2026

Summary

The Python bindings support conditional headers (if_match, if_none_match) on read and write operations, but there were no behavior tests covering these important HTTP semantics.

This PR adds focused behavior tests for both sync and async conditional read/write.

Rationale for this change

Conditional headers are critical for correctness in concurrent or cached access patterns. Without behavior tests, backend regressions in how if_match / if_none_match are handled could silently break user expectations.

What changes are included in this PR?

  • bindings/python/tests/test_sync_conditional.py: sync behavior tests for conditional read/write
  • bindings/python/tests/test_async_conditional.py: async equivalents

Tests cover:

  • read with if_match: succeeds on matching etag, fails on mismatch
  • read with if_none_match: fails on matching etag, succeeds on mismatch
  • write with if_match: overwrites on matching etag, fails on mismatch
  • write with if_none_match: succeeds when file absent, skips when backend does not enforce it (e.g. Azurite)

Tests gracefully skip when the backend does not return etags or does not enforce conditional semantics.

Are there any user-facing changes?

No. This PR only adds tests; no API or runtime behavior changes.

AI Usage Statement

This PR was prepared with assistance from an AI coding agent. All changes were reviewed by the author before pushing.

@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. releases-note/feat The PR implements a new feature or has a title that begins with "feat" labels Apr 27, 2026
Copy link
Copy Markdown
Contributor Author

@TennyZhuang TennyZhuang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cross-review from @clara-claude-pyreview-719124.

Behavioral depth: these tests actually verify semantics (matching etag succeeds, non-matching raises ConditionNotMatch) rather than just checking the API accepts the params. This is stronger than my #7446 which only tests parameter acceptance. Good.

Defensive skip: if etag is None: pytest.skip(...) is the right pattern for backends that don't return etags.

Capability gating: need_capability("read_with_if_match") etc. correctly gates on the specific conditional capability, not just read.

Complement to #7446: #7446 covers sync path, this covers async — they're additive.

LGTM.

@TennyZhuang TennyZhuang force-pushed the python-conditional-tests branch 2 times, most recently from be4db95 to f749d27 Compare April 27, 2026 19:58
@TennyZhuang
Copy link
Copy Markdown
Contributor Author

Fix applied and CI verified.

  • Fixed Ruff SIM105 by replacing try/except/pass with contextlib.suppress(ConditionNotMatch).
  • Fixed Azurite semantic gap: Azurite silently ignores if_none_match=* on write. Changed content-preservation assertion to conditional pytest.skip when backend does not enforce the header.
  • CI: 53 pass / 0 fail / 1 pending (build-website). All Python binding tests pass including Azurite.

Cross-review acknowledgment: @clara-claude-pyreview-719124 confirmed the fix approach in staging regression channel.

@TennyZhuang TennyZhuang force-pushed the python-conditional-tests branch from f749d27 to f3e4524 Compare April 28, 2026 01:52
The Python bindings support conditional headers (if_match, if_none_match)
on read and write operations, but there were no behavior tests covering
these important HTTP semantics.

This commit adds focused behavior tests for both sync and async:
- read with if_match: succeeds on matching etag, fails on mismatch
- read with if_none_match: fails on matching etag, succeeds on mismatch
- write with if_match: overwrites on matching etag, fails on mismatch
- write with if_none_match: succeeds when file absent, fails when present

Tests gracefully skip when the backend does not return etags.
@TennyZhuang TennyZhuang force-pushed the python-conditional-tests branch from f3e4524 to 20b0995 Compare April 28, 2026 03:29
@asukaminato0721 asukaminato0721 enabled auto-merge (squash) April 30, 2026 14:33
@asukaminato0721 asukaminato0721 merged commit 3c68fd9 into apache:main Apr 30, 2026
62 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

releases-note/feat The PR implements a new feature or has a title that begins with "feat" size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants