From b6b8dc07fd6ae426ff0eab1b3ecc6b961f301531 Mon Sep 17 00:00:00 2001 From: Mainak Jas Date: Wed, 5 May 2021 16:14:22 -0400 Subject: [PATCH] TST: add tests for cell class --- hnn_core/cell.py | 4 ++-- hnn_core/tests/test_cell.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/hnn_core/cell.py b/hnn_core/cell.py index 22a94792e..1969a6a67 100644 --- a/hnn_core/cell.py +++ b/hnn_core/cell.py @@ -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 @@ -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) diff --git a/hnn_core/tests/test_cell.py b/hnn_core/tests/test_cell.py index 69901013d..6f257a14f 100644 --- a/hnn_core/tests/test_cell.py +++ b/hnn_core/tests/test_cell.py @@ -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... @@ -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."""