Skip to content

Commit

Permalink
linted
Browse files Browse the repository at this point in the history
  • Loading branch information
BalzaniEdoardo committed Oct 23, 2024
1 parent 9c04c91 commit ee8291b
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 33 deletions.
5 changes: 3 additions & 2 deletions src/nemos/basis.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ class Basis(Base, abc.ABC):
**kwargs :
Only used in "conv" mode. Additional keyword arguments that are passed to
`nemos.convolve.create_convolutional_predictor`
Raises
------
ValueError:
Expand Down Expand Up @@ -521,7 +521,8 @@ def __init__(
)
convolve_params = inspect.signature(create_convolutional_predictor).parameters
convolve_configs = {
key for key, param in convolve_params.items()
key
for key, param in convolve_params.items()
if param.default is not inspect.Parameter.empty
}
if not set(kwargs.keys()).issubset(convolve_configs):
Expand Down
127 changes: 96 additions & 31 deletions tests/test_basis.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,13 +500,22 @@ def test_init_mode(self, mode, expectation):
[
(dict(), does_not_raise()),
(dict(axis=0), does_not_raise()),
(dict(axis=1), pytest.raises(ValueError, match="Invalid `axis=1` provided")),
(
dict(axis=1),
pytest.raises(ValueError, match="Invalid `axis=1` provided"),
),
(dict(shift=True), does_not_raise()),
(dict(shift=True, axis=0), does_not_raise()),
(dict(shifts=True, axis=0), pytest.raises(ValueError, match="Unrecognized keyword arguments")),
(
dict(shifts=True, axis=0),
pytest.raises(ValueError, match="Unrecognized keyword arguments"),
),
(dict(shift=True, axis=0, predictor_causality="causal"), does_not_raise()),
(dict(shift=True, axis=0, time_series=np.arange(10)), pytest.raises(ValueError, match="Unrecognized keyword arguments")),
]
(
dict(shift=True, axis=0, time_series=np.arange(10)),
pytest.raises(ValueError, match="Unrecognized keyword arguments"),
),
],
)
def test_init_conv_kwargs(self, conv_kwargs, expectation):
with expectation:
Expand Down Expand Up @@ -584,7 +593,10 @@ def test_set_params(

for i in range(len(pars)):
for j in range(i + 1, len(pars)):
with pytest.raises(AttributeError, match="can't set attribute 'mode'|property 'mode' of "):
with pytest.raises(
AttributeError,
match="can't set attribute 'mode'|property 'mode' of ",
):
par_set = {
keys[i]: pars[keys[i]],
keys[j]: pars[keys[j]],
Expand Down Expand Up @@ -1166,14 +1178,22 @@ def test_init_mode(self, mode, expectation):
[
(dict(), does_not_raise()),
(dict(axis=0), does_not_raise()),
(dict(axis=1), pytest.raises(ValueError, match="Invalid `axis=1` provided")),
(
dict(axis=1),
pytest.raises(ValueError, match="Invalid `axis=1` provided"),
),
(dict(shift=True), does_not_raise()),
(dict(shift=True, axis=0), does_not_raise()),
(dict(shifts=True, axis=0), pytest.raises(ValueError, match="Unrecognized keyword arguments")),
(
dict(shifts=True, axis=0),
pytest.raises(ValueError, match="Unrecognized keyword arguments"),
),
(dict(shift=True, axis=0, predictor_causality="causal"), does_not_raise()),
(dict(shift=True, axis=0, time_series=np.arange(10)),
pytest.raises(ValueError, match="Unrecognized keyword arguments")),
]
(
dict(shift=True, axis=0, time_series=np.arange(10)),
pytest.raises(ValueError, match="Unrecognized keyword arguments"),
),
],
)
def test_init_conv_kwargs(self, conv_kwargs, expectation):
with expectation:
Expand Down Expand Up @@ -1237,7 +1257,10 @@ def test_set_params(

for i in range(len(pars)):
for j in range(i + 1, len(pars)):
with pytest.raises(AttributeError, match="can't set attribute 'mode'|property 'mode' of "):
with pytest.raises(
AttributeError,
match="can't set attribute 'mode'|property 'mode' of ",
):
par_set = {
keys[i]: pars[keys[i]],
keys[j]: pars[keys[j]],
Expand Down Expand Up @@ -1818,14 +1841,22 @@ def test_init_mode(self, mode, expectation):
[
(dict(), does_not_raise()),
(dict(axis=0), does_not_raise()),
(dict(axis=1), pytest.raises(ValueError, match="Invalid `axis=1` provided")),
(
dict(axis=1),
pytest.raises(ValueError, match="Invalid `axis=1` provided"),
),
(dict(shift=True), does_not_raise()),
(dict(shift=True, axis=0), does_not_raise()),
(dict(shifts=True, axis=0), pytest.raises(ValueError, match="Unrecognized keyword arguments")),
(
dict(shifts=True, axis=0),
pytest.raises(ValueError, match="Unrecognized keyword arguments"),
),
(dict(shift=True, axis=0, predictor_causality="causal"), does_not_raise()),
(dict(shift=True, axis=0, time_series=np.arange(10)),
pytest.raises(ValueError, match="Unrecognized keyword arguments")),
]
(
dict(shift=True, axis=0, time_series=np.arange(10)),
pytest.raises(ValueError, match="Unrecognized keyword arguments"),
),
],
)
def test_init_conv_kwargs(self, conv_kwargs, expectation):
with expectation:
Expand Down Expand Up @@ -1889,7 +1920,10 @@ def test_set_params(

for i in range(len(pars)):
for j in range(i + 1, len(pars)):
with pytest.raises(AttributeError, match="can't set attribute 'mode'|property 'mode' of "):
with pytest.raises(
AttributeError,
match="can't set attribute 'mode'|property 'mode' of ",
):
par_set = {
keys[i]: pars[keys[i]],
keys[j]: pars[keys[j]],
Expand Down Expand Up @@ -2548,18 +2582,32 @@ def test_init_mode(self, mode, expectation):
[
(dict(), does_not_raise()),
(dict(axis=0), does_not_raise()),
(dict(axis=1), pytest.raises(ValueError, match="Invalid `axis=1` provided")),
(
dict(axis=1),
pytest.raises(ValueError, match="Invalid `axis=1` provided"),
),
(dict(shift=True), does_not_raise()),
(dict(shift=True, axis=0), does_not_raise()),
(dict(shifts=True, axis=0), pytest.raises(ValueError, match="Unrecognized keyword arguments")),
(
dict(shifts=True, axis=0),
pytest.raises(ValueError, match="Unrecognized keyword arguments"),
),
(dict(shift=True, axis=0, predictor_causality="causal"), does_not_raise()),
(dict(shift=True, axis=0, time_series=np.arange(10)),
pytest.raises(ValueError, match="Unrecognized keyword arguments")),
]
(
dict(shift=True, axis=0, time_series=np.arange(10)),
pytest.raises(ValueError, match="Unrecognized keyword arguments"),
),
],
)
def test_init_conv_kwargs(self, conv_kwargs, expectation):
with expectation:
self.cls(5, mode="conv", window_size=200, decay_rates=np.arange(1, 6), **conv_kwargs)
self.cls(
5,
mode="conv",
window_size=200,
decay_rates=np.arange(1, 6),
**conv_kwargs,
)

@pytest.mark.parametrize(
"mode, ws, expectation",
Expand Down Expand Up @@ -2628,7 +2676,10 @@ def test_set_params(

for i in range(len(pars)):
for j in range(i + 1, len(pars)):
with pytest.raises(AttributeError, match="can't set attribute 'mode'|property 'mode' of "):
with pytest.raises(
AttributeError,
match="can't set attribute 'mode'|property 'mode' of ",
):
par_set = {
keys[i]: pars[keys[i]],
keys[j]: pars[keys[j]],
Expand Down Expand Up @@ -3154,14 +3205,22 @@ def test_init_mode(self, mode, expectation):
[
(dict(), does_not_raise()),
(dict(axis=0), does_not_raise()),
(dict(axis=1), pytest.raises(ValueError, match="Invalid `axis=1` provided")),
(
dict(axis=1),
pytest.raises(ValueError, match="Invalid `axis=1` provided"),
),
(dict(shift=True), does_not_raise()),
(dict(shift=True, axis=0), does_not_raise()),
(dict(shifts=True, axis=0), pytest.raises(ValueError, match="Unrecognized keyword arguments")),
(
dict(shifts=True, axis=0),
pytest.raises(ValueError, match="Unrecognized keyword arguments"),
),
(dict(shift=True, axis=0, predictor_causality="causal"), does_not_raise()),
(dict(shift=True, axis=0, time_series=np.arange(10)),
pytest.raises(ValueError, match="Unrecognized keyword arguments")),
]
(
dict(shift=True, axis=0, time_series=np.arange(10)),
pytest.raises(ValueError, match="Unrecognized keyword arguments"),
),
],
)
def test_init_conv_kwargs(self, conv_kwargs, expectation):
with expectation:
Expand Down Expand Up @@ -3225,7 +3284,10 @@ def test_set_params(

for i in range(len(pars)):
for j in range(i + 1, len(pars)):
with pytest.raises(AttributeError, match="can't set attribute 'mode'|property 'mode' of "):
with pytest.raises(
AttributeError,
match="can't set attribute 'mode'|property 'mode' of ",
):
par_set = {
keys[i]: pars[keys[i]],
keys[j]: pars[keys[j]],
Expand Down Expand Up @@ -3881,7 +3943,10 @@ def test_set_params(

for i in range(len(pars)):
for j in range(i + 1, len(pars)):
with pytest.raises(AttributeError, match="can't set attribute 'mode'|property 'mode' of "):
with pytest.raises(
AttributeError,
match="can't set attribute 'mode'|property 'mode' of ",
):
par_set = {
keys[i]: pars[keys[i]],
keys[j]: pars[keys[j]],
Expand Down

0 comments on commit ee8291b

Please sign in to comment.