tests: add Hypothesis property tests for URL roundtrip invariants#1686
Draft
aiolibsbot wants to merge 4 commits into
Draft
tests: add Hypothesis property tests for URL roundtrip invariants#1686aiolibsbot wants to merge 4 commits into
aiolibsbot wants to merge 4 commits into
Conversation
Lock in the current normalization behavior of yarl.URL by asserting idempotency invariants over restricted alphabets (RFC 3986 unreserved characters): * str(URL(s)) reparses to an equal URL * URL.build(...) components survive a str()/URL() roundtrip * yarl normalization reaches a fixed point in one application * equal URLs hash equal Alphabets are intentionally restricted to characters yarl never re-encodes, so any future failure here is almost certainly a regression rather than a property false-positive.
for more information, see https://pre-commit.ci
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1686 +/- ##
=======================================
Coverage 99.80% 99.80%
=======================================
Files 21 22 +1
Lines 4128 4197 +69
Branches 241 242 +1
=======================================
+ Hits 4120 4189 +69
Misses 5 5
Partials 3 3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
The yarl mypy config sets `disallow_any_decorated = True`, which flags every Hypothesis `@given`-decorated function because their type signatures still surface ``Any`` after decoration. The existing ``test_quoting.py`` works around this by tagging each decorated test with ``# type: ignore[misc]`` — apply the same marker on the new roundtrip tests so the lint job goes green. The non-Hypothesis ``test_str_url_roundtrip_concrete_examples`` (only ``pytest.mark.parametrize``) does not trigger the rule and stays unannotated. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What do these changes do?
Add a new test module
tests/test_url_roundtrip.pywithHypothesis-driven property tests that pin down
yarl.URLnormalization invariants:
URL(str(URL(s))) == URL(s)— parsing the textual form of a URLyields an equal object (idempotency of
str->URL).URL.build(...)are recovered after astr()->URL()roundtrip when they only use charactersyarlnever re-encodes.str(URL(str(URL(s)))) == str(URL(s)).__eq__/__hash__contract).Alphabets are restricted to RFC 3986
unreservedcharacters,schemes whose default ports get stripped are filtered out, and
.is excluded from path strategies (yarl normalizes
.segments perRFC 3986 §5.2.4, which is intentional and not a roundtrip property).
The tests were stress-checked across eight Hypothesis seeds.
Are there changes in behavior for the user?
No. Tests-only addition — no production code is touched.
Related issue number
Related to #1482 (webknjaz suggested adding Hypothesis coverage for
quoting roundtrip behavior). This PR focuses on the broader
URLparse/build roundtrip surface and lays the foundation forextending into quoter-level invariants later.
Checklist
CHANGES/folder1686.contrib.rstcontrib🤖 Generated with Claude Code
Quality Report
Changes: 6 files changed, 181 insertions(+), 342 deletions(-)
Code scan: clean
Tests: failed (FAILED)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline