Skip to content

Commit

Permalink
TST: add tests for cell class
Browse files Browse the repository at this point in the history
  • Loading branch information
jasmainak committed May 5, 2021
1 parent 6b76eec commit b6b8dc0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
4 changes: 2 additions & 2 deletions hnn_core/cell.py
Expand Up @@ -190,8 +190,6 @@ def _create_sections(self, p_secs, topology):
for height and xz plane for depth. This is opposite for model as a
whole, but convention is followed in this function ease use of gui.
"""
if 'soma' not in p_secs:
raise KeyError('soma must be defined for cell')
for sec_name in p_secs:
sec = h.Section(name=f'{self.name}_{sec_name}')
self.sections[sec_name] = sec
Expand Down Expand Up @@ -269,6 +267,8 @@ def build(self, p_secs, p_syn, topology, sect_loc):
}
}
"""
if 'soma' not in p_secs:
raise KeyError('soma must be defined for cell')
self._create_sections(p_secs, topology)
self._create_synapses(p_secs, p_syn)
self._set_biophysics(p_secs)
Expand Down
34 changes: 34 additions & 0 deletions hnn_core/tests/test_cell.py
Expand Up @@ -10,6 +10,8 @@

def test_cell():
"""Test cells object."""
load_custom_mechanisms()

pos = (0., 0., 0.)
name = 'test'
# GID is assigned exactly once for each cell, either at initialisation...
Expand All @@ -36,6 +38,38 @@ def test_cell():
with pytest.raises(TypeError, match='secloc must be instance of'):
cell.syn_create(0.5, e=0., tau1=0.5, tau2=5.)

p_secs = {'blah': 1}
p_syn = {'ampa': dict(e=0, tau1=0.5, tau2=5.)}
topology = None
sect_loc = {'proximal': 'soma'}
with pytest.raises(KeyError, match='soma must be defined'):
cell.build(p_secs, p_syn, topology, sect_loc)

p_secs = {
'soma':
{
'L': 39,
'diam': 20,
'cm': 0.85,
'Ra': 200.,
'sec_pts': [[0, 0, 0], [0, 39., 0]],
'syns': ['ampa'],
'mechs': {
'km': {
'gbar_km': 60
},
'ca': {
'gbar_ca': lambda x: 3e-3 * x
}
}
}
}
cell.build(p_secs, p_syn, topology, sect_loc)
assert 'soma' in cell.sections
assert cell.sections['soma'].L == p_secs['soma']['L']
assert cell.sections['soma'].gbar_km == p_secs[
'soma']['mechs']['km']['gbar_km']


def test_artificial_cell():
"""Test artificial cell object."""
Expand Down

0 comments on commit b6b8dc0

Please sign in to comment.