Skip to content

Commit

Permalink
Merge pull request #10 from oruebel/enh/enforceids
Browse files Browse the repository at this point in the history
Enforce that ids are unique in all ICEPhys tables
  • Loading branch information
oruebel authored Oct 24, 2019
2 parents daa5bb6 + cb6feb4 commit 9834b5c
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 5 deletions.
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

0 comments on commit 9834b5c

Please sign in to comment.