Skip to content

Commit

Permalink
Revert time-machine back to freezegun (#7937)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamsorcerer committed Dec 3, 2023
1 parent da2e349 commit 43f92fa
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 52 deletions.
16 changes: 3 additions & 13 deletions requirements/constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ exceptiongroup==1.1.2
# via pytest
filelock==3.12.2
# via virtualenv
freezegun==1.3.0
# via -r requirements/test.in
frozenlist==1.4.0
# via
# -r requirements/runtime-deps.in
Expand All @@ -83,10 +85,6 @@ idna==3.4
# yarl
imagesize==1.4.1
# via sphinx
importlib-metadata==6.8.0
# via sphinx
importlib-resources==6.1.0
# via towncrier
incremental==22.10.0
# via towncrier
iniconfig==2.0.0
Expand Down Expand Up @@ -157,11 +155,9 @@ pytest-cov==4.1.0
pytest-mock==3.12.0
# via -r requirements/test.in
python-dateutil==2.8.2
# via time-machine
# via freezegun
python-on-whales==0.67.0
# via -r requirements/test.in
pytz==2023.3.post1
# via babel
pyyaml==6.0.1
# via pre-commit
re-assert==1.1.0
Expand Down Expand Up @@ -205,8 +201,6 @@ sphinxcontrib-spelling==8.0.0 ; platform_system != "Windows"
# via -r requirements/doc-spelling.in
sphinxcontrib-towncrier==0.4.0a0
# via -r requirements/doc.in
time-machine==2.13.0 ; implementation_name == "cpython"
# via -r requirements/test.in
tomli==2.0.1
# via
# build
Expand Down Expand Up @@ -254,10 +248,6 @@ wheel==0.41.0
# via pip-tools
yarl==1.9.3
# via -r requirements/runtime-deps.in
zipp==3.17.0
# via
# importlib-metadata
# importlib-resources

# The following packages are considered to be unsafe in a requirements file:
pip==23.2.1
Expand Down
16 changes: 3 additions & 13 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ exceptiongroup==1.1.2
# via pytest
filelock==3.12.2
# via virtualenv
freezegun==1.3.0
# via -r requirements/test.in
frozenlist==1.4.0
# via
# -r requirements/runtime-deps.in
Expand All @@ -81,10 +83,6 @@ idna==3.4
# yarl
imagesize==1.4.1
# via sphinx
importlib-metadata==6.8.0
# via sphinx
importlib-resources==6.1.0
# via towncrier
incremental==22.10.0
# via towncrier
iniconfig==2.0.0
Expand Down Expand Up @@ -152,11 +150,9 @@ pytest-cov==4.1.0
pytest-mock==3.12.0
# via -r requirements/test.in
python-dateutil==2.8.2
# via time-machine
# via freezegun
python-on-whales==0.67.0
# via -r requirements/test.in
pytz==2023.3.post1
# via babel
pyyaml==6.0.1
# via pre-commit
re-assert==1.1.0
Expand Down Expand Up @@ -197,8 +193,6 @@ sphinxcontrib-serializinghtml==1.1.5
# via sphinx
sphinxcontrib-towncrier==0.4.0a0
# via -r requirements/doc.in
time-machine==2.13.0 ; implementation_name == "cpython"
# via -r requirements/test.in
tomli==2.0.1
# via
# build
Expand Down Expand Up @@ -246,10 +240,6 @@ wheel==0.41.0
# via pip-tools
yarl==1.9.3
# via -r requirements/runtime-deps.in
zipp==3.17.0
# via
# importlib-metadata
# importlib-resources

# The following packages are considered to be unsafe in a requirements file:
pip==23.2.1
Expand Down
2 changes: 1 addition & 1 deletion requirements/test.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
-r base.in

coverage
freezegun
mypy; implementation_name == "cpython"
proxy.py >= 2.4.4rc4
pytest
Expand All @@ -10,6 +11,5 @@ pytest-mock
python-on-whales
re-assert
setuptools-git
time-machine; implementation_name == "cpython"
trustme; platform_machine != "i686" # no 32-bit wheels
wait-for-it
6 changes: 3 additions & 3 deletions requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ cryptography==41.0.3
# via trustme
exceptiongroup==1.1.2
# via pytest
freezegun==1.3.0
# via -r requirements/test.in
frozenlist==1.4.0
# via
# -r requirements/runtime-deps.in
Expand Down Expand Up @@ -77,7 +79,7 @@ pytest-cov==4.1.0
pytest-mock==3.12.0
# via -r requirements/test.in
python-dateutil==2.8.2
# via time-machine
# via freezegun
python-on-whales==0.67.0
# via -r requirements/test.in
re-assert==1.1.0
Expand All @@ -90,8 +92,6 @@ setuptools-git==1.2
# via -r requirements/test.in
six==1.16.0
# via python-dateutil
time-machine==2.13.0 ; implementation_name == "cpython"
# via -r requirements/test.in
tomli==2.0.1
# via
# coverage
Expand Down
27 changes: 5 additions & 22 deletions tests/test_cookiejar.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,17 @@
import itertools
import pathlib
import pickle
import sys
import unittest
from http.cookies import BaseCookie, Morsel, SimpleCookie
from typing import Any
from unittest import mock

import pytest
from freezegun import freeze_time
from yarl import URL

from aiohttp import CookieJar, DummyCookieJar

try:
from time_machine import travel
except ImportError:
travel = None # type: ignore[assignment]


def dump_cookiejar() -> bytes: # pragma: no cover
"""Create pickled data for test_pickle_format()."""
Expand Down Expand Up @@ -427,10 +422,10 @@ def timed_request(self, url: Any, update_time: Any, send_time: Any):
elif isinstance(send_time, float):
send_time = datetime.datetime.fromtimestamp(send_time)

with travel(update_time, tick=False):
with freeze_time(update_time):
self.jar.update_cookies(self.cookies_to_send)

with travel(send_time, tick=False):
with freeze_time(send_time):
cookies_sent = self.jar.filter_cookies(URL(url))

self.jar.clear()
Expand Down Expand Up @@ -617,10 +612,6 @@ def test_path_value(self) -> None:
self.assertEqual(cookies_received["path-cookie"]["path"], "/somepath")
self.assertEqual(cookies_received["wrong-path-cookie"]["path"], "/")

@unittest.skipIf(
sys.implementation.name != "cpython",
reason="time_machine leverages CPython specific pointers https://github.com/adamchainz/time-machine/issues/305",
)
def test_expires(self) -> None:
ts_before = datetime.datetime(
1975, 1, 1, tzinfo=datetime.timezone.utc
Expand All @@ -642,10 +633,6 @@ def test_expires(self) -> None:

self.assertEqual(set(cookies_sent.keys()), {"shared-cookie"})

@unittest.skipIf(
sys.implementation.name != "cpython",
reason="time_machine leverages CPython specific pointers https://github.com/adamchainz/time-machine/issues/305",
)
def test_max_age(self) -> None:
cookies_sent = self.timed_request("http://maxagetest.com/", 1000, 1000)

Expand Down Expand Up @@ -793,10 +780,6 @@ async def test_cookie_jar_clear_all() -> None:
assert len(sut) == 0


@pytest.mark.skipif(
sys.implementation.name != "cpython",
reason="time_machine leverages CPython specific pointers https://github.com/adamchainz/time-machine/issues/305",
)
async def test_cookie_jar_clear_expired():
sut = CookieJar()

Expand All @@ -805,11 +788,11 @@ async def test_cookie_jar_clear_expired():
cookie["foo"] = "bar"
cookie["foo"]["expires"] = "Tue, 1 Jan 1990 12:00:00 GMT"

with travel("1980-01-01", tick=False):
with freeze_time("1980-01-01"):
sut.update_cookies(cookie)

sut.clear(lambda x: False)
with travel("1980-01-01", tick=False):
with freeze_time("1980-01-01"):
assert len(sut) == 0


Expand Down

0 comments on commit 43f92fa

Please sign in to comment.