Skip to content

Commit

Permalink
SpikeEventSeries: add test for timestamp check (#1507)
Browse files Browse the repository at this point in the history
Co-authored-by: Ryan Ly <[email protected]>
  • Loading branch information
bendichter and rly authored Dec 5, 2022
1 parent f01dabf commit 03740d0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/pynwb/ecephys.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def __init__(self, **kwargs):
args_to_set = popargs_to_dict(('description', 'location', 'device', 'position'), kwargs)
super().__init__(**kwargs)
if args_to_set['position'] and len(args_to_set['position']) != 3:
raise Exception('ElectrodeGroup position argument must have three elements: x, y, z, but received: %s'
% args_to_set['position'])
raise ValueError('ElectrodeGroup position argument must have three elements: x, y, z, but received: %s'
% str(args_to_set['position']))
for key, val in args_to_set.items():
setattr(self, key, val)

Expand Down Expand Up @@ -122,7 +122,7 @@ def __init__(self, **kwargs):
if not (isinstance(data, TimeSeries) or isinstance(timestamps, TimeSeries)):
if not (isinstance(data, DataChunkIterator) or isinstance(timestamps, DataChunkIterator)):
if len(data) != len(timestamps):
raise Exception('Must provide the same number of timestamps and spike events')
raise ValueError('Must provide the same number of timestamps and spike events')
else:
# TODO: add check when we have DataChunkIterators
pass
Expand Down
8 changes: 7 additions & 1 deletion tests/unit/test_ecephys.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ def test_no_rate(self):
with self.assertRaises(TypeError):
SpikeEventSeries(name='test_sES', data=data, electrodes=region, rate=1.)

def test_incorrect_timestamps(self):
table, region = self._create_table_and_region()
data = ((1, 1, 1), (2, 2, 2))
with self.assertRaisesWith(ValueError, "Must provide the same number of timestamps and spike events"):
SpikeEventSeries(name='test_sES', data=data, electrodes=region, timestamps=[1.0, 2.0, 3.0])


class ElectrodeGroupConstructor(TestCase):

Expand All @@ -156,7 +162,7 @@ def test_init_position_none(self):

def test_init_position_bad(self):
dev1 = Device('dev1')
with self.assertRaises(TypeError):
with self.assertRaises(ValueError):
ElectrodeGroup('elec1', 'electrode description', 'electrode location', dev1, (1, 2))


Expand Down

0 comments on commit 03740d0

Please sign in to comment.