Skip to content

Commit b7d9525

Browse files
authored
Merge pull request Colin-b#24 from Colin-b/develop
Release 0.6.0
2 parents d29a5a8 + 133fc01 commit b7d9525

File tree

9 files changed

+23
-31
lines changed

9 files changed

+23
-31
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [0.6.0] - 2020-08-07
10+
### Changed
11+
- Requires [`httpx`](https://www.python-httpx.org)==0.14.*
12+
913
## [0.5.0] - 2020-07-31
1014
### Changed
1115
- requires [`pytest`](https://docs.pytest.org/en/latest/) 6.
@@ -84,7 +88,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
8488
### Added
8589
- First release, should be considered as unstable for now as design might change.
8690

87-
[Unreleased]: https://github.com/Colin-b/pytest_httpx/compare/v0.5.0...HEAD
91+
[Unreleased]: https://github.com/Colin-b/pytest_httpx/compare/v0.6.0...HEAD
92+
[0.6.0]: https://github.com/Colin-b/pytest_httpx/compare/v0.5.0...v0.6.0
8893
[0.5.0]: https://github.com/Colin-b/pytest_httpx/compare/v0.4.0...v0.5.0
8994
[0.4.0]: https://github.com/Colin-b/pytest_httpx/compare/v0.3.0...v0.4.0
9095
[0.3.0]: https://github.com/Colin-b/pytest_httpx/compare/v0.2.1...v0.3.0

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ from pytest_httpx import HTTPXMock
152152

153153

154154
def test_headers_matching(httpx_mock: HTTPXMock):
155-
httpx_mock.add_response(match_headers={'user-agent': 'python-httpx/0.11.1'})
155+
httpx_mock.add_response(match_headers={'user-agent': 'python-httpx/0.14.0'})
156156

157157
with httpx.Client() as client:
158158
response = client.get("http://test_url")
@@ -382,8 +382,8 @@ from pytest_httpx import HTTPXMock
382382

383383

384384
def test_exception_raising(httpx_mock: HTTPXMock):
385-
def raise_timeout(*args, **kwargs):
386-
raise httpx.ReadTimeout()
385+
def raise_timeout(request, timeout):
386+
raise httpx.ReadTimeout(f"Unable to read within {timeout}", request=request)
387387

388388
httpx_mock.add_callback(raise_timeout)
389389

pytest_httpx/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ def httpx_mock(monkeypatch, assert_all_responses_were_requested: bool) -> HTTPXM
2020
mock = HTTPXMock()
2121
# Mock synchronous requests
2222
monkeypatch.setattr(
23-
httpx.Client, "transport_for_url", lambda self, url: _PytestSyncTransport(mock)
23+
httpx.Client, "_transport_for_url", lambda self, url: _PytestSyncTransport(mock)
2424
)
2525
# Mock asynchronous requests
2626
monkeypatch.setattr(
2727
httpx.AsyncClient,
28-
"transport_for_url",
28+
"_transport_for_url",
2929
lambda self, url: _PytestAsyncTransport(mock),
3030
)
3131
yield mock

pytest_httpx/_httpx_internals.py

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,13 @@
1-
from typing import Union, Any, Iterator, AsyncIterator
1+
from typing import Union, Any
22
from json import dumps
33

44
import httpcore
55

66

7-
class ByteStream(httpcore.AsyncByteStream, httpcore.SyncByteStream):
8-
def __init__(self, data: bytes):
9-
httpcore.AsyncByteStream.__init__(self)
10-
httpcore.SyncByteStream.__init__(self)
11-
self.data = data
12-
13-
def __iter__(self) -> Iterator[bytes]:
14-
yield self.data
15-
16-
async def __aiter__(self) -> AsyncIterator[bytes]:
17-
yield self.data
18-
19-
20-
class IteratorStream(httpcore.AsyncByteStream, httpcore.SyncByteStream):
7+
class IteratorStream(httpcore.AsyncIteratorByteStream, httpcore.IteratorByteStream):
218
def __init__(self, iterator):
22-
httpcore.AsyncByteStream.__init__(self, aiterator=iterator)
23-
httpcore.SyncByteStream.__init__(self, iterator=iterator)
9+
httpcore.AsyncIteratorByteStream.__init__(self, aiterator=iterator)
10+
httpcore.IteratorByteStream.__init__(self, iterator=iterator)
2411

2512

2613
def stream(
@@ -41,6 +28,6 @@ def stream(
4128
data = b""
4229

4330
if isinstance(data, bytes):
44-
return ByteStream(data)
31+
return httpcore.PlainByteStream(data)
4532

4633
return IteratorStream(data)

pytest_httpx/_httpx_mock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def to_request(
2424
stream: Union[httpcore.SyncByteStream, httpcore.AsyncByteStream] = None,
2525
) -> httpx.Request:
2626
scheme, host, port, path = url
27-
port = f":{port}" if port not in [80, 443] else ""
27+
port = f":{port}" if port not in [80, 443, None] else ""
2828
path = path.decode() if path != b"/" else ""
2929
if path.startswith("/?"):
3030
path = path[1:]

pytest_httpx/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
# Major should be incremented in case there is a breaking change. (eg: 2.5.8 -> 3.0.0)
44
# Minor should be incremented in case there is an enhancement. (eg: 2.5.8 -> 2.6.0)
55
# Patch should be incremented in case there is a bug fix. (eg: 2.5.8 -> 2.5.9)
6-
__version__ = "0.5.0"
6+
__version__ = "0.6.0"

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
keywords=["pytest", "testing", "mock", "httpx"],
3737
packages=find_packages(exclude=["tests*"]),
3838
entry_points={"pytest11": ["pytest_httpx = pytest_httpx"]},
39-
install_requires=["httpx==0.13.*", "pytest==6.*"],
39+
install_requires=["httpx==0.14.*", "pytest==6.*"],
4040
extras_require={
4141
"testing": [
4242
# Used to run async test functions

tests/test_httpx_async.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,8 +585,8 @@ async def test_requests_json_body(httpx_mock: HTTPXMock):
585585

586586
@pytest.mark.asyncio
587587
async def test_callback_raising_exception(httpx_mock: HTTPXMock):
588-
def raise_timeout(*args, **kwargs):
589-
raise httpx.ReadTimeout()
588+
def raise_timeout(request, timeout):
589+
raise httpx.ReadTimeout(f"Unable to read within {timeout}", request=request)
590590

591591
httpx_mock.add_callback(raise_timeout, url="http://test_url")
592592

tests/test_httpx_sync.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -546,8 +546,8 @@ def test_requests_json_body(httpx_mock: HTTPXMock):
546546

547547

548548
def test_callback_raising_exception(httpx_mock: HTTPXMock):
549-
def raise_timeout(*args, **kwargs):
550-
raise httpx.ReadTimeout()
549+
def raise_timeout(request, timeout):
550+
raise httpx.ReadTimeout(f"Unable to read within {timeout}", request=request)
551551

552552
httpx_mock.add_callback(raise_timeout, url="http://test_url")
553553

0 commit comments

Comments
 (0)