]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Include URL.__hash__ in test (#64)
authorYeray Diaz Diaz <yeray.diaz@farfetch.com>
Wed, 15 May 2019 13:30:00 +0000 (14:30 +0100)
committerTom Christie <tom@tomchristie.com>
Wed, 15 May 2019 13:30:00 +0000 (14:30 +0100)
* Include URL.__hash__ in test

* Add test for URLs being used in a set

Remove hash assertion on test requests

* Cleanup models.py

* Use membership test instead of equality to avoid ordering problems

httpcore/models.py
tests/models/test_requests.py
tests/models/test_url.py

index 946ae16685fccf08411a0f2c535a5b862a0c3bc0..68ab4b2d72f31ec50ee949b93b4e93517dec8e64 100644 (file)
@@ -4,10 +4,8 @@ import typing
 from urllib.parse import parse_qsl, urlencode
 
 import chardet
-import idna
 import rfc3986
 
-from .config import SSLConfig, TimeoutConfig
 from .decoders import (
     ACCEPT_ENCODING,
     SUPPORTED_DECODERS,
@@ -808,7 +806,7 @@ class SyncResponse:
         while True:
             try:
                 yield self._loop.run_until_complete(inner.__anext__())
-            except StopAsyncIteration as exc:
+            except StopAsyncIteration:
                 break
 
     def raw(self) -> typing.Iterator[bytes]:
@@ -816,7 +814,7 @@ class SyncResponse:
         while True:
             try:
                 yield self._loop.run_until_complete(inner.__anext__())
-            except StopAsyncIteration as exc:
+            except StopAsyncIteration:
                 break
 
     def close(self) -> None:
index f010db8cedd61495d7bc8f6fcf4bfbf5e47beaaf..c7faf816a9a51a20d3373509e7ca21bf9ee69b03 100644 (file)
@@ -98,12 +98,14 @@ def test_override_content_length_header():
 
 
 def test_url():
-    request = httpcore.Request("GET", "http://example.org")
+    url = "http://example.org"
+    request = httpcore.Request("GET", url)
     assert request.url.scheme == "http"
     assert request.url.port == 80
     assert request.url.full_path == "/"
 
-    request = httpcore.Request("GET", "https://example.org/abc?foo=bar")
+    url = "https://example.org/abc?foo=bar"
+    request = httpcore.Request("GET", url)
     assert request.url.scheme == "https"
     assert request.url.port == 443
     assert request.url.full_path == "/abc?foo=bar"
index 9ed96f6d610586a3b54db5a65a38d5c9c2098726..98e01d9d1d58656428f988a6e79bff90f8476346 100644 (file)
@@ -33,3 +33,14 @@ def test_url_query_params():
         "https://example.org:123/path/to/somewhere?b=456", query_params={"a": "123"}
     )
     assert str(url) == "https://example.org:123/path/to/somewhere?a=123"
+
+
+def test_url_set():
+    urls = (
+        URL("http://example.org:123/path/to/somewhere"),
+        URL("http://example.org:123/path/to/somewhere/else"),
+    )
+
+    url_set = set(urls)
+
+    assert all(url in urls for url in url_set)