-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
118 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ pre-commit | |
proxy.py | ||
pytest | ||
pytest-mock | ||
pytest_codspeed | ||
python-on-whales | ||
slotscheck | ||
trustme | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
"""codspeed benchmarks for client requests.""" | ||
|
||
import asyncio | ||
from http.cookies import Morsel | ||
|
||
from pytest_codspeed import BenchmarkFixture # type: ignore[import-untyped] | ||
from yarl import URL | ||
|
||
from aiohttp.client_reqrep import ClientRequest | ||
|
||
|
||
def test_client_request_update_cookies( | ||
loop: asyncio.AbstractEventLoop, benchmark: BenchmarkFixture | ||
) -> None: | ||
req = ClientRequest("get", URL("http://python.org"), loop=loop) | ||
morsel: "Morsel[str]" = Morsel() | ||
morsel.set(key="string", val="Another string", coded_val="really") | ||
morsel_cookie = {"str": morsel} | ||
|
||
@benchmark | ||
def _run() -> None: | ||
req.update_cookies(cookies=morsel_cookie) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
"""codspeed benchmarks for cookies.""" | ||
|
||
from http.cookies import BaseCookie | ||
|
||
from pytest_codspeed import BenchmarkFixture # type: ignore[import-untyped] | ||
from yarl import URL | ||
|
||
from aiohttp.cookiejar import CookieJar | ||
|
||
|
||
async def test_load_cookies_into_temp_cookiejar(benchmark: BenchmarkFixture) -> None: | ||
"""Benchmark for creating a temp CookieJar and filtering by URL. | ||
This benchmark matches what the client request does when cookies | ||
are passed to the request. | ||
""" | ||
all_cookies: BaseCookie[str] = BaseCookie() | ||
url = URL("http://example.com") | ||
cookies = {"cookie1": "value1", "cookie2": "value2"} | ||
|
||
@benchmark | ||
def _run() -> None: | ||
tmp_cookie_jar = CookieJar() | ||
tmp_cookie_jar.update_cookies(cookies) | ||
req_cookies = tmp_cookie_jar.filter_cookies(url) | ||
all_cookies.load(req_cookies) |