Skip to content

Commit 5ae6ee0

Browse files
committed
Add missing test cases for URL constructor edge cases
- Add test for invalid URL type with params parameter (covers line 124) - Add test for explicit params=None handling (covers line 141) - Achieves 100% test coverage for httpx/_urls.py
1 parent 2d141a8 commit 5ae6ee0

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

tests/models/test_url.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,21 @@ class ExternalURLClass: # representing external URL class
467467
httpx.URL(ExternalURLClass()) # type: ignore
468468

469469

470+
def test_url_invalid_type_with_params():
471+
with pytest.raises(TypeError):
472+
httpx.URL(123, params={"a": "b"}) # type: ignore
473+
474+
475+
def test_url_with_params_none():
476+
# Test with existing query parameters
477+
url = httpx.URL("https://example.com?existing=param", params=None)
478+
assert "existing=param" in str(url)
479+
480+
# Test without existing query parameters
481+
url = httpx.URL("https://example.com", params=None)
482+
assert str(url) == "https://example.com"
483+
484+
470485
def test_url_with_invalid_component():
471486
with pytest.raises(TypeError) as exc:
472487
httpx.URL(scheme="https", host="www.example.com", incorrect="/")

0 commit comments

Comments
 (0)