Skip to content

Commit

Permalink
Merge pull request #20 from pomponchik/develop
Browse files Browse the repository at this point in the history
0.0.15
  • Loading branch information
pomponchik authored Jan 17, 2024
2 parents 9603345 + c2fbd21 commit ac261d7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ test.py
.ruff_cache
venv2
.DS_Store
.ipynb_checkpoints
.coverage
2 changes: 1 addition & 1 deletion docs/docs/types_of_tokens/ConditionToken.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ConditionToken has superpower, it can check arbitrary conditions. In addition to this, it can do all the same things as [`SimpleToken`](/types_of_tokens/SimpleToken/). The condition must be passed to the token constructor as the first argument. The condition is a function that should return an answer (`True`/`False`) to the question "has the token been canceled?", it must be passed to the token constructor with the first argument:
`ConditionToken has superpower`: it can check arbitrary conditions. In addition to this, it can do all the same things as [`SimpleToken`](/types_of_tokens/SimpleToken/). The condition is a function that returns an answer to the question "has the token been canceled" (`True`/`False`), it is passed to the token as the first required argument during initialization:

```python
from cantok import ConditionToken
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "cantok"
version = "0.0.14"
version = "0.0.15"
authors = [
{ name="Evgeniy Blinov", email="zheni-b@yandex.ru" },
]
Expand Down
17 changes: 13 additions & 4 deletions tests/units/tokens/test_condition_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,18 @@ async def runner():
assert finish_time - start_time >= timeout


def test_order_of_callbacks():

@pytest.mark.parametrize(
'options',
[
{},
{'suppress_exceptions': True},
{'suppress_exceptions': False},
],
)
def test_order_of_callbacks(options):
lst = []
token = ConditionToken(lambda: lst.append(2) is not None, before=lambda: lst.append(1), after=lambda: lst.append(3))
token = ConditionToken(lambda: lst.append(2) is not None, before=lambda: lst.append(1), after=lambda: lst.append(3), **options)

token.check()

Expand All @@ -234,7 +243,7 @@ def test_order_of_callbacks():
'options',
[
{},
{'suppress_exceptions': True}
{'suppress_exceptions': True},
],
)
def test_raise_suppressed_exception_in_before_callback(options):
Expand All @@ -255,7 +264,7 @@ def before_callback():
'options',
[
{},
{'suppress_exceptions': True}
{'suppress_exceptions': True},
],
)
def test_raise_suppressed_exception_in_after_callback(options):
Expand Down

0 comments on commit ac261d7

Please sign in to comment.