diff --git a/Makefile b/Makefile index b2a9586..315ffa5 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -TEST_REQUIREMENTS=nose coverage +TEST_REQUIREMENTS=nose coverage mock all: install install: diff --git a/bluepyopt/ephys/simulators.py b/bluepyopt/ephys/simulators.py index 6c0e7b7..6853f69 100644 --- a/bluepyopt/ephys/simulators.py +++ b/bluepyopt/ephys/simulators.py @@ -110,8 +110,6 @@ def run( if cvode_active is None: cvode_active = self.cvode_active - self.neuron.h.cvode_active(1 if cvode_active else 0) - if not cvode_active and dt is None: # use dt of simulator if self.neuron.h.dt != self.dt: raise Exception( @@ -122,6 +120,8 @@ def run( 'init dt: %.6g' % (self.neuron.h.dt, self.dt)) dt = self.dt + self.neuron.h.cvode_active(1 if cvode_active else 0) + if cvode_active: logger.debug('Running Neuron simulator %.6g ms, with cvode', tstop) else: diff --git a/bluepyopt/tests/test_ephys/test_simulators.py b/bluepyopt/tests/test_ephys/test_simulators.py index 4e78de5..a2cd984 100644 --- a/bluepyopt/tests/test_ephys/test_simulators.py +++ b/bluepyopt/tests/test_ephys/test_simulators.py @@ -25,6 +25,8 @@ import nose.tools as nt from nose.plugins.attrib import attr +import mock + import bluepyopt.ephys as ephys @@ -37,12 +39,29 @@ def test_nrnsimulator_init(): @attr('unit') +def test_nrnsimulator_init_windows(): + """ephys.simulators: test if NrnSimulator constructor works on Windows""" + + with mock.patch('platform.system', mock.MagicMock(return_value="Windows")): + neuron_sim = ephys.simulators.NrnSimulator() + nt.assert_is_instance(neuron_sim, ephys.simulators.NrnSimulator) + nt.assert_false(neuron_sim.disable_banner) + nt.assert_false(neuron_sim.banner_disabled) + + neuron_sim.neuron.h.celsius = 34 + + nt.assert_false(neuron_sim.disable_banner) + nt.assert_false(neuron_sim.banner_disabled) + + +@attr('unit') def test_nrnsimulator_cvode_minstep(): """ephys.simulators: test if NrnSimulator constructor works""" # Check with minstep specified neuron_sim = ephys.simulators.NrnSimulator() nt.assert_equal(neuron_sim.cvode.minstep(), 0.0) + nt.assert_equal(neuron_sim.cvode_minstep, 0.0) # Check with minstep specified, before after simulation neuron_sim = ephys.simulators.NrnSimulator(cvode_minstep=0.01) @@ -64,3 +83,35 @@ def test_neuron_import(): from bluepyopt import ephys # NOQA neuron_sim = ephys.simulators.NrnSimulator() nt.assert_is_instance(neuron_sim.neuron, types.ModuleType) + + +@attr('unit') +def test_nrnsim_run_dt_exception(): + """ephys.simulators: test if run return exception when dt was changed""" + + from bluepyopt import ephys # NOQA + neuron_sim = ephys.simulators.NrnSimulator() + neuron_sim.neuron.h.dt = 1.0 + nt.assert_raises(Exception, neuron_sim.run, 10, cvode_active=False) + + +@attr('unit') +def test_nrnsim_run_cvodeactive_dt_exception(): + """ephys.simulators: test if run return exception cvode and dt both used""" + + from bluepyopt import ephys # NOQA + neuron_sim = ephys.simulators.NrnSimulator() + neuron_sim.neuron.h.dt = 1.0 + nt.assert_raises(ValueError, neuron_sim.run, 10, dt=0.1, cvode_active=True) + + +@attr('unit') +@mock.patch('glob.glob') +def test_disable_banner_exception(mock_glob): + """ephys.simulators: test if disable_banner raises exception""" + mock_glob.return_value = [] + + nt.assert_raises( + Exception, + ephys.simulators.NrnSimulator. # pylint: disable=W0212 + _nrn_disable_banner)