Skip to content

Commit fb77c00

Browse files
authored
fix: Test matrix python version not being cached properly (#346)
* fix: Test matrix python version not being cached properly and resulting errors
1 parent 7663a5a commit fb77c00

4 files changed

Lines changed: 40 additions & 32 deletions

File tree

.github/workflows/python-package.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
uses: actions/cache@v3
3838
with:
3939
path: .venv
40-
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
40+
key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }}
4141
- name: Install dependencies
4242
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
4343
run: poetry install --no-interaction --no-root

tests/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
import sys
12
from datetime import datetime
23

34
import pytest
45

6+
# We support Python 3.8+ positional only syntax
7+
if sys.version_info[:2] < (3, 8):
8+
collect_ignore_glob = ["*_positional_only.py"]
9+
510

611
@pytest.fixture()
712
def current_time():

tests/test_signature.py

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import inspect
2-
import sys
32

43
import pytest
54

@@ -155,33 +154,3 @@ def test_wrap_fn_single_positional_parameter(self, func, args, kwargs, expected)
155154
wrapped_func(*args, **kwargs)
156155
else:
157156
assert wrapped_func(*args, **kwargs) == expected
158-
159-
@pytest.mark.parametrize(
160-
("args", "kwargs", "expected"),
161-
[
162-
([], {}, TypeError),
163-
([1, 2, 3], {}, TypeError),
164-
([1, 2], {"kw_only_param": 42}, (1, 2, 42)),
165-
([1], {"pos_or_kw_param": 21, "kw_only_param": 42}, (1, 21, 42)),
166-
(
167-
[],
168-
{"pos_only": 10, "pos_or_kw_param": 21, "kw_only_param": 42},
169-
TypeError,
170-
),
171-
],
172-
)
173-
@pytest.mark.skipif(
174-
sys.version_info < (3, 8), reason="requires python3.8 or higher"
175-
)
176-
def test_positional_ony(self, args, kwargs, expected):
177-
def func(pos_only, /, pos_or_kw_param, *, kw_only_param):
178-
# https://peps.python.org/pep-0570/
179-
return pos_only, pos_or_kw_param, kw_only_param
180-
181-
wrapped_func = SignatureAdapter.wrap(func)
182-
183-
if inspect.isclass(expected) and issubclass(expected, Exception):
184-
with pytest.raises(expected):
185-
wrapped_func(*args, **kwargs)
186-
else:
187-
assert wrapped_func(*args, **kwargs) == expected
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import inspect
2+
3+
import pytest
4+
5+
from statemachine.signature import SignatureAdapter
6+
7+
8+
class TestSignatureAdapter:
9+
@pytest.mark.parametrize(
10+
("args", "kwargs", "expected"),
11+
[
12+
([], {}, TypeError),
13+
([1, 2, 3], {}, TypeError),
14+
([1, 2], {"kw_only_param": 42}, (1, 2, 42)),
15+
([1], {"pos_or_kw_param": 21, "kw_only_param": 42}, (1, 21, 42)),
16+
(
17+
[],
18+
{"pos_only": 10, "pos_or_kw_param": 21, "kw_only_param": 42},
19+
TypeError,
20+
),
21+
],
22+
)
23+
def test_positional_ony(self, args, kwargs, expected):
24+
def func(pos_only, /, pos_or_kw_param, *, kw_only_param):
25+
# https://peps.python.org/pep-0570/
26+
return pos_only, pos_or_kw_param, kw_only_param
27+
28+
wrapped_func = SignatureAdapter.wrap(func)
29+
30+
if inspect.isclass(expected) and issubclass(expected, Exception):
31+
with pytest.raises(expected):
32+
wrapped_func(*args, **kwargs)
33+
else:
34+
assert wrapped_func(*args, **kwargs) == expected

0 commit comments

Comments
 (0)