Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce that ids are unique in all ICEPhys tables #10

Merged
merged 1 commit into from
Oct 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/pynwb/ndx_icephys_meta/icephys.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def add_recording(self, **kwargs):
'stimulus': (stimulus_start_index, stimulus_index_count, stimulus),
'response': (response_start_index, response_index_count, response)}
row_kwargs.update(kwargs)
return super(IntracellularRecordings, self).add_row(**row_kwargs)
return super(IntracellularRecordings, self).add_row(enforce_unique_id=True, **row_kwargs)


@register_class('Sweeps', namespace)
Expand Down Expand Up @@ -171,7 +171,7 @@ def add_sweep(self, **kwargs):
recordings = getargs('recordings', kwargs)
if recordings is None:
kwargs['recordings'] = []
re = super(Sweeps, self).add_row(**kwargs)
re = super(Sweeps, self).add_row(enforce_unique_id=True, **kwargs)
return re


Expand Down Expand Up @@ -232,7 +232,7 @@ def add_sweep_sequence(self, **kwargs):
sweeps = getargs('sweeps', kwargs)
if sweeps is None:
kwargs['sweeps'] = []
re = super(SweepSequences, self).add_row(**kwargs)
re = super(SweepSequences, self).add_row(enforce_unique_id=True, **kwargs)
return re


Expand Down Expand Up @@ -291,7 +291,7 @@ def add_run(self, **kwargs):
sweep_sequences = getargs('sweep_sequences', kwargs)
if sweep_sequences is None:
kwargs['sweep_sequences'] = []
re = super(Runs, self).add_row(**kwargs)
re = super(Runs, self).add_row(enforce_unique_id=True, **kwargs)
return re


Expand Down Expand Up @@ -346,7 +346,7 @@ def add_condition(self, **kwargs):
runs = getargs('runs', kwargs)
if runs is None:
kwargs['runs'] = []
re = super(Conditions, self).add_row(**kwargs)
re = super(Conditions, self).add_row(enforce_unique_id=True, **kwargs)
return re


Expand Down
83 changes: 83 additions & 0 deletions src/pynwb/ndx_icephys_meta/test/test_icephys.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,21 @@ def test_add_row_no_stimulus_and_response(self):
stimulus=None,
response=None)

def test_enforce_unique_id(self):
"""
Test to ensure that unique ids are enforced on Runs table
"""
ir = IntracellularRecordings()
ir.add_recording(electrode=self.electrode,
stimulus=self.stimulus,
response=self.response,
id=10)
with self.assertRaises(ValueError):
ir.add_recording(electrode=self.electrode,
stimulus=self.stimulus,
response=self.response,
id=10)


class SweepsTests(ICEphysMetaTestBase):
"""
Expand Down Expand Up @@ -284,6 +299,20 @@ def test_basic_write(self):
sw.add_sweep(recordings=[0])
self.write_test_helper(ir=ir, sw=sw)

def test_enforce_unique_id(self):
"""
Test to ensure that unique ids are enforced on Runs table
"""
ir = IntracellularRecordings()
ir.add_recording(electrode=self.electrode,
stimulus=self.stimulus,
response=self.response,
id=10)
sw = Sweeps(intracellular_recordings_table=ir)
sw.add_sweep(recordings=[0], id=10)
with self.assertRaises(ValueError):
sw.add_sweep(recordings=[0], id=10)


class SweepSequencesTests(ICEphysMetaTestBase):
"""
Expand Down Expand Up @@ -323,6 +352,22 @@ def test_basic_write(self):
sws.add_sweep_sequence(sweeps=[0, ])
self.write_test_helper(ir=ir, sw=sw, sws=sws)

def test_enforce_unique_id(self):
"""
Test to ensure that unique ids are enforced on Runs table
"""
ir = IntracellularRecordings()
ir.add_recording(electrode=self.electrode,
stimulus=self.stimulus,
response=self.response,
id=10)
sw = Sweeps(intracellular_recordings_table=ir)
sw.add_sweep(recordings=[0])
sws = SweepSequences(sw)
sws.add_sweep_sequence(sweeps=[0, ], id=10)
with self.assertRaises(ValueError):
sws.add_sweep_sequence(sweeps=[0, ], id=10)


class RunsTests(ICEphysMetaTestBase):
"""
Expand Down Expand Up @@ -365,6 +410,24 @@ def test_basic_write(self):
runs.add_run(sweep_sequences=[0, ])
self.write_test_helper(ir=ir, sw=sw, sws=sws, runs=runs)

def test_enforce_unique_id(self):
"""
Test to ensure that unique ids are enforced on Runs table
"""
ir = IntracellularRecordings()
ir.add_recording(electrode=self.electrode,
stimulus=self.stimulus,
response=self.response,
id=10)
sw = Sweeps(intracellular_recordings_table=ir)
sw.add_sweep(recordings=[0])
sws = SweepSequences(sw)
sws.add_sweep_sequence(sweeps=[0, ])
runs = Runs(sweep_sequences_table=sws)
runs.add_run(sweep_sequences=[0, ], id=10)
with self.assertRaises(ValueError):
runs.add_run(sweep_sequences=[0, ], id=10)


class ConditionsTests(ICEphysMetaTestBase):
"""
Expand Down Expand Up @@ -410,6 +473,26 @@ def test_basic_write(self):
cond.add_condition(runs=[0, ])
self.write_test_helper(ir=ir, sw=sw, sws=sws, runs=runs, cond=cond)

def test_enforce_unique_id(self):
"""
Test to ensure that unique ids are enforced on Runs table
"""
ir = IntracellularRecordings()
ir.add_recording(electrode=self.electrode,
stimulus=self.stimulus,
response=self.response,
id=10)
sw = Sweeps(intracellular_recordings_table=ir)
sw.add_sweep(recordings=[0])
sws = SweepSequences(sw)
sws.add_sweep_sequence(sweeps=[0, ])
runs = Runs(sweep_sequences_table=sws)
runs.add_run(sweep_sequences=[0, ])
cond = Conditions(runs_table=runs)
cond.add_condition(runs=[0, ], id=10)
with self.assertRaises(ValueError):
cond.add_condition(runs=[0, ], id=10)


class ICEphysFileTests(ICEphysMetaTestBase):
"""
Expand Down