Skip to content

Compare read-only containers recursively in test operations - #257

Merged
stefankoegl merged 2 commits into
stefankoegl:masterfrom
liugedragon:fix/readonly-mapping-tests
Nov 10, 2026
Merged

stefankoegl merged 2 commits into
stefankoegl:masterfrom
liugedragon:fix/readonly-mapping-tests

Conversation

@liugedragon

@liugedragon liugedragon commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Whole read-only containers can fall back to Python equality instead of applying JSON equality recursively. For example, MappingProxyType({'a': True}) passes a root test against {'a': 1}, and (True,) passes against (1,). Equivalent list and tuple values can also compare unequal.

Use Mapping and non-text Sequence in _json_equal. Both are already accepted by the module and documented in its stubs; immutable sequences are also handled by the existing restoration code. Objects and arrays are compared recursively under the RFC 6902 rules. Strings and bytes remain scalar values, and mutation requirements are unchanged.

Regression coverage includes root and nested read-only mappings, tuple/list comparisons in both directions, a generic read-only sequence, Boolean/number rejection, numeric 1/1.0 equivalence, length/order differences, text/bytes exclusions, and preservation of input identity and content. The sequence follow-up adds 95 subcases; 33 fail on the previous PR revision and pass after the fix.

Validation on Windows / Python 3.13.4:

  • python tests.py: 322 tests run, OK (1 skipped).
  • Standard-profile python property_tests.py: 26 tests, OK.
  • CI's fatal Flake8 checks: passed with Flake8 7.3.0.
  • Additional bounded local RFC oracle: three properties at 1,000 examples each, mixing native and read-only mappings/sequences; all passed.
  • git diff --check: passed.

Earlier validation: a 5,000-example single-process stress run hit a Hypothesis MemoryError and replay error; the affected two properties each passed at the same budget in fresh processes. On the previous CI revision, all unit-test and property-test matrix steps passed; coverage-upload jobs failed while downloading the Coveralls binary/checksum.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Note

Copilot was unable to run its full agentic suite in this review.

Copilot review overview

2 open issues
What changed in this PR

This PR updates JSON Patch test operation equality semantics so read-only mapping types (e.g., MappingProxyType) are compared structurally instead of via Python’s default equality, preventing True/1 and False/0 from being treated as equal.

Changes:

  • Broaden _json_equal mapping comparison from MutableMapping to Mapping.
  • Add regression tests ensuring test fails for bool-vs-int mismatches on read-only mappings and does not mutate input documents on success/failure.
File Description
jsonpatch.py Fixes _json_equal to structurally compare read-only mappings, preserving RFC6902 bool/number distinction.
tests.py Adds regression coverage for MappingProxyType and nested read-only mapping scenarios (success and failure).

Review effort: Lite

Comment thread jsonpatch.py Resolved
Comment thread tests.py Resolved
@liugedragon liugedragon changed the title Compare read-only mappings recursively in test operations Compare read-only containers recursively in test operations Nov 10, 2026
@stefankoegl
stefankoegl requested a balanced review from Copilot November 10, 2026 19:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues block the recursive JSON equality update for read-only containers.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

@stefankoegl
stefankoegl merged commit 181b0ba into stefankoegl:master Nov 10, 2026
21 checks passed
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 100.0%. remained the same — liugedragon:fix/readonly-mapping-tests into stefankoegl:master

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.

4 participants