File: test_benchmarks_cookiejar.py

package info (click to toggle)
python-aiohttp 3.11.16-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 16,156 kB
  • sloc: python: 51,898; ansic: 20,843; makefile: 395; javascript: 31; sh: 3
file content (26 lines) | stat: -rw-r--r-- 810 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
"""codspeed benchmarks for cookies."""

from http.cookies import BaseCookie

from pytest_codspeed import BenchmarkFixture
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)