Skip to content

Commit

Permalink
Merge pull request #72 from paulineribeyre/master
Browse files Browse the repository at this point in the history
fix(pop): expose pop in api
  • Loading branch information
lundberg committed Sep 22, 2020
2 parents edfad32 + ce9b81a commit 8c5fbbc
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
2 changes: 2 additions & 0 deletions respx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
stop,
clear,
reset,
pop,
add,
request,
get,
Expand All @@ -36,6 +37,7 @@
"stop",
"clear",
"reset",
"pop",
"add",
"request",
"get",
Expand Down
19 changes: 17 additions & 2 deletions respx/api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Callable, Optional, Pattern, Union
from typing import Callable, Optional, Pattern, Union, overload

from .mocks import MockTransport
from .models import ContentDataTypes, HeaderTypes, RequestPattern
from .models import ContentDataTypes, DefaultType, HeaderTypes, RequestPattern

mock = MockTransport(assert_all_called=False)

Expand Down Expand Up @@ -30,6 +30,21 @@ def reset() -> None:
mock.reset()


@overload
def pop(alias: str) -> RequestPattern:
...


@overload
def pop(alias: str, default: DefaultType) -> Union[RequestPattern, DefaultType]:
...


def pop(alias, default=...):
global mock
return mock.pop(alias=alias, default=default)


def add(
method: Union[str, Callable],
url: Optional[Union[str, Pattern]] = None,
Expand Down
3 changes: 3 additions & 0 deletions respx/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
Pattern,
Sequence,
Tuple,
TypeVar,
Union,
)
from unittest import mock
Expand Down Expand Up @@ -47,6 +48,8 @@
Sequence[Tuple[bytes, bytes]],
]

DefaultType = TypeVar("DefaultType", bound=Any)

Regex = type(re.compile(""))
Kwargs = Dict[str, Any]
URLPatternTypes = Union[str, Pattern[str], URL]
Expand Down
4 changes: 1 addition & 3 deletions respx/transports.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
Optional,
Pattern,
Tuple,
TypeVar,
Union,
overload,
)
Expand All @@ -24,6 +23,7 @@
from .models import (
URL,
ContentDataTypes,
DefaultType,
Headers,
HeaderTypes,
Request,
Expand All @@ -35,8 +35,6 @@
build_response,
)

DefaultType = TypeVar("DefaultType", bound=Any)


class BaseMockTransport:
def __init__(
Expand Down

0 comments on commit 8c5fbbc

Please sign in to comment.