Skip to content

Commit

Permalink
Merge pull request #36 from pomponchik/develop
Browse files Browse the repository at this point in the history
0.0.25
  • Loading branch information
pomponchik authored Jul 24, 2024
2 parents 5c01a6a + ede3b15 commit f2f2c15
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests_and_coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
run: pip list

- name: Run tests and show coverage on the command line
run: coverage run --source=cantok --omit="*tests*" -m pytest --cache-clear --assert=plain && coverage report -m
run: coverage run --source=cantok --omit="*tests*" -m pytest --cache-clear --assert=plain && coverage report -m --fail-under=100

- name: Upload reports to codecov
env:
Expand All @@ -45,4 +45,4 @@ jobs:
./codecov -t ${CODECOV_TOKEN}
- name: Run tests and show the branch coverage on the command line
run: coverage run --branch --source=cantok --omit="*tests*" -m pytest --cache-clear --assert=plain && coverage report -m
run: coverage run --branch --source=cantok --omit="*tests*" -m pytest --cache-clear --assert=plain && coverage report -m --fail-under=100
4 changes: 2 additions & 2 deletions .github/workflows/tests_and_coverage_old.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
run: pip list

- name: Run tests and show coverage on the command line
run: coverage run --source=cantok --omit="*tests*" -m pytest --cache-clear --assert=plain && coverage report -m
run: coverage run --source=cantok --omit="*tests*" -m pytest --cache-clear --assert=plain && coverage report -m --fail-under=100

- name: Upload reports to codecov
env:
Expand All @@ -45,4 +45,4 @@ jobs:
./codecov -t ${CODECOV_TOKEN}
- name: Run tests and show the branch coverage on the command line
run: coverage run --branch --source=cantok --omit="*tests*" -m pytest --cache-clear --assert=plain && coverage report -m
run: coverage run --branch --source=cantok --omit="*tests*" -m pytest --cache-clear --assert=plain && coverage report -m --fail-under=100
4 changes: 3 additions & 1 deletion cantok/tokens/abstract_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ class AbstractToken(ABC):
rollback_if_nondirect_polling = False

def __init__(self, *tokens: 'AbstractToken', cancelled: bool = False) -> None:
self.tokens = tokens
from cantok import DefaultToken

self.tokens = [token for token in tokens if not isinstance(token, DefaultToken)]
self._cancelled = cancelled
self.lock = RLock()

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.24"
version = "0.0.25"
authors = [
{ name="Evgeniy Blinov", email="zheni-b@yandex.ru" },
]
Expand Down
45 changes: 43 additions & 2 deletions tests/units/tokens/test_abstract_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ def test_str(token_fabric):

@pytest.mark.parametrize(
'first_token_fabric',
ALL_TOKENS_FABRICS + [DefaultToken],
ALL_TOKENS_FABRICS,
)
@pytest.mark.parametrize(
'second_token_fabric',
ALL_TOKENS_FABRICS + [DefaultToken],
ALL_TOKENS_FABRICS,
)
def test_add_tokens(first_token_fabric, second_token_fabric):
first_token = first_token_fabric()
Expand All @@ -138,6 +138,36 @@ def test_add_tokens(first_token_fabric, second_token_fabric):
assert tokens_sum.tokens[1] is second_token


@pytest.mark.parametrize(
'second_token_fabric',
ALL_TOKENS_FABRICS,
)
def test_add_tokens_and_first_is_default_token(second_token_fabric):
first_token = DefaultToken()
second_token = second_token_fabric()

tokens_sum = first_token + second_token

assert isinstance(tokens_sum, SimpleToken)
assert len(tokens_sum.tokens) == 1
assert tokens_sum.tokens[0] is second_token


@pytest.mark.parametrize(
'first_token_fabric',
ALL_TOKENS_FABRICS,
)
def test_add_tokens_and_second_one_is_default_token(first_token_fabric):
first_token = first_token_fabric()
second_token = DefaultToken()

tokens_sum = first_token + second_token

assert isinstance(tokens_sum, SimpleToken)
assert len(tokens_sum.tokens) == 1
assert tokens_sum.tokens[0] is first_token


@pytest.mark.parametrize(
'token_fabric',
ALL_TOKENS_FABRICS + [DefaultToken],
Expand Down Expand Up @@ -405,3 +435,14 @@ def cancel_with_timeout(token):
finish_time = perf_counter()

assert finish_time - start_time >= timeout


@pytest.mark.parametrize(
'token_fabric',
ALL_TOKENS_FABRICS,
)
def test_insert_default_token_to_another_tokens(token_fabric):
token = token_fabric(DefaultToken())

assert not isinstance(token, DefaultToken)
assert len(token.tokens) == 0
11 changes: 9 additions & 2 deletions tests/units/tokens/test_default_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,17 @@ def test_str_for_default_token():
@pytest.mark.skipif(sys.version_info >= (3, 10), reason='Format of this exception messages was changed.')
def test_you_cannot_neste_another_token_to_default_one_old_pythons():
with pytest.raises(TypeError, match=full_match('__init__() takes 1 positional argument but 2 were given')):
DefaultToken(SimpleToken(TypeError))
DefaultToken(SimpleToken())


@pytest.mark.skipif(sys.version_info < (3, 10), reason='Format of this exception messages was changed.')
def test_you_cannot_neste_another_token_to_default_one_new_pythons():
with pytest.raises(TypeError, match=full_match('DefaultToken.__init__() takes 1 positional argument but 2 were given')):
DefaultToken(SimpleToken(TypeError))
DefaultToken(SimpleToken())


def test_default_plus_default():
empty_sum = DefaultToken() + DefaultToken()

assert isinstance(empty_sum, SimpleToken)
assert len(empty_sum.tokens) == 0

0 comments on commit f2f2c15

Please sign in to comment.