diff options
| author | robot-piglet <[email protected]> | 2025-06-09 07:25:14 +0300 |
|---|---|---|
| committer | robot-piglet <[email protected]> | 2025-06-09 07:39:53 +0300 |
| commit | bc34b5ec56db799a4d012975e932cfc1b2bbe240 (patch) | |
| tree | b5eab224b56957043fe318f927b52f102b491567 /contrib/python | |
| parent | fcd092027e287c0484ebc99524aa5e4d9e365dfa (diff) | |
Intermediate changes
commit_hash:59c53f005f0ded2f215a7fc2259a4cac90dda72a
Diffstat (limited to 'contrib/python')
| -rw-r--r-- | contrib/python/freezegun/py3/.dist-info/METADATA | 58 | ||||
| -rw-r--r-- | contrib/python/freezegun/py3/README.rst | 44 | ||||
| -rw-r--r-- | contrib/python/freezegun/py3/freezegun/__init__.py | 2 | ||||
| -rw-r--r-- | contrib/python/freezegun/py3/freezegun/api.py | 53 | ||||
| -rw-r--r-- | contrib/python/freezegun/py3/ya.make | 2 |
5 files changed, 142 insertions, 17 deletions
diff --git a/contrib/python/freezegun/py3/.dist-info/METADATA b/contrib/python/freezegun/py3/.dist-info/METADATA index c61e501f538..fc6e39814b0 100644 --- a/contrib/python/freezegun/py3/.dist-info/METADATA +++ b/contrib/python/freezegun/py3/.dist-info/METADATA @@ -1,29 +1,29 @@ -Metadata-Version: 2.1 +Metadata-Version: 2.4 Name: freezegun -Version: 1.5.1 +Version: 1.5.2 Summary: Let your Python tests travel through time Home-page: https://github.com/spulec/freezegun Author: Steve Pulec Author-email: [email protected] -License: Apache 2.0 +License: Apache-2.0 Project-URL: Bug Tracker, https://github.com/spulec/freezegun/issues Project-URL: Changes, https://github.com/spulec/freezegun/blob/master/CHANGELOG Project-URL: Documentation, https://github.com/spulec/freezegun/blob/master/README.rst Project-URL: Source Code, https://github.com/spulec/freezegun -Classifier: License :: OSI Approved :: Apache Software License Classifier: Programming Language :: Python :: 3 -Classifier: Programming Language :: Python :: 3.7 Classifier: Programming Language :: Python :: 3.8 Classifier: Programming Language :: Python :: 3.9 Classifier: Programming Language :: Python :: 3.10 Classifier: Programming Language :: Python :: 3.11 Classifier: Programming Language :: Python :: 3.12 +Classifier: Programming Language :: Python :: 3.13 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Programming Language :: Python :: Implementation :: PyPy -Requires-Python: >=3.7 +Requires-Python: >=3.8 License-File: LICENSE License-File: AUTHORS.rst -Requires-Dist: python-dateutil >=2.7 +Requires-Dist: python-dateutil>=2.7 +Dynamic: license-file FreezeGun: Let your Python tests travel through time ==================================================== @@ -81,12 +81,12 @@ Decorator @freeze_time('2013-04-09', as_kwarg='frozen_time') def test_method_decorator_works_on_unittest(self, frozen_time): self.assertEqual(datetime.date(2013, 4, 9), datetime.date.today()) - self.assertEqual(datetime.date(2013, 4, 9), frozen_time.time_to_freeze.today()) + self.assertEqual(datetime.date(2013, 4, 9), frozen_time.time_to_freeze.date()) @freeze_time('2013-04-09', as_kwarg='hello') def test_method_decorator_works_on_unittest(self, **kwargs): self.assertEqual(datetime.date(2013, 4, 9), datetime.date.today()) - self.assertEqual(datetime.date(2013, 4, 9), kwargs.get('hello').time_to_freeze.today()) + self.assertEqual(datetime.date(2013, 4, 9), kwargs.get('hello').time_to_freeze.date()) Context manager ~~~~~~~~~~~~~~~ @@ -258,6 +258,46 @@ FreezeGun allows moving time to specific dates. Parameter for ``move_to`` can be any valid ``freeze_time`` date (string, date, datetime). +``real_asyncio`` parameter +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +FreezeGun has an additional ``real_asyncio`` parameter which allows asyncio event loops to see real monotonic time even though time.monotonic() is frozen. This is useful to avoid breaking asyncio.sleep() and other asyncio functions that rely on monotonic time. + +.. code-block:: python + + @freeze_time("2012-01-14", real_asyncio=True) + async def test_asyncio(): + await asyncio.sleep(1) + assert datetime.datetime.now() == datetime.datetime(2012, 1, 14) + +API Documentation +~~~~~~~~~~~~~~~~~ + +Here is a succinct API documentation with all options listed: + +.. code-block:: python + + freeze_time(time_to_freeze: Optional[_Freezable]=None, tz_offset: Union[int, datetime.timedelta]=0, ignore: Optional[List[str]]=None, tick: bool=False, as_arg: bool=False, as_kwarg: str='', auto_tick_seconds: float=0, real_asyncio: bool=False) -> _freeze_time + + _freeze_time(time_to_freeze_str: Optional[_Freezable], tz_offset: Union[int, datetime.timedelta], ignore: List[str], tick: bool, as_arg: bool, as_kwarg: str, auto_tick_seconds: float, real_asyncio: Optional[bool]) + + _freeze_time.start() -> Union[StepTickTimeFactory, TickingDateTimeFactory, FrozenDateTimeFactory] + + _freeze_time.stop() -> None + + _freeze_time.move_to(target_datetime: _Freezable) -> None + + _freeze_time.tick(delta: Union[datetime.timedelta, float]=datetime.timedelta(seconds=1)) -> datetime.datetime + + _freeze_time.decorate_class(klass: Type[T2]) -> Type[T2] + + _freeze_time.decorate_coroutine(coroutine: Callable[P, Awaitable[T]]) -> Callable[P, Awaitable[T]] + + _freeze_time.decorate_callable(func: Callable[P, T]) -> Callable[P, T] + + _freeze_time.__enter__() -> Union[StepTickTimeFactory, TickingDateTimeFactory, FrozenDateTimeFactory] + + _freeze_time.__exit__(*args: Any) -> None Default arguments ~~~~~~~~~~~~~~~~~ diff --git a/contrib/python/freezegun/py3/README.rst b/contrib/python/freezegun/py3/README.rst index 1545d18bc88..34cdbcbafa4 100644 --- a/contrib/python/freezegun/py3/README.rst +++ b/contrib/python/freezegun/py3/README.rst @@ -54,12 +54,12 @@ Decorator @freeze_time('2013-04-09', as_kwarg='frozen_time') def test_method_decorator_works_on_unittest(self, frozen_time): self.assertEqual(datetime.date(2013, 4, 9), datetime.date.today()) - self.assertEqual(datetime.date(2013, 4, 9), frozen_time.time_to_freeze.today()) + self.assertEqual(datetime.date(2013, 4, 9), frozen_time.time_to_freeze.date()) @freeze_time('2013-04-09', as_kwarg='hello') def test_method_decorator_works_on_unittest(self, **kwargs): self.assertEqual(datetime.date(2013, 4, 9), datetime.date.today()) - self.assertEqual(datetime.date(2013, 4, 9), kwargs.get('hello').time_to_freeze.today()) + self.assertEqual(datetime.date(2013, 4, 9), kwargs.get('hello').time_to_freeze.date()) Context manager ~~~~~~~~~~~~~~~ @@ -231,6 +231,46 @@ FreezeGun allows moving time to specific dates. Parameter for ``move_to`` can be any valid ``freeze_time`` date (string, date, datetime). +``real_asyncio`` parameter +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +FreezeGun has an additional ``real_asyncio`` parameter which allows asyncio event loops to see real monotonic time even though time.monotonic() is frozen. This is useful to avoid breaking asyncio.sleep() and other asyncio functions that rely on monotonic time. + +.. code-block:: python + + @freeze_time("2012-01-14", real_asyncio=True) + async def test_asyncio(): + await asyncio.sleep(1) + assert datetime.datetime.now() == datetime.datetime(2012, 1, 14) + +API Documentation +~~~~~~~~~~~~~~~~~ + +Here is a succinct API documentation with all options listed: + +.. code-block:: python + + freeze_time(time_to_freeze: Optional[_Freezable]=None, tz_offset: Union[int, datetime.timedelta]=0, ignore: Optional[List[str]]=None, tick: bool=False, as_arg: bool=False, as_kwarg: str='', auto_tick_seconds: float=0, real_asyncio: bool=False) -> _freeze_time + + _freeze_time(time_to_freeze_str: Optional[_Freezable], tz_offset: Union[int, datetime.timedelta], ignore: List[str], tick: bool, as_arg: bool, as_kwarg: str, auto_tick_seconds: float, real_asyncio: Optional[bool]) + + _freeze_time.start() -> Union[StepTickTimeFactory, TickingDateTimeFactory, FrozenDateTimeFactory] + + _freeze_time.stop() -> None + + _freeze_time.move_to(target_datetime: _Freezable) -> None + + _freeze_time.tick(delta: Union[datetime.timedelta, float]=datetime.timedelta(seconds=1)) -> datetime.datetime + + _freeze_time.decorate_class(klass: Type[T2]) -> Type[T2] + + _freeze_time.decorate_coroutine(coroutine: Callable[P, Awaitable[T]]) -> Callable[P, Awaitable[T]] + + _freeze_time.decorate_callable(func: Callable[P, T]) -> Callable[P, T] + + _freeze_time.__enter__() -> Union[StepTickTimeFactory, TickingDateTimeFactory, FrozenDateTimeFactory] + + _freeze_time.__exit__(*args: Any) -> None Default arguments ~~~~~~~~~~~~~~~~~ diff --git a/contrib/python/freezegun/py3/freezegun/__init__.py b/contrib/python/freezegun/py3/freezegun/__init__.py index cab37a3f7e0..ca3524f77fd 100644 --- a/contrib/python/freezegun/py3/freezegun/__init__.py +++ b/contrib/python/freezegun/py3/freezegun/__init__.py @@ -9,7 +9,7 @@ from .api import freeze_time from .config import configure __title__ = 'freezegun' -__version__ = '1.5.1' +__version__ = '1.5.2' __author__ = 'Steve Pulec' __license__ = 'Apache License 2.0' __copyright__ = 'Copyright 2012 Steve Pulec' diff --git a/contrib/python/freezegun/py3/freezegun/api.py b/contrib/python/freezegun/py3/freezegun/api.py index d2352926e46..0799162fdb0 100644 --- a/contrib/python/freezegun/py3/freezegun/api.py +++ b/contrib/python/freezegun/py3/freezegun/api.py @@ -580,6 +580,35 @@ class StepTickTimeFactory: class _freeze_time: + """ + A class to freeze time for testing purposes. + + This class can be used as a context manager or a decorator to freeze time + during the execution of a block of code or a function. It provides various + options to customize the behavior of the frozen time. + + Attributes: + time_to_freeze (datetime.datetime): The datetime to freeze time at. + tz_offset (datetime.timedelta): The timezone offset to apply to the frozen time. + ignore (List[str]): A list of module names to ignore when freezing time. + tick (bool): Whether to allow time to tick forward. + auto_tick_seconds (float): The number of seconds to auto-tick the frozen time. + undo_changes (List[Tuple[types.ModuleType, str, Any]]): A list of changes to undo when stopping the frozen time. + modules_at_start (Set[str]): A set of module names that were loaded at the start of freezing time. + as_arg (bool): Whether to pass the frozen time as an argument to the decorated function. + as_kwarg (str): The name of the keyword argument to pass the frozen time to the decorated function. + real_asyncio (Optional[bool]): Whether to allow asyncio event loops to see real monotonic time. + + Methods: + __call__(func): Decorates a function or class to freeze time during its execution. + decorate_class(klass): Decorates a class to freeze time during its execution. + __enter__(): Starts freezing time and returns the time factory. + __exit__(*args): Stops freezing time. + start(): Starts freezing time and returns the time factory. + stop(): Stops freezing time and restores the original time functions. + decorate_coroutine(coroutine): Decorates a coroutine to freeze time during its execution. + decorate_callable(func): Decorates a callable to freeze time during its execution. + """ def __init__( self, @@ -604,10 +633,6 @@ class _freeze_time: self.real_asyncio = real_asyncio @overload - def __call__(self, func: Type[T2]) -> Type[T2]: - ... - - @overload def __call__(self, func: "Callable[P, Awaitable[Any]]") -> "Callable[P, Awaitable[Any]]": ... @@ -890,6 +915,26 @@ class _freeze_time: def freeze_time(time_to_freeze: Optional[_Freezable]=None, tz_offset: Union[int, datetime.timedelta]=0, ignore: Optional[List[str]]=None, tick: bool=False, as_arg: bool=False, as_kwarg: str='', auto_tick_seconds: float=0, real_asyncio: bool=False) -> _freeze_time: + """ + Freezes time for testing purposes. + + This function can be used as a decorator or a context manager to freeze time + during the execution of a block of code or a function. It provides various + options to customize the behavior of the frozen time. + + Args: + time_to_freeze (Optional[_Freezable]): The datetime to freeze time at. + tz_offset (Union[int, datetime.timedelta]): The timezone offset to apply to the frozen time. + ignore (Optional[List[str]]): A list of module names to ignore when freezing time. + tick (bool): Whether to allow time to tick forward. + as_arg (bool): Whether to pass the frozen time as an argument to the decorated function. + as_kwarg (str): The name of the keyword argument to pass the frozen time to the decorated function. + auto_tick_seconds (float): The number of seconds to auto-tick the frozen time. + real_asyncio (bool): Whether to allow asyncio event loops to see real monotonic time. + + Returns: + _freeze_time: An instance of the _freeze_time class. + """ acceptable_times: Any = (type(None), str, datetime.date, datetime.timedelta, types.FunctionType, types.GeneratorType) diff --git a/contrib/python/freezegun/py3/ya.make b/contrib/python/freezegun/py3/ya.make index fc4d4bf1ba3..4bec269f46c 100644 --- a/contrib/python/freezegun/py3/ya.make +++ b/contrib/python/freezegun/py3/ya.make @@ -4,7 +4,7 @@ PY3_LIBRARY() PROVIDES(freezegun) -VERSION(1.5.1) +VERSION(1.5.2) LICENSE(Apache-2.0) |
