@@ -54,26 +54,52 @@ def test_compute_perievent_windowsize():
54
54
def test_compute_perievent_raise_error ():
55
55
tsd = nap .Ts (t = np .arange (100 ))
56
56
tref = nap .Ts (t = np .arange (10 , 100 , 10 ))
57
- with pytest .raises (AssertionError ) as e_info :
58
- nap .compute_perievent (tsd , [0 , 1 , 2 ], windowsize = (- 10 , 10 ))
59
- assert str (e_info .value ) == "tref should be a Ts or Tsd object."
57
+ with pytest .raises (TypeError ) as e_info :
58
+ nap .compute_perievent (tsd , tref = [0 , 1 , 2 ], windowsize = (- 10 , 10 ))
59
+ assert (
60
+ str (e_info .value )
61
+ == "Invalid type. Parameter tref must be of type ['Ts', 'Tsd', 'TsdFrame', 'TsdTensor']."
62
+ )
60
63
61
- with pytest .raises (AssertionError ) as e_info :
62
- nap .compute_perievent ([0 , 1 , 2 ], tref , windowsize = (- 10 , 10 ))
63
- assert str (e_info .value ) == "data should be a Ts, Tsd or TsGroup."
64
+ with pytest .raises (TypeError ) as e_info :
65
+ nap .compute_perievent (timestamps = [0 , 1 , 2 ], tref = tref , windowsize = (- 10 , 10 ))
66
+ assert (
67
+ str (e_info .value )
68
+ == "Invalid type. Parameter timestamps must be of type ['Ts', 'Tsd', 'TsdFrame', 'TsdTensor', 'TsGroup']."
69
+ )
64
70
65
- with pytest .raises (AssertionError ) as e_info :
71
+ with pytest .raises (TypeError ) as e_info :
66
72
nap .compute_perievent (tsd , tref , windowsize = {0 : 1 })
67
- assert str (e_info .value ) == "windowsize should be a tuple or int or float."
73
+ assert (
74
+ str (e_info .value )
75
+ == "Invalid type. Parameter windowsize must be of type ['tuple', 'Number']."
76
+ )
68
77
69
- with pytest .raises (AssertionError ) as e_info :
78
+ with pytest .raises (TypeError ) as e_info :
70
79
nap .compute_perievent (tsd , tref , windowsize = 10 , time_unit = 1 )
71
- assert str (e_info .value ) == "time_unit should be a str."
80
+ assert (
81
+ str (e_info .value )
82
+ == "Invalid type. Parameter time_unit must be of type ['str']."
83
+ )
72
84
73
- with pytest .raises (AssertionError ) as e_info :
85
+ with pytest .raises (RuntimeError ) as e_info :
74
86
nap .compute_perievent (tsd , tref , windowsize = 10 , time_unit = "a" )
75
87
assert str (e_info .value ) == "time_unit should be 's', 'ms' or 'us'"
76
88
89
+ with pytest .raises (RuntimeError ) as e_info :
90
+ nap .compute_perievent (tsd , tref , windowsize = (1 , 2 , 3 ))
91
+ assert (
92
+ str (e_info .value )
93
+ == "windowsize should be a tuple of 2 numbers or a single number."
94
+ )
95
+
96
+ with pytest .raises (RuntimeError ) as e_info :
97
+ nap .compute_perievent (tsd , tref , windowsize = (1 , "2" ))
98
+ assert (
99
+ str (e_info .value )
100
+ == "windowsize should be a tuple of 2 numbers or a single number."
101
+ )
102
+
77
103
78
104
def test_compute_perievent_with_tsgroup ():
79
105
tsgroup = nap .TsGroup (
@@ -97,7 +123,9 @@ def test_compute_perievent_time_units():
97
123
tsd = nap .Tsd (t = np .arange (100 ), d = np .arange (100 ))
98
124
tref = nap .Ts (t = np .arange (10 , 100 , 10 ))
99
125
for tu , fa in zip (["s" , "ms" , "us" ], [1 , 1e3 , 1e6 ]):
100
- peth = nap .compute_perievent (tsd , tref , windowsize = (- 10 * fa , 10 * fa ), time_unit = tu )
126
+ peth = nap .compute_perievent (
127
+ tsd , tref , windowsize = (- 10 * fa , 10 * fa ), time_unit = tu
128
+ )
101
129
for i , j in zip (peth .keys (), np .arange (0 , 100 , 10 )):
102
130
np .testing .assert_array_almost_equal (peth [i ].index , np .arange (- 10 , 10 ))
103
131
np .testing .assert_array_almost_equal (peth [i ].values , np .arange (j , j + 20 ))
@@ -127,7 +155,9 @@ def test_compute_perievent_continuous():
127
155
np .testing .assert_array_almost_equal (
128
156
pe .index .values , np .arange (windowsize [0 ], windowsize [- 1 ] + 1 )
129
157
)
130
- tmp = np .array ([np .arange (t + windowsize [0 ], t + windowsize [1 ] + 1 ) for t in tref .t ]).T
158
+ tmp = np .array (
159
+ [np .arange (t + windowsize [0 ], t + windowsize [1 ] + 1 ) for t in tref .t ]
160
+ ).T
131
161
np .testing .assert_array_almost_equal (pe .values , tmp )
132
162
133
163
windowsize = (5 , 10 )
@@ -184,11 +214,15 @@ def test_compute_perievent_continuous_time_units():
184
214
tref = nap .Ts (t = np .array ([20 , 60 ]))
185
215
windowsize = (- 5 , 10 )
186
216
for tu , fa in zip (["s" , "ms" , "us" ], [1 , 1e3 , 1e6 ]):
187
- pe = nap .compute_perievent_continuous (tsd , tref , windowsize = (windowsize [0 ] * fa , windowsize [1 ] * fa ), time_unit = tu )
217
+ pe = nap .compute_perievent_continuous (
218
+ tsd , tref , windowsize = (windowsize [0 ] * fa , windowsize [1 ] * fa ), time_unit = tu
219
+ )
188
220
np .testing .assert_array_almost_equal (
189
221
pe .index .values , np .arange (windowsize [0 ], windowsize [1 ] + 1 )
190
222
)
191
- tmp = np .array ([np .arange (t + windowsize [0 ], t + windowsize [1 ] + 1 ) for t in tref .t ]).T
223
+ tmp = np .array (
224
+ [np .arange (t + windowsize [0 ], t + windowsize [1 ] + 1 ) for t in tref .t ]
225
+ ).T
192
226
np .testing .assert_array_almost_equal (pe .values , tmp )
193
227
194
228
@@ -201,7 +235,10 @@ def test_compute_perievent_continuous_with_ep():
201
235
202
236
assert pe .shape [1 ] == len (tref ) - 1
203
237
tmp = np .array (
204
- [np .arange (t + windowsize [0 ], t + windowsize [1 ] + 1 ) for t in tref .restrict (ep ).t ]
238
+ [
239
+ np .arange (t + windowsize [0 ], t + windowsize [1 ] + 1 )
240
+ for t in tref .restrict (ep ).t
241
+ ]
205
242
).T
206
243
np .testing .assert_array_almost_equal (pe .values , tmp )
207
244
@@ -237,26 +274,55 @@ def test_compute_perievent_continuous_with_ep():
237
274
def test_compute_perievent_continuous_raise_error ():
238
275
tsd = nap .Tsd (t = np .arange (100 ), d = np .arange (100 ))
239
276
tref = nap .Ts (t = np .arange (10 , 100 , 10 ))
240
- with pytest .raises (AssertionError ) as e_info :
241
- nap .compute_perievent_continuous (tsd , [0 , 1 , 2 ], windowsize = (- 10 , 10 ))
242
- assert str (e_info .value ) == "tref should be a Ts or Tsd object."
277
+ with pytest .raises (TypeError ) as e_info :
278
+ nap .compute_perievent_continuous (tsd , tref = [0 , 1 , 2 ], windowsize = (- 10 , 10 ))
279
+ assert (
280
+ str (e_info .value )
281
+ == "Invalid type. Parameter tref must be of type ['Ts', 'Tsd', 'TsdFrame', 'TsdTensor']."
282
+ )
243
283
244
- with pytest .raises (AssertionError ) as e_info :
284
+ with pytest .raises (TypeError ) as e_info :
245
285
nap .compute_perievent_continuous ([0 , 1 , 2 ], tref , windowsize = (- 10 , 10 ))
246
- assert str (e_info .value ) == "data should be a Tsd, TsdFrame or TsdTensor."
286
+ assert (
287
+ str (e_info .value )
288
+ == "Invalid type. Parameter timeseries must be of type ['Tsd', 'TsdFrame', 'TsdTensor']."
289
+ )
247
290
248
- with pytest .raises (AssertionError ) as e_info :
291
+ with pytest .raises (TypeError ) as e_info :
249
292
nap .compute_perievent_continuous (tsd , tref , windowsize = {0 : 1 })
250
- assert str (e_info .value ) == "windowsize should be a tuple or int or float."
293
+ assert (
294
+ str (e_info .value )
295
+ == "Invalid type. Parameter windowsize must be of type ['tuple', 'Number']."
296
+ )
251
297
252
- with pytest .raises (AssertionError ) as e_info :
298
+ with pytest .raises (TypeError ) as e_info :
253
299
nap .compute_perievent_continuous (tsd , tref , windowsize = 10 , time_unit = 1 )
254
- assert str (e_info .value ) == "time_unit should be a str."
300
+ assert (
301
+ str (e_info .value )
302
+ == "Invalid type. Parameter time_unit must be of type ['str']."
303
+ )
255
304
256
- with pytest .raises (AssertionError ) as e_info :
305
+ with pytest .raises (RuntimeError ) as e_info :
257
306
nap .compute_perievent_continuous (tsd , tref , windowsize = 10 , time_unit = "a" )
258
307
assert str (e_info .value ) == "time_unit should be 's', 'ms' or 'us'"
259
308
260
- with pytest .raises (AssertionError ) as e_info :
309
+ with pytest .raises (TypeError ) as e_info :
261
310
nap .compute_perievent_continuous (tsd , tref , windowsize = 10 , ep = "a" )
262
- assert str (e_info .value ) == "ep should be an IntervalSet object."
311
+ assert (
312
+ str (e_info .value )
313
+ == "Invalid type. Parameter ep must be of type ['IntervalSet']."
314
+ )
315
+
316
+ with pytest .raises (RuntimeError ) as e_info :
317
+ nap .compute_perievent_continuous (tsd , tref , windowsize = (1 , 2 , 3 ))
318
+ assert (
319
+ str (e_info .value )
320
+ == "windowsize should be a tuple of 2 numbers or a single number."
321
+ )
322
+
323
+ with pytest .raises (RuntimeError ) as e_info :
324
+ nap .compute_perievent_continuous (tsd , tref , windowsize = (1 , "2" ))
325
+ assert (
326
+ str (e_info .value )
327
+ == "windowsize should be a tuple of 2 numbers or a single number."
328
+ )
0 commit comments