Skip to content

Commit

Permalink
Fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gviejo committed Jan 26, 2024
1 parent c4119b5 commit 5f417b2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
10 changes: 7 additions & 3 deletions pynapple/process/tuning_curves.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# @Author: gviejo
# @Date: 2022-01-02 23:33:42
# @Last Modified by: Guillaume Viejo
# @Last Modified time: 2024-01-26 15:12:33
# @Last Modified time: 2024-01-26 15:28:51

import warnings

Expand Down Expand Up @@ -58,7 +58,7 @@ def compute_discrete_tuning_curves(group, dict_ep):
for k in idx:
assert isinstance(
dict_ep[k], nap.IntervalSet
), "dict_ep argument should contain only IntervalSet. \n Key {} in dict_ep is not an IntervalSet".format(
), "dict_ep argument should contain only IntervalSet. Key {} in dict_ep is not an IntervalSet".format(
k
)

Expand Down Expand Up @@ -112,7 +112,11 @@ def compute_1d_tuning_curves(group, feature, nb_bins, ep=None, minmax=None):
feature.shape[1] == 1
), "feature should be a Tsd (or TsdFrame with 1 column only)"
assert isinstance(nb_bins, int)
assert isinstance(ep, nap.IntervalSet), "ep should be an IntervalSet"

if ep is None:
ep = feature.time_support
else:
assert isinstance(ep, nap.IntervalSet), "ep should be an IntervalSet"

if minmax is None:
bins = np.linspace(np.min(feature), np.max(feature), nb_bins + 1)
Expand Down
14 changes: 7 additions & 7 deletions tests/test_tuning_curves.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# @Author: gviejo
# @Date: 2022-03-30 11:16:30
# @Last Modified by: Guillaume Viejo
# @Last Modified time: 2024-01-26 15:09:42
# @Last Modified time: 2024-01-26 15:23:20

"""Tests of tuning curves for `pynapple` package."""

Expand Down Expand Up @@ -36,7 +36,7 @@ def test_compute_discrete_tuning_curves_with_strings():
def test_compute_discrete_tuning_curves_error():
dict_ep = { "0":nap.IntervalSet(start=0, end=50),
"1":nap.IntervalSet(start=50, end=100)}
with pytest.raises(RuntimeError) as e_info:
with pytest.raises(AssertionError) as e_info:
nap.compute_discrete_tuning_curves([1,2,3], dict_ep)
assert str(e_info.value) == "group should be a TsGroup."

Expand All @@ -45,9 +45,9 @@ def test_compute_discrete_tuning_curves_error():
"1":nap.IntervalSet(start=50, end=100)}
k = [1,2,3]
dict_ep["2"] = k
with pytest.raises(RuntimeError) as e_info:
with pytest.raises(AssertionError) as e_info:
nap.compute_discrete_tuning_curves(tsgroup, dict_ep)
assert str(e_info.value) == "dict_ep argument should contain only IntervalSet. \n Key 2 in dict_ep is not an IntervalSet"
assert str(e_info.value) == "dict_ep argument should contain only IntervalSet. Key 2 in dict_ep is not an IntervalSet"

def test_compute_1d_tuning_curves():
tsgroup = nap.TsGroup({0: nap.Ts(t=np.arange(0, 100))})
Expand All @@ -61,7 +61,7 @@ def test_compute_1d_tuning_curves():

def test_compute_1d_tuning_curves_error():
feature = nap.Tsd(t=np.arange(0, 100, 0.1), d=np.arange(0, 100, 0.1) % 1.0)
with pytest.raises(RuntimeError) as e_info:
with pytest.raises(AssertionError) as e_info:
nap.compute_1d_tuning_curves([1,2,3], feature, nb_bins=10)
assert str(e_info.value) == "group should be a TsGroup."

Expand Down Expand Up @@ -110,15 +110,15 @@ def test_compute_2d_tuning_curves_error():
(np.repeat(np.arange(0, 100), 10), np.tile(np.arange(0, 100), 10))
).T
features = nap.TsdFrame(t=np.arange(0, 200, 0.1), d=np.vstack((tmp, tmp[::-1])))
with pytest.raises(RuntimeError) as e_info:
with pytest.raises(AssertionError) as e_info:
nap.compute_2d_tuning_curves([1,2,3], features, 10)
assert str(e_info.value) == "group should be a TsGroup."

tsgroup = nap.TsGroup(
{0: nap.Ts(t=np.arange(0, 100, 10)), 1: nap.Ts(t=np.array([50, 149]))}
)
features = nap.TsdFrame(t=np.arange(100), d=np.random.rand(100, 3))
with pytest.raises(RuntimeError) as e_info:
with pytest.raises(AssertionError) as e_info:
nap.compute_2d_tuning_curves(tsgroup, features, 10)
assert str(e_info.value) == "feature should have 2 columns only."

Expand Down

0 comments on commit 5f417b2

Please sign in to comment.