From 134a7380eb9b91f8e9fc60e1c8bfe692fa683a9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D0=B2=D0=B3=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=91=D0=BB?= =?UTF-8?q?=D0=B8=D0=BD=D0=BE=D0=B2?= Date: Thu, 18 Jun 2026 21:53:56 +0300 Subject: [PATCH 1/9] Add AGENTS.md to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 825653f..137fc2a 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ html .qwen .claude CLAUDE.md +AGENTS.md From a3ae8fca74dffa8227cd6edad1e0eca2f5bed348 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D0=B2=D0=B3=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=91=D0=BB?= =?UTF-8?q?=D0=B8=D0=BD=D0=BE=D0=B2?= Date: Thu, 18 Jun 2026 21:55:28 +0300 Subject: [PATCH 2/9] Update mutmut paths_to_mutate to use array syntax for consistency --- pyproject.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 9ca835d..975c3a5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,8 +41,7 @@ keywords = ['cancellation tokens', 'parallel programming', 'concurrency'] "cantok" = ["py.typed"] [tool.mutmut] -paths_to_mutate = "cantok" -runner = "pytest" +paths_to_mutate = ["cantok"] [tool.ruff] lint.ignore = ['E501', 'E712', 'PTH123', 'PTH118', 'PLR2004', 'PTH107', 'SIM105', 'SIM102', 'RET503', 'PLR0912', 'C901', 'E731', 'F821'] From 460a0db77e06e92f3786cddd9630f9e04dde0ca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D0=B2=D0=B3=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=91=D0=BB?= =?UTF-8?q?=D0=B8=D0=BD=D0=BE=D0=B2?= Date: Thu, 18 Jun 2026 22:03:38 +0300 Subject: [PATCH 3/9] Bumped version to 0.0.37 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 975c3a5..3d841c0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "cantok" -version = "0.0.36" +version = "0.0.37" authors = [{ name = "Evgeniy Blinov", email = "zheni-b@yandex.ru" }] description = 'Implementation of the "Cancellation Token" pattern' readme = "README.md" From 61b6e6fb338ef2db72398c907fc85b899b567c0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D0=B2=D0=B3=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=91=D0=BB?= =?UTF-8?q?=D0=B8=D0=BD=D0=BE=D0=B2?= Date: Mon, 22 Jun 2026 22:48:58 +0300 Subject: [PATCH 4/9] Simplify token composition logic and remove sys._getframe inspection --- cantok/tokens/abstract/abstract_token.py | 66 ++++-------------------- 1 file changed, 9 insertions(+), 57 deletions(-) diff --git a/cantok/tokens/abstract/abstract_token.py b/cantok/tokens/abstract/abstract_token.py index 4c33f69..62071f9 100644 --- a/cantok/tokens/abstract/abstract_token.py +++ b/cantok/tokens/abstract/abstract_token.py @@ -1,4 +1,3 @@ -import sys from abc import ABC, abstractmethod from threading import RLock from typing import Any, Awaitable, Dict, List, Optional, Union @@ -76,64 +75,17 @@ def __str__(self) -> str: cancelled_flag = 'cancelled' if self.is_cancelled(direct=False) else 'not cancelled' return f'<{type(self).__name__} ({cancelled_flag})>' - def __add__(self, item: 'AbstractToken') -> 'AbstractToken': # noqa: PLR0911 + def __add__(self, item: 'AbstractToken') -> 'AbstractToken': if not isinstance(item, AbstractToken): - raise TypeError('Cancellation Token can only be combined with another Cancellation Token.') - - from cantok import DefaultToken, SimpleToken, TimeoutToken # noqa: PLC0415 - - if self._cancelled or item._cancelled: - return SimpleToken(cancelled=True) - - nested_tokens = [] - container_token: Optional[AbstractToken] = None - - # Inspect the caller's frame to determine if a token is "temporary" - # (not stored in any variable). This is robust across all Python versions, - # unlike refcount-based detection which varies with bytecode optimizations. - _frame = sys._getframe(1) - _caller_locals = list(_frame.f_locals.values()) - _caller_globals = list(_frame.f_globals.values()) - - def is_temp(token: 'AbstractToken') -> bool: - for v in _caller_locals: - if v is token: - return False - return all(v is not token for v in _caller_globals) - - _self_is_temp = is_temp(self) - _item_is_temp = is_temp(item) - - if isinstance(self, TimeoutToken) and isinstance(item, TimeoutToken) and self._monotonic == item._monotonic: - if self._deadline >= item._deadline and _self_is_temp: - if _item_is_temp: - item._tokens.extend(self._tokens) - return item - if self._tokens: - return SimpleToken(*(self._tokens), item) - return item - if self._deadline < item._deadline and _item_is_temp: - if _self_is_temp: - self._tokens.extend(item._tokens) - return self - if item._tokens: - return SimpleToken(*(item._tokens), self) - return self - - for token in self, item: - if isinstance(token, SimpleToken) and is_temp(token): - nested_tokens.extend(token._tokens) - elif isinstance(token, DefaultToken): - pass - elif not isinstance(token, SimpleToken) and is_temp(token) and container_token is None: - container_token = token - else: - nested_tokens.append(token) + raise TypeError( + 'Cancellation Token can only be combined with another Cancellation Token.', + ) - if container_token is None: - return SimpleToken(*nested_tokens) - container_token._tokens.extend(container_token._filter_tokens(nested_tokens)) - return container_token + from cantok import DefaultToken, SimpleToken # noqa: PLC0415 + + return SimpleToken( + *[token for token in (self, item) if not isinstance(token, DefaultToken)], + ) def __bool__(self) -> bool: return self.keep_on() From 9d2ce93dc03b62f8431a7fd0db953a6454f66608 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D0=B2=D0=B3=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=91=D0=BB?= =?UTF-8?q?=D0=B8=D0=BD=D0=BE=D0=B2?= Date: Mon, 22 Jun 2026 22:54:57 +0300 Subject: [PATCH 5/9] Update token summation docs to clarify behavior and simplify examples --- docs/what_are_tokens/summation.md | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/docs/what_are_tokens/summation.md b/docs/what_are_tokens/summation.md index 168477e..8c83b9a 100644 --- a/docs/what_are_tokens/summation.md +++ b/docs/what_are_tokens/summation.md @@ -18,22 +18,4 @@ def function(token: AbstractToken): ... ``` -The token summation operation always generates a new token. If at least one of the operand tokens is cancelled, the sum will also be cancelled. It is also guaranteed that the cancellation of this token does not lead to the cancellation of the operands. That is, the sum of two tokens always behaves as if it were a [`SimpleToken`](../types_of_tokens/SimpleToken.md) in which both operands were [nested](embedding.md). However, it is difficult to say exactly which token will result from the summation, since the library strives to minimize the generated graph of tokens for performance reasons. - -You may notice that some tokens disappear altogether during summation: - -```python -print(repr(SimpleToken() + TimeoutToken(5))) -#> TimeoutToken(5) -print(repr(SimpleToken(cancelled=True) + TimeoutToken(5))) -#> SimpleToken(cancelled=True) -``` - -In addition, you can safely sum more than 2 tokens — this does not generate anything superfluous: - -```python -print(repr(TimeoutToken(5) + ConditionToken(lambda: False) + CounterToken(23))) -#> TimeoutToken(5, ConditionToken(λ), CounterToken(23)) -``` - -In fact, there are quite a few effective ways to optimize the token addition operation that are implemented in the library. This operation is well optimized, so it is recommended in all cases when you need to combine the constraints of different tokens into one. +The token summation operation always generates a new [`SimpleToken`](../types_of_tokens/SimpleToken.md). If at least one of the nested operand tokens is cancelled, the sum will also be cancelled. It is also guaranteed that the cancellation of this token does not lead to the cancellation of the operands. Direct [`DefaultToken`](../types_of_tokens/DefaultToken.md) operands are not nested into the sum. From 8f216eb6de7fe15c063d48f1f3211b6c5aa2eaba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D0=B2=D0=B3=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=91=D0=BB?= =?UTF-8?q?=D0=B8=D0=BD=D0=BE=D0=B2?= Date: Mon, 22 Jun 2026 22:56:11 +0300 Subject: [PATCH 6/9] Add skipped tests directory structure --- tests/skipped/__init__.py | 0 tests/skipped/tokens/__init__.py | 0 tests/skipped/tokens/abstract/__init__.py | 0 3 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/skipped/__init__.py create mode 100644 tests/skipped/tokens/__init__.py create mode 100644 tests/skipped/tokens/abstract/__init__.py diff --git a/tests/skipped/__init__.py b/tests/skipped/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/skipped/tokens/__init__.py b/tests/skipped/tokens/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/skipped/tokens/abstract/__init__.py b/tests/skipped/tokens/abstract/__init__.py new file mode 100644 index 0000000..e69de29 From 5fb8edbd741caf0b1088770a7b70ffa59c9f2faa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D0=B2=D0=B3=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=91=D0=BB?= =?UTF-8?q?=D0=B8=D0=BD=D0=BE=D0=B2?= Date: Tue, 23 Jun 2026 11:16:14 +0300 Subject: [PATCH 7/9] Remove deprecated IterableWithTokens type alias and inline DefaultToken filtering --- cantok/tokens/abstract/abstract_token.py | 49 ++++++++++++++---------- cantok/tokens/timeout_token.py | 2 - cantok/types.py | 14 ------- 3 files changed, 28 insertions(+), 37 deletions(-) delete mode 100644 cantok/types.py diff --git a/cantok/tokens/abstract/abstract_token.py b/cantok/tokens/abstract/abstract_token.py index 62071f9..6fed09a 100644 --- a/cantok/tokens/abstract/abstract_token.py +++ b/cantok/tokens/abstract/abstract_token.py @@ -6,7 +6,6 @@ from cantok.tokens.abstract.cancel_cause import CancelCause from cantok.tokens.abstract.coroutine_wrapper import WaitCoroutineWrapper from cantok.tokens.abstract.report import CancellationReport -from cantok.types import IterableWithTokens class AbstractToken(ABC): @@ -42,9 +41,13 @@ class AbstractToken(ABC): _rollback_if_nondirect_polling = False def __init__(self, *tokens: 'AbstractToken', cancelled: bool = False) -> None: + from cantok import DefaultToken # noqa: PLC0415 + self._cached_report: Optional[CancellationReport] = None self._cancelled: bool = cancelled - self._tokens: List[AbstractToken] = self._filter_tokens(tokens) + self._tokens: List[AbstractToken] = [ + token for token in tokens if not isinstance(token, DefaultToken) + ] self._lock: RLock = RLock() @@ -64,7 +67,9 @@ def __repr__(self) -> str: else: extra_kwargs = {} extra_kwargs.update(**(self._get_extra_kwargs())) - text_representation_of_extra_kwargs = self._text_representation_of_kwargs(**extra_kwargs) + text_representation_of_extra_kwargs = self._text_representation_of_kwargs( + **extra_kwargs, + ) if text_representation_of_extra_kwargs: chunks.append(text_representation_of_extra_kwargs) @@ -72,7 +77,9 @@ def __repr__(self) -> str: return f'{type(self).__name__}({glued_chunks})' def __str__(self) -> str: - cancelled_flag = 'cancelled' if self.is_cancelled(direct=False) else 'not cancelled' + cancelled_flag = ( + 'cancelled' if self.is_cancelled(direct=False) else 'not cancelled' + ) return f'<{type(self).__name__} ({cancelled_flag})>' def __add__(self, item: 'AbstractToken') -> 'AbstractToken': @@ -147,7 +154,11 @@ def is_cancelled(self, direct: bool = True) -> bool: """ return self._get_report(direct=direct).cause != CancelCause.NOT_CANCELLED - def wait(self, step: Union[int, float] = 0.0001, timeout: Optional[Union[int, float]] = None) -> Awaitable: # type: ignore[type-arg] + def wait( + self, + step: Union[int, float] = 0.0001, + timeout: Optional[Union[int, float]] = None, + ) -> Awaitable: # type: ignore[type-arg] """ Waits until the token is cancelled. @@ -165,17 +176,23 @@ def wait(self, step: Union[int, float] = 0.0001, timeout: Optional[Union[int, fl >>> asyncio.run(TimeoutToken(5).wait()) # non-blocking, inside an asyncio event loop """ if step < 0: - raise ValueError('The token polling iteration time cannot be less than zero.') + raise ValueError( + 'The token polling iteration time cannot be less than zero.', + ) if timeout is not None and timeout < 0: raise ValueError('The total timeout of waiting cannot be less than zero.') if timeout is not None and step > timeout: - raise ValueError('The total timeout of waiting cannot be less than the time of one iteration of the token polling.') + raise ValueError( + 'The total timeout of waiting cannot be less than the time of one iteration of the token polling.', + ) if timeout is None: from cantok import SimpleToken # noqa: PLC0415 + token: AbstractToken = SimpleToken() else: from cantok import TimeoutToken # noqa: PLC0415 + token = TimeoutToken(timeout) return WaitCoroutineWrapper(step, self + token, token) @@ -217,19 +234,6 @@ def check(self) -> None: elif report.cause == CancelCause.SUPERPOWER: report.from_token._raise_superpower_exception() - def _filter_tokens(self, tokens: IterableWithTokens) -> List['AbstractToken']: - from cantok import DefaultToken # noqa: PLC0415 - - result: List[AbstractToken] = [] - - for token in tokens: - if isinstance(token, DefaultToken): - pass - else: - result.append(token) - - return result - def _get_report(self, direct: bool = True) -> CancellationReport: if self._cancelled: return CancellationReport( @@ -259,7 +263,10 @@ def _get_report(self, direct: bool = True) -> CancellationReport: def _superpower(self) -> bool: # pragma: no cover pass - def _superpower_rollback(self, superpower_data: Dict[str, Any]) -> None: # pragma: no cover # noqa: B027 + def _superpower_rollback( # noqa: B027 + self, + superpower_data: Dict[str, Any], + ) -> None: # pragma: no cover pass def _check_superpower(self, direct: bool) -> bool: diff --git a/cantok/tokens/timeout_token.py b/cantok/tokens/timeout_token.py index b751b55..28ad548 100644 --- a/cantok/tokens/timeout_token.py +++ b/cantok/tokens/timeout_token.py @@ -49,8 +49,6 @@ def __init__(self, timeout: Union[int, float], *tokens: AbstractToken, cancelled def function() -> bool: return timer() >= deadline - self._deadline = deadline - super().__init__(function, *tokens, cancelled=cancelled) def _text_representation_of_superpower(self) -> str: diff --git a/cantok/types.py b/cantok/types.py deleted file mode 100644 index c2c794f..0000000 --- a/cantok/types.py +++ /dev/null @@ -1,14 +0,0 @@ -import sys -from collections.abc import Iterable as IterableFromCollections -from typing import Iterable as IterableFromTyping - -if sys.version_info >= (3, 10): - from typing import TypeAlias # pragma: no cover -else: - from typing_extensions import TypeAlias # pragma: no cover - - -if sys.version_info >= (3, 9): - IterableWithTokens: TypeAlias = IterableFromCollections['AbstractToken'] # type: ignore[name-defined, unused-ignore] # pragma: no cover -else: - IterableWithTokens = IterableFromTyping['AbstractToken'] # type: ignore[name-defined] # pragma: no cover From af0130738c32a34026bab53b2831288086ff8301 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D0=B2=D0=B3=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=91=D0=BB?= =?UTF-8?q?=D0=B8=D0=BD=D0=BE=D0=B2?= Date: Tue, 23 Jun 2026 11:21:53 +0300 Subject: [PATCH 8/9] Skip some tests for token addition behavior --- .../tokens/abstract/test_abstract_token.py | 195 ++ tests/skipped/tokens/test_condition_token.py | 64 + tests/skipped/tokens/test_counter_token.py | 65 + tests/skipped/tokens/test_default_token.py | 37 + tests/skipped/tokens/test_simple_token.py | 273 +++ tests/skipped/tokens/test_timeout_token.py | 1324 +++++++++++++ .../tokens/abstract/test_abstract_token.py | 420 ++-- tests/units/tokens/test_condition_token.py | 60 +- tests/units/tokens/test_counter_token.py | 60 +- tests/units/tokens/test_default_token.py | 44 +- tests/units/tokens/test_simple_token.py | 252 +-- tests/units/tokens/test_timeout_token.py | 1688 +++-------------- 12 files changed, 2502 insertions(+), 1980 deletions(-) create mode 100644 tests/skipped/tokens/abstract/test_abstract_token.py create mode 100644 tests/skipped/tokens/test_condition_token.py create mode 100644 tests/skipped/tokens/test_counter_token.py create mode 100644 tests/skipped/tokens/test_default_token.py create mode 100644 tests/skipped/tokens/test_simple_token.py create mode 100644 tests/skipped/tokens/test_timeout_token.py diff --git a/tests/skipped/tokens/abstract/test_abstract_token.py b/tests/skipped/tokens/abstract/test_abstract_token.py new file mode 100644 index 0000000..1d422af --- /dev/null +++ b/tests/skipped/tokens/abstract/test_abstract_token.py @@ -0,0 +1,195 @@ +from functools import partial + +import pytest + +from cantok import ( + ConditionToken, + CounterToken, + SimpleToken, + TimeoutToken, +) + +ALL_TOKEN_CLASSES = [SimpleToken, ConditionToken, TimeoutToken, CounterToken] +ALL_SUPERPOWER_TOKEN_CLASSES = [ConditionToken, TimeoutToken, CounterToken] +ALL_ARGUMENTS_FOR_TOKEN_CLASSES = [tuple(), (lambda: False, ), (15, ), (15, )] +ALL_CANCELLING_ARGUMENTS_FOR_TOKEN_CLASSES_WITH_SUPERPOWERS = [(lambda: True, ), (0, ), (0, )] +ALL_NOT_CANCELLING_ARGUMENTS_FOR_TOKEN_CLASSES_WITH_SUPERPOWERS = [(lambda: False, ), (15, ), (15, )] +ALL_TOKENS_FABRICS = [partial(token_class, *arguments) for token_class, arguments in zip(ALL_TOKEN_CLASSES, ALL_ARGUMENTS_FOR_TOKEN_CLASSES)] +ALL_TOKENS_FABRICS_WITH_CANCELLING_SUPERPOWER = [partial(token_class, *arguments) for token_class, arguments in zip(ALL_SUPERPOWER_TOKEN_CLASSES, ALL_CANCELLING_ARGUMENTS_FOR_TOKEN_CLASSES_WITH_SUPERPOWERS)] +ALL_TOKENS_FABRICS_WITH_NOT_CANCELLING_SUPERPOWER = [partial(token_class, *arguments) for token_class, arguments in zip(ALL_SUPERPOWER_TOKEN_CLASSES, ALL_NOT_CANCELLING_ARGUMENTS_FOR_TOKEN_CLASSES_WITH_SUPERPOWERS)] + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + ('first_token_class', 'first_arguments'), + [ + (TimeoutToken, [15]), + (ConditionToken, [lambda: False]), + (CounterToken, [15]), + ], +) +@pytest.mark.parametrize( + ('second_token_class', 'second_arguments'), + [ + (TimeoutToken, [15]), + (ConditionToken, [lambda: False]), + (CounterToken, [15]), + ], +) +def test_add_temp_tokens(first_token_class, second_token_class, first_arguments, second_arguments): + tokens_sum = first_token_class(*first_arguments) + second_token_class(*second_arguments) + + if not (first_token_class is TimeoutToken and second_token_class is TimeoutToken): + assert isinstance(tokens_sum, first_token_class) + assert len(tokens_sum._tokens) == 1 + assert isinstance(tokens_sum._tokens[0], second_token_class) + assert len(tokens_sum._tokens[0]._tokens) == 0 + else: + assert isinstance(tokens_sum, TimeoutToken) + assert len(tokens_sum._tokens) == 0 + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + ('first_token_class', 'first_arguments'), + [ + (TimeoutToken, [15]), + (ConditionToken, [lambda: False]), + (CounterToken, [15]), + ], +) +@pytest.mark.parametrize( + ('second_token_class', 'second_arguments'), + [ + (TimeoutToken, [15]), + (ConditionToken, [lambda: False]), + (CounterToken, [15]), + ], +) +def test_add_not_temp_token_and_temp_token(first_token_class, second_token_class, first_arguments, second_arguments): + first_token = first_token_class(*first_arguments) + tokens_sum = first_token + second_token_class(*second_arguments) + + if first_token_class is TimeoutToken and second_token_class is TimeoutToken: + assert tokens_sum is first_token + assert not tokens_sum._tokens + else: + assert isinstance(tokens_sum, second_token_class) + assert len(tokens_sum._tokens) == 1 + assert isinstance(tokens_sum._tokens[0], first_token_class) + assert len(tokens_sum._tokens[0]._tokens) == 0 + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + ('first_token_class', 'first_arguments'), + [ + (TimeoutToken, [15]), + (ConditionToken, [lambda: False]), + (CounterToken, [15]), + ], +) +@pytest.mark.parametrize( + ('second_token_class', 'second_arguments'), + [ + (TimeoutToken, [15]), + (ConditionToken, [lambda: False]), + (CounterToken, [15]), + ], +) +def test_add_temp_token_and_not_temp_token(first_token_class, second_token_class, first_arguments, second_arguments): + second_token = second_token_class(*second_arguments) + tokens_sum = first_token_class(*first_arguments) + second_token + + if first_token_class is TimeoutToken and second_token_class is TimeoutToken: + assert isinstance(tokens_sum, TimeoutToken) + assert len(tokens_sum._tokens) == 0 + else: + assert isinstance(tokens_sum, first_token_class) + assert len(tokens_sum._tokens) == 1 + assert isinstance(tokens_sum._tokens[0], second_token_class) + assert len(tokens_sum._tokens[0]._tokens) == 0 + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + 'first_token_fabric', + ALL_TOKENS_FABRICS_WITH_NOT_CANCELLING_SUPERPOWER, +) +@pytest.mark.parametrize( + 'second_token_fabric', + ALL_TOKENS_FABRICS_WITH_NOT_CANCELLING_SUPERPOWER, +) +@pytest.mark.parametrize( + 'third_token_fabric', + ALL_TOKENS_FABRICS_WITH_NOT_CANCELLING_SUPERPOWER, +) +def test_add_three_tokens_except_simple_token(first_token_fabric, second_token_fabric, third_token_fabric): + first_token = first_token_fabric() + second_token = second_token_fabric() + third_token = third_token_fabric() + + tokens_sum = first_token + second_token + third_token + + assert isinstance(tokens_sum, SimpleToken) + assert len(tokens_sum._tokens) == 3 + assert tokens_sum._tokens[0] is first_token + assert tokens_sum._tokens[1] is second_token + assert tokens_sum._tokens[2] is third_token + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + 'first_token_fabric', + ALL_TOKENS_FABRICS_WITH_NOT_CANCELLING_SUPERPOWER, +) +def test_add_another_token_and_temp_simple_token(first_token_fabric): + first_token = first_token_fabric() + + tokens_sum = first_token + SimpleToken() + + assert isinstance(tokens_sum, SimpleToken) + assert len(tokens_sum._tokens) == 1 + assert tokens_sum._tokens[0] is first_token + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + 'second_token_fabric', + ALL_TOKENS_FABRICS_WITH_NOT_CANCELLING_SUPERPOWER, +) +def test_add_temp_simple_token_and_another_token(second_token_fabric): + second_token = second_token_fabric() + + tokens_sum = SimpleToken() + second_token + + assert isinstance(tokens_sum, SimpleToken) + assert len(tokens_sum._tokens) == 1 + assert tokens_sum._tokens[0] is second_token + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + 'token_fabric', + ALL_TOKENS_FABRICS, +) +def test_any_token_plus_temp_cancelled_simple_token_gives_cancelled_simple_token(token_fabric): + token = token_fabric() + SimpleToken(cancelled=True) + + assert isinstance(token, SimpleToken) + assert len(token._tokens) == 0 + assert not token + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + 'token_fabric', + ALL_TOKENS_FABRICS, +) +def test_any_token_plus_cancelled_simple_token_gives_cancelled_simple_token(token_fabric): + simple_token = SimpleToken(cancelled=True) + token = token_fabric() + simple_token + + assert isinstance(token, SimpleToken) + assert len(token._tokens) == 0 + assert not token diff --git a/tests/skipped/tokens/test_condition_token.py b/tests/skipped/tokens/test_condition_token.py new file mode 100644 index 0000000..dcf6f46 --- /dev/null +++ b/tests/skipped/tokens/test_condition_token.py @@ -0,0 +1,64 @@ +import pytest + +from cantok import ConditionToken, SimpleToken + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_quasitemp_condition_token_plus_temp_simple_token(): + token = ConditionToken(lambda: False) + SimpleToken() + + assert isinstance(token, ConditionToken) + assert len(token._tokens) == 0 + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_not_quasitemp_condition_token_plus_temp_simple_token(): + condition_token = ConditionToken(lambda: False) + token = condition_token + SimpleToken() + + assert isinstance(token, SimpleToken) + assert len(token._tokens) == 1 + assert isinstance(token._tokens[0], ConditionToken) + assert token._tokens[0] is condition_token + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_quasitemp_condition_token_plus_not_temp_simple_token(): + simple_token = SimpleToken() + token = ConditionToken(lambda: False) + simple_token + + assert isinstance(token, ConditionToken) + assert token is not simple_token + assert len(token._tokens) == 1 + assert isinstance(token._tokens[0], SimpleToken) + assert token._tokens[0] is simple_token + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_quasitemp_condition_token_plus_temp_simple_token_reverse(): + token = SimpleToken() + ConditionToken(lambda: False) + + assert isinstance(token, ConditionToken) + assert len(token._tokens) == 0 + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_not_quasitemp_condition_token_plus_temp_simple_token_reverse(): + condition_token = ConditionToken(lambda: False) + token = SimpleToken() + condition_token + + assert isinstance(token, SimpleToken) + assert len(token._tokens) == 1 + assert isinstance(token._tokens[0], ConditionToken) + assert token._tokens[0] is condition_token + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_quasitemp_condition_token_plus_not_temp_simple_token_reverse(): + simple_token = SimpleToken() + token = simple_token + ConditionToken(lambda: False) + + assert isinstance(token, ConditionToken) + assert token is not simple_token + assert len(token._tokens) == 1 + assert token._tokens[0] is simple_token diff --git a/tests/skipped/tokens/test_counter_token.py b/tests/skipped/tokens/test_counter_token.py new file mode 100644 index 0000000..b3e2b7a --- /dev/null +++ b/tests/skipped/tokens/test_counter_token.py @@ -0,0 +1,65 @@ +import pytest + +from cantok import CounterToken, SimpleToken + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_quasitemp_counter_token_plus_temp_simple_token(): + token = CounterToken(0) + SimpleToken() + + assert isinstance(token, CounterToken) + assert len(token._tokens) == 0 + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_not_quasitemp_counter_token_plus_temp_simple_token(): + counter_token = CounterToken(1) + token = counter_token + SimpleToken() + + assert isinstance(token, SimpleToken) + assert len(token._tokens) == 1 + assert isinstance(token._tokens[0], CounterToken) + assert token._tokens[0] is counter_token + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_quasitemp_counter_token_plus_not_temp_simple_token(): + simple_token = SimpleToken() + token = CounterToken(1) + simple_token + + assert isinstance(token, CounterToken) + assert token is not simple_token + assert len(token._tokens) == 1 + assert isinstance(token._tokens[0], SimpleToken) + assert token._tokens[0] is simple_token + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_quasitemp_counter_token_plus_temp_simple_token_reverse(): + token = SimpleToken() + CounterToken(1) + + assert isinstance(token, CounterToken) + assert len(token._tokens) == 0 + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_not_quasitemp_counter_token_plus_temp_simple_token_reverse(): + counter_token = CounterToken(1) + token = SimpleToken() + counter_token + + assert isinstance(token, SimpleToken) + assert len(token._tokens) == 1 + assert isinstance(token._tokens[0], CounterToken) + assert token._tokens[0] is counter_token + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_quasitemp_counter_token_plus_not_temp_simple_token_reverse(): + simple_token = SimpleToken() + token = simple_token + CounterToken(1) + + assert isinstance(token, CounterToken) + assert token is not simple_token + assert len(token._tokens) == 1 + assert isinstance(token._tokens[0], SimpleToken) + assert token._tokens[0] is simple_token diff --git a/tests/skipped/tokens/test_default_token.py b/tests/skipped/tokens/test_default_token.py new file mode 100644 index 0000000..5e65b91 --- /dev/null +++ b/tests/skipped/tokens/test_default_token.py @@ -0,0 +1,37 @@ +import pytest + +from cantok import DefaultToken, SimpleToken, TimeoutToken + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_default_plus_default_plus_default(): + empty_sum = DefaultToken() + DefaultToken() + DefaultToken() + + assert isinstance(empty_sum, SimpleToken) + assert len(empty_sum._tokens) == 0 + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_default_token_plus_temp_simple_token(): + empty_sum = DefaultToken() + SimpleToken() + + assert isinstance(empty_sum, SimpleToken) + assert len(empty_sum._tokens) == 0 + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_temp_default_token_plus_temp_timeout_token(): + token = DefaultToken() + TimeoutToken(1) + + assert isinstance(token, TimeoutToken) + assert token._timeout == 1 + assert len(token._tokens) == 0 + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_temp_timeout_token_plus_temp_default_token(): + token = TimeoutToken(1) + DefaultToken() + + assert isinstance(token, TimeoutToken) + assert token._timeout == 1 + assert len(token._tokens) == 0 diff --git a/tests/skipped/tokens/test_simple_token.py b/tests/skipped/tokens/test_simple_token.py new file mode 100644 index 0000000..31eedcd --- /dev/null +++ b/tests/skipped/tokens/test_simple_token.py @@ -0,0 +1,273 @@ +import pytest + +from cantok import ConditionToken, SimpleToken, TimeoutToken + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_sum_of_2_temp_simple_tokens(): + token = SimpleToken() + SimpleToken() + + assert isinstance(token, SimpleToken) + assert len(token._tokens) == 0 + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_sum_of_5_temp_simple_tokens(): + token = SimpleToken() + SimpleToken() + SimpleToken() + SimpleToken() + SimpleToken() + + assert isinstance(token, SimpleToken) + assert len(token._tokens) == 0 + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_sum_of_1_temp_and_1_not_temp_simple_tokens(): + second_token = SimpleToken() + result = SimpleToken() + second_token + + assert isinstance(result, SimpleToken) + assert len(result._tokens) == 1 + assert result._tokens[0] is second_token + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_sum_of_1_not_temp_and_1_temp_simple_tokens(): + first_token = SimpleToken() + result = first_token + SimpleToken() + + assert isinstance(result, SimpleToken) + assert len(result._tokens) == 1 + assert result._tokens[0] is first_token + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_sum_of_2_not_temp_simple_tokens_and_one_temp(): + first_token = SimpleToken() + second_token = SimpleToken() + result = first_token + second_token + SimpleToken() + + assert isinstance(result, SimpleToken) + assert len(result._tokens) == 2 + assert result._tokens[0] is first_token + assert result._tokens[1] is second_token + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_sum_of_3_not_temp_simple_tokens(): + first_token = SimpleToken() + second_token = SimpleToken() + third_token = SimpleToken() + result = first_token + second_token + third_token + + assert isinstance(result, SimpleToken) + assert len(result._tokens) == 3 + assert result._tokens[0] is first_token + assert result._tokens[1] is second_token + assert result._tokens[2] is third_token + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_sum_of_2_temp_timeout_tokens_throw_temp_simple_tokens(): + token = SimpleToken(TimeoutToken(1)) + SimpleToken(TimeoutToken(2)) + + assert isinstance(token, SimpleToken) + assert len(token._tokens) == 2 + + assert isinstance(token._tokens[0], TimeoutToken) + assert token._tokens[0]._timeout == 1 + + assert isinstance(token._tokens[1], TimeoutToken) + assert token._tokens[1]._timeout == 2 + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_sum_of_2_temp_timeout_tokens_throw_right_temp_simple_token(): + token = TimeoutToken(1) + SimpleToken(TimeoutToken(2)) + + assert isinstance(token, TimeoutToken) + assert len(token._tokens) == 1 + assert len(token._tokens[0]._tokens) == 0 + assert token._timeout == 1 + assert token._tokens[0]._timeout == 2 + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_sum_of_2_temp_timeout_tokens_throw_left_temp_simple_token(): + token = SimpleToken(TimeoutToken(1)) + TimeoutToken(2) + + assert isinstance(token, TimeoutToken) + assert len(token._tokens) == 1 + assert token._timeout == 2 + + assert isinstance(token._tokens[0], TimeoutToken) + assert token._tokens[0]._timeout == 1 + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_sum_of_2_not_temp_timeout_tokens_throw_temp_simple_tokens(): + first_timeout_token = TimeoutToken(1) + second_timeout_token = TimeoutToken(2) + token = SimpleToken(first_timeout_token) + SimpleToken(second_timeout_token) + + assert isinstance(token, SimpleToken) + assert len(token._tokens) == 2 + + assert token._tokens[0] is first_timeout_token + assert isinstance(token._tokens[0], TimeoutToken) + assert token._tokens[0]._timeout == 1 + + assert token._tokens[1] is second_timeout_token + assert isinstance(token._tokens[1], TimeoutToken) + assert token._tokens[1]._timeout == 2 + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_sum_of_first_temp_and_second_not_temp_timeout_tokens_throw_temp_simple_tokens(): + second_timeout_token = TimeoutToken(2) + token = SimpleToken(TimeoutToken(1)) + SimpleToken(second_timeout_token) + + assert isinstance(token, SimpleToken) + assert len(token._tokens) == 2 + + assert isinstance(token._tokens[0], TimeoutToken) + assert token._tokens[0]._timeout == 1 + + assert token._tokens[1] is second_timeout_token + assert isinstance(token._tokens[1], TimeoutToken) + assert token._tokens[1]._timeout == 2 + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_sum_of_first_not_temp_and_second_temp_timeout_tokens_throw_temp_simple_tokens(): + first_timeout_token = TimeoutToken(1) + token = SimpleToken(first_timeout_token) + SimpleToken(TimeoutToken(2)) + + assert isinstance(token, SimpleToken) + assert len(token._tokens) == 2 + + assert token._tokens[0] is first_timeout_token + assert isinstance(token._tokens[0], TimeoutToken) + assert token._tokens[0]._timeout == 1 + + assert isinstance(token._tokens[1], TimeoutToken) + assert token._tokens[1]._timeout == 2 + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_sum_of_temp_timeout_token_and_temp_condition_token_throw_temp_simple_tokens(): + token = SimpleToken(TimeoutToken(1)) + SimpleToken(ConditionToken(lambda: False)) + + assert isinstance(token, SimpleToken) + assert len(token._tokens) == 2 + assert token + + assert isinstance(token._tokens[0], TimeoutToken) + assert token._tokens[0]._timeout == 1 + + assert isinstance(token._tokens[1], ConditionToken) + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_sum_of_temp_condition_token_and_temp_timeout_token_throw_temp_simple_tokens(): + token = SimpleToken(ConditionToken(lambda: False)) + SimpleToken(TimeoutToken(1)) + + assert isinstance(token, SimpleToken) + assert len(token._tokens) == 2 + assert token + + assert isinstance(token._tokens[0], ConditionToken) + + assert isinstance(token._tokens[1], TimeoutToken) + assert token._tokens[1]._timeout == 1 + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_sum_of_not_temp_timeout_token_and_temp_condition_token_throw_temp_simple_tokens(): + timeout_token = TimeoutToken(1) + token = SimpleToken(timeout_token) + SimpleToken(ConditionToken(lambda: False)) + + assert isinstance(token, SimpleToken) + assert len(token._tokens) == 2 + assert token + + assert token._tokens[0] is timeout_token + assert isinstance(token._tokens[0], TimeoutToken) + assert token._tokens[0]._timeout == 1 + + assert isinstance(token._tokens[1], ConditionToken) + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_sum_of_temp_timeout_token_and_not_temp_condition_token_throw_temp_simple_tokens(): + condition_token = ConditionToken(lambda: False) + token = SimpleToken(TimeoutToken(1)) + SimpleToken(condition_token) + + assert isinstance(token, SimpleToken) + assert len(token._tokens) == 2 + assert token + + assert isinstance(token._tokens[0], TimeoutToken) + assert token._tokens[0]._timeout == 1 + + assert isinstance(token._tokens[1], ConditionToken) + assert token._tokens[1] is condition_token + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_sum_of_not_temp_condition_token_and_temp_timeout_token_throw_temp_simple_tokens(): + condition_token = ConditionToken(lambda: False) + token = SimpleToken(condition_token) + SimpleToken(TimeoutToken(1)) + + assert isinstance(token, SimpleToken) + assert len(token._tokens) == 2 + assert token + + assert isinstance(token._tokens[0], ConditionToken) + assert token._tokens[0] is condition_token + + assert isinstance(token._tokens[1], TimeoutToken) + assert token._tokens[1]._timeout == 1 + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_sum_of_not_temp_timeout_token_and_not_temp_condition_token_throw_temp_simple_tokens(): + timeout_token = TimeoutToken(1) + condition_token = ConditionToken(lambda: False) + token = SimpleToken(timeout_token) + SimpleToken(condition_token) + + assert isinstance(token, SimpleToken) + assert len(token._tokens) == 2 + assert token + + assert token._tokens[0] is timeout_token + assert isinstance(token._tokens[0], TimeoutToken) + assert token._tokens[0]._timeout == 1 + + assert token._tokens[1] is condition_token + assert isinstance(token._tokens[1], ConditionToken) + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_sum_of_not_temp_condition_token_and_not_temp_timeout_token_throw_temp_simple_tokens(): + timeout_token = TimeoutToken(1) + condition_token = ConditionToken(lambda: False) + token = SimpleToken(condition_token) + SimpleToken(timeout_token) + + assert isinstance(token, SimpleToken) + assert len(token._tokens) == 2 + assert token + + assert token._tokens[0] is condition_token + assert isinstance(token._tokens[0], ConditionToken) + + assert token._tokens[1] is timeout_token + assert isinstance(token._tokens[1], TimeoutToken) + assert token._tokens[1]._timeout == 1 + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_temp_timeout_token_plus_temp_cancelled_simple_token(): + token = TimeoutToken(1) + SimpleToken(cancelled=True) + + assert isinstance(token, SimpleToken) + assert not token + assert len(token._tokens) == 0 diff --git a/tests/skipped/tokens/test_timeout_token.py b/tests/skipped/tokens/test_timeout_token.py new file mode 100644 index 0000000..757ba8c --- /dev/null +++ b/tests/skipped/tokens/test_timeout_token.py @@ -0,0 +1,1324 @@ +import pytest + +from cantok import ( + ConditionToken, + CounterToken, + SimpleToken, + TimeoutToken, +) + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_quasitemp_timeout_token_plus_temp_simple_token(): + token = TimeoutToken(1) + SimpleToken() + + assert isinstance(token, TimeoutToken) + assert len(token._tokens) == 0 + assert token._timeout == 1 + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_not_quasitemp_timeout_token_plus_temp_simple_token(): + timeout_token = TimeoutToken(1) + token = timeout_token + SimpleToken() + + assert isinstance(token, SimpleToken) + assert len(token._tokens) == 1 + assert isinstance(token._tokens[0], TimeoutToken) + assert token._tokens[0] is timeout_token + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_quasitemp_timeout_token_plus_not_temp_simple_token(): + simple_token = SimpleToken() + token = TimeoutToken(1) + simple_token + + assert isinstance(token, TimeoutToken) + assert token is not simple_token + assert len(token._tokens) == 1 + assert isinstance(token._tokens[0], SimpleToken) + assert token._tokens[0] is simple_token + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_quasitemp_timeout_token_plus_temp_simple_token_reverse(): + token = SimpleToken() + TimeoutToken(1) + + assert isinstance(token, TimeoutToken) + assert len(token._tokens) == 0 + assert token._timeout == 1 + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_not_quasitemp_timeout_token_plus_temp_simple_token_reverse(): + timeout_token = TimeoutToken(1) + token = SimpleToken() + timeout_token + + assert isinstance(token, SimpleToken) + assert len(token._tokens) == 1 + assert isinstance(token._tokens[0], TimeoutToken) + assert token._tokens[0] is timeout_token + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_quasitemp_timeout_token_plus_not_temp_simple_token_reverse(): + simple_token = SimpleToken() + token = simple_token + TimeoutToken(1) + + assert isinstance(token, TimeoutToken) + assert token._timeout == 1 + assert token is not simple_token + assert len(token._tokens) == 1 + assert isinstance(token._tokens[0], SimpleToken) + assert token._tokens[0] is simple_token + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + 'addictional_kwargs', + [ + {'monotonic': False}, + {}, + {'monotonic': True}, + ], +) +def test_bigger_temp_timeout_token_plus_less_temp_timeout_token_with_same_monotonic_flag(addictional_kwargs): + token = TimeoutToken(2, **addictional_kwargs) + TimeoutToken(1, **addictional_kwargs) + + assert isinstance(token, TimeoutToken) + assert token._timeout == 1 + assert len(token._tokens) == 0 + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + ('left_addictional_kwargs', 'right_addictional_kwargs'), + [ + ({'monotonic': False}, {'monotonic': True}), + ({}, {'monotonic': True}), + ({'monotonic': True}, {'monotonic': False}), + ({'monotonic': True}, {}), + ], +) +def test_bigger_temp_timeout_token_plus_less_temp_timeout_token_with_not_same_monotonic_flag(left_addictional_kwargs, right_addictional_kwargs): + token = TimeoutToken(2, **left_addictional_kwargs) + TimeoutToken(1, **right_addictional_kwargs) + + assert isinstance(token, TimeoutToken) + assert token._timeout == 2 + assert len(token._tokens) == 1 + assert len(token._tokens[0]._tokens) == 0 + assert isinstance(token._tokens[0], TimeoutToken) + assert token._tokens[0]._timeout == 1 + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + 'timeout_for_equal_or_bigger_token', + [ + 1, + 2, + ], +) +@pytest.mark.parametrize( + 'addictional_kwargs', + [ + {'monotonic': False}, + {}, + {'monotonic': True}, + ], +) +def test_less_or_equal_temp_not_monotonic_timeout_token_plus_bigger_or_equal_temp_not_monotonic_timeout_token_with_same_monotonic_flag(timeout_for_equal_or_bigger_token, addictional_kwargs): + token = TimeoutToken(1, **addictional_kwargs) + TimeoutToken(timeout_for_equal_or_bigger_token, **addictional_kwargs) + + assert isinstance(token, TimeoutToken) + assert token._timeout == 1 + assert len(token._tokens) == 0 + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + 'timeout_for_equal_or_bigger_token', + [ + 1, + 2, + ], +) +@pytest.mark.parametrize( + ('left_addictional_kwargs', 'right_addictional_kwargs'), + [ + ({'monotonic': False}, {'monotonic': True}), + ({}, {'monotonic': True}), + ({'monotonic': True}, {'monotonic': False}), + ({'monotonic': True}, {}), + ], +) +def test_less_or_equal_temp_not_monotonic_timeout_token_plus_bigger_or_equal_temp_not_monotonic_timeout_token_with_not_same_monotonic_flag(timeout_for_equal_or_bigger_token, left_addictional_kwargs, right_addictional_kwargs): + token = TimeoutToken(1, **left_addictional_kwargs) + TimeoutToken(timeout_for_equal_or_bigger_token, **right_addictional_kwargs) + + assert isinstance(token, TimeoutToken) + assert token._timeout == 1 + assert len(token._tokens) == 1 + assert len(token._tokens[0]._tokens) == 0 + assert isinstance(token._tokens[0], TimeoutToken) + assert token._tokens[0]._timeout == timeout_for_equal_or_bigger_token + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + 'addictional_kwargs', + [ + {'monotonic': False}, + {}, + {'monotonic': True}, + ], +) +def test_bigger_timeout_token_plus_less_temp_timeout_token_with_same_monotonic_flag(addictional_kwargs): + left_timeout_token = TimeoutToken(2, **addictional_kwargs) + token = left_timeout_token + TimeoutToken(1, **addictional_kwargs) + + assert isinstance(token, TimeoutToken) + assert token is not left_timeout_token + assert token._timeout == 1 + assert len(token._tokens) == 1 + assert len(token._tokens[0]._tokens) == 0 + assert isinstance(token._tokens[0], TimeoutToken) + assert token._tokens[0]._timeout == 2 + assert token._tokens[0] is left_timeout_token + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + ('left_addictional_kwargs', 'right_addictional_kwargs'), + [ + ({'monotonic': False}, {'monotonic': True}), + ({}, {'monotonic': True}), + ({'monotonic': True}, {'monotonic': False}), + ({'monotonic': True}, {}), + ], +) +def test_bigger_timeout_token_plus_less_temp_timeout_token_with_not_same_monotonic_flag(left_addictional_kwargs, right_addictional_kwargs): + left_timeout_token = TimeoutToken(2, **left_addictional_kwargs) + token = left_timeout_token + TimeoutToken(1, **right_addictional_kwargs) + + assert isinstance(token, TimeoutToken) + assert token._timeout == 1 + assert len(token._tokens) == 1 + assert len(token._tokens[0]._tokens) == 0 + assert isinstance(token._tokens[0], TimeoutToken) + assert token._tokens[0]._timeout == 2 + assert token._tokens[0] is left_timeout_token + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + 'addictional_kwargs', + [ + {'monotonic': False}, + {}, + {'monotonic': True}, + ], +) +def test_less_not_monotonic_timeout_token_plus_bigger_temp_not_monotonic_timeout_token_with_same_monotonic_flag(addictional_kwargs): + left_timeout_token = TimeoutToken(1, **addictional_kwargs) + token = left_timeout_token + TimeoutToken(2, **addictional_kwargs) + + assert isinstance(token, TimeoutToken) + assert token._timeout == 1 + assert len(token._tokens) == 0 + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + ('left_addictional_kwargs', 'right_addictional_kwargs'), + [ + ({'monotonic': False}, {'monotonic': True}), + ({}, {'monotonic': True}), + ({'monotonic': True}, {'monotonic': False}), + ({'monotonic': True}, {}), + ], +) +def test_less_not_monotonic_timeout_token_plus_bigger_temp_not_monotonic_timeout_token_with_not_same_monotonic_flag(left_addictional_kwargs, right_addictional_kwargs): + left_timeout_token = TimeoutToken(1, **left_addictional_kwargs) + token = left_timeout_token + TimeoutToken(2, **right_addictional_kwargs) + + assert isinstance(token, TimeoutToken) + assert token._timeout == 2 + assert len(token._tokens) == 1 + assert len(token._tokens[0]._tokens) == 0 + assert isinstance(token._tokens[0], TimeoutToken) + assert token._tokens[0]._timeout == 1 + assert token._tokens[0] is left_timeout_token + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + 'addictional_kwargs', + [ + {'monotonic': False}, + {}, + {'monotonic': True}, + ], +) +def test_bigger_temp_timeout_token_plus_less_timeout_token_with_same_monotonic_flag(addictional_kwargs): + right_timeout_token = TimeoutToken(1, **addictional_kwargs) + token = TimeoutToken(2, **addictional_kwargs) + right_timeout_token + + assert isinstance(token, TimeoutToken) + assert token._timeout == 1 + assert len(token._tokens) == 0 + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + ('left_addictional_kwargs', 'right_addictional_kwargs'), + [ + ({'monotonic': False}, {'monotonic': True}), + ({}, {'monotonic': True}), + ({'monotonic': True}, {'monotonic': False}), + ({'monotonic': True}, {}), + ], +) +def test_bigger_temp_timeout_token_plus_less_timeout_token_with_not_same_monotonic_flag(left_addictional_kwargs, right_addictional_kwargs): + right_timeout_token = TimeoutToken(1, **right_addictional_kwargs) + token = TimeoutToken(2, **left_addictional_kwargs) + right_timeout_token + + assert isinstance(token, TimeoutToken) + assert token._timeout == 2 + assert len(token._tokens) == 1 + assert len(token._tokens[0]._tokens) == 0 + assert isinstance(token._tokens[0], TimeoutToken) + assert token._tokens[0]._timeout == 1 + assert token._tokens[0] is right_timeout_token + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + 'addictional_kwargs', + [ + {'monotonic': False}, + {}, + {'monotonic': True}, + ], +) +def test_less_temp_not_monotonic_timeout_token_plus_bigger_not_monotonic_timeout_token_with_same_monotonic_flag(addictional_kwargs): + right_timeout_token = TimeoutToken(2, **addictional_kwargs) + token = TimeoutToken(1, **addictional_kwargs) + right_timeout_token + + assert isinstance(token, TimeoutToken) + assert token._timeout == 1 + assert len(token._tokens) == 1 + assert len(token._tokens[0]._tokens) == 0 + assert token._tokens[0]._timeout == 2 + assert token._tokens[0] is right_timeout_token + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + ('left_addictional_kwargs', 'right_addictional_kwargs'), + [ + ({'monotonic': False}, {'monotonic': True}), + ({}, {'monotonic': True}), + ({'monotonic': True}, {'monotonic': False}), + ({'monotonic': True}, {}), + ], +) +def test_less_temp_not_monotonic_timeout_token_plus_bigger_not_monotonic_timeout_token_with_not_same_monotonic_flag(left_addictional_kwargs, right_addictional_kwargs): + right_timeout_token = TimeoutToken(2, **right_addictional_kwargs) + token = TimeoutToken(1, **left_addictional_kwargs) + right_timeout_token + + assert isinstance(token, TimeoutToken) + assert token._timeout == 1 + assert len(token._tokens) == 1 + assert len(token._tokens[0]._tokens) == 0 + assert isinstance(token._tokens[0], TimeoutToken) + assert token._tokens[0]._timeout == 2 + assert token._tokens[0] is right_timeout_token + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + 'addictional_kwargs', + [ + {'monotonic': False}, + {}, + {'monotonic': True}, + ], +) +def test_bigger_temp_timeout_token_plus_less_temp_timeout_token_with_same_monotonic_flag_with_temp_condition_token_at_right(addictional_kwargs): + token = TimeoutToken(2, **addictional_kwargs) + TimeoutToken(1, ConditionToken(lambda: True), **addictional_kwargs) + + assert isinstance(token, TimeoutToken) + assert token._timeout == 1 + assert len(token._tokens) == 1 + assert isinstance(token._tokens[0], ConditionToken) + assert len(token._tokens[0]._tokens) == 0 + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + ('left_addictional_kwargs', 'right_addictional_kwargs'), + [ + ({'monotonic': False}, {'monotonic': True}), + ({}, {'monotonic': True}), + ({'monotonic': True}, {'monotonic': False}), + ({'monotonic': True}, {}), + ], +) +def test_bigger_temp_timeout_token_plus_less_temp_timeout_token_with_not_same_monotonic_flag_with_temp_condition_token_at_right(left_addictional_kwargs, right_addictional_kwargs): + token = TimeoutToken(2, **left_addictional_kwargs) + TimeoutToken(1, ConditionToken(lambda: True), **right_addictional_kwargs) + + assert isinstance(token, TimeoutToken) + assert token._timeout == 2 + assert len(token._tokens) == 1 + assert len(token._tokens[0]._tokens) == 1 + assert isinstance(token._tokens[0], TimeoutToken) + assert token._tokens[0]._timeout == 1 + assert isinstance(token._tokens[0]._tokens[0], ConditionToken) + assert len(token._tokens[0]._tokens[0]._tokens) == 0 + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + 'timeout_for_equal_or_bigger_token', + [ + 1, + 2, + ], +) +@pytest.mark.parametrize( + 'addictional_kwargs', + [ + {'monotonic': False}, + {}, + {'monotonic': True}, + ], +) +def test_less_or_equal_temp_not_monotonic_timeout_token_plus_bigger_or_equal_temp_not_monotonic_timeout_token_with_same_monotonic_flag_with_temp_condition_token_at_right(timeout_for_equal_or_bigger_token, addictional_kwargs): + token = TimeoutToken(1, **addictional_kwargs) + TimeoutToken(timeout_for_equal_or_bigger_token, ConditionToken(lambda: True), **addictional_kwargs) + + assert isinstance(token, TimeoutToken) + assert token._timeout == 1 + assert len(token._tokens) == 1 + assert len(token._tokens[0]._tokens) == 0 + assert isinstance(token._tokens[0], ConditionToken) + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + 'timeout_for_equal_or_bigger_token', + [ + 1, + 2, + ], +) +@pytest.mark.parametrize( + ('left_addictional_kwargs', 'right_addictional_kwargs'), + [ + ({'monotonic': False}, {'monotonic': True}), + ({}, {'monotonic': True}), + ({'monotonic': True}, {'monotonic': False}), + ({'monotonic': True}, {}), + ], +) +def test_less_or_equal_temp_not_monotonic_timeout_token_plus_bigger_or_equal_temp_not_monotonic_timeout_token_with_not_same_monotonic_flag_with_temp_condition_token_at_right(timeout_for_equal_or_bigger_token, left_addictional_kwargs, right_addictional_kwargs): + token = TimeoutToken(1, **left_addictional_kwargs) + TimeoutToken(timeout_for_equal_or_bigger_token, ConditionToken(lambda: True), **right_addictional_kwargs) + + assert isinstance(token, TimeoutToken) + assert token._timeout == 1 + assert len(token._tokens) == 1 + assert len(token._tokens[0]._tokens) == 1 + assert isinstance(token._tokens[0], TimeoutToken) + assert token._tokens[0]._timeout == timeout_for_equal_or_bigger_token + assert isinstance(token._tokens[0]._tokens[0], ConditionToken) + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + 'addictional_kwargs', + [ + {'monotonic': False}, + {}, + {'monotonic': True}, + ], +) +def test_bigger_timeout_token_plus_less_temp_timeout_token_with_same_monotonic_flag_with_temp_condition_token_at_right(addictional_kwargs): + left_timeout_token = TimeoutToken(2, **addictional_kwargs) + token = left_timeout_token + TimeoutToken(1, ConditionToken(lambda: True), **addictional_kwargs) + + assert isinstance(token, TimeoutToken) + assert token is not left_timeout_token + assert token._timeout == 1 + assert len(token._tokens) == 2 + assert len(token._tokens[0]._tokens) == 0 + assert len(token._tokens[1]._tokens) == 0 + assert isinstance(token._tokens[0], ConditionToken) + assert isinstance(token._tokens[1], TimeoutToken) + assert token._tokens[1]._timeout == 2 + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + ('left_addictional_kwargs', 'right_addictional_kwargs'), + [ + ({'monotonic': False}, {'monotonic': True}), + ({}, {'monotonic': True}), + ({'monotonic': True}, {'monotonic': False}), + ({'monotonic': True}, {}), + ], +) +def test_bigger_timeout_token_plus_less_temp_timeout_token_with_not_same_monotonic_flag_with_temp_condition_token_at_right(left_addictional_kwargs, right_addictional_kwargs): + left_timeout_token = TimeoutToken(2, **left_addictional_kwargs) + token = left_timeout_token + TimeoutToken(1, ConditionToken(lambda: True), **right_addictional_kwargs) + + assert isinstance(token, TimeoutToken) + assert token._timeout == 1 + assert len(token._tokens) == 2 + assert len(token._tokens[0]._tokens) == 0 + assert len(token._tokens[1]._tokens) == 0 + assert isinstance(token._tokens[0], ConditionToken) + assert token._tokens[0] is not left_timeout_token + assert isinstance(token._tokens[1], TimeoutToken) + assert token._tokens[1]._timeout == 2 + assert token._tokens[1] is left_timeout_token + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + 'addictional_kwargs', + [ + {'monotonic': False}, + {}, + {'monotonic': True}, + ], +) +def test_less_not_monotonic_timeout_token_plus_bigger_temp_not_monotonic_timeout_token_with_same_monotonic_flag_with_temp_condition_token_at_right(addictional_kwargs): + left_timeout_token = TimeoutToken(1, **addictional_kwargs) + token = left_timeout_token + TimeoutToken(2, ConditionToken(lambda: True), **addictional_kwargs) + + assert isinstance(token, SimpleToken) + assert len(token._tokens) == 2 + assert len(token._tokens[0]._tokens) == 0 + assert len(token._tokens[1]._tokens) == 0 + assert isinstance(token._tokens[0], ConditionToken) + assert isinstance(token._tokens[1], TimeoutToken) + assert token._tokens[1]._timeout == 1 + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + ('left_addictional_kwargs', 'right_addictional_kwargs'), + [ + ({'monotonic': False}, {'monotonic': True}), + ({}, {'monotonic': True}), + ({'monotonic': True}, {'monotonic': False}), + ({'monotonic': True}, {}), + ], +) +def test_less_not_monotonic_timeout_token_plus_bigger_temp_not_monotonic_timeout_token_with_not_same_monotonic_flag_with_temp_condition_token_at_right(left_addictional_kwargs, right_addictional_kwargs): + left_timeout_token = TimeoutToken(1, **left_addictional_kwargs) + token = left_timeout_token + TimeoutToken(2, ConditionToken(lambda: True), **right_addictional_kwargs) + + assert isinstance(token, TimeoutToken) + assert token._timeout == 2 + assert len(token._tokens) == 2 + assert len(token._tokens[0]._tokens) == 0 + assert len(token._tokens[1]._tokens) == 0 + assert isinstance(token._tokens[0], ConditionToken) + assert token._tokens[0] is not left_timeout_token + assert isinstance(token._tokens[1], TimeoutToken) + assert token._tokens[1]._timeout == 1 + assert token._tokens[1] is left_timeout_token + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + 'addictional_kwargs', + [ + {'monotonic': False}, + {}, + {'monotonic': True}, + ], +) +def test_bigger_temp_timeout_token_plus_less_timeout_token_with_same_monotonic_flag_with_temp_condition_token_at_right(addictional_kwargs): + right_timeout_token = TimeoutToken(1, ConditionToken(lambda: True), **addictional_kwargs) + token = TimeoutToken(2, **addictional_kwargs) + right_timeout_token + + assert isinstance(token, TimeoutToken) + assert token._timeout == 1 + assert len(token._tokens) == 1 + assert len(token._tokens[0]._tokens) == 0 + assert isinstance(token._tokens[0], ConditionToken) + assert token is right_timeout_token + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + ('left_addictional_kwargs', 'right_addictional_kwargs'), + [ + ({'monotonic': False}, {'monotonic': True}), + ({}, {'monotonic': True}), + ({'monotonic': True}, {'monotonic': False}), + ({'monotonic': True}, {}), + ], +) +def test_bigger_temp_timeout_token_plus_less_timeout_token_with_not_same_monotonic_flag_with_temp_condition_token_at_right(left_addictional_kwargs, right_addictional_kwargs): + right_timeout_token = TimeoutToken(1, ConditionToken(lambda: True), **right_addictional_kwargs) + token = TimeoutToken(2, **left_addictional_kwargs) + right_timeout_token + + assert isinstance(token, TimeoutToken) + assert token._timeout == 2 + assert len(token._tokens) == 1 + assert len(token._tokens[0]._tokens) == 1 + assert len(token._tokens[0]._tokens[0]._tokens) == 0 + assert isinstance(token._tokens[0], TimeoutToken) + assert token._tokens[0]._timeout == 1 + assert token._tokens[0] is right_timeout_token + assert isinstance(token._tokens[0]._tokens[0], ConditionToken) + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + 'addictional_kwargs', + [ + {'monotonic': False}, + {}, + {'monotonic': True}, + ], +) +def test_less_temp_not_monotonic_timeout_token_plus_bigger_not_monotonic_timeout_token_with_same_monotonic_flag_with_temp_condition_token_at_right(addictional_kwargs): + right_timeout_token = TimeoutToken(2, ConditionToken(lambda: True), **addictional_kwargs) + token = TimeoutToken(1, **addictional_kwargs) + right_timeout_token + + assert isinstance(token, TimeoutToken) + assert token._timeout == 1 + assert len(token._tokens) == 1 + assert len(token._tokens[0]._tokens) == 1 + assert len(token._tokens[0]._tokens[0]._tokens) == 0 + assert token._tokens[0]._timeout == 2 + assert token._tokens[0] is right_timeout_token + assert isinstance(token._tokens[0]._tokens[0], ConditionToken) + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + ('left_addictional_kwargs', 'right_addictional_kwargs'), + [ + ({'monotonic': False}, {'monotonic': True}), + ({}, {'monotonic': True}), + ({'monotonic': True}, {'monotonic': False}), + ({'monotonic': True}, {}), + ], +) +def test_less_temp_not_monotonic_timeout_token_plus_bigger_not_monotonic_timeout_token_with_not_same_monotonic_flag_with_temp_condition_token_at_right(left_addictional_kwargs, right_addictional_kwargs): + right_timeout_token = TimeoutToken(2, ConditionToken(lambda: True), **right_addictional_kwargs) + token = TimeoutToken(1, **left_addictional_kwargs) + right_timeout_token + + assert isinstance(token, TimeoutToken) + assert token._timeout == 1 + assert len(token._tokens) == 1 + assert len(token._tokens[0]._tokens) == 1 + assert len(token._tokens[0]._tokens[0]._tokens) == 0 + assert isinstance(token._tokens[0], TimeoutToken) + assert token._tokens[0]._timeout == 2 + assert token._tokens[0] is right_timeout_token + assert isinstance(token._tokens[0]._tokens[0], ConditionToken) + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + 'addictional_kwargs', + [ + {'monotonic': False}, + {}, + {'monotonic': True}, + ], +) +def test_bigger_temp_timeout_token_plus_less_temp_timeout_token_with_same_monotonic_flag_with_temp_condition_token_at_right_and_counter_token_at_left(addictional_kwargs): + token = TimeoutToken(2, CounterToken(5), **addictional_kwargs) + TimeoutToken(1, ConditionToken(lambda: True), **addictional_kwargs) + + assert isinstance(token, TimeoutToken) + assert token._timeout == 1 + assert len(token._tokens) == 2 + assert len(token._tokens[0]._tokens) == 0 + assert len(token._tokens[1]._tokens) == 0 + assert isinstance(token._tokens[0], ConditionToken) + assert isinstance(token._tokens[1], CounterToken) + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + ('left_addictional_kwargs', 'right_addictional_kwargs'), + [ + ({'monotonic': False}, {'monotonic': True}), + ({}, {'monotonic': True}), + ({'monotonic': True}, {'monotonic': False}), + ({'monotonic': True}, {}), + ], +) +def test_bigger_temp_timeout_token_plus_less_temp_timeout_token_with_not_same_monotonic_flag_with_temp_condition_token_at_right_and_counter_token_at_left(left_addictional_kwargs, right_addictional_kwargs): + token = TimeoutToken(2, CounterToken(5), **left_addictional_kwargs) + TimeoutToken(1, ConditionToken(lambda: True), **right_addictional_kwargs) + + assert isinstance(token, TimeoutToken) + assert token._timeout == 2 + assert len(token._tokens) == 2 + assert len(token._tokens[1]._tokens) == 1 + assert isinstance(token._tokens[1], TimeoutToken) + assert token._tokens[1]._timeout == 1 + assert isinstance(token._tokens[1]._tokens[0], ConditionToken) + assert len(token._tokens[1]._tokens[0]._tokens) == 0 + assert len(token._tokens[0]._tokens) == 0 + assert isinstance(token._tokens[0], CounterToken) + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + 'timeout_for_equal_or_bigger_token', + [ + 1, + 2, + ], +) +@pytest.mark.parametrize( + 'addictional_kwargs', + [ + {'monotonic': False}, + {}, + {'monotonic': True}, + ], +) +def test_less_or_equal_temp_not_monotonic_timeout_token_plus_bigger_or_equal_temp_not_monotonic_timeout_token_with_same_monotonic_flag_with_temp_condition_token_at_right_and_counter_token_at_left(timeout_for_equal_or_bigger_token, addictional_kwargs): + token = TimeoutToken(1, CounterToken(5), **addictional_kwargs) + TimeoutToken(timeout_for_equal_or_bigger_token, ConditionToken(lambda: True), **addictional_kwargs) + + assert isinstance(token, TimeoutToken) + assert token._timeout == 1 + assert len(token._tokens) == 2 + assert len(token._tokens[0]._tokens) == 0 + assert len(token._tokens[1]._tokens) == 0 + assert {type(token._tokens[0]), type(token._tokens[1])} == {CounterToken, ConditionToken} + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + 'timeout_for_equal_or_bigger_token', + [ + 1, + 2, + ], +) +@pytest.mark.parametrize( + ('left_addictional_kwargs', 'right_addictional_kwargs'), + [ + ({'monotonic': False}, {'monotonic': True}), + ({}, {'monotonic': True}), + ({'monotonic': True}, {'monotonic': False}), + ({'monotonic': True}, {}), + ], +) +def test_less_or_equal_temp_not_monotonic_timeout_token_plus_bigger_or_equal_temp_not_monotonic_timeout_token_with_not_same_monotonic_flag_with_temp_condition_token_at_right_and_counter_token_at_left(timeout_for_equal_or_bigger_token, left_addictional_kwargs, right_addictional_kwargs): + token = TimeoutToken(1, CounterToken(5), **left_addictional_kwargs) + TimeoutToken(timeout_for_equal_or_bigger_token, ConditionToken(lambda: True), **right_addictional_kwargs) + + assert isinstance(token, TimeoutToken) + assert token._timeout == 1 + assert len(token._tokens) == 2 + assert len(token._tokens[0]._tokens) == 0 + assert len(token._tokens[1]._tokens) == 1 + assert len(token._tokens[1]._tokens[0]._tokens) == 0 + assert isinstance(token._tokens[0], CounterToken) + assert isinstance(token._tokens[1], TimeoutToken) + assert isinstance(token._tokens[1]._tokens[0], ConditionToken) + assert token._tokens[1]._timeout == timeout_for_equal_or_bigger_token + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + 'addictional_kwargs', + [ + {'monotonic': False}, + {}, + {'monotonic': True}, + ], +) +def test_bigger_timeout_token_plus_less_temp_timeout_token_with_same_monotonic_flag_with_temp_condition_token_at_right_and_counter_token_at_left(addictional_kwargs): + left_timeout_token = TimeoutToken(2, CounterToken(5), **addictional_kwargs) + token = left_timeout_token + TimeoutToken(1, ConditionToken(lambda: True), **addictional_kwargs) + + assert isinstance(token, TimeoutToken) + assert token is not left_timeout_token + assert token._tokens[1] is left_timeout_token + assert token._timeout == 1 + assert len(token._tokens) == 2 + assert len(token._tokens[0]._tokens) == 0 + assert len(token._tokens[1]._tokens) == 1 + assert len(token._tokens[1]._tokens[0]._tokens) == 0 + assert isinstance(token._tokens[0], ConditionToken) + assert isinstance(token._tokens[1], TimeoutToken) + assert token._tokens[1]._timeout == 2 + assert isinstance(token._tokens[1]._tokens[0], CounterToken) + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + ('left_addictional_kwargs', 'right_addictional_kwargs'), + [ + ({'monotonic': False}, {'monotonic': True}), + ({}, {'monotonic': True}), + ({'monotonic': True}, {'monotonic': False}), + ({'monotonic': True}, {}), + ], +) +def test_bigger_timeout_token_plus_less_temp_timeout_token_with_not_same_monotonic_flag_with_temp_condition_token_at_right_and_counter_token_at_left(left_addictional_kwargs, right_addictional_kwargs): + left_timeout_token = TimeoutToken(2, CounterToken(5), **left_addictional_kwargs) + token = left_timeout_token + TimeoutToken(1, ConditionToken(lambda: True), **right_addictional_kwargs) + + assert isinstance(token, TimeoutToken) + assert token is not left_timeout_token + assert token._tokens[1] is left_timeout_token + assert token._timeout == 1 + assert len(token._tokens) == 2 + assert len(token._tokens[0]._tokens) == 0 + assert len(token._tokens[1]._tokens) == 1 + assert len(token._tokens[1]._tokens[0]._tokens) == 0 + assert isinstance(token._tokens[0], ConditionToken) + assert isinstance(token._tokens[1], TimeoutToken) + assert token._tokens[1]._timeout == 2 + assert isinstance(token._tokens[1]._tokens[0], CounterToken) + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + 'addictional_kwargs', + [ + {'monotonic': False}, + {}, + {'monotonic': True}, + ], +) +def test_less_not_monotonic_timeout_token_plus_bigger_temp_not_monotonic_timeout_token_with_same_monotonic_flag_with_temp_condition_token_at_right_and_counter_token_at_left(addictional_kwargs): + left_timeout_token = TimeoutToken(1, CounterToken(5), **addictional_kwargs) + token = left_timeout_token + TimeoutToken(2, ConditionToken(lambda: True), **addictional_kwargs) + + assert isinstance(token, SimpleToken) + assert len(token._tokens) == 2 + assert len(token._tokens[0]._tokens) == 0 + assert len(token._tokens[1]._tokens) == 1 + assert len(token._tokens[1]._tokens[0]._tokens) == 0 + assert isinstance(token._tokens[0], ConditionToken) + assert isinstance(token._tokens[1], TimeoutToken) + assert token._tokens[1]._timeout == 1 + assert isinstance(token._tokens[1]._tokens[0], CounterToken) + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + ('left_addictional_kwargs', 'right_addictional_kwargs'), + [ + ({'monotonic': False}, {'monotonic': True}), + ({}, {'monotonic': True}), + ({'monotonic': True}, {'monotonic': False}), + ({'monotonic': True}, {}), + ], +) +def test_less_not_monotonic_timeout_token_plus_bigger_temp_not_monotonic_timeout_token_with_not_same_monotonic_flag_with_temp_condition_token_at_right_and_counter_token_at_left(left_addictional_kwargs, right_addictional_kwargs): + left_timeout_token = TimeoutToken(1, CounterToken(5), **left_addictional_kwargs) + token = left_timeout_token + TimeoutToken(2, ConditionToken(lambda: True), **right_addictional_kwargs) + + assert isinstance(token, TimeoutToken) + assert token._timeout == 2 + assert len(token._tokens) == 2 + assert len(token._tokens[0]._tokens) == 0 + assert len(token._tokens[1]._tokens) == 1 + assert len(token._tokens[1]._tokens[0]._tokens) == 0 + assert isinstance(token._tokens[0], ConditionToken) + assert token._tokens[0] is not left_timeout_token + assert isinstance(token._tokens[1], TimeoutToken) + assert token._tokens[1]._timeout == 1 + assert token._tokens[1] is left_timeout_token + assert isinstance(token._tokens[1]._tokens[0], CounterToken) + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + 'addictional_kwargs', + [ + {'monotonic': False}, + {}, + {'monotonic': True}, + ], +) +def test_bigger_temp_timeout_token_plus_less_timeout_token_with_same_monotonic_flag_with_temp_condition_token_at_right_and_counter_token_at_left(addictional_kwargs): + right_timeout_token = TimeoutToken(1, ConditionToken(lambda: True), **addictional_kwargs) + token = TimeoutToken(2, CounterToken(5), **addictional_kwargs) + right_timeout_token + + assert isinstance(token, SimpleToken) + assert isinstance(token._tokens[0], CounterToken) + assert isinstance(token._tokens[1], TimeoutToken) + assert isinstance(token._tokens[1]._tokens[0], ConditionToken) + assert token._tokens[1]._timeout == 1 + assert len(token._tokens) == 2 + assert len(token._tokens[0]._tokens) == 0 + assert len(token._tokens[1]._tokens) == 1 + assert len(token._tokens[1]._tokens[0]._tokens) == 0 + assert token._tokens[1] is right_timeout_token + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + ('left_addictional_kwargs', 'right_addictional_kwargs'), + [ + ({'monotonic': False}, {'monotonic': True}), + ({}, {'monotonic': True}), + ({'monotonic': True}, {'monotonic': False}), + ({'monotonic': True}, {}), + ], +) +def test_bigger_temp_timeout_token_plus_less_timeout_token_with_not_same_monotonic_flag_with_temp_condition_token_at_right_and_counter_token_at_left(left_addictional_kwargs, right_addictional_kwargs): + right_timeout_token = TimeoutToken(1, ConditionToken(lambda: True), **right_addictional_kwargs) + token = TimeoutToken(2, CounterToken(5), **left_addictional_kwargs) + right_timeout_token + + assert isinstance(token, TimeoutToken) + assert isinstance(token._tokens[0], CounterToken) + assert isinstance(token._tokens[1], TimeoutToken) + assert isinstance(token._tokens[1]._tokens[0], ConditionToken) + assert token._tokens[1]._timeout == 1 + assert token._timeout == 2 + assert len(token._tokens) == 2 + assert len(token._tokens[0]._tokens) == 0 + assert len(token._tokens[1]._tokens) == 1 + assert len(token._tokens[1]._tokens[0]._tokens) == 0 + assert token._tokens[1] is right_timeout_token + assert token is not right_timeout_token + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + 'addictional_kwargs', + [ + {'monotonic': False}, + {}, + {'monotonic': True}, + ], +) +def test_less_temp_not_monotonic_timeout_token_plus_bigger_not_monotonic_timeout_token_with_same_monotonic_flag_with_temp_condition_token_at_right_and_counter_token_at_left(addictional_kwargs): + right_timeout_token = TimeoutToken(2, ConditionToken(lambda: True), **addictional_kwargs) + token = TimeoutToken(1, CounterToken(5), **addictional_kwargs) + right_timeout_token + + TimeoutToken(1, CounterToken(5), TimeoutToken(2, ConditionToken(lambda: True))) + + assert isinstance(token, TimeoutToken) + assert token._timeout == 1 + assert len(token._tokens) == 2 + assert len(token._tokens[0]._tokens) == 0 + assert len(token._tokens[1]._tokens) == 1 + assert len(token._tokens[1]._tokens[0]._tokens) == 0 + assert token._timeout == 1 + assert token._tokens[1]._timeout == 2 + assert token._tokens[1] is right_timeout_token + assert isinstance(token._tokens[1]._tokens[0], ConditionToken) + assert isinstance(token._tokens[0], CounterToken) + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + ('left_addictional_kwargs', 'right_addictional_kwargs'), + [ + ({'monotonic': False}, {'monotonic': True}), + ({}, {'monotonic': True}), + ({'monotonic': True}, {'monotonic': False}), + ({'monotonic': True}, {}), + ], +) +def test_less_temp_not_monotonic_timeout_token_plus_bigger_not_monotonic_timeout_token_with_not_same_monotonic_flag_with_temp_condition_token_at_right_and_counter_token_at_left(left_addictional_kwargs, right_addictional_kwargs): + right_timeout_token = TimeoutToken(2, ConditionToken(lambda: True), **right_addictional_kwargs) + token = TimeoutToken(1, CounterToken(5), **left_addictional_kwargs) + right_timeout_token + + TimeoutToken(1, CounterToken(5), TimeoutToken(2, ConditionToken(lambda: True))) + + assert isinstance(token, TimeoutToken) + assert isinstance(token._tokens[0], CounterToken) + assert isinstance(token._tokens[1], TimeoutToken) + assert isinstance(token._tokens[1]._tokens[0], ConditionToken) + assert token._timeout == 1 + assert token._tokens[1]._timeout == 2 + assert len(token._tokens) == 2 + assert len(token._tokens[0]._tokens) == 0 + assert len(token._tokens[1]._tokens) == 1 + assert len(token._tokens[1]._tokens[0]._tokens) == 0 + assert token._tokens[1] is right_timeout_token + assert token is not right_timeout_token + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + 'addictional_kwargs', + [ + {'monotonic': False}, + {}, + {'monotonic': True}, + ], +) +def test_bigger_temp_timeout_token_plus_less_temp_timeout_token_with_same_monotonic_flag_with_temp_counter_token_at_left(addictional_kwargs): + token = TimeoutToken(2, CounterToken(5), **addictional_kwargs) + TimeoutToken(1, **addictional_kwargs) + + assert isinstance(token, TimeoutToken) + assert token._timeout == 1 + assert len(token._tokens) == 1 + assert len(token._tokens[0]._tokens) == 0 + assert isinstance(token._tokens[0], CounterToken) + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + ('left_addictional_kwargs', 'right_addictional_kwargs'), + [ + ({'monotonic': False}, {'monotonic': True}), + ({}, {'monotonic': True}), + ({'monotonic': True}, {'monotonic': False}), + ({'monotonic': True}, {}), + ], +) +def test_bigger_temp_timeout_token_plus_less_temp_timeout_token_with_not_same_monotonic_flag_with_temp_counter_token_at_left(left_addictional_kwargs, right_addictional_kwargs): + token = TimeoutToken(2, CounterToken(5), **left_addictional_kwargs) + TimeoutToken(1, **right_addictional_kwargs) + + assert isinstance(token, TimeoutToken) + assert token._timeout == 2 + assert len(token._tokens) == 2 + assert len(token._tokens[0]._tokens) == 0 + assert len(token._tokens[1]._tokens) == 0 + assert isinstance(token._tokens[0], CounterToken) + assert isinstance(token._tokens[1], TimeoutToken) + assert token._tokens[1]._timeout == 1 + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + 'timeout_for_equal_or_bigger_token', + [ + 1, + 2, + ], +) +@pytest.mark.parametrize( + 'addictional_kwargs', + [ + {'monotonic': False}, + {}, + {'monotonic': True}, + ], +) +def test_less_or_equal_temp_not_monotonic_timeout_token_plus_bigger_or_equal_temp_not_monotonic_timeout_token_with_same_monotonic_flag_with_temp_counter_token_at_left(timeout_for_equal_or_bigger_token, addictional_kwargs): + token = TimeoutToken(1, CounterToken(5), **addictional_kwargs) + TimeoutToken(timeout_for_equal_or_bigger_token, **addictional_kwargs) + + assert isinstance(token, TimeoutToken) + assert isinstance(token._tokens[0], CounterToken) + assert token._timeout == 1 + assert len(token._tokens) == 1 + assert len(token._tokens[0]._tokens) == 0 + assert isinstance(token._tokens[0], CounterToken) + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + 'timeout_for_equal_or_bigger_token', + [ + 1, + 2, + ], +) +@pytest.mark.parametrize( + ('left_addictional_kwargs', 'right_addictional_kwargs'), + [ + ({'monotonic': False}, {'monotonic': True}), + ({}, {'monotonic': True}), + ({'monotonic': True}, {'monotonic': False}), + ({'monotonic': True}, {}), + ], +) +def test_less_or_equal_temp_not_monotonic_timeout_token_plus_bigger_or_equal_temp_not_monotonic_timeout_token_with_not_same_monotonic_flag_with_temp_counter_token_at_left(timeout_for_equal_or_bigger_token, left_addictional_kwargs, right_addictional_kwargs): + token = TimeoutToken(1, CounterToken(5), **left_addictional_kwargs) + TimeoutToken(timeout_for_equal_or_bigger_token, **right_addictional_kwargs) + + assert isinstance(token, TimeoutToken) + assert token._timeout == 1 + assert token._tokens[1]._timeout == timeout_for_equal_or_bigger_token + assert len(token._tokens) == 2 + assert len(token._tokens[0]._tokens) == 0 + assert len(token._tokens[1]._tokens) == 0 + assert isinstance(token._tokens[0], CounterToken) + assert isinstance(token._tokens[1], TimeoutToken) + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + 'addictional_kwargs', + [ + {'monotonic': False}, + {}, + {'monotonic': True}, + ], +) +def test_bigger_timeout_token_plus_less_temp_timeout_token_with_same_monotonic_flag_with_temp_counter_token_at_left(addictional_kwargs): + left_timeout_token = TimeoutToken(2, CounterToken(5), **addictional_kwargs) + token = left_timeout_token + TimeoutToken(1, **addictional_kwargs) + + assert isinstance(token, TimeoutToken) + assert isinstance(token._tokens[0], TimeoutToken) + assert isinstance(token._tokens[0]._tokens[0], CounterToken) + assert token is not left_timeout_token + assert token._tokens[0] is left_timeout_token + assert token._timeout == 1 + assert token._tokens[0]._timeout == 2 + assert len(token._tokens) == 1 + assert len(token._tokens[0]._tokens) == 1 + assert len(token._tokens[0]._tokens[0]._tokens) == 0 + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + ('left_addictional_kwargs', 'right_addictional_kwargs'), + [ + ({'monotonic': False}, {'monotonic': True}), + ({}, {'monotonic': True}), + ({'monotonic': True}, {'monotonic': False}), + ({'monotonic': True}, {}), + ], +) +def test_bigger_timeout_token_plus_less_temp_timeout_token_with_not_same_monotonic_flag_with_temp_counter_token_at_left(left_addictional_kwargs, right_addictional_kwargs): + left_timeout_token = TimeoutToken(2, CounterToken(5), **left_addictional_kwargs) + token = left_timeout_token + TimeoutToken(1, **right_addictional_kwargs) + + assert isinstance(token, TimeoutToken) + assert isinstance(token._tokens[0], TimeoutToken) + assert isinstance(token._tokens[0]._tokens[0], CounterToken) + assert token is not left_timeout_token + assert token._tokens[0] is left_timeout_token + assert token._timeout == 1 + assert token._tokens[0]._timeout == 2 + assert len(token._tokens) == 1 + assert len(token._tokens[0]._tokens) == 1 + assert len(token._tokens[0]._tokens[0]._tokens) == 0 + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + 'addictional_kwargs', + [ + {'monotonic': False}, + {}, + {'monotonic': True}, + ], +) +def test_less_not_monotonic_timeout_token_plus_bigger_temp_not_monotonic_timeout_token_with_same_monotonic_flag_with_temp_counter_token_at_left(addictional_kwargs): + left_timeout_token = TimeoutToken(1, CounterToken(5), **addictional_kwargs) + token = left_timeout_token + TimeoutToken(2, **addictional_kwargs) + + assert isinstance(token, TimeoutToken) + assert isinstance(token._tokens[0], CounterToken) + assert len(token._tokens) == 1 + assert len(token._tokens[0]._tokens) == 0 + assert token is left_timeout_token + assert token._timeout == 1 + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + ('left_addictional_kwargs', 'right_addictional_kwargs'), + [ + ({'monotonic': False}, {'monotonic': True}), + ({}, {'monotonic': True}), + ({'monotonic': True}, {'monotonic': False}), + ({'monotonic': True}, {}), + ], +) +def test_less_not_monotonic_timeout_token_plus_bigger_temp_not_monotonic_timeout_token_with_not_same_monotonic_flag_with_temp_counter_token_at_left(left_addictional_kwargs, right_addictional_kwargs): + left_timeout_token = TimeoutToken(1, CounterToken(5), **left_addictional_kwargs) + token = left_timeout_token + TimeoutToken(2, **right_addictional_kwargs) + + assert isinstance(token, TimeoutToken) + assert isinstance(token._tokens[0], TimeoutToken) + assert isinstance(token._tokens[0]._tokens[0], CounterToken) + assert token._timeout == 2 + assert token._tokens[0]._timeout == 1 + assert token._tokens[0] is left_timeout_token + assert token is not left_timeout_token + assert token._timeout == 2 + assert len(token._tokens) == 1 + assert len(token._tokens[0]._tokens) == 1 + assert len(token._tokens[0]._tokens[0]._tokens) == 0 + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + 'addictional_kwargs', + [ + {'monotonic': False}, + {}, + {'monotonic': True}, + ], +) +def test_bigger_temp_timeout_token_plus_less_timeout_token_with_same_monotonic_flag_with_temp_counter_token_at_left(addictional_kwargs): + right_timeout_token = TimeoutToken(1, **addictional_kwargs) + token = TimeoutToken(2, CounterToken(5), **addictional_kwargs) + right_timeout_token + + assert isinstance(token, SimpleToken) + assert isinstance(token._tokens[0], CounterToken) + assert isinstance(token._tokens[1], TimeoutToken) + assert token._tokens[1]._timeout == 1 + assert len(token._tokens) == 2 + assert len(token._tokens[0]._tokens) == 0 + assert len(token._tokens[1]._tokens) == 0 + assert token._tokens[1] is right_timeout_token + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + ('left_addictional_kwargs', 'right_addictional_kwargs'), + [ + ({'monotonic': False}, {'monotonic': True}), + ({}, {'monotonic': True}), + ({'monotonic': True}, {'monotonic': False}), + ({'monotonic': True}, {}), + ], +) +def test_bigger_temp_timeout_token_plus_less_timeout_token_with_not_same_monotonic_flag_with_temp_counter_token_at_left(left_addictional_kwargs, right_addictional_kwargs): + right_timeout_token = TimeoutToken(1, **right_addictional_kwargs) + token = TimeoutToken(2, CounterToken(5), **left_addictional_kwargs) + right_timeout_token + + assert isinstance(token, TimeoutToken) + assert isinstance(token._tokens[0], CounterToken) + assert isinstance(token._tokens[1], TimeoutToken) + assert token._tokens[1]._timeout == 1 + assert token._timeout == 2 + assert len(token._tokens) == 2 + assert len(token._tokens[0]._tokens) == 0 + assert len(token._tokens[1]._tokens) == 0 + assert token._tokens[1] is right_timeout_token + assert token is not right_timeout_token + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + 'addictional_kwargs', + [ + {'monotonic': False}, + {}, + {'monotonic': True}, + ], +) +def test_less_temp_not_monotonic_timeout_token_plus_bigger_not_monotonic_timeout_token_with_same_monotonic_flag_with_temp_counter_token_at_left(addictional_kwargs): + right_timeout_token = TimeoutToken(2, **addictional_kwargs) + token = TimeoutToken(1, CounterToken(5), **addictional_kwargs) + right_timeout_token + + assert isinstance(token, TimeoutToken) + assert token._timeout == 1 + assert len(token._tokens) == 2 + assert len(token._tokens[0]._tokens) == 0 + assert len(token._tokens[1]._tokens) == 0 + assert token._tokens[1]._timeout == 2 + assert token._tokens[1] is right_timeout_token + assert isinstance(token._tokens[0], CounterToken) + assert isinstance(token._tokens[1], TimeoutToken) + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +@pytest.mark.parametrize( + ('left_addictional_kwargs', 'right_addictional_kwargs'), + [ + ({'monotonic': False}, {'monotonic': True}), + ({}, {'monotonic': True}), + ({'monotonic': True}, {'monotonic': False}), + ({'monotonic': True}, {}), + ], +) +def test_less_temp_not_monotonic_timeout_token_plus_bigger_not_monotonic_timeout_token_with_not_same_monotonic_flag_with_temp_counter_token_at_left(left_addictional_kwargs, right_addictional_kwargs): + right_timeout_token = TimeoutToken(2, **right_addictional_kwargs) + token = TimeoutToken(1, CounterToken(5), **left_addictional_kwargs) + right_timeout_token + + assert isinstance(token, TimeoutToken) + assert isinstance(token._tokens[0], CounterToken) + assert isinstance(token._tokens[1], TimeoutToken) + assert token._timeout == 1 + assert token._tokens[1]._timeout == 2 + assert len(token._tokens) == 2 + assert len(token._tokens[0]._tokens) == 0 + assert len(token._tokens[1]._tokens) == 0 + assert token._tokens[1] is right_timeout_token + assert token is not right_timeout_token + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_temp_negative_timeout_token_plus_temp_timeout_token(): + token = TimeoutToken(1, cancelled=True) + TimeoutToken(1) + + assert isinstance(token, SimpleToken) + assert not token + assert not token._tokens + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_temp_timeout_token_plus_temp_negative_timeout_token(): + token = TimeoutToken(1) + TimeoutToken(1, cancelled=True) + + assert isinstance(token, SimpleToken) + assert not token + assert not token._tokens + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_not_temp_negative_timeout_token_plus_temp_timeout_token(): + first = TimeoutToken(1, cancelled=True) + token = first + TimeoutToken(1) + + assert isinstance(token, SimpleToken) + assert not token + assert not token._tokens + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_not_temp_timeout_token_plus_temp_negative_timeout_token(): + first = TimeoutToken(1) + token = first + TimeoutToken(1, cancelled=True) + + assert isinstance(token, SimpleToken) + assert not token + assert not token._tokens + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_not_temp_negative_timeout_token_plus_timeout_token(): + first = TimeoutToken(1, cancelled=True) + second = TimeoutToken(1) + token = first + second + + assert isinstance(token, SimpleToken) + assert not token + assert not token._tokens + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_not_temp_timeout_token_plus_negative_timeout_token(): + first = TimeoutToken(1) + second = TimeoutToken(1, cancelled=True) + token = first + second + + assert isinstance(token, SimpleToken) + assert not token + assert not token._tokens + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_temp_negative_timeout_token_plus_timeout_token(): + second = TimeoutToken(1) + token = TimeoutToken(1, cancelled=True) + second + + assert isinstance(token, SimpleToken) + assert not token + assert not token._tokens + + +@pytest.mark.skip(reason='Token addition optimization is no longer supported because Python 3.14 changed reference-counting details.') +def test_temp_timeout_token_plus_negative_timeout_token(): + second = TimeoutToken(1, cancelled=True) + token = TimeoutToken(1) + second + + assert isinstance(token, SimpleToken) + assert not token + assert not token._tokens diff --git a/tests/units/tokens/abstract/test_abstract_token.py b/tests/units/tokens/abstract/test_abstract_token.py index bb7bc95..1af628d 100644 --- a/tests/units/tokens/abstract/test_abstract_token.py +++ b/tests/units/tokens/abstract/test_abstract_token.py @@ -152,120 +152,74 @@ def test_str(token_fabric): 'second_token_fabric', ALL_TOKENS_FABRICS, ) -def test_add_not_temp_tokens(first_token_fabric, second_token_fabric): +def test_add_bound_tokens(first_token_fabric, second_token_fabric): first_token = first_token_fabric() second_token = second_token_fabric() tokens_sum = first_token + second_token assert isinstance(tokens_sum, SimpleToken) + assert tokens_sum is not first_token + assert tokens_sum is not second_token assert len(tokens_sum._tokens) == 2 assert tokens_sum._tokens[0] is first_token assert tokens_sum._tokens[1] is second_token @pytest.mark.parametrize( - ('first_token_class', 'first_arguments'), - [ - (TimeoutToken, [15]), - (ConditionToken, [lambda: False]), - (CounterToken, [15]), - ], + 'first_token_fabric', + ALL_TOKENS_FABRICS, ) @pytest.mark.parametrize( - ('second_token_class', 'second_arguments'), - [ - (TimeoutToken, [15]), - (ConditionToken, [lambda: False]), - (CounterToken, [15]), - ], + 'second_token_fabric', + ALL_TOKENS_FABRICS, ) -def test_add_temp_tokens(first_token_class, second_token_class, first_arguments, second_arguments): - tokens_sum = first_token_class(*first_arguments) + second_token_class(*second_arguments) +def test_add_inline_tokens(first_token_fabric, second_token_fabric): + tokens_sum = first_token_fabric() + second_token_fabric() - if not (first_token_class is TimeoutToken and second_token_class is TimeoutToken): - assert isinstance(tokens_sum, first_token_class) - assert len(tokens_sum._tokens) == 1 - assert isinstance(tokens_sum._tokens[0], second_token_class) - assert len(tokens_sum._tokens[0]._tokens) == 0 - else: - assert isinstance(tokens_sum, TimeoutToken) - assert len(tokens_sum._tokens) == 0 + assert isinstance(tokens_sum, SimpleToken) + assert len(tokens_sum._tokens) == 2 + assert isinstance(tokens_sum._tokens[0], first_token_fabric.func) + assert isinstance(tokens_sum._tokens[1], second_token_fabric.func) @pytest.mark.parametrize( - ('first_token_class', 'first_arguments'), - [ - (TimeoutToken, [15]), - (ConditionToken, [lambda: False]), - (CounterToken, [15]), - ], -) -@pytest.mark.parametrize( - ('second_token_class', 'second_arguments'), - [ - (TimeoutToken, [15]), - (ConditionToken, [lambda: False]), - (CounterToken, [15]), - ], + 'token_fabric', + ALL_TOKENS_FABRICS, ) -def test_add_not_temp_token_and_temp_token(first_token_class, second_token_class, first_arguments, second_arguments): - first_token = first_token_class(*first_arguments) - tokens_sum = first_token + second_token_class(*second_arguments) +def test_add_default_token_and_inline_token(token_fabric): + tokens_sum = DefaultToken() + token_fabric() - if first_token_class is TimeoutToken and second_token_class is TimeoutToken: - assert tokens_sum is first_token - assert not tokens_sum._tokens - else: - assert isinstance(tokens_sum, second_token_class) - assert len(tokens_sum._tokens) == 1 - assert isinstance(tokens_sum._tokens[0], first_token_class) - assert len(tokens_sum._tokens[0]._tokens) == 0 + assert isinstance(tokens_sum, SimpleToken) + assert len(tokens_sum._tokens) == 1 + assert isinstance(tokens_sum._tokens[0], token_fabric.func) @pytest.mark.parametrize( - ('first_token_class', 'first_arguments'), - [ - (TimeoutToken, [15]), - (ConditionToken, [lambda: False]), - (CounterToken, [15]), - ], -) -@pytest.mark.parametrize( - ('second_token_class', 'second_arguments'), - [ - (TimeoutToken, [15]), - (ConditionToken, [lambda: False]), - (CounterToken, [15]), - ], + 'token_fabric', + ALL_TOKENS_FABRICS, ) -def test_add_temp_token_and_not_temp_token(first_token_class, second_token_class, first_arguments, second_arguments): - second_token = second_token_class(*second_arguments) - tokens_sum = first_token_class(*first_arguments) + second_token +def test_add_inline_token_and_default_token(token_fabric): + tokens_sum = token_fabric() + DefaultToken() - if first_token_class is TimeoutToken and second_token_class is TimeoutToken: - assert isinstance(tokens_sum, TimeoutToken) - assert len(tokens_sum._tokens) == 0 - else: - assert isinstance(tokens_sum, first_token_class) - assert len(tokens_sum._tokens) == 1 - assert isinstance(tokens_sum._tokens[0], second_token_class) - assert len(tokens_sum._tokens[0]._tokens) == 0 + assert isinstance(tokens_sum, SimpleToken) + assert len(tokens_sum._tokens) == 1 + assert isinstance(tokens_sum._tokens[0], token_fabric.func) @pytest.mark.parametrize( 'first_token_fabric', - ALL_TOKENS_FABRICS_WITH_NOT_CANCELLING_SUPERPOWER, + ALL_TOKENS_FABRICS, ) @pytest.mark.parametrize( 'second_token_fabric', - ALL_TOKENS_FABRICS_WITH_NOT_CANCELLING_SUPERPOWER, + ALL_TOKENS_FABRICS, ) @pytest.mark.parametrize( 'third_token_fabric', - ALL_TOKENS_FABRICS_WITH_NOT_CANCELLING_SUPERPOWER, + ALL_TOKENS_FABRICS, ) -def test_add_three_tokens_except_simple_token(first_token_fabric, second_token_fabric, third_token_fabric): +def test_add_three_tokens_keeps_intermediate_sum(first_token_fabric, second_token_fabric, third_token_fabric): first_token = first_token_fabric() second_token = second_token_fabric() third_token = third_token_fabric() @@ -273,45 +227,291 @@ def test_add_three_tokens_except_simple_token(first_token_fabric, second_token_f tokens_sum = first_token + second_token + third_token assert isinstance(tokens_sum, SimpleToken) - assert len(tokens_sum._tokens) == 3 - assert tokens_sum._tokens[0] is first_token - assert tokens_sum._tokens[1] is second_token - assert tokens_sum._tokens[2] is third_token + assert len(tokens_sum._tokens) == 2 + assert isinstance(tokens_sum._tokens[0], SimpleToken) + assert tokens_sum._tokens[1] is third_token + assert tokens_sum._tokens[0]._tokens[0] is first_token + assert tokens_sum._tokens[0]._tokens[1] is second_token @pytest.mark.parametrize( - 'first_token_fabric', - ALL_TOKENS_FABRICS_WITH_NOT_CANCELLING_SUPERPOWER, + 'token_fabric', + ALL_TOKENS_FABRICS, ) -def test_add_another_token_and_temp_simple_token(first_token_fabric): - first_token = first_token_fabric() +def test_add_empty_simple_token_intermediate_as_regular_operand(token_fabric): + empty_sum = DefaultToken() + DefaultToken() + another_token = token_fabric() - tokens_sum = first_token + SimpleToken() + tokens_sum = empty_sum + another_token assert isinstance(tokens_sum, SimpleToken) - assert len(tokens_sum._tokens) == 1 - assert tokens_sum._tokens[0] is first_token + assert len(tokens_sum._tokens) == 2 + assert tokens_sum._tokens[0] is empty_sum + assert tokens_sum._tokens[1] is another_token + assert tokens_sum + + empty_sum.cancel() + + assert not tokens_sum @pytest.mark.parametrize( - 'second_token_fabric', - ALL_TOKENS_FABRICS_WITH_NOT_CANCELLING_SUPERPOWER, + 'token_fabric', + ALL_TOKENS_FABRICS, ) -def test_add_temp_simple_token_and_another_token(second_token_fabric): - second_token = second_token_fabric() +def test_add_cancelled_first_operand_keeps_original_operand(token_fabric): + cancelled_token = token_fabric(cancelled=True) + another_token = SimpleToken() - tokens_sum = SimpleToken() + second_token + tokens_sum = cancelled_token + another_token assert isinstance(tokens_sum, SimpleToken) - assert len(tokens_sum._tokens) == 1 - assert tokens_sum._tokens[0] is second_token + assert len(tokens_sum._tokens) == 2 + assert tokens_sum._tokens[0] is cancelled_token + assert tokens_sum._tokens[1] is another_token + assert not tokens_sum + + +@pytest.mark.parametrize( + 'token_fabric', + ALL_TOKENS_FABRICS, +) +def test_add_cancelled_second_operand_keeps_original_operand(token_fabric): + another_token = SimpleToken() + cancelled_token = token_fabric(cancelled=True) + + tokens_sum = another_token + cancelled_token + + assert isinstance(tokens_sum, SimpleToken) + assert len(tokens_sum._tokens) == 2 + assert tokens_sum._tokens[0] is another_token + assert tokens_sum._tokens[1] is cancelled_token + assert not tokens_sum + + +@pytest.mark.parametrize( + 'stored_token_fabric', + ALL_TOKENS_FABRICS, +) +def test_add_preserves_link_to_attribute_operand_on_right(stored_token_fabric): + class Holder: + def __init__(self, token): + self.token = token + + def combine(self): + return DefaultToken() + self.token + + holder = Holder(stored_token_fabric()) + tokens_sum = holder.combine() + + assert tokens_sum + + holder.token.cancel() + + assert not holder.token + assert not tokens_sum + + +@pytest.mark.parametrize( + 'stored_token_fabric', + ALL_TOKENS_FABRICS, +) +def test_add_preserves_link_to_attribute_operand_on_left(stored_token_fabric): + class Holder: + def __init__(self, token): + self.token = token + + def combine(self): + return self.token + DefaultToken() + + holder = Holder(stored_token_fabric()) + tokens_sum = holder.combine() + + assert tokens_sum + + holder.token.cancel() + + assert not holder.token + assert not tokens_sum + + +@pytest.mark.parametrize( + 'extra_token_fabric', + ALL_TOKENS_FABRICS, +) +@pytest.mark.parametrize( + 'stored_token_fabric', + ALL_TOKENS_FABRICS, +) +def test_add_preserves_link_to_attribute_operand_with_extra_token(extra_token_fabric, stored_token_fabric): + class Holder: + def __init__(self, token): + self.token = token + + def combine(self, extra_token): + return extra_token + self.token + + holder = Holder(stored_token_fabric()) + tokens_sum = holder.combine(extra_token_fabric()) + + assert tokens_sum + + holder.token.cancel() + + assert not holder.token + assert not tokens_sum + + +@pytest.mark.parametrize( + 'stored_token_fabric', + ALL_TOKENS_FABRICS, +) +def test_add_inside_generator_preserves_link_to_attribute_operand(stored_token_fabric): + class Crawler: + def __init__(self, token): + self.token = token + + def go(self, token=DefaultToken()): # noqa: B008 + token = token + self.token + for index in range(5): + yield index, bool(token) + + instance_token = stored_token_fabric() + crawler = Crawler(instance_token) + iterator = crawler.go() + + assert next(iterator) == (0, True) + + instance_token.cancel() + + assert not instance_token + assert next(iterator) == (1, False) + + +@pytest.mark.parametrize( + 'stored_token_fabric', + ALL_TOKENS_FABRICS, +) +def test_add_preserves_link_to_property_operand(stored_token_fabric): + class Holder: + def __init__(self, token): + self._token = token + + @property + def token(self): + return self._token + + def combine(self): + return DefaultToken() + self.token + + holder = Holder(stored_token_fabric()) + tokens_sum = holder.combine() + + assert tokens_sum + + holder.token.cancel() + + assert not tokens_sum + + +@pytest.mark.parametrize( + 'stored_token_fabric', + ALL_TOKENS_FABRICS, +) +def test_add_preserves_link_to_list_item_operand(stored_token_fabric): + class Holder: + def __init__(self, token): + self.tokens = [token] + + def combine(self): + return DefaultToken() + self.tokens[0] + + holder = Holder(stored_token_fabric()) + tokens_sum = holder.combine() + + assert tokens_sum + + holder.tokens[0].cancel() + + assert not tokens_sum + + +@pytest.mark.parametrize( + 'stored_token_fabric', + ALL_TOKENS_FABRICS, +) +def test_add_preserves_link_to_dict_item_operand(stored_token_fabric): + class Holder: + def __init__(self, token): + self.tokens = {'main': token} + + def combine(self): + return DefaultToken() + self.tokens['main'] + + holder = Holder(stored_token_fabric()) + tokens_sum = holder.combine() + + assert tokens_sum + + holder.tokens['main'].cancel() + + assert not tokens_sum + + +@pytest.mark.parametrize( + 'stored_token_fabric', + ALL_TOKENS_FABRICS, +) +def test_add_preserves_link_to_nested_attribute_operand(stored_token_fabric): + class Child: + def __init__(self, token): + self.token = token + + class Holder: + def __init__(self, child): + self.child = child + + def combine(self): + return DefaultToken() + self.child.token + + child = Child(stored_token_fabric()) + holder = Holder(child) + tokens_sum = holder.combine() + + assert tokens_sum + + child.token.cancel() + + assert not tokens_sum + + +@pytest.mark.parametrize( + 'stored_token_fabric', + ALL_TOKENS_FABRICS, +) +def test_add_preserves_link_to_class_attribute_operand(stored_token_fabric): + class Holder: + token: AbstractToken + + def combine(self): + return DefaultToken() + self.token + + Holder.token = stored_token_fabric() + holder = Holder() + tokens_sum = holder.combine() + + assert tokens_sum + + Holder.token.cancel() + + assert not tokens_sum @pytest.mark.parametrize( 'first_token_fabric', ALL_TOKENS_FABRICS_WITH_NOT_CANCELLING_SUPERPOWER, ) -def test_add_another_token_and_not_temp_simple_token(first_token_fabric): +def test_add_another_token_and_bound_simple_token(first_token_fabric): simple_token = SimpleToken() first_token = first_token_fabric() @@ -327,7 +527,7 @@ def test_add_another_token_and_not_temp_simple_token(first_token_fabric): 'second_token_fabric', [x for x in ALL_TOKENS_FABRICS if x is not SimpleToken], ) -def test_add_not_temp_simple_token_and_another_token(second_token_fabric): +def test_add_bound_simple_token_and_another_token(second_token_fabric): simple_token = SimpleToken() second_token = second_token_fabric() @@ -770,34 +970,10 @@ def test_superpower_is_more_important_than_cache(first_token_fabric, second_toke 'token_fabric', ALL_TOKENS_FABRICS, ) -def test_just_neste_temp_simple_token_to_another_token(token_fabric): +def test_just_neste_simple_token_to_another_token(token_fabric): token = token_fabric(SimpleToken()) assert len(token._tokens) == 1 assert isinstance(token._tokens[0], SimpleToken) assert token - -@pytest.mark.parametrize( - 'token_fabric', - ALL_TOKENS_FABRICS, -) -def test_any_token_plus_temp_cancelled_simple_token_gives_cancelled_simple_token(token_fabric): - token = token_fabric() + SimpleToken(cancelled=True) - - assert isinstance(token, SimpleToken) - assert len(token._tokens) == 0 - assert not token - - -@pytest.mark.parametrize( - 'token_fabric', - ALL_TOKENS_FABRICS, -) -def test_any_token_plus_cancelled_simple_token_gives_cancelled_simple_token(token_fabric): - simple_token = SimpleToken(cancelled=True) - token = token_fabric() + simple_token - - assert isinstance(token, SimpleToken) - assert len(token._tokens) == 0 - assert not token diff --git a/tests/units/tokens/test_condition_token.py b/tests/units/tokens/test_condition_token.py index 78ead10..6db177b 100644 --- a/tests/units/tokens/test_condition_token.py +++ b/tests/units/tokens/test_condition_token.py @@ -203,7 +203,6 @@ async def runner(): assert finish_time - start_time >= timeout - @pytest.mark.parametrize( 'options', [ @@ -324,35 +323,7 @@ def condition(): assert counter == 6 -def test_quasitemp_condition_token_plus_temp_simple_token(): - token = ConditionToken(lambda: False) + SimpleToken() - - assert isinstance(token, ConditionToken) - assert len(token._tokens) == 0 - - -def test_not_quasitemp_condition_token_plus_temp_simple_token(): - condition_token = ConditionToken(lambda: False) - token = condition_token + SimpleToken() - - assert isinstance(token, SimpleToken) - assert len(token._tokens) == 1 - assert isinstance(token._tokens[0], ConditionToken) - assert token._tokens[0] is condition_token - - -def test_quasitemp_condition_token_plus_not_temp_simple_token(): - simple_token = SimpleToken() - token = ConditionToken(lambda: False) + simple_token - - assert isinstance(token, ConditionToken) - assert token is not simple_token - assert len(token._tokens) == 1 - assert isinstance(token._tokens[0], SimpleToken) - assert token._tokens[0] is simple_token - - -def test_not_quasitemp_condition_token_plus_not_temp_simple_token(): +def test_condition_token_plus_simple_token(): simple_token = SimpleToken() condition_token = ConditionToken(lambda: False) token = condition_token + simple_token @@ -365,34 +336,7 @@ def test_not_quasitemp_condition_token_plus_not_temp_simple_token(): assert token._tokens[1] is simple_token -def test_quasitemp_condition_token_plus_temp_simple_token_reverse(): - token = SimpleToken() + ConditionToken(lambda: False) - - assert isinstance(token, ConditionToken) - assert len(token._tokens) == 0 - - -def test_not_quasitemp_condition_token_plus_temp_simple_token_reverse(): - condition_token = ConditionToken(lambda: False) - token = SimpleToken() + condition_token - - assert isinstance(token, SimpleToken) - assert len(token._tokens) == 1 - assert isinstance(token._tokens[0], ConditionToken) - assert token._tokens[0] is condition_token - - -def test_quasitemp_condition_token_plus_not_temp_simple_token_reverse(): - simple_token = SimpleToken() - token = simple_token + ConditionToken(lambda: False) - - assert isinstance(token, ConditionToken) - assert token is not simple_token - assert len(token._tokens) == 1 - assert token._tokens[0] is simple_token - - -def test_not_quasitemp_condition_token_plus_not_temp_simple_token_reverse(): +def test_simple_token_plus_condition_token(): simple_token = SimpleToken() condition_token = ConditionToken(lambda: False) token = simple_token + condition_token diff --git a/tests/units/tokens/test_counter_token.py b/tests/units/tokens/test_counter_token.py index 8945482..87eb912 100644 --- a/tests/units/tokens/test_counter_token.py +++ b/tests/units/tokens/test_counter_token.py @@ -224,35 +224,7 @@ def test_decrement_counter_after_zero(): assert token.counter == 0 -def test_quasitemp_counter_token_plus_temp_simple_token(): - token = CounterToken(0) + SimpleToken() - - assert isinstance(token, CounterToken) - assert len(token._tokens) == 0 - - -def test_not_quasitemp_counter_token_plus_temp_simple_token(): - counter_token = CounterToken(1) - token = counter_token + SimpleToken() - - assert isinstance(token, SimpleToken) - assert len(token._tokens) == 1 - assert isinstance(token._tokens[0], CounterToken) - assert token._tokens[0] is counter_token - - -def test_quasitemp_counter_token_plus_not_temp_simple_token(): - simple_token = SimpleToken() - token = CounterToken(1) + simple_token - - assert isinstance(token, CounterToken) - assert token is not simple_token - assert len(token._tokens) == 1 - assert isinstance(token._tokens[0], SimpleToken) - assert token._tokens[0] is simple_token - - -def test_not_quasitemp_counter_token_plus_not_temp_simple_token(): +def test_counter_token_plus_simple_token(): simple_token = SimpleToken() counter_token = CounterToken(1) token = counter_token + simple_token @@ -265,35 +237,7 @@ def test_not_quasitemp_counter_token_plus_not_temp_simple_token(): assert token._tokens[1] is simple_token -def test_quasitemp_counter_token_plus_temp_simple_token_reverse(): - token = SimpleToken() + CounterToken(1) - - assert isinstance(token, CounterToken) - assert len(token._tokens) == 0 - - -def test_not_quasitemp_counter_token_plus_temp_simple_token_reverse(): - counter_token = CounterToken(1) - token = SimpleToken() + counter_token - - assert isinstance(token, SimpleToken) - assert len(token._tokens) == 1 - assert isinstance(token._tokens[0], CounterToken) - assert token._tokens[0] is counter_token - - -def test_quasitemp_counter_token_plus_not_temp_simple_token_reverse(): - simple_token = SimpleToken() - token = simple_token + CounterToken(1) - - assert isinstance(token, CounterToken) - assert token is not simple_token - assert len(token._tokens) == 1 - assert isinstance(token._tokens[0], SimpleToken) - assert token._tokens[0] is simple_token - - -def test_not_quasitemp_counter_token_plus_not_temp_simple_token_reverse(): +def test_simple_token_plus_counter_token(): simple_token = SimpleToken() counter_token = CounterToken(1) token = simple_token + counter_token diff --git a/tests/units/tokens/test_default_token.py b/tests/units/tokens/test_default_token.py index 5a24a85..a9d1e42 100644 --- a/tests/units/tokens/test_default_token.py +++ b/tests/units/tokens/test_default_token.py @@ -3,7 +3,7 @@ import pytest from full_match import match -from cantok import DefaultToken, ImpossibleCancelError, SimpleToken, TimeoutToken +from cantok import DefaultToken, ImpossibleCancelError, SimpleToken def test_dafault_token_is_not_cancelled_by_default(): @@ -75,17 +75,33 @@ def test_default_plus_default_plus_default(): empty_sum = DefaultToken() + DefaultToken() + DefaultToken() assert isinstance(empty_sum, SimpleToken) - assert len(empty_sum._tokens) == 0 + assert len(empty_sum._tokens) == 1 + assert isinstance(empty_sum._tokens[0], SimpleToken) + assert len(empty_sum._tokens[0]._tokens) == 0 -def test_default_token_plus_temp_simple_token(): - empty_sum = DefaultToken() + SimpleToken() +def test_default_plus_default_plus_default_preserves_intermediate_simple_token(): + inner_sum = DefaultToken() + DefaultToken() + total = inner_sum + DefaultToken() + + assert isinstance(total, SimpleToken) + assert len(total._tokens) == 1 + assert total._tokens[0] is inner_sum + + inner_sum.cancel() + + assert not total - assert isinstance(empty_sum, SimpleToken) - assert len(empty_sum._tokens) == 0 +def test_default_token_plus_inline_simple_token(): + total = DefaultToken() + SimpleToken() -def test_default_token_plus_not_temp_simple_token(): + assert isinstance(total, SimpleToken) + assert len(total._tokens) == 1 + assert isinstance(total._tokens[0], SimpleToken) + + +def test_default_token_plus_bound_simple_token(): simple_token = SimpleToken() total = DefaultToken() + simple_token @@ -95,17 +111,3 @@ def test_default_token_plus_not_temp_simple_token(): assert total._tokens[0] is simple_token -def test_temp_default_token_plus_temp_timeout_token(): - token = DefaultToken() + TimeoutToken(1) - - assert isinstance(token, TimeoutToken) - assert token._timeout == 1 - assert len(token._tokens) == 0 - - -def test_temp_timeout_token_plus_temp_default_token(): - token = TimeoutToken(1) + DefaultToken() - - assert isinstance(token, TimeoutToken) - assert token._timeout == 1 - assert len(token._tokens) == 0 diff --git a/tests/units/tokens/test_simple_token.py b/tests/units/tokens/test_simple_token.py index 141b2ec..67ad0d1 100644 --- a/tests/units/tokens/test_simple_token.py +++ b/tests/units/tokens/test_simple_token.py @@ -1,6 +1,6 @@ import pytest -from cantok import CancellationError, ConditionToken, SimpleToken, TimeoutToken +from cantok import CancellationError, SimpleToken from cantok.tokens.abstract.abstract_token import CancelCause, CancellationReport @@ -110,39 +110,7 @@ def test_get_report_cancelled_nested(cancelled_flag, cancelled_flag_nested, from assert report.from_token is token -def test_sum_of_2_temp_simple_tokens(): - token = SimpleToken() + SimpleToken() - - assert isinstance(token, SimpleToken) - assert len(token._tokens) == 0 - - -def test_sum_of_5_temp_simple_tokens(): - token = SimpleToken() + SimpleToken() + SimpleToken() + SimpleToken() + SimpleToken() - - assert isinstance(token, SimpleToken) - assert len(token._tokens) == 0 - - -def test_sum_of_1_temp_and_1_not_temp_simple_tokens(): - second_token = SimpleToken() - result = SimpleToken() + second_token - - assert isinstance(result, SimpleToken) - assert len(result._tokens) == 1 - assert result._tokens[0] is second_token - - -def test_sum_of_1_not_temp_and_1_temp_simple_tokens(): - first_token = SimpleToken() - result = first_token + SimpleToken() - - assert isinstance(result, SimpleToken) - assert len(result._tokens) == 1 - assert result._tokens[0] is first_token - - -def test_sum_of_2_not_temp_simple_tokens(): +def test_sum_of_2_bound_simple_tokens(): first_token = SimpleToken() second_token = SimpleToken() result = first_token + second_token @@ -153,219 +121,3 @@ def test_sum_of_2_not_temp_simple_tokens(): assert result._tokens[1] is second_token -def test_sum_of_2_not_temp_simple_tokens_and_one_temp(): - first_token = SimpleToken() - second_token = SimpleToken() - result = first_token + second_token + SimpleToken() - - assert isinstance(result, SimpleToken) - assert len(result._tokens) == 2 - assert result._tokens[0] is first_token - assert result._tokens[1] is second_token - - -def test_sum_of_3_not_temp_simple_tokens(): - first_token = SimpleToken() - second_token = SimpleToken() - third_token = SimpleToken() - result = first_token + second_token + third_token - - assert isinstance(result, SimpleToken) - assert len(result._tokens) == 3 - assert result._tokens[0] is first_token - assert result._tokens[1] is second_token - assert result._tokens[2] is third_token - - -def test_sum_of_2_temp_timeout_tokens_throw_temp_simple_tokens(): - token = SimpleToken(TimeoutToken(1)) + SimpleToken(TimeoutToken(2)) - - assert isinstance(token, SimpleToken) - assert len(token._tokens) == 2 - - assert isinstance(token._tokens[0], TimeoutToken) - assert token._tokens[0]._timeout == 1 - - assert isinstance(token._tokens[1], TimeoutToken) - assert token._tokens[1]._timeout == 2 - - -def test_sum_of_2_temp_timeout_tokens_throw_right_temp_simple_token(): - token = TimeoutToken(1) + SimpleToken(TimeoutToken(2)) - - assert isinstance(token, TimeoutToken) - assert len(token._tokens) == 1 - assert len(token._tokens[0]._tokens) == 0 - assert token._timeout == 1 - assert token._tokens[0]._timeout == 2 - - -def test_sum_of_2_temp_timeout_tokens_throw_left_temp_simple_token(): - token = SimpleToken(TimeoutToken(1)) + TimeoutToken(2) - - assert isinstance(token, TimeoutToken) - assert len(token._tokens) == 1 - assert token._timeout == 2 - - assert isinstance(token._tokens[0], TimeoutToken) - assert token._tokens[0]._timeout == 1 - - -def test_sum_of_2_not_temp_timeout_tokens_throw_temp_simple_tokens(): - first_timeout_token = TimeoutToken(1) - second_timeout_token = TimeoutToken(2) - token = SimpleToken(first_timeout_token) + SimpleToken(second_timeout_token) - - assert isinstance(token, SimpleToken) - assert len(token._tokens) == 2 - - assert token._tokens[0] is first_timeout_token - assert isinstance(token._tokens[0], TimeoutToken) - assert token._tokens[0]._timeout == 1 - - assert token._tokens[1] is second_timeout_token - assert isinstance(token._tokens[1], TimeoutToken) - assert token._tokens[1]._timeout == 2 - - -def test_sum_of_first_temp_and_second_not_temp_timeout_tokens_throw_temp_simple_tokens(): - second_timeout_token = TimeoutToken(2) - token = SimpleToken(TimeoutToken(1)) + SimpleToken(second_timeout_token) - - assert isinstance(token, SimpleToken) - assert len(token._tokens) == 2 - - assert isinstance(token._tokens[0], TimeoutToken) - assert token._tokens[0]._timeout == 1 - - assert token._tokens[1] is second_timeout_token - assert isinstance(token._tokens[1], TimeoutToken) - assert token._tokens[1]._timeout == 2 - - -def test_sum_of_first_not_temp_and_second_temp_timeout_tokens_throw_temp_simple_tokens(): - first_timeout_token = TimeoutToken(1) - token = SimpleToken(first_timeout_token) + SimpleToken(TimeoutToken(2)) - - assert isinstance(token, SimpleToken) - assert len(token._tokens) == 2 - - assert token._tokens[0] is first_timeout_token - assert isinstance(token._tokens[0], TimeoutToken) - assert token._tokens[0]._timeout == 1 - - assert isinstance(token._tokens[1], TimeoutToken) - assert token._tokens[1]._timeout == 2 - - -def test_sum_of_temp_timeout_token_and_temp_condition_token_throw_temp_simple_tokens(): - token = SimpleToken(TimeoutToken(1)) + SimpleToken(ConditionToken(lambda: False)) - - assert isinstance(token, SimpleToken) - assert len(token._tokens) == 2 - assert token - - assert isinstance(token._tokens[0], TimeoutToken) - assert token._tokens[0]._timeout == 1 - - assert isinstance(token._tokens[1], ConditionToken) - - -def test_sum_of_temp_condition_token_and_temp_timeout_token_throw_temp_simple_tokens(): - token = SimpleToken(ConditionToken(lambda: False)) + SimpleToken(TimeoutToken(1)) - - assert isinstance(token, SimpleToken) - assert len(token._tokens) == 2 - assert token - - assert isinstance(token._tokens[0], ConditionToken) - - assert isinstance(token._tokens[1], TimeoutToken) - assert token._tokens[1]._timeout == 1 - - -def test_sum_of_not_temp_timeout_token_and_temp_condition_token_throw_temp_simple_tokens(): - timeout_token = TimeoutToken(1) - token = SimpleToken(timeout_token) + SimpleToken(ConditionToken(lambda: False)) - - assert isinstance(token, SimpleToken) - assert len(token._tokens) == 2 - assert token - - assert token._tokens[0] is timeout_token - assert isinstance(token._tokens[0], TimeoutToken) - assert token._tokens[0]._timeout == 1 - - assert isinstance(token._tokens[1], ConditionToken) - - -def test_sum_of_temp_timeout_token_and_not_temp_condition_token_throw_temp_simple_tokens(): - condition_token = ConditionToken(lambda: False) - token = SimpleToken(TimeoutToken(1)) + SimpleToken(condition_token) - - assert isinstance(token, SimpleToken) - assert len(token._tokens) == 2 - assert token - - assert isinstance(token._tokens[0], TimeoutToken) - assert token._tokens[0]._timeout == 1 - - assert isinstance(token._tokens[1], ConditionToken) - assert token._tokens[1] is condition_token - - -def test_sum_of_not_temp_condition_token_and_temp_timeout_token_throw_temp_simple_tokens(): - condition_token = ConditionToken(lambda: False) - token = SimpleToken(condition_token) + SimpleToken(TimeoutToken(1)) - - assert isinstance(token, SimpleToken) - assert len(token._tokens) == 2 - assert token - - assert isinstance(token._tokens[0], ConditionToken) - assert token._tokens[0] is condition_token - - assert isinstance(token._tokens[1], TimeoutToken) - assert token._tokens[1]._timeout == 1 - - -def test_sum_of_not_temp_timeout_token_and_not_temp_condition_token_throw_temp_simple_tokens(): - timeout_token = TimeoutToken(1) - condition_token = ConditionToken(lambda: False) - token = SimpleToken(timeout_token) + SimpleToken(condition_token) - - assert isinstance(token, SimpleToken) - assert len(token._tokens) == 2 - assert token - - assert token._tokens[0] is timeout_token - assert isinstance(token._tokens[0], TimeoutToken) - assert token._tokens[0]._timeout == 1 - - assert token._tokens[1] is condition_token - assert isinstance(token._tokens[1], ConditionToken) - - -def test_sum_of_not_temp_condition_token_and_not_temp_timeout_token_throw_temp_simple_tokens(): - timeout_token = TimeoutToken(1) - condition_token = ConditionToken(lambda: False) - token = SimpleToken(condition_token) + SimpleToken(timeout_token) - - assert isinstance(token, SimpleToken) - assert len(token._tokens) == 2 - assert token - - assert token._tokens[0] is condition_token - assert isinstance(token._tokens[0], ConditionToken) - - assert token._tokens[1] is timeout_token - assert isinstance(token._tokens[1], TimeoutToken) - assert token._tokens[1]._timeout == 1 - - -def test_temp_timeout_token_plus_temp_cancelled_simple_token(): - token = TimeoutToken(1) + SimpleToken(cancelled=True) - - assert isinstance(token, SimpleToken) - assert not token - assert len(token._tokens) == 0 diff --git a/tests/units/tokens/test_timeout_token.py b/tests/units/tokens/test_timeout_token.py index 4bd6b14..018e2f3 100644 --- a/tests/units/tokens/test_timeout_token.py +++ b/tests/units/tokens/test_timeout_token.py @@ -223,36 +223,7 @@ def test_timeout_wait(): assert sleep_duration <= finish_time - start_time -def test_quasitemp_timeout_token_plus_temp_simple_token(): - token = TimeoutToken(1) + SimpleToken() - - assert isinstance(token, TimeoutToken) - assert len(token._tokens) == 0 - assert token._timeout == 1 - - -def test_not_quasitemp_timeout_token_plus_temp_simple_token(): - timeout_token = TimeoutToken(1) - token = timeout_token + SimpleToken() - - assert isinstance(token, SimpleToken) - assert len(token._tokens) == 1 - assert isinstance(token._tokens[0], TimeoutToken) - assert token._tokens[0] is timeout_token - - -def test_quasitemp_timeout_token_plus_not_temp_simple_token(): - simple_token = SimpleToken() - token = TimeoutToken(1) + simple_token - - assert isinstance(token, TimeoutToken) - assert token is not simple_token - assert len(token._tokens) == 1 - assert isinstance(token._tokens[0], SimpleToken) - assert token._tokens[0] is simple_token - - -def test_not_quasitemp_timeout_token_plus_not_temp_simple_token(): +def test_timeout_token_plus_simple_token(): simple_token = SimpleToken() timeout_token = TimeoutToken(1) token = timeout_token + simple_token @@ -265,37 +236,7 @@ def test_not_quasitemp_timeout_token_plus_not_temp_simple_token(): assert token._tokens[1] is simple_token -def test_quasitemp_timeout_token_plus_temp_simple_token_reverse(): - token = SimpleToken() + TimeoutToken(1) - - assert isinstance(token, TimeoutToken) - assert len(token._tokens) == 0 - assert token._timeout == 1 - - -def test_not_quasitemp_timeout_token_plus_temp_simple_token_reverse(): - timeout_token = TimeoutToken(1) - token = SimpleToken() + timeout_token - - assert isinstance(token, SimpleToken) - assert len(token._tokens) == 1 - assert isinstance(token._tokens[0], TimeoutToken) - assert token._tokens[0] is timeout_token - - -def test_quasitemp_timeout_token_plus_not_temp_simple_token_reverse(): - simple_token = SimpleToken() - token = simple_token + TimeoutToken(1) - - assert isinstance(token, TimeoutToken) - assert token._timeout == 1 - assert token is not simple_token - assert len(token._tokens) == 1 - assert isinstance(token._tokens[0], SimpleToken) - assert token._tokens[0] is simple_token - - -def test_not_quasitemp_timeout_token_plus_not_temp_simple_token_reverse(): +def test_simple_token_plus_timeout_token(): simple_token = SimpleToken() timeout_token = TimeoutToken(1) token = simple_token + timeout_token @@ -328,1233 +269,11 @@ def test_timeout_is_more_important_than_cache(): assert report.cause == CancelCause.SUPERPOWER -def test_zero_timeout_token_report_is_about_superpower(): - for report in TimeoutToken(0)._get_report(True), TimeoutToken(0)._get_report(False): - assert report.cause == CancelCause.SUPERPOWER - - -@pytest.mark.parametrize( - 'addictional_kwargs', - [ - {'monotonic': False}, - {}, - {'monotonic': True}, - ], -) -def test_bigger_temp_timeout_token_plus_less_temp_timeout_token_with_same_monotonic_flag(addictional_kwargs): - token = TimeoutToken(2, **addictional_kwargs) + TimeoutToken(1, **addictional_kwargs) - - assert isinstance(token, TimeoutToken) - assert token._timeout == 1 - assert len(token._tokens) == 0 - - -@pytest.mark.parametrize( - ('left_addictional_kwargs', 'right_addictional_kwargs'), - [ - ({'monotonic': False}, {'monotonic': True}), - ({}, {'monotonic': True}), - ({'monotonic': True}, {'monotonic': False}), - ({'monotonic': True}, {}), - ], -) -def test_bigger_temp_timeout_token_plus_less_temp_timeout_token_with_not_same_monotonic_flag(left_addictional_kwargs, right_addictional_kwargs): - token = TimeoutToken(2, **left_addictional_kwargs) + TimeoutToken(1, **right_addictional_kwargs) - - assert isinstance(token, TimeoutToken) - assert token._timeout == 2 - assert len(token._tokens) == 1 - assert len(token._tokens[0]._tokens) == 0 - assert isinstance(token._tokens[0], TimeoutToken) - assert token._tokens[0]._timeout == 1 - - -@pytest.mark.parametrize( - 'timeout_for_equal_or_bigger_token', - [ - 1, - 2, - ], -) -@pytest.mark.parametrize( - 'addictional_kwargs', - [ - {'monotonic': False}, - {}, - {'monotonic': True}, - ], -) -def test_less_or_equal_temp_not_monotonic_timeout_token_plus_bigger_or_equal_temp_not_monotonic_timeout_token_with_same_monotonic_flag(timeout_for_equal_or_bigger_token, addictional_kwargs): - token = TimeoutToken(1, **addictional_kwargs) + TimeoutToken(timeout_for_equal_or_bigger_token, **addictional_kwargs) - - assert isinstance(token, TimeoutToken) - assert token._timeout == 1 - assert len(token._tokens) == 0 - - -@pytest.mark.parametrize( - 'timeout_for_equal_or_bigger_token', - [ - 1, - 2, - ], -) -@pytest.mark.parametrize( - ('left_addictional_kwargs', 'right_addictional_kwargs'), - [ - ({'monotonic': False}, {'monotonic': True}), - ({}, {'monotonic': True}), - ({'monotonic': True}, {'monotonic': False}), - ({'monotonic': True}, {}), - ], -) -def test_less_or_equal_temp_not_monotonic_timeout_token_plus_bigger_or_equal_temp_not_monotonic_timeout_token_with_not_same_monotonic_flag(timeout_for_equal_or_bigger_token, left_addictional_kwargs, right_addictional_kwargs): - token = TimeoutToken(1, **left_addictional_kwargs) + TimeoutToken(timeout_for_equal_or_bigger_token, **right_addictional_kwargs) - - assert isinstance(token, TimeoutToken) - assert token._timeout == 1 - assert len(token._tokens) == 1 - assert len(token._tokens[0]._tokens) == 0 - assert isinstance(token._tokens[0], TimeoutToken) - assert token._tokens[0]._timeout == timeout_for_equal_or_bigger_token - - -@pytest.mark.parametrize( - 'addictional_kwargs', - [ - {'monotonic': False}, - {}, - {'monotonic': True}, - ], -) -def test_bigger_timeout_token_plus_less_temp_timeout_token_with_same_monotonic_flag(addictional_kwargs): - left_timeout_token = TimeoutToken(2, **addictional_kwargs) - token = left_timeout_token + TimeoutToken(1, **addictional_kwargs) - - assert isinstance(token, TimeoutToken) - assert token is not left_timeout_token - assert token._timeout == 1 - assert len(token._tokens) == 1 - assert len(token._tokens[0]._tokens) == 0 - assert isinstance(token._tokens[0], TimeoutToken) - assert token._tokens[0]._timeout == 2 - assert token._tokens[0] is left_timeout_token - - -@pytest.mark.parametrize( - ('left_addictional_kwargs', 'right_addictional_kwargs'), - [ - ({'monotonic': False}, {'monotonic': True}), - ({}, {'monotonic': True}), - ({'monotonic': True}, {'monotonic': False}), - ({'monotonic': True}, {}), - ], -) -def test_bigger_timeout_token_plus_less_temp_timeout_token_with_not_same_monotonic_flag(left_addictional_kwargs, right_addictional_kwargs): - left_timeout_token = TimeoutToken(2, **left_addictional_kwargs) - token = left_timeout_token + TimeoutToken(1, **right_addictional_kwargs) - - assert isinstance(token, TimeoutToken) - assert token._timeout == 1 - assert len(token._tokens) == 1 - assert len(token._tokens[0]._tokens) == 0 - assert isinstance(token._tokens[0], TimeoutToken) - assert token._tokens[0]._timeout == 2 - assert token._tokens[0] is left_timeout_token - - -@pytest.mark.parametrize( - 'addictional_kwargs', - [ - {'monotonic': False}, - {}, - {'monotonic': True}, - ], -) -def test_less_not_monotonic_timeout_token_plus_bigger_temp_not_monotonic_timeout_token_with_same_monotonic_flag(addictional_kwargs): - left_timeout_token = TimeoutToken(1, **addictional_kwargs) - token = left_timeout_token + TimeoutToken(2, **addictional_kwargs) - - assert isinstance(token, TimeoutToken) - assert token._timeout == 1 - assert len(token._tokens) == 0 - - -@pytest.mark.parametrize( - ('left_addictional_kwargs', 'right_addictional_kwargs'), - [ - ({'monotonic': False}, {'monotonic': True}), - ({}, {'monotonic': True}), - ({'monotonic': True}, {'monotonic': False}), - ({'monotonic': True}, {}), - ], -) -def test_less_not_monotonic_timeout_token_plus_bigger_temp_not_monotonic_timeout_token_with_not_same_monotonic_flag(left_addictional_kwargs, right_addictional_kwargs): - left_timeout_token = TimeoutToken(1, **left_addictional_kwargs) - token = left_timeout_token + TimeoutToken(2, **right_addictional_kwargs) - - assert isinstance(token, TimeoutToken) - assert token._timeout == 2 - assert len(token._tokens) == 1 - assert len(token._tokens[0]._tokens) == 0 - assert isinstance(token._tokens[0], TimeoutToken) - assert token._tokens[0]._timeout == 1 - assert token._tokens[0] is left_timeout_token - - -@pytest.mark.parametrize( - 'addictional_kwargs', - [ - {'monotonic': False}, - {}, - {'monotonic': True}, - ], -) -def test_bigger_temp_timeout_token_plus_less_timeout_token_with_same_monotonic_flag(addictional_kwargs): - right_timeout_token = TimeoutToken(1, **addictional_kwargs) - token = TimeoutToken(2, **addictional_kwargs) + right_timeout_token - - assert isinstance(token, TimeoutToken) - assert token._timeout == 1 - assert len(token._tokens) == 0 - - -@pytest.mark.parametrize( - ('left_addictional_kwargs', 'right_addictional_kwargs'), - [ - ({'monotonic': False}, {'monotonic': True}), - ({}, {'monotonic': True}), - ({'monotonic': True}, {'monotonic': False}), - ({'monotonic': True}, {}), - ], -) -def test_bigger_temp_timeout_token_plus_less_timeout_token_with_not_same_monotonic_flag(left_addictional_kwargs, right_addictional_kwargs): - right_timeout_token = TimeoutToken(1, **right_addictional_kwargs) - token = TimeoutToken(2, **left_addictional_kwargs) + right_timeout_token - - assert isinstance(token, TimeoutToken) - assert token._timeout == 2 - assert len(token._tokens) == 1 - assert len(token._tokens[0]._tokens) == 0 - assert isinstance(token._tokens[0], TimeoutToken) - assert token._tokens[0]._timeout == 1 - assert token._tokens[0] is right_timeout_token - - -@pytest.mark.parametrize( - 'addictional_kwargs', - [ - {'monotonic': False}, - {}, - {'monotonic': True}, - ], -) -def test_less_temp_not_monotonic_timeout_token_plus_bigger_not_monotonic_timeout_token_with_same_monotonic_flag(addictional_kwargs): - right_timeout_token = TimeoutToken(2, **addictional_kwargs) - token = TimeoutToken(1, **addictional_kwargs) + right_timeout_token - - assert isinstance(token, TimeoutToken) - assert token._timeout == 1 - assert len(token._tokens) == 1 - assert len(token._tokens[0]._tokens) == 0 - assert token._tokens[0]._timeout == 2 - assert token._tokens[0] is right_timeout_token - - -@pytest.mark.parametrize( - ('left_addictional_kwargs', 'right_addictional_kwargs'), - [ - ({'monotonic': False}, {'monotonic': True}), - ({}, {'monotonic': True}), - ({'monotonic': True}, {'monotonic': False}), - ({'monotonic': True}, {}), - ], -) -def test_less_temp_not_monotonic_timeout_token_plus_bigger_not_monotonic_timeout_token_with_not_same_monotonic_flag(left_addictional_kwargs, right_addictional_kwargs): - right_timeout_token = TimeoutToken(2, **right_addictional_kwargs) - token = TimeoutToken(1, **left_addictional_kwargs) + right_timeout_token - - assert isinstance(token, TimeoutToken) - assert token._timeout == 1 - assert len(token._tokens) == 1 - assert len(token._tokens[0]._tokens) == 0 - assert isinstance(token._tokens[0], TimeoutToken) - assert token._tokens[0]._timeout == 2 - assert token._tokens[0] is right_timeout_token - - -@pytest.mark.parametrize( - 'addictional_kwargs', - [ - {'monotonic': False}, - {}, - {'monotonic': True}, - ], -) -def test_bigger_timeout_token_plus_less_timeout_token_with_same_monotonic_flag(addictional_kwargs): - left = TimeoutToken(2, **addictional_kwargs) - right = TimeoutToken(1, **addictional_kwargs) - token = left + right - - assert isinstance(token, SimpleToken) - assert token - assert len(token._tokens) == 2 - assert len(token._tokens[0]._tokens) == 0 - assert len(token._tokens[1]._tokens) == 0 - assert isinstance(token._tokens[0], TimeoutToken) - assert isinstance(token._tokens[1], TimeoutToken) - assert token._tokens[0]._timeout == 2 - assert token._tokens[1]._timeout == 1 - assert token._tokens[0] is left - assert token._tokens[1] is right - - -@pytest.mark.parametrize( - ('left_addictional_kwargs', 'right_addictional_kwargs'), - [ - ({'monotonic': False}, {'monotonic': True}), - ({}, {'monotonic': True}), - ({'monotonic': True}, {'monotonic': False}), - ({'monotonic': True}, {}), - ], -) -def test_bigger_timeout_token_plus_less_timeout_token_with_not_same_monotonic_flag(left_addictional_kwargs, right_addictional_kwargs): - left = TimeoutToken(2, **left_addictional_kwargs) - right = TimeoutToken(1, **right_addictional_kwargs) - token = left + right - - assert isinstance(token, SimpleToken) - assert token - assert len(token._tokens) == 2 - assert len(token._tokens[0]._tokens) == 0 - assert len(token._tokens[1]._tokens) == 0 - assert isinstance(token._tokens[0], TimeoutToken) - assert isinstance(token._tokens[1], TimeoutToken) - assert token._tokens[0]._timeout == 2 - assert token._tokens[1]._timeout == 1 - assert token._tokens[0] is left - assert token._tokens[1] is right - - -@pytest.mark.parametrize( - 'timeout_for_equal_or_bigger_token', - [ - 1, - 2, - ], -) -@pytest.mark.parametrize( - 'addictional_kwargs', - [ - {'monotonic': False}, - {}, - {'monotonic': True}, - ], -) -def test_less_or_equal_not_monotonic_timeout_token_plus_bigger_or_equal_not_monotonic_timeout_token_with_same_monotonic_flag(timeout_for_equal_or_bigger_token, addictional_kwargs): - left = TimeoutToken(1, **addictional_kwargs) - right = TimeoutToken(timeout_for_equal_or_bigger_token, **addictional_kwargs) - token = left + right - - assert isinstance(token, SimpleToken) - assert token - assert len(token._tokens) == 2 - assert len(token._tokens[0]._tokens) == 0 - assert len(token._tokens[1]._tokens) == 0 - assert isinstance(token._tokens[0], TimeoutToken) - assert isinstance(token._tokens[1], TimeoutToken) - assert token._tokens[0]._timeout == 1 - assert token._tokens[1]._timeout == timeout_for_equal_or_bigger_token - assert token._tokens[0] is left - assert token._tokens[1] is right - - -@pytest.mark.parametrize( - 'timeout_for_equal_or_bigger_token', - [ - 1, - 2, - ], -) -@pytest.mark.parametrize( - ('left_addictional_kwargs', 'right_addictional_kwargs'), - [ - ({'monotonic': False}, {'monotonic': True}), - ({}, {'monotonic': True}), - ({'monotonic': True}, {'monotonic': False}), - ({'monotonic': True}, {}), - ], -) -def test_less_or_equal_not_monotonic_timeout_token_plus_bigger_or_equal_not_monotonic_timeout_token_with_not_same_monotonic_flag(timeout_for_equal_or_bigger_token, left_addictional_kwargs, right_addictional_kwargs): - left = TimeoutToken(1, **left_addictional_kwargs) - right = TimeoutToken(timeout_for_equal_or_bigger_token, **right_addictional_kwargs) - token = left + right - - assert isinstance(token, SimpleToken) - assert token - assert len(token._tokens) == 2 - assert len(token._tokens[0]._tokens) == 0 - assert len(token._tokens[1]._tokens) == 0 - assert isinstance(token._tokens[0], TimeoutToken) - assert isinstance(token._tokens[1], TimeoutToken) - assert token._tokens[0]._timeout == 1 - assert token._tokens[1]._timeout == timeout_for_equal_or_bigger_token - assert token._tokens[0] is left - assert token._tokens[1] is right - - -@pytest.mark.parametrize( - 'addictional_kwargs', - [ - {'monotonic': False}, - {}, - {'monotonic': True}, - ], -) -def test_bigger_temp_timeout_token_plus_less_temp_timeout_token_with_same_monotonic_flag_with_temp_condition_token_at_right(addictional_kwargs): - token = TimeoutToken(2, **addictional_kwargs) + TimeoutToken(1, ConditionToken(lambda: True), **addictional_kwargs) - - assert isinstance(token, TimeoutToken) - assert token._timeout == 1 - assert len(token._tokens) == 1 - assert isinstance(token._tokens[0], ConditionToken) - assert len(token._tokens[0]._tokens) == 0 - - -@pytest.mark.parametrize( - ('left_addictional_kwargs', 'right_addictional_kwargs'), - [ - ({'monotonic': False}, {'monotonic': True}), - ({}, {'monotonic': True}), - ({'monotonic': True}, {'monotonic': False}), - ({'monotonic': True}, {}), - ], -) -def test_bigger_temp_timeout_token_plus_less_temp_timeout_token_with_not_same_monotonic_flag_with_temp_condition_token_at_right(left_addictional_kwargs, right_addictional_kwargs): - token = TimeoutToken(2, **left_addictional_kwargs) + TimeoutToken(1, ConditionToken(lambda: True), **right_addictional_kwargs) - - assert isinstance(token, TimeoutToken) - assert token._timeout == 2 - assert len(token._tokens) == 1 - assert len(token._tokens[0]._tokens) == 1 - assert isinstance(token._tokens[0], TimeoutToken) - assert token._tokens[0]._timeout == 1 - assert isinstance(token._tokens[0]._tokens[0], ConditionToken) - assert len(token._tokens[0]._tokens[0]._tokens) == 0 - - -@pytest.mark.parametrize( - 'timeout_for_equal_or_bigger_token', - [ - 1, - 2, - ], -) -@pytest.mark.parametrize( - 'addictional_kwargs', - [ - {'monotonic': False}, - {}, - {'monotonic': True}, - ], -) -def test_less_or_equal_temp_not_monotonic_timeout_token_plus_bigger_or_equal_temp_not_monotonic_timeout_token_with_same_monotonic_flag_with_temp_condition_token_at_right(timeout_for_equal_or_bigger_token, addictional_kwargs): - token = TimeoutToken(1, **addictional_kwargs) + TimeoutToken(timeout_for_equal_or_bigger_token, ConditionToken(lambda: True), **addictional_kwargs) - - assert isinstance(token, TimeoutToken) - assert token._timeout == 1 - assert len(token._tokens) == 1 - assert len(token._tokens[0]._tokens) == 0 - assert isinstance(token._tokens[0], ConditionToken) - - -@pytest.mark.parametrize( - 'timeout_for_equal_or_bigger_token', - [ - 1, - 2, - ], -) -@pytest.mark.parametrize( - ('left_addictional_kwargs', 'right_addictional_kwargs'), - [ - ({'monotonic': False}, {'monotonic': True}), - ({}, {'monotonic': True}), - ({'monotonic': True}, {'monotonic': False}), - ({'monotonic': True}, {}), - ], -) -def test_less_or_equal_temp_not_monotonic_timeout_token_plus_bigger_or_equal_temp_not_monotonic_timeout_token_with_not_same_monotonic_flag_with_temp_condition_token_at_right(timeout_for_equal_or_bigger_token, left_addictional_kwargs, right_addictional_kwargs): - token = TimeoutToken(1, **left_addictional_kwargs) + TimeoutToken(timeout_for_equal_or_bigger_token, ConditionToken(lambda: True), **right_addictional_kwargs) - - assert isinstance(token, TimeoutToken) - assert token._timeout == 1 - assert len(token._tokens) == 1 - assert len(token._tokens[0]._tokens) == 1 - assert isinstance(token._tokens[0], TimeoutToken) - assert token._tokens[0]._timeout == timeout_for_equal_or_bigger_token - assert isinstance(token._tokens[0]._tokens[0], ConditionToken) - - -@pytest.mark.parametrize( - 'addictional_kwargs', - [ - {'monotonic': False}, - {}, - {'monotonic': True}, - ], -) -def test_bigger_timeout_token_plus_less_temp_timeout_token_with_same_monotonic_flag_with_temp_condition_token_at_right(addictional_kwargs): - left_timeout_token = TimeoutToken(2, **addictional_kwargs) - token = left_timeout_token + TimeoutToken(1, ConditionToken(lambda: True), **addictional_kwargs) - - assert isinstance(token, TimeoutToken) - assert token is not left_timeout_token - assert token._timeout == 1 - assert len(token._tokens) == 2 - assert len(token._tokens[0]._tokens) == 0 - assert len(token._tokens[1]._tokens) == 0 - assert isinstance(token._tokens[0], ConditionToken) - assert isinstance(token._tokens[1], TimeoutToken) - assert token._tokens[1]._timeout == 2 - - -@pytest.mark.parametrize( - ('left_addictional_kwargs', 'right_addictional_kwargs'), - [ - ({'monotonic': False}, {'monotonic': True}), - ({}, {'monotonic': True}), - ({'monotonic': True}, {'monotonic': False}), - ({'monotonic': True}, {}), - ], -) -def test_bigger_timeout_token_plus_less_temp_timeout_token_with_not_same_monotonic_flag_with_temp_condition_token_at_right(left_addictional_kwargs, right_addictional_kwargs): - left_timeout_token = TimeoutToken(2, **left_addictional_kwargs) - token = left_timeout_token + TimeoutToken(1, ConditionToken(lambda: True), **right_addictional_kwargs) - - assert isinstance(token, TimeoutToken) - assert token._timeout == 1 - assert len(token._tokens) == 2 - assert len(token._tokens[0]._tokens) == 0 - assert len(token._tokens[1]._tokens) == 0 - assert isinstance(token._tokens[0], ConditionToken) - assert token._tokens[0] is not left_timeout_token - assert isinstance(token._tokens[1], TimeoutToken) - assert token._tokens[1]._timeout == 2 - assert token._tokens[1] is left_timeout_token - - -@pytest.mark.parametrize( - 'addictional_kwargs', - [ - {'monotonic': False}, - {}, - {'monotonic': True}, - ], -) -def test_less_not_monotonic_timeout_token_plus_bigger_temp_not_monotonic_timeout_token_with_same_monotonic_flag_with_temp_condition_token_at_right(addictional_kwargs): - left_timeout_token = TimeoutToken(1, **addictional_kwargs) - token = left_timeout_token + TimeoutToken(2, ConditionToken(lambda: True), **addictional_kwargs) - - assert isinstance(token, SimpleToken) - assert len(token._tokens) == 2 - assert len(token._tokens[0]._tokens) == 0 - assert len(token._tokens[1]._tokens) == 0 - assert isinstance(token._tokens[0], ConditionToken) - assert isinstance(token._tokens[1], TimeoutToken) - assert token._tokens[1]._timeout == 1 - - -@pytest.mark.parametrize( - ('left_addictional_kwargs', 'right_addictional_kwargs'), - [ - ({'monotonic': False}, {'monotonic': True}), - ({}, {'monotonic': True}), - ({'monotonic': True}, {'monotonic': False}), - ({'monotonic': True}, {}), - ], -) -def test_less_not_monotonic_timeout_token_plus_bigger_temp_not_monotonic_timeout_token_with_not_same_monotonic_flag_with_temp_condition_token_at_right(left_addictional_kwargs, right_addictional_kwargs): - left_timeout_token = TimeoutToken(1, **left_addictional_kwargs) - token = left_timeout_token + TimeoutToken(2, ConditionToken(lambda: True), **right_addictional_kwargs) - - assert isinstance(token, TimeoutToken) - assert token._timeout == 2 - assert len(token._tokens) == 2 - assert len(token._tokens[0]._tokens) == 0 - assert len(token._tokens[1]._tokens) == 0 - assert isinstance(token._tokens[0], ConditionToken) - assert token._tokens[0] is not left_timeout_token - assert isinstance(token._tokens[1], TimeoutToken) - assert token._tokens[1]._timeout == 1 - assert token._tokens[1] is left_timeout_token - - -@pytest.mark.parametrize( - 'addictional_kwargs', - [ - {'monotonic': False}, - {}, - {'monotonic': True}, - ], -) -def test_bigger_temp_timeout_token_plus_less_timeout_token_with_same_monotonic_flag_with_temp_condition_token_at_right(addictional_kwargs): - right_timeout_token = TimeoutToken(1, ConditionToken(lambda: True), **addictional_kwargs) - token = TimeoutToken(2, **addictional_kwargs) + right_timeout_token - - assert isinstance(token, TimeoutToken) - assert token._timeout == 1 - assert len(token._tokens) == 1 - assert len(token._tokens[0]._tokens) == 0 - assert isinstance(token._tokens[0], ConditionToken) - assert token is right_timeout_token - - -@pytest.mark.parametrize( - ('left_addictional_kwargs', 'right_addictional_kwargs'), - [ - ({'monotonic': False}, {'monotonic': True}), - ({}, {'monotonic': True}), - ({'monotonic': True}, {'monotonic': False}), - ({'monotonic': True}, {}), - ], -) -def test_bigger_temp_timeout_token_plus_less_timeout_token_with_not_same_monotonic_flag_with_temp_condition_token_at_right(left_addictional_kwargs, right_addictional_kwargs): - right_timeout_token = TimeoutToken(1, ConditionToken(lambda: True), **right_addictional_kwargs) - token = TimeoutToken(2, **left_addictional_kwargs) + right_timeout_token - - assert isinstance(token, TimeoutToken) - assert token._timeout == 2 - assert len(token._tokens) == 1 - assert len(token._tokens[0]._tokens) == 1 - assert len(token._tokens[0]._tokens[0]._tokens) == 0 - assert isinstance(token._tokens[0], TimeoutToken) - assert token._tokens[0]._timeout == 1 - assert token._tokens[0] is right_timeout_token - assert isinstance(token._tokens[0]._tokens[0], ConditionToken) - - -@pytest.mark.parametrize( - 'addictional_kwargs', - [ - {'monotonic': False}, - {}, - {'monotonic': True}, - ], -) -def test_less_temp_not_monotonic_timeout_token_plus_bigger_not_monotonic_timeout_token_with_same_monotonic_flag_with_temp_condition_token_at_right(addictional_kwargs): - right_timeout_token = TimeoutToken(2, ConditionToken(lambda: True), **addictional_kwargs) - token = TimeoutToken(1, **addictional_kwargs) + right_timeout_token - - assert isinstance(token, TimeoutToken) - assert token._timeout == 1 - assert len(token._tokens) == 1 - assert len(token._tokens[0]._tokens) == 1 - assert len(token._tokens[0]._tokens[0]._tokens) == 0 - assert token._tokens[0]._timeout == 2 - assert token._tokens[0] is right_timeout_token - assert isinstance(token._tokens[0]._tokens[0], ConditionToken) - - -@pytest.mark.parametrize( - ('left_addictional_kwargs', 'right_addictional_kwargs'), - [ - ({'monotonic': False}, {'monotonic': True}), - ({}, {'monotonic': True}), - ({'monotonic': True}, {'monotonic': False}), - ({'monotonic': True}, {}), - ], -) -def test_less_temp_not_monotonic_timeout_token_plus_bigger_not_monotonic_timeout_token_with_not_same_monotonic_flag_with_temp_condition_token_at_right(left_addictional_kwargs, right_addictional_kwargs): - right_timeout_token = TimeoutToken(2, ConditionToken(lambda: True), **right_addictional_kwargs) - token = TimeoutToken(1, **left_addictional_kwargs) + right_timeout_token - - assert isinstance(token, TimeoutToken) - assert token._timeout == 1 - assert len(token._tokens) == 1 - assert len(token._tokens[0]._tokens) == 1 - assert len(token._tokens[0]._tokens[0]._tokens) == 0 - assert isinstance(token._tokens[0], TimeoutToken) - assert token._tokens[0]._timeout == 2 - assert token._tokens[0] is right_timeout_token - assert isinstance(token._tokens[0]._tokens[0], ConditionToken) - - -@pytest.mark.parametrize( - 'addictional_kwargs', - [ - {'monotonic': False}, - {}, - {'monotonic': True}, - ], -) -def test_bigger_timeout_token_plus_less_timeout_token_with_same_monotonic_flag_with_temp_condition_token_at_right(addictional_kwargs): - left = TimeoutToken(2, **addictional_kwargs) - right = TimeoutToken(1, ConditionToken(lambda: False), **addictional_kwargs) - token = left + right - - assert isinstance(token, SimpleToken) - assert token - assert len(token._tokens) == 2 - assert len(token._tokens[0]._tokens) == 0 - assert len(token._tokens[1]._tokens) == 1 - assert len(token._tokens[1]._tokens[0]._tokens) == 0 - assert isinstance(token._tokens[0], TimeoutToken) - assert isinstance(token._tokens[1], TimeoutToken) - assert token._tokens[0]._timeout == 2 - assert token._tokens[1]._timeout == 1 - assert token._tokens[0] is left - assert token._tokens[1] is right - assert isinstance(token._tokens[1]._tokens[0], ConditionToken) - - -@pytest.mark.parametrize( - ('left_addictional_kwargs', 'right_addictional_kwargs'), - [ - ({'monotonic': False}, {'monotonic': True}), - ({}, {'monotonic': True}), - ({'monotonic': True}, {'monotonic': False}), - ({'monotonic': True}, {}), - ], -) -def test_bigger_timeout_token_plus_less_timeout_token_with_not_same_monotonic_flag_with_temp_condition_token_at_right(left_addictional_kwargs, right_addictional_kwargs): - left = TimeoutToken(2, **left_addictional_kwargs) - right = TimeoutToken(1, ConditionToken(lambda: False), **right_addictional_kwargs) - token = left + right - - assert isinstance(token, SimpleToken) - assert token - assert len(token._tokens) == 2 - assert len(token._tokens[0]._tokens) == 0 - assert len(token._tokens[1]._tokens) == 1 - assert len(token._tokens[1]._tokens[0]._tokens) == 0 - assert isinstance(token._tokens[0], TimeoutToken) - assert isinstance(token._tokens[1], TimeoutToken) - assert token._tokens[0]._timeout == 2 - assert token._tokens[1]._timeout == 1 - assert token._tokens[0] is left - assert token._tokens[1] is right - assert isinstance(token._tokens[1]._tokens[0], ConditionToken) - - -@pytest.mark.parametrize( - 'timeout_for_equal_or_bigger_token', - [ - 1, - 2, - ], -) -@pytest.mark.parametrize( - 'addictional_kwargs', - [ - {'monotonic': False}, - {}, - {'monotonic': True}, - ], -) -def test_less_or_equal_not_monotonic_timeout_token_plus_bigger_or_equal_not_monotonic_timeout_token_with_same_monotonic_flag_with_temp_condition_token_at_right(timeout_for_equal_or_bigger_token, addictional_kwargs): - left = TimeoutToken(1, **addictional_kwargs) - right = TimeoutToken(timeout_for_equal_or_bigger_token, ConditionToken(lambda: False), **addictional_kwargs) - token = left + right - - assert isinstance(token, SimpleToken) - assert token - assert len(token._tokens) == 2 - assert len(token._tokens[0]._tokens) == 0 - assert len(token._tokens[1]._tokens) == 1 - assert len(token._tokens[1]._tokens[0]._tokens) == 0 - assert isinstance(token._tokens[0], TimeoutToken) - assert isinstance(token._tokens[1], TimeoutToken) - assert token._tokens[0]._timeout == 1 - assert token._tokens[1]._timeout == timeout_for_equal_or_bigger_token - assert token._tokens[0] is left - assert token._tokens[1] is right - assert isinstance(token._tokens[1]._tokens[0], ConditionToken) - - -@pytest.mark.parametrize( - 'timeout_for_equal_or_bigger_token', - [ - 1, - 2, - ], -) -@pytest.mark.parametrize( - ('left_addictional_kwargs', 'right_addictional_kwargs'), - [ - ({'monotonic': False}, {'monotonic': True}), - ({}, {'monotonic': True}), - ({'monotonic': True}, {'monotonic': False}), - ({'monotonic': True}, {}), - ], -) -def test_less_or_equal_not_monotonic_timeout_token_plus_bigger_or_equal_not_monotonic_timeout_token_with_not_same_monotonic_flag_with_temp_condition_token_at_right(timeout_for_equal_or_bigger_token, left_addictional_kwargs, right_addictional_kwargs): - left = TimeoutToken(1, **left_addictional_kwargs) - right = TimeoutToken(timeout_for_equal_or_bigger_token, ConditionToken(lambda: False), **right_addictional_kwargs) - token = left + right - - assert isinstance(token, SimpleToken) - assert token - assert len(token._tokens) == 2 - assert len(token._tokens[0]._tokens) == 0 - assert len(token._tokens[1]._tokens) == 1 - assert len(token._tokens[1]._tokens[0]._tokens) == 0 - assert isinstance(token._tokens[0], TimeoutToken) - assert isinstance(token._tokens[1], TimeoutToken) - assert token._tokens[0]._timeout == 1 - assert token._tokens[1]._timeout == timeout_for_equal_or_bigger_token - assert token._tokens[0] is left - assert token._tokens[1] is right - assert isinstance(token._tokens[1]._tokens[0], ConditionToken) - - -@pytest.mark.parametrize( - 'addictional_kwargs', - [ - {'monotonic': False}, - {}, - {'monotonic': True}, - ], -) -def test_bigger_temp_timeout_token_plus_less_temp_timeout_token_with_same_monotonic_flag_with_temp_condition_token_at_right_and_counter_token_at_left(addictional_kwargs): - token = TimeoutToken(2, CounterToken(5), **addictional_kwargs) + TimeoutToken(1, ConditionToken(lambda: True), **addictional_kwargs) - - assert isinstance(token, TimeoutToken) - assert token._timeout == 1 - assert len(token._tokens) == 2 - assert len(token._tokens[0]._tokens) == 0 - assert len(token._tokens[1]._tokens) == 0 - assert isinstance(token._tokens[0], ConditionToken) - assert isinstance(token._tokens[1], CounterToken) - - -@pytest.mark.parametrize( - ('left_addictional_kwargs', 'right_addictional_kwargs'), - [ - ({'monotonic': False}, {'monotonic': True}), - ({}, {'monotonic': True}), - ({'monotonic': True}, {'monotonic': False}), - ({'monotonic': True}, {}), - ], -) -def test_bigger_temp_timeout_token_plus_less_temp_timeout_token_with_not_same_monotonic_flag_with_temp_condition_token_at_right_and_counter_token_at_left(left_addictional_kwargs, right_addictional_kwargs): - token = TimeoutToken(2, CounterToken(5), **left_addictional_kwargs) + TimeoutToken(1, ConditionToken(lambda: True), **right_addictional_kwargs) - - assert isinstance(token, TimeoutToken) - assert token._timeout == 2 - assert len(token._tokens) == 2 - assert len(token._tokens[1]._tokens) == 1 - assert isinstance(token._tokens[1], TimeoutToken) - assert token._tokens[1]._timeout == 1 - assert isinstance(token._tokens[1]._tokens[0], ConditionToken) - assert len(token._tokens[1]._tokens[0]._tokens) == 0 - assert len(token._tokens[0]._tokens) == 0 - assert isinstance(token._tokens[0], CounterToken) - - -@pytest.mark.parametrize( - 'timeout_for_equal_or_bigger_token', - [ - 1, - 2, - ], -) -@pytest.mark.parametrize( - 'addictional_kwargs', - [ - {'monotonic': False}, - {}, - {'monotonic': True}, - ], -) -def test_less_or_equal_temp_not_monotonic_timeout_token_plus_bigger_or_equal_temp_not_monotonic_timeout_token_with_same_monotonic_flag_with_temp_condition_token_at_right_and_counter_token_at_left(timeout_for_equal_or_bigger_token, addictional_kwargs): - token = TimeoutToken(1, CounterToken(5), **addictional_kwargs) + TimeoutToken(timeout_for_equal_or_bigger_token, ConditionToken(lambda: True), **addictional_kwargs) - - assert isinstance(token, TimeoutToken) - assert token._timeout == 1 - assert len(token._tokens) == 2 - assert len(token._tokens[0]._tokens) == 0 - assert len(token._tokens[1]._tokens) == 0 - assert {type(token._tokens[0]), type(token._tokens[1])} == {CounterToken, ConditionToken} - - -@pytest.mark.parametrize( - 'timeout_for_equal_or_bigger_token', - [ - 1, - 2, - ], -) -@pytest.mark.parametrize( - ('left_addictional_kwargs', 'right_addictional_kwargs'), - [ - ({'monotonic': False}, {'monotonic': True}), - ({}, {'monotonic': True}), - ({'monotonic': True}, {'monotonic': False}), - ({'monotonic': True}, {}), - ], -) -def test_less_or_equal_temp_not_monotonic_timeout_token_plus_bigger_or_equal_temp_not_monotonic_timeout_token_with_not_same_monotonic_flag_with_temp_condition_token_at_right_and_counter_token_at_left(timeout_for_equal_or_bigger_token, left_addictional_kwargs, right_addictional_kwargs): - token = TimeoutToken(1, CounterToken(5), **left_addictional_kwargs) + TimeoutToken(timeout_for_equal_or_bigger_token, ConditionToken(lambda: True), **right_addictional_kwargs) - - assert isinstance(token, TimeoutToken) - assert token._timeout == 1 - assert len(token._tokens) == 2 - assert len(token._tokens[0]._tokens) == 0 - assert len(token._tokens[1]._tokens) == 1 - assert len(token._tokens[1]._tokens[0]._tokens) == 0 - assert isinstance(token._tokens[0], CounterToken) - assert isinstance(token._tokens[1], TimeoutToken) - assert isinstance(token._tokens[1]._tokens[0], ConditionToken) - assert token._tokens[1]._timeout == timeout_for_equal_or_bigger_token - - -@pytest.mark.parametrize( - 'addictional_kwargs', - [ - {'monotonic': False}, - {}, - {'monotonic': True}, - ], -) -def test_bigger_timeout_token_plus_less_temp_timeout_token_with_same_monotonic_flag_with_temp_condition_token_at_right_and_counter_token_at_left(addictional_kwargs): - left_timeout_token = TimeoutToken(2, CounterToken(5), **addictional_kwargs) - token = left_timeout_token + TimeoutToken(1, ConditionToken(lambda: True), **addictional_kwargs) - - assert isinstance(token, TimeoutToken) - assert token is not left_timeout_token - assert token._tokens[1] is left_timeout_token - assert token._timeout == 1 - assert len(token._tokens) == 2 - assert len(token._tokens[0]._tokens) == 0 - assert len(token._tokens[1]._tokens) == 1 - assert len(token._tokens[1]._tokens[0]._tokens) == 0 - assert isinstance(token._tokens[0], ConditionToken) - assert isinstance(token._tokens[1], TimeoutToken) - assert token._tokens[1]._timeout == 2 - assert isinstance(token._tokens[1]._tokens[0], CounterToken) - - -@pytest.mark.parametrize( - ('left_addictional_kwargs', 'right_addictional_kwargs'), - [ - ({'monotonic': False}, {'monotonic': True}), - ({}, {'monotonic': True}), - ({'monotonic': True}, {'monotonic': False}), - ({'monotonic': True}, {}), - ], -) -def test_bigger_timeout_token_plus_less_temp_timeout_token_with_not_same_monotonic_flag_with_temp_condition_token_at_right_and_counter_token_at_left(left_addictional_kwargs, right_addictional_kwargs): - left_timeout_token = TimeoutToken(2, CounterToken(5), **left_addictional_kwargs) - token = left_timeout_token + TimeoutToken(1, ConditionToken(lambda: True), **right_addictional_kwargs) - - assert isinstance(token, TimeoutToken) - assert token is not left_timeout_token - assert token._tokens[1] is left_timeout_token - assert token._timeout == 1 - assert len(token._tokens) == 2 - assert len(token._tokens[0]._tokens) == 0 - assert len(token._tokens[1]._tokens) == 1 - assert len(token._tokens[1]._tokens[0]._tokens) == 0 - assert isinstance(token._tokens[0], ConditionToken) - assert isinstance(token._tokens[1], TimeoutToken) - assert token._tokens[1]._timeout == 2 - assert isinstance(token._tokens[1]._tokens[0], CounterToken) - - -@pytest.mark.parametrize( - 'addictional_kwargs', - [ - {'monotonic': False}, - {}, - {'monotonic': True}, - ], -) -def test_less_not_monotonic_timeout_token_plus_bigger_temp_not_monotonic_timeout_token_with_same_monotonic_flag_with_temp_condition_token_at_right_and_counter_token_at_left(addictional_kwargs): - left_timeout_token = TimeoutToken(1, CounterToken(5), **addictional_kwargs) - token = left_timeout_token + TimeoutToken(2, ConditionToken(lambda: True), **addictional_kwargs) - - assert isinstance(token, SimpleToken) - assert len(token._tokens) == 2 - assert len(token._tokens[0]._tokens) == 0 - assert len(token._tokens[1]._tokens) == 1 - assert len(token._tokens[1]._tokens[0]._tokens) == 0 - assert isinstance(token._tokens[0], ConditionToken) - assert isinstance(token._tokens[1], TimeoutToken) - assert token._tokens[1]._timeout == 1 - assert isinstance(token._tokens[1]._tokens[0], CounterToken) - - -@pytest.mark.parametrize( - ('left_addictional_kwargs', 'right_addictional_kwargs'), - [ - ({'monotonic': False}, {'monotonic': True}), - ({}, {'monotonic': True}), - ({'monotonic': True}, {'monotonic': False}), - ({'monotonic': True}, {}), - ], -) -def test_less_not_monotonic_timeout_token_plus_bigger_temp_not_monotonic_timeout_token_with_not_same_monotonic_flag_with_temp_condition_token_at_right_and_counter_token_at_left(left_addictional_kwargs, right_addictional_kwargs): - left_timeout_token = TimeoutToken(1, CounterToken(5), **left_addictional_kwargs) - token = left_timeout_token + TimeoutToken(2, ConditionToken(lambda: True), **right_addictional_kwargs) - - assert isinstance(token, TimeoutToken) - assert token._timeout == 2 - assert len(token._tokens) == 2 - assert len(token._tokens[0]._tokens) == 0 - assert len(token._tokens[1]._tokens) == 1 - assert len(token._tokens[1]._tokens[0]._tokens) == 0 - assert isinstance(token._tokens[0], ConditionToken) - assert token._tokens[0] is not left_timeout_token - assert isinstance(token._tokens[1], TimeoutToken) - assert token._tokens[1]._timeout == 1 - assert token._tokens[1] is left_timeout_token - assert isinstance(token._tokens[1]._tokens[0], CounterToken) - - -@pytest.mark.parametrize( - 'addictional_kwargs', - [ - {'monotonic': False}, - {}, - {'monotonic': True}, - ], -) -def test_bigger_temp_timeout_token_plus_less_timeout_token_with_same_monotonic_flag_with_temp_condition_token_at_right_and_counter_token_at_left(addictional_kwargs): - right_timeout_token = TimeoutToken(1, ConditionToken(lambda: True), **addictional_kwargs) - token = TimeoutToken(2, CounterToken(5), **addictional_kwargs) + right_timeout_token - - assert isinstance(token, SimpleToken) - assert isinstance(token._tokens[0], CounterToken) - assert isinstance(token._tokens[1], TimeoutToken) - assert isinstance(token._tokens[1]._tokens[0], ConditionToken) - assert token._tokens[1]._timeout == 1 - assert len(token._tokens) == 2 - assert len(token._tokens[0]._tokens) == 0 - assert len(token._tokens[1]._tokens) == 1 - assert len(token._tokens[1]._tokens[0]._tokens) == 0 - assert token._tokens[1] is right_timeout_token - - -@pytest.mark.parametrize( - ('left_addictional_kwargs', 'right_addictional_kwargs'), - [ - ({'monotonic': False}, {'monotonic': True}), - ({}, {'monotonic': True}), - ({'monotonic': True}, {'monotonic': False}), - ({'monotonic': True}, {}), - ], -) -def test_bigger_temp_timeout_token_plus_less_timeout_token_with_not_same_monotonic_flag_with_temp_condition_token_at_right_and_counter_token_at_left(left_addictional_kwargs, right_addictional_kwargs): - right_timeout_token = TimeoutToken(1, ConditionToken(lambda: True), **right_addictional_kwargs) - token = TimeoutToken(2, CounterToken(5), **left_addictional_kwargs) + right_timeout_token - - assert isinstance(token, TimeoutToken) - assert isinstance(token._tokens[0], CounterToken) - assert isinstance(token._tokens[1], TimeoutToken) - assert isinstance(token._tokens[1]._tokens[0], ConditionToken) - assert token._tokens[1]._timeout == 1 - assert token._timeout == 2 - assert len(token._tokens) == 2 - assert len(token._tokens[0]._tokens) == 0 - assert len(token._tokens[1]._tokens) == 1 - assert len(token._tokens[1]._tokens[0]._tokens) == 0 - assert token._tokens[1] is right_timeout_token - assert token is not right_timeout_token - - -@pytest.mark.parametrize( - 'addictional_kwargs', - [ - {'monotonic': False}, - {}, - {'monotonic': True}, - ], -) -def test_less_temp_not_monotonic_timeout_token_plus_bigger_not_monotonic_timeout_token_with_same_monotonic_flag_with_temp_condition_token_at_right_and_counter_token_at_left(addictional_kwargs): - right_timeout_token = TimeoutToken(2, ConditionToken(lambda: True), **addictional_kwargs) - token = TimeoutToken(1, CounterToken(5), **addictional_kwargs) + right_timeout_token - - TimeoutToken(1, CounterToken(5), TimeoutToken(2, ConditionToken(lambda: True))) - - assert isinstance(token, TimeoutToken) - assert token._timeout == 1 - assert len(token._tokens) == 2 - assert len(token._tokens[0]._tokens) == 0 - assert len(token._tokens[1]._tokens) == 1 - assert len(token._tokens[1]._tokens[0]._tokens) == 0 - assert token._timeout == 1 - assert token._tokens[1]._timeout == 2 - assert token._tokens[1] is right_timeout_token - assert isinstance(token._tokens[1]._tokens[0], ConditionToken) - assert isinstance(token._tokens[0], CounterToken) - - -@pytest.mark.parametrize( - ('left_addictional_kwargs', 'right_addictional_kwargs'), - [ - ({'monotonic': False}, {'monotonic': True}), - ({}, {'monotonic': True}), - ({'monotonic': True}, {'monotonic': False}), - ({'monotonic': True}, {}), - ], -) -def test_less_temp_not_monotonic_timeout_token_plus_bigger_not_monotonic_timeout_token_with_not_same_monotonic_flag_with_temp_condition_token_at_right_and_counter_token_at_left(left_addictional_kwargs, right_addictional_kwargs): - right_timeout_token = TimeoutToken(2, ConditionToken(lambda: True), **right_addictional_kwargs) - token = TimeoutToken(1, CounterToken(5), **left_addictional_kwargs) + right_timeout_token - - TimeoutToken(1, CounterToken(5), TimeoutToken(2, ConditionToken(lambda: True))) - - assert isinstance(token, TimeoutToken) - assert isinstance(token._tokens[0], CounterToken) - assert isinstance(token._tokens[1], TimeoutToken) - assert isinstance(token._tokens[1]._tokens[0], ConditionToken) - assert token._timeout == 1 - assert token._tokens[1]._timeout == 2 - assert len(token._tokens) == 2 - assert len(token._tokens[0]._tokens) == 0 - assert len(token._tokens[1]._tokens) == 1 - assert len(token._tokens[1]._tokens[0]._tokens) == 0 - assert token._tokens[1] is right_timeout_token - assert token is not right_timeout_token - - -@pytest.mark.parametrize( - 'addictional_kwargs', - [ - {'monotonic': False}, - {}, - {'monotonic': True}, - ], -) -def test_bigger_timeout_token_plus_less_timeout_token_with_same_monotonic_flag_with_temp_condition_token_at_right_and_counter_token_at_left(addictional_kwargs): - left = TimeoutToken(2, CounterToken(5), **addictional_kwargs) - right = TimeoutToken(1, ConditionToken(lambda: False), **addictional_kwargs) - token = left + right - - assert isinstance(token, SimpleToken) - assert isinstance(token._tokens[0], TimeoutToken) - assert isinstance(token._tokens[1], TimeoutToken) - assert isinstance(token._tokens[0]._tokens[0], CounterToken) - assert isinstance(token._tokens[1]._tokens[0], ConditionToken) - assert token - assert len(token._tokens) == 2 - assert len(token._tokens[0]._tokens) == 1 - assert len(token._tokens[1]._tokens) == 1 - assert len(token._tokens[1]._tokens[0]._tokens) == 0 - assert len(token._tokens[0]._tokens[0]._tokens) == 0 - assert token._tokens[0] is left - assert token._tokens[1] is right - assert token._tokens[0]._timeout == 2 - assert token._tokens[1]._timeout == 1 - - -@pytest.mark.parametrize( - ('left_addictional_kwargs', 'right_addictional_kwargs'), - [ - ({'monotonic': False}, {'monotonic': True}), - ({}, {'monotonic': True}), - ({'monotonic': True}, {'monotonic': False}), - ({'monotonic': True}, {}), - ], -) -def test_bigger_timeout_token_plus_less_timeout_token_with_not_same_monotonic_flag_with_temp_condition_token_at_right_and_counter_token_at_left(left_addictional_kwargs, right_addictional_kwargs): - left = TimeoutToken(2, CounterToken(5), **left_addictional_kwargs) - right = TimeoutToken(1, ConditionToken(lambda: False), **right_addictional_kwargs) - token = left + right - - assert isinstance(token, SimpleToken) - assert isinstance(token._tokens[0], TimeoutToken) - assert isinstance(token._tokens[1], TimeoutToken) - assert isinstance(token._tokens[0]._tokens[0], CounterToken) - assert isinstance(token._tokens[1]._tokens[0], ConditionToken) - assert token - assert len(token._tokens) == 2 - assert len(token._tokens[0]._tokens) == 1 - assert len(token._tokens[1]._tokens) == 1 - assert len(token._tokens[1]._tokens[0]._tokens) == 0 - assert len(token._tokens[0]._tokens[0]._tokens) == 0 - assert token._tokens[0] is left - assert token._tokens[1] is right - assert token._tokens[0]._timeout == 2 - assert token._tokens[1]._timeout == 1 - - -@pytest.mark.parametrize( - 'timeout_for_equal_or_bigger_token', - [ - 1, - 2, - ], -) -@pytest.mark.parametrize( - 'addictional_kwargs', - [ - {'monotonic': False}, - {}, - {'monotonic': True}, - ], -) -def test_less_or_equal_not_monotonic_timeout_token_plus_bigger_or_equal_not_monotonic_timeout_token_with_same_monotonic_flag_with_temp_condition_token_at_right_and_counter_token_at_left(timeout_for_equal_or_bigger_token, addictional_kwargs): - left = TimeoutToken(1, CounterToken(5), **addictional_kwargs) - right = TimeoutToken(timeout_for_equal_or_bigger_token, ConditionToken(lambda: False), **addictional_kwargs) - token = left + right - - assert isinstance(token, SimpleToken) - assert isinstance(token._tokens[0], TimeoutToken) - assert isinstance(token._tokens[1], TimeoutToken) - assert isinstance(token._tokens[0]._tokens[0], CounterToken) - assert isinstance(token._tokens[1]._tokens[0], ConditionToken) - assert token - assert len(token._tokens) == 2 - assert len(token._tokens[0]._tokens) == 1 - assert len(token._tokens[1]._tokens) == 1 - assert len(token._tokens[1]._tokens[0]._tokens) == 0 - assert len(token._tokens[0]._tokens[0]._tokens) == 0 - assert token._tokens[0] is left - assert token._tokens[1] is right - assert token._tokens[0]._timeout == 1 - assert token._tokens[1]._timeout == timeout_for_equal_or_bigger_token - - -@pytest.mark.parametrize( - 'timeout_for_equal_or_bigger_token', - [ - 1, - 2, - ], -) -@pytest.mark.parametrize( - ('left_addictional_kwargs', 'right_addictional_kwargs'), - [ - ({'monotonic': False}, {'monotonic': True}), - ({}, {'monotonic': True}), - ({'monotonic': True}, {'monotonic': False}), - ({'monotonic': True}, {}), - ], -) -def test_less_or_equal_not_monotonic_timeout_token_plus_bigger_or_equal_not_monotonic_timeout_token_with_not_same_monotonic_flag_with_temp_condition_token_at_right_and_counter_token_at_left(timeout_for_equal_or_bigger_token, left_addictional_kwargs, right_addictional_kwargs): - left = TimeoutToken(1, CounterToken(5), **left_addictional_kwargs) - right = TimeoutToken(timeout_for_equal_or_bigger_token, ConditionToken(lambda: False), **right_addictional_kwargs) - token = left + right - - assert isinstance(token, SimpleToken) - assert isinstance(token._tokens[0], TimeoutToken) - assert isinstance(token._tokens[1], TimeoutToken) - assert isinstance(token._tokens[0]._tokens[0], CounterToken) - assert isinstance(token._tokens[1]._tokens[0], ConditionToken) - assert token - assert len(token._tokens) == 2 - assert len(token._tokens[0]._tokens) == 1 - assert len(token._tokens[1]._tokens) == 1 - assert len(token._tokens[1]._tokens[0]._tokens) == 0 - assert len(token._tokens[0]._tokens[0]._tokens) == 0 - assert token._tokens[0] is left - assert token._tokens[1] is right - assert token._tokens[0]._timeout == 1 - assert token._tokens[1]._timeout == timeout_for_equal_or_bigger_token - - +def test_zero_timeout_token_report_is_about_superpower(): + for report in TimeoutToken(0)._get_report(True), TimeoutToken(0)._get_report(False): + assert report.cause == CancelCause.SUPERPOWER + + @pytest.mark.parametrize( 'addictional_kwargs', [ @@ -1563,14 +282,22 @@ def test_less_or_equal_not_monotonic_timeout_token_plus_bigger_or_equal_not_mono {'monotonic': True}, ], ) -def test_bigger_temp_timeout_token_plus_less_temp_timeout_token_with_same_monotonic_flag_with_temp_counter_token_at_left(addictional_kwargs): - token = TimeoutToken(2, CounterToken(5), **addictional_kwargs) + TimeoutToken(1, **addictional_kwargs) +def test_bigger_timeout_token_plus_less_timeout_token_with_same_monotonic_flag(addictional_kwargs): + left = TimeoutToken(2, **addictional_kwargs) + right = TimeoutToken(1, **addictional_kwargs) + token = left + right - assert isinstance(token, TimeoutToken) - assert token._timeout == 1 - assert len(token._tokens) == 1 + assert isinstance(token, SimpleToken) + assert token + assert len(token._tokens) == 2 assert len(token._tokens[0]._tokens) == 0 - assert isinstance(token._tokens[0], CounterToken) + assert len(token._tokens[1]._tokens) == 0 + assert isinstance(token._tokens[0], TimeoutToken) + assert isinstance(token._tokens[1], TimeoutToken) + assert token._tokens[0]._timeout == 2 + assert token._tokens[1]._timeout == 1 + assert token._tokens[0] is left + assert token._tokens[1] is right @pytest.mark.parametrize( @@ -1582,17 +309,22 @@ def test_bigger_temp_timeout_token_plus_less_temp_timeout_token_with_same_monoto ({'monotonic': True}, {}), ], ) -def test_bigger_temp_timeout_token_plus_less_temp_timeout_token_with_not_same_monotonic_flag_with_temp_counter_token_at_left(left_addictional_kwargs, right_addictional_kwargs): - token = TimeoutToken(2, CounterToken(5), **left_addictional_kwargs) + TimeoutToken(1, **right_addictional_kwargs) +def test_bigger_timeout_token_plus_less_timeout_token_with_not_same_monotonic_flag(left_addictional_kwargs, right_addictional_kwargs): + left = TimeoutToken(2, **left_addictional_kwargs) + right = TimeoutToken(1, **right_addictional_kwargs) + token = left + right - assert isinstance(token, TimeoutToken) - assert token._timeout == 2 + assert isinstance(token, SimpleToken) + assert token assert len(token._tokens) == 2 assert len(token._tokens[0]._tokens) == 0 assert len(token._tokens[1]._tokens) == 0 - assert isinstance(token._tokens[0], CounterToken) + assert isinstance(token._tokens[0], TimeoutToken) assert isinstance(token._tokens[1], TimeoutToken) + assert token._tokens[0]._timeout == 2 assert token._tokens[1]._timeout == 1 + assert token._tokens[0] is left + assert token._tokens[1] is right @pytest.mark.parametrize( @@ -1610,15 +342,22 @@ def test_bigger_temp_timeout_token_plus_less_temp_timeout_token_with_not_same_mo {'monotonic': True}, ], ) -def test_less_or_equal_temp_not_monotonic_timeout_token_plus_bigger_or_equal_temp_not_monotonic_timeout_token_with_same_monotonic_flag_with_temp_counter_token_at_left(timeout_for_equal_or_bigger_token, addictional_kwargs): - token = TimeoutToken(1, CounterToken(5), **addictional_kwargs) + TimeoutToken(timeout_for_equal_or_bigger_token, **addictional_kwargs) +def test_less_or_equal_not_monotonic_timeout_token_plus_bigger_or_equal_not_monotonic_timeout_token_with_same_monotonic_flag(timeout_for_equal_or_bigger_token, addictional_kwargs): + left = TimeoutToken(1, **addictional_kwargs) + right = TimeoutToken(timeout_for_equal_or_bigger_token, **addictional_kwargs) + token = left + right - assert isinstance(token, TimeoutToken) - assert isinstance(token._tokens[0], CounterToken) - assert token._timeout == 1 - assert len(token._tokens) == 1 + assert isinstance(token, SimpleToken) + assert token + assert len(token._tokens) == 2 assert len(token._tokens[0]._tokens) == 0 - assert isinstance(token._tokens[0], CounterToken) + assert len(token._tokens[1]._tokens) == 0 + assert isinstance(token._tokens[0], TimeoutToken) + assert isinstance(token._tokens[1], TimeoutToken) + assert token._tokens[0]._timeout == 1 + assert token._tokens[1]._timeout == timeout_for_equal_or_bigger_token + assert token._tokens[0] is left + assert token._tokens[1] is right @pytest.mark.parametrize( @@ -1637,17 +376,22 @@ def test_less_or_equal_temp_not_monotonic_timeout_token_plus_bigger_or_equal_tem ({'monotonic': True}, {}), ], ) -def test_less_or_equal_temp_not_monotonic_timeout_token_plus_bigger_or_equal_temp_not_monotonic_timeout_token_with_not_same_monotonic_flag_with_temp_counter_token_at_left(timeout_for_equal_or_bigger_token, left_addictional_kwargs, right_addictional_kwargs): - token = TimeoutToken(1, CounterToken(5), **left_addictional_kwargs) + TimeoutToken(timeout_for_equal_or_bigger_token, **right_addictional_kwargs) +def test_less_or_equal_not_monotonic_timeout_token_plus_bigger_or_equal_not_monotonic_timeout_token_with_not_same_monotonic_flag(timeout_for_equal_or_bigger_token, left_addictional_kwargs, right_addictional_kwargs): + left = TimeoutToken(1, **left_addictional_kwargs) + right = TimeoutToken(timeout_for_equal_or_bigger_token, **right_addictional_kwargs) + token = left + right - assert isinstance(token, TimeoutToken) - assert token._timeout == 1 - assert token._tokens[1]._timeout == timeout_for_equal_or_bigger_token + assert isinstance(token, SimpleToken) + assert token assert len(token._tokens) == 2 assert len(token._tokens[0]._tokens) == 0 assert len(token._tokens[1]._tokens) == 0 - assert isinstance(token._tokens[0], CounterToken) + assert isinstance(token._tokens[0], TimeoutToken) assert isinstance(token._tokens[1], TimeoutToken) + assert token._tokens[0]._timeout == 1 + assert token._tokens[1]._timeout == timeout_for_equal_or_bigger_token + assert token._tokens[0] is left + assert token._tokens[1] is right @pytest.mark.parametrize( @@ -1658,20 +402,24 @@ def test_less_or_equal_temp_not_monotonic_timeout_token_plus_bigger_or_equal_tem {'monotonic': True}, ], ) -def test_bigger_timeout_token_plus_less_temp_timeout_token_with_same_monotonic_flag_with_temp_counter_token_at_left(addictional_kwargs): - left_timeout_token = TimeoutToken(2, CounterToken(5), **addictional_kwargs) - token = left_timeout_token + TimeoutToken(1, **addictional_kwargs) +def test_bigger_timeout_token_plus_less_timeout_token_with_same_monotonic_flag_with_nested_condition_token_at_right(addictional_kwargs): + left = TimeoutToken(2, **addictional_kwargs) + right = TimeoutToken(1, ConditionToken(lambda: False), **addictional_kwargs) + token = left + right - assert isinstance(token, TimeoutToken) + assert isinstance(token, SimpleToken) + assert token + assert len(token._tokens) == 2 + assert len(token._tokens[0]._tokens) == 0 + assert len(token._tokens[1]._tokens) == 1 + assert len(token._tokens[1]._tokens[0]._tokens) == 0 assert isinstance(token._tokens[0], TimeoutToken) - assert isinstance(token._tokens[0]._tokens[0], CounterToken) - assert token is not left_timeout_token - assert token._tokens[0] is left_timeout_token - assert token._timeout == 1 + assert isinstance(token._tokens[1], TimeoutToken) assert token._tokens[0]._timeout == 2 - assert len(token._tokens) == 1 - assert len(token._tokens[0]._tokens) == 1 - assert len(token._tokens[0]._tokens[0]._tokens) == 0 + assert token._tokens[1]._timeout == 1 + assert token._tokens[0] is left + assert token._tokens[1] is right + assert isinstance(token._tokens[1]._tokens[0], ConditionToken) @pytest.mark.parametrize( @@ -1683,22 +431,33 @@ def test_bigger_timeout_token_plus_less_temp_timeout_token_with_same_monotonic_f ({'monotonic': True}, {}), ], ) -def test_bigger_timeout_token_plus_less_temp_timeout_token_with_not_same_monotonic_flag_with_temp_counter_token_at_left(left_addictional_kwargs, right_addictional_kwargs): - left_timeout_token = TimeoutToken(2, CounterToken(5), **left_addictional_kwargs) - token = left_timeout_token + TimeoutToken(1, **right_addictional_kwargs) +def test_bigger_timeout_token_plus_less_timeout_token_with_not_same_monotonic_flag_with_nested_condition_token_at_right(left_addictional_kwargs, right_addictional_kwargs): + left = TimeoutToken(2, **left_addictional_kwargs) + right = TimeoutToken(1, ConditionToken(lambda: False), **right_addictional_kwargs) + token = left + right - assert isinstance(token, TimeoutToken) + assert isinstance(token, SimpleToken) + assert token + assert len(token._tokens) == 2 + assert len(token._tokens[0]._tokens) == 0 + assert len(token._tokens[1]._tokens) == 1 + assert len(token._tokens[1]._tokens[0]._tokens) == 0 assert isinstance(token._tokens[0], TimeoutToken) - assert isinstance(token._tokens[0]._tokens[0], CounterToken) - assert token is not left_timeout_token - assert token._tokens[0] is left_timeout_token - assert token._timeout == 1 + assert isinstance(token._tokens[1], TimeoutToken) assert token._tokens[0]._timeout == 2 - assert len(token._tokens) == 1 - assert len(token._tokens[0]._tokens) == 1 - assert len(token._tokens[0]._tokens[0]._tokens) == 0 + assert token._tokens[1]._timeout == 1 + assert token._tokens[0] is left + assert token._tokens[1] is right + assert isinstance(token._tokens[1]._tokens[0], ConditionToken) +@pytest.mark.parametrize( + 'timeout_for_equal_or_bigger_token', + [ + 1, + 2, + ], +) @pytest.mark.parametrize( 'addictional_kwargs', [ @@ -1707,18 +466,33 @@ def test_bigger_timeout_token_plus_less_temp_timeout_token_with_not_same_monoton {'monotonic': True}, ], ) -def test_less_not_monotonic_timeout_token_plus_bigger_temp_not_monotonic_timeout_token_with_same_monotonic_flag_with_temp_counter_token_at_left(addictional_kwargs): - left_timeout_token = TimeoutToken(1, CounterToken(5), **addictional_kwargs) - token = left_timeout_token + TimeoutToken(2, **addictional_kwargs) +def test_less_or_equal_not_monotonic_timeout_token_plus_bigger_or_equal_not_monotonic_timeout_token_with_same_monotonic_flag_with_nested_condition_token_at_right(timeout_for_equal_or_bigger_token, addictional_kwargs): + left = TimeoutToken(1, **addictional_kwargs) + right = TimeoutToken(timeout_for_equal_or_bigger_token, ConditionToken(lambda: False), **addictional_kwargs) + token = left + right - assert isinstance(token, TimeoutToken) - assert isinstance(token._tokens[0], CounterToken) - assert len(token._tokens) == 1 + assert isinstance(token, SimpleToken) + assert token + assert len(token._tokens) == 2 assert len(token._tokens[0]._tokens) == 0 - assert token is left_timeout_token - assert token._timeout == 1 + assert len(token._tokens[1]._tokens) == 1 + assert len(token._tokens[1]._tokens[0]._tokens) == 0 + assert isinstance(token._tokens[0], TimeoutToken) + assert isinstance(token._tokens[1], TimeoutToken) + assert token._tokens[0]._timeout == 1 + assert token._tokens[1]._timeout == timeout_for_equal_or_bigger_token + assert token._tokens[0] is left + assert token._tokens[1] is right + assert isinstance(token._tokens[1]._tokens[0], ConditionToken) +@pytest.mark.parametrize( + 'timeout_for_equal_or_bigger_token', + [ + 1, + 2, + ], +) @pytest.mark.parametrize( ('left_addictional_kwargs', 'right_addictional_kwargs'), [ @@ -1728,21 +502,24 @@ def test_less_not_monotonic_timeout_token_plus_bigger_temp_not_monotonic_timeout ({'monotonic': True}, {}), ], ) -def test_less_not_monotonic_timeout_token_plus_bigger_temp_not_monotonic_timeout_token_with_not_same_monotonic_flag_with_temp_counter_token_at_left(left_addictional_kwargs, right_addictional_kwargs): - left_timeout_token = TimeoutToken(1, CounterToken(5), **left_addictional_kwargs) - token = left_timeout_token + TimeoutToken(2, **right_addictional_kwargs) +def test_less_or_equal_not_monotonic_timeout_token_plus_bigger_or_equal_not_monotonic_timeout_token_with_not_same_monotonic_flag_with_nested_condition_token_at_right(timeout_for_equal_or_bigger_token, left_addictional_kwargs, right_addictional_kwargs): + left = TimeoutToken(1, **left_addictional_kwargs) + right = TimeoutToken(timeout_for_equal_or_bigger_token, ConditionToken(lambda: False), **right_addictional_kwargs) + token = left + right - assert isinstance(token, TimeoutToken) + assert isinstance(token, SimpleToken) + assert token + assert len(token._tokens) == 2 + assert len(token._tokens[0]._tokens) == 0 + assert len(token._tokens[1]._tokens) == 1 + assert len(token._tokens[1]._tokens[0]._tokens) == 0 assert isinstance(token._tokens[0], TimeoutToken) - assert isinstance(token._tokens[0]._tokens[0], CounterToken) - assert token._timeout == 2 + assert isinstance(token._tokens[1], TimeoutToken) assert token._tokens[0]._timeout == 1 - assert token._tokens[0] is left_timeout_token - assert token is not left_timeout_token - assert token._timeout == 2 - assert len(token._tokens) == 1 - assert len(token._tokens[0]._tokens) == 1 - assert len(token._tokens[0]._tokens[0]._tokens) == 0 + assert token._tokens[1]._timeout == timeout_for_equal_or_bigger_token + assert token._tokens[0] is left + assert token._tokens[1] is right + assert isinstance(token._tokens[1]._tokens[0], ConditionToken) @pytest.mark.parametrize( @@ -1753,18 +530,26 @@ def test_less_not_monotonic_timeout_token_plus_bigger_temp_not_monotonic_timeout {'monotonic': True}, ], ) -def test_bigger_temp_timeout_token_plus_less_timeout_token_with_same_monotonic_flag_with_temp_counter_token_at_left(addictional_kwargs): - right_timeout_token = TimeoutToken(1, **addictional_kwargs) - token = TimeoutToken(2, CounterToken(5), **addictional_kwargs) + right_timeout_token +def test_bigger_timeout_token_plus_less_timeout_token_with_same_monotonic_flag_with_nested_condition_token_at_right_and_counter_token_at_left(addictional_kwargs): + left = TimeoutToken(2, CounterToken(5), **addictional_kwargs) + right = TimeoutToken(1, ConditionToken(lambda: False), **addictional_kwargs) + token = left + right assert isinstance(token, SimpleToken) - assert isinstance(token._tokens[0], CounterToken) + assert isinstance(token._tokens[0], TimeoutToken) assert isinstance(token._tokens[1], TimeoutToken) - assert token._tokens[1]._timeout == 1 + assert isinstance(token._tokens[0]._tokens[0], CounterToken) + assert isinstance(token._tokens[1]._tokens[0], ConditionToken) + assert token assert len(token._tokens) == 2 - assert len(token._tokens[0]._tokens) == 0 - assert len(token._tokens[1]._tokens) == 0 - assert token._tokens[1] is right_timeout_token + assert len(token._tokens[0]._tokens) == 1 + assert len(token._tokens[1]._tokens) == 1 + assert len(token._tokens[1]._tokens[0]._tokens) == 0 + assert len(token._tokens[0]._tokens[0]._tokens) == 0 + assert token._tokens[0] is left + assert token._tokens[1] is right + assert token._tokens[0]._timeout == 2 + assert token._tokens[1]._timeout == 1 @pytest.mark.parametrize( @@ -1776,22 +561,35 @@ def test_bigger_temp_timeout_token_plus_less_timeout_token_with_same_monotonic_f ({'monotonic': True}, {}), ], ) -def test_bigger_temp_timeout_token_plus_less_timeout_token_with_not_same_monotonic_flag_with_temp_counter_token_at_left(left_addictional_kwargs, right_addictional_kwargs): - right_timeout_token = TimeoutToken(1, **right_addictional_kwargs) - token = TimeoutToken(2, CounterToken(5), **left_addictional_kwargs) + right_timeout_token +def test_bigger_timeout_token_plus_less_timeout_token_with_not_same_monotonic_flag_with_nested_condition_token_at_right_and_counter_token_at_left(left_addictional_kwargs, right_addictional_kwargs): + left = TimeoutToken(2, CounterToken(5), **left_addictional_kwargs) + right = TimeoutToken(1, ConditionToken(lambda: False), **right_addictional_kwargs) + token = left + right - assert isinstance(token, TimeoutToken) - assert isinstance(token._tokens[0], CounterToken) + assert isinstance(token, SimpleToken) + assert isinstance(token._tokens[0], TimeoutToken) assert isinstance(token._tokens[1], TimeoutToken) - assert token._tokens[1]._timeout == 1 - assert token._timeout == 2 + assert isinstance(token._tokens[0]._tokens[0], CounterToken) + assert isinstance(token._tokens[1]._tokens[0], ConditionToken) + assert token assert len(token._tokens) == 2 - assert len(token._tokens[0]._tokens) == 0 - assert len(token._tokens[1]._tokens) == 0 - assert token._tokens[1] is right_timeout_token - assert token is not right_timeout_token + assert len(token._tokens[0]._tokens) == 1 + assert len(token._tokens[1]._tokens) == 1 + assert len(token._tokens[1]._tokens[0]._tokens) == 0 + assert len(token._tokens[0]._tokens[0]._tokens) == 0 + assert token._tokens[0] is left + assert token._tokens[1] is right + assert token._tokens[0]._timeout == 2 + assert token._tokens[1]._timeout == 1 +@pytest.mark.parametrize( + 'timeout_for_equal_or_bigger_token', + [ + 1, + 2, + ], +) @pytest.mark.parametrize( 'addictional_kwargs', [ @@ -1800,21 +598,35 @@ def test_bigger_temp_timeout_token_plus_less_timeout_token_with_not_same_monoton {'monotonic': True}, ], ) -def test_less_temp_not_monotonic_timeout_token_plus_bigger_not_monotonic_timeout_token_with_same_monotonic_flag_with_temp_counter_token_at_left(addictional_kwargs): - right_timeout_token = TimeoutToken(2, **addictional_kwargs) - token = TimeoutToken(1, CounterToken(5), **addictional_kwargs) + right_timeout_token +def test_less_or_equal_not_monotonic_timeout_token_plus_bigger_or_equal_not_monotonic_timeout_token_with_same_monotonic_flag_with_nested_condition_token_at_right_and_counter_token_at_left(timeout_for_equal_or_bigger_token, addictional_kwargs): + left = TimeoutToken(1, CounterToken(5), **addictional_kwargs) + right = TimeoutToken(timeout_for_equal_or_bigger_token, ConditionToken(lambda: False), **addictional_kwargs) + token = left + right - assert isinstance(token, TimeoutToken) - assert token._timeout == 1 - assert len(token._tokens) == 2 - assert len(token._tokens[0]._tokens) == 0 - assert len(token._tokens[1]._tokens) == 0 - assert token._tokens[1]._timeout == 2 - assert token._tokens[1] is right_timeout_token - assert isinstance(token._tokens[0], CounterToken) + assert isinstance(token, SimpleToken) + assert isinstance(token._tokens[0], TimeoutToken) assert isinstance(token._tokens[1], TimeoutToken) + assert isinstance(token._tokens[0]._tokens[0], CounterToken) + assert isinstance(token._tokens[1]._tokens[0], ConditionToken) + assert token + assert len(token._tokens) == 2 + assert len(token._tokens[0]._tokens) == 1 + assert len(token._tokens[1]._tokens) == 1 + assert len(token._tokens[1]._tokens[0]._tokens) == 0 + assert len(token._tokens[0]._tokens[0]._tokens) == 0 + assert token._tokens[0] is left + assert token._tokens[1] is right + assert token._tokens[0]._timeout == 1 + assert token._tokens[1]._timeout == timeout_for_equal_or_bigger_token +@pytest.mark.parametrize( + 'timeout_for_equal_or_bigger_token', + [ + 1, + 2, + ], +) @pytest.mark.parametrize( ('left_addictional_kwargs', 'right_addictional_kwargs'), [ @@ -1824,20 +636,26 @@ def test_less_temp_not_monotonic_timeout_token_plus_bigger_not_monotonic_timeout ({'monotonic': True}, {}), ], ) -def test_less_temp_not_monotonic_timeout_token_plus_bigger_not_monotonic_timeout_token_with_not_same_monotonic_flag_with_temp_counter_token_at_left(left_addictional_kwargs, right_addictional_kwargs): - right_timeout_token = TimeoutToken(2, **right_addictional_kwargs) - token = TimeoutToken(1, CounterToken(5), **left_addictional_kwargs) + right_timeout_token +def test_less_or_equal_not_monotonic_timeout_token_plus_bigger_or_equal_not_monotonic_timeout_token_with_not_same_monotonic_flag_with_nested_condition_token_at_right_and_counter_token_at_left(timeout_for_equal_or_bigger_token, left_addictional_kwargs, right_addictional_kwargs): + left = TimeoutToken(1, CounterToken(5), **left_addictional_kwargs) + right = TimeoutToken(timeout_for_equal_or_bigger_token, ConditionToken(lambda: False), **right_addictional_kwargs) + token = left + right - assert isinstance(token, TimeoutToken) - assert isinstance(token._tokens[0], CounterToken) + assert isinstance(token, SimpleToken) + assert isinstance(token._tokens[0], TimeoutToken) assert isinstance(token._tokens[1], TimeoutToken) - assert token._timeout == 1 - assert token._tokens[1]._timeout == 2 + assert isinstance(token._tokens[0]._tokens[0], CounterToken) + assert isinstance(token._tokens[1]._tokens[0], ConditionToken) + assert token assert len(token._tokens) == 2 - assert len(token._tokens[0]._tokens) == 0 - assert len(token._tokens[1]._tokens) == 0 - assert token._tokens[1] is right_timeout_token - assert token is not right_timeout_token + assert len(token._tokens[0]._tokens) == 1 + assert len(token._tokens[1]._tokens) == 1 + assert len(token._tokens[1]._tokens[0]._tokens) == 0 + assert len(token._tokens[0]._tokens[0]._tokens) == 0 + assert token._tokens[0] is left + assert token._tokens[1] is right + assert token._tokens[0]._timeout == 1 + assert token._tokens[1]._timeout == timeout_for_equal_or_bigger_token @pytest.mark.parametrize( @@ -1848,7 +666,7 @@ def test_less_temp_not_monotonic_timeout_token_plus_bigger_not_monotonic_timeout {'monotonic': True}, ], ) -def test_bigger_timeout_token_plus_less_timeout_token_with_same_monotonic_flag_with_temp_counter_token_at_left(addictional_kwargs): +def test_bigger_timeout_token_plus_less_timeout_token_with_same_monotonic_flag_with_nested_counter_token_at_left(addictional_kwargs): left = TimeoutToken(2, CounterToken(5), **addictional_kwargs) right = TimeoutToken(1, **addictional_kwargs) token = left + right @@ -1877,7 +695,7 @@ def test_bigger_timeout_token_plus_less_timeout_token_with_same_monotonic_flag_w ({'monotonic': True}, {}), ], ) -def test_bigger_timeout_token_plus_less_timeout_token_with_not_same_monotonic_flag_with_temp_counter_token_at_left(left_addictional_kwargs, right_addictional_kwargs): +def test_bigger_timeout_token_plus_less_timeout_token_with_not_same_monotonic_flag_with_nested_counter_token_at_left(left_addictional_kwargs, right_addictional_kwargs): left = TimeoutToken(2, CounterToken(5), **left_addictional_kwargs) right = TimeoutToken(1, **right_addictional_kwargs) token = left + right @@ -1912,7 +730,7 @@ def test_bigger_timeout_token_plus_less_timeout_token_with_not_same_monotonic_fl {'monotonic': True}, ], ) -def test_less_or_equal_not_monotonic_timeout_token_plus_bigger_or_equal_not_monotonic_timeout_token_with_same_monotonic_flag_with_temp_counter_token_at_left(timeout_for_equal_or_bigger_token, addictional_kwargs): +def test_less_or_equal_not_monotonic_timeout_token_plus_bigger_or_equal_not_monotonic_timeout_token_with_same_monotonic_flag_with_nested_counter_token_at_left(timeout_for_equal_or_bigger_token, addictional_kwargs): left = TimeoutToken(1, CounterToken(5), **addictional_kwargs) right = TimeoutToken(timeout_for_equal_or_bigger_token, **addictional_kwargs) token = left + right @@ -1948,7 +766,7 @@ def test_less_or_equal_not_monotonic_timeout_token_plus_bigger_or_equal_not_mono ({'monotonic': True}, {}), ], ) -def test_less_or_equal_not_monotonic_timeout_token_plus_bigger_or_equal_not_monotonic_timeout_token_with_not_same_monotonic_flag_with_temp_counter_token_at_left(timeout_for_equal_or_bigger_token, left_addictional_kwargs, right_addictional_kwargs): +def test_less_or_equal_not_monotonic_timeout_token_plus_bigger_or_equal_not_monotonic_timeout_token_with_not_same_monotonic_flag_with_nested_counter_token_at_left(timeout_for_equal_or_bigger_token, left_addictional_kwargs, right_addictional_kwargs): left = TimeoutToken(1, CounterToken(5), **left_addictional_kwargs) right = TimeoutToken(timeout_for_equal_or_bigger_token, **right_addictional_kwargs) token = left + right @@ -1966,75 +784,3 @@ def test_less_or_equal_not_monotonic_timeout_token_plus_bigger_or_equal_not_mono assert token._tokens[1] is right assert token._tokens[0]._timeout == 1 assert token._tokens[1]._timeout == timeout_for_equal_or_bigger_token - - -def test_temp_negative_timeout_token_plus_temp_timeout_token(): - token = TimeoutToken(1, cancelled=True) + TimeoutToken(1) - - assert isinstance(token, SimpleToken) - assert not token - assert not token._tokens - - -def test_temp_timeout_token_plus_temp_negative_timeout_token(): - token = TimeoutToken(1) + TimeoutToken(1, cancelled=True) - - assert isinstance(token, SimpleToken) - assert not token - assert not token._tokens - - -def test_not_temp_negative_timeout_token_plus_temp_timeout_token(): - first = TimeoutToken(1, cancelled=True) - token = first + TimeoutToken(1) - - assert isinstance(token, SimpleToken) - assert not token - assert not token._tokens - - -def test_not_temp_timeout_token_plus_temp_negative_timeout_token(): - first = TimeoutToken(1) - token = first + TimeoutToken(1, cancelled=True) - - assert isinstance(token, SimpleToken) - assert not token - assert not token._tokens - - -def test_not_temp_negative_timeout_token_plus_timeout_token(): - first = TimeoutToken(1, cancelled=True) - second = TimeoutToken(1) - token = first + second - - assert isinstance(token, SimpleToken) - assert not token - assert not token._tokens - - -def test_not_temp_timeout_token_plus_negative_timeout_token(): - first = TimeoutToken(1) - second = TimeoutToken(1, cancelled=True) - token = first + second - - assert isinstance(token, SimpleToken) - assert not token - assert not token._tokens - - -def test_temp_negative_timeout_token_plus_timeout_token(): - second = TimeoutToken(1) - token = TimeoutToken(1, cancelled=True) + second - - assert isinstance(token, SimpleToken) - assert not token - assert not token._tokens - - -def test_temp_timeout_token_plus_negative_timeout_token(): - second = TimeoutToken(1, cancelled=True) - token = TimeoutToken(1) + second - - assert isinstance(token, SimpleToken) - assert not token - assert not token._tokens From 987fb06a38ea98c5ace62bcb11f2a94ea7e45d97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D0=B2=D0=B3=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=91=D0=BB?= =?UTF-8?q?=D0=B8=D0=BD=D0=BE=D0=B2?= Date: Tue, 23 Jun 2026 11:43:25 +0300 Subject: [PATCH 9/9] Simplify token composition logic in AbstractToken --- cantok/tokens/abstract/abstract_token.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cantok/tokens/abstract/abstract_token.py b/cantok/tokens/abstract/abstract_token.py index 6fed09a..411d8aa 100644 --- a/cantok/tokens/abstract/abstract_token.py +++ b/cantok/tokens/abstract/abstract_token.py @@ -88,11 +88,9 @@ def __add__(self, item: 'AbstractToken') -> 'AbstractToken': 'Cancellation Token can only be combined with another Cancellation Token.', ) - from cantok import DefaultToken, SimpleToken # noqa: PLC0415 + from cantok import SimpleToken # noqa: PLC0415 - return SimpleToken( - *[token for token in (self, item) if not isinstance(token, DefaultToken)], - ) + return SimpleToken(self, item) def __bool__(self) -> bool: return self.keep_on()