Include URL.__hash__ in test (#64)

* 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
This commit is contained in:
Yeray Diaz Diaz 2019-05-15 14:30:00 +01:00 committed by Tom Christie
parent 019c5d1613
commit 2e9ab2e904
3 changed files with 17 additions and 6 deletions

View 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:

View 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"

View 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)