Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.

Commit d21c674

Browse files
authored
Merge pull request #359 from BlueBrain/switch_pytest
Switch pytest
2 parents 1c93677 + 5b90e1f commit d21c674

36 files changed

+714
-715
lines changed

bluepyopt/ephys/examples/simplecell/simplecell.py

Lines changed: 103 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -4,100 +4,106 @@
44

55
import bluepyopt.ephys as ephys
66

7-
nrn_sim = ephys.simulators.NrnSimulator()
8-
9-
morph = ephys.morphologies.NrnFileMorphology(
10-
os.path.join(
11-
os.path.dirname(os.path.abspath(__file__)),
12-
'simple.swc'))
13-
somatic_loc = ephys.locations.NrnSeclistLocation(
14-
'somatic',
15-
seclist_name='somatic')
16-
somacenter_loc = ephys.locations.NrnSeclistCompLocation(
17-
name='somacenter',
18-
seclist_name='somatic',
19-
sec_index=0,
20-
comp_x=0.5)
21-
hh_mech = ephys.mechanisms.NrnMODMechanism(
22-
name='hh',
23-
suffix='hh',
24-
locations=[somatic_loc])
25-
26-
27-
cm_param = ephys.parameters.NrnSectionParameter(
28-
name='cm',
29-
param_name='cm',
30-
value=1.0,
31-
locations=[somatic_loc],
32-
frozen=True)
33-
34-
35-
gnabar_param = ephys.parameters.NrnSectionParameter(
36-
name='gnabar_hh',
37-
param_name='gnabar_hh',
38-
locations=[somatic_loc],
39-
bounds=[0.05, 0.125],
40-
frozen=False)
41-
gkbar_param = ephys.parameters.NrnSectionParameter(
42-
name='gkbar_hh',
43-
param_name='gkbar_hh',
44-
bounds=[0.01, 0.075],
45-
locations=[somatic_loc],
46-
frozen=False)
47-
48-
cell_model = ephys.models.CellModel(
49-
name='simple_cell',
50-
morph=morph,
51-
mechs=[hh_mech],
52-
params=[cm_param, gnabar_param, gkbar_param])
53-
54-
default_param_values = {'gnabar_hh': 0.1, 'gkbar_hh': 0.03}
55-
56-
efel_feature_means = {'step1': {'Spikecount': 1}, 'step2': {'Spikecount': 5}}
57-
58-
objectives = []
59-
60-
soma_loc = ephys.locations.NrnSeclistCompLocation(
61-
name='soma',
62-
seclist_name='somatic',
63-
sec_index=0,
64-
comp_x=0.5)
65-
66-
stim = ephys.stimuli.NrnSquarePulse(
67-
step_amplitude=0.01,
68-
step_delay=100,
69-
step_duration=50,
70-
location=soma_loc,
71-
total_duration=200)
72-
rec = ephys.recordings.CompRecording(
73-
name='Step1.soma.v',
74-
location=soma_loc,
75-
variable='v')
76-
protocol = ephys.protocols.SweepProtocol('Step1', [stim], [rec])
77-
78-
stim_start = 100
79-
stim_end = 150
80-
81-
feature_name = 'Step1.Spikecount'
82-
feature = ephys.efeatures.eFELFeature(
83-
feature_name,
84-
efel_feature_name='Spikecount',
85-
recording_names={'': '%s.soma.v' % protocol.name},
86-
stim_start=stim_start,
87-
stim_end=stim_end,
88-
exp_mean=1.0,
89-
exp_std=0.05)
90-
objective = ephys.objectives.SingletonObjective(
91-
feature_name,
92-
feature)
93-
94-
score_calc = ephys.objectivescalculators.ObjectivesCalculator([objective])
95-
96-
nrn = ephys.simulators.NrnSimulator()
97-
98-
cell_evaluator = ephys.evaluators.CellEvaluator(
99-
cell_model=cell_model,
100-
param_names=['gnabar_hh', 'gkbar_hh'],
101-
fitness_protocols={'Step1': protocol},
102-
fitness_calculator=score_calc,
103-
sim=nrn)
7+
8+
class SimpleCell:
9+
def __init__(self):
10+
self.nrn_sim = ephys.simulators.NrnSimulator()
11+
12+
self.morph = ephys.morphologies.NrnFileMorphology(
13+
os.path.join(
14+
os.path.dirname(os.path.abspath(__file__)),
15+
'simple.swc'))
16+
self.somatic_loc = ephys.locations.NrnSeclistLocation(
17+
'somatic',
18+
seclist_name='somatic')
19+
self.somacenter_loc = ephys.locations.NrnSeclistCompLocation(
20+
name='somacenter',
21+
seclist_name='somatic',
22+
sec_index=0,
23+
comp_x=0.5)
24+
self.hh_mech = ephys.mechanisms.NrnMODMechanism(
25+
name='hh',
26+
suffix='hh',
27+
locations=[self.somatic_loc])
28+
29+
self.cm_param = ephys.parameters.NrnSectionParameter(
30+
name='cm',
31+
param_name='cm',
32+
value=1.0,
33+
locations=[self.somatic_loc],
34+
frozen=True)
35+
36+
self.gnabar_param = ephys.parameters.NrnSectionParameter(
37+
name='gnabar_hh',
38+
param_name='gnabar_hh',
39+
locations=[self.somatic_loc],
40+
bounds=[0.05, 0.125],
41+
frozen=False)
42+
self.gkbar_param = ephys.parameters.NrnSectionParameter(
43+
name='gkbar_hh',
44+
param_name='gkbar_hh',
45+
bounds=[0.01, 0.075],
46+
locations=[self.somatic_loc],
47+
frozen=False)
48+
49+
self.cell_model = ephys.models.CellModel(
50+
name='simple_cell',
51+
morph=self.morph,
52+
mechs=[self.hh_mech],
53+
params=[self.cm_param, self.gnabar_param, self.gkbar_param])
54+
55+
self.default_param_values = {'gnabar_hh': 0.1, 'gkbar_hh': 0.03}
56+
57+
self.efel_feature_means = {
58+
'step1': {
59+
'Spikecount': 1}, 'step2': {
60+
'Spikecount': 5}}
61+
62+
self.objectives = []
63+
64+
self.soma_loc = ephys.locations.NrnSeclistCompLocation(
65+
name='soma',
66+
seclist_name='somatic',
67+
sec_index=0,
68+
comp_x=0.5)
69+
70+
self.stim = ephys.stimuli.NrnSquarePulse(
71+
step_amplitude=0.01,
72+
step_delay=100,
73+
step_duration=50,
74+
location=self.soma_loc,
75+
total_duration=200)
76+
self.rec = ephys.recordings.CompRecording(
77+
name='Step1.soma.v',
78+
location=self.soma_loc,
79+
variable='v')
80+
self.protocol = ephys.protocols.SweepProtocol(
81+
'Step1', [self.stim], [self.rec])
82+
83+
self.stim_start = 100
84+
self.stim_end = 150
85+
86+
self.feature_name = 'Step1.Spikecount'
87+
self.feature = ephys.efeatures.eFELFeature(
88+
self.feature_name,
89+
efel_feature_name='Spikecount',
90+
recording_names={'': '%s.soma.v' % self.protocol.name},
91+
stim_start=self.stim_start,
92+
stim_end=self.stim_end,
93+
exp_mean=1.0,
94+
exp_std=0.05)
95+
self.objective = ephys.objectives.SingletonObjective(
96+
self.feature_name,
97+
self.feature)
98+
99+
self.score_calc = \
100+
ephys.objectivescalculators.ObjectivesCalculator([self.objective])
101+
102+
self.nrn = ephys.simulators.NrnSimulator()
103+
104+
self.cell_evaluator = ephys.evaluators.CellEvaluator(
105+
cell_model=self.cell_model,
106+
param_names=['gnabar_hh', 'gkbar_hh'],
107+
fitness_protocols={'Step1': self.protocol},
108+
fitness_calculator=self.score_calc,
109+
sim=self.nrn)

bluepyopt/tests/__init__.py

Whitespace-only changes.

bluepyopt/tests/disable_simplecell_scoop.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
'''
1212

1313
import os
14-
import nose.tools as nt
14+
1515
import subprocess
1616

1717
import bluepyopt as nrp
@@ -31,7 +31,7 @@ def disabled_scoop():
3131
for line in output.split('\n'):
3232
if line.startswith('BEST'):
3333
break
34-
nt.eq_(line, 'BEST: [0.11268238279399023, 0.038129859413828474]')
34+
assert line == 'BEST: [0.11268238279399023, 0.038129859413828474]'
3535

3636

3737
# The rest defines the optimization we run with scoop
Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
11
{
22
"TestL5PCEvaluator.test_eval": {
3-
"Step3.soma.ISI_CV": 0.6622534567234923,
4-
"Step1.soma.adaptation_index2": 0.03197850002471388,
5-
"Step1.soma.doublet_ISI": 1.2362026337828265,
6-
"Step2.soma.doublet_ISI": 0.15421929984301117,
7-
"Step2.soma.adaptation_index2": 0.3162582516145222,
8-
"Step1.soma.ISI_CV": 0.5455435147409059,
9-
"bAP.dend1.AP_amplitude_from_voltagebase": 0.7385516687872027,
10-
"Step1.soma.AP_height": 4.921193388226067,
11-
"Step3.soma.AP_height": 5.61404848409021,
12-
"Step2.soma.mean_frequency": 10.81612636478934,
13-
"Step1.soma.AP_width": 3.1387628026077556,
14-
"Step2.soma.AP_height": 4.267242244939659,
15-
"Step1.soma.AHP_depth_abs": 7.821876775320901,
16-
"Step1.soma.AHP_slow_time": 0.49491112230438067,
17-
"Step3.soma.AHP_depth_abs": 8.533806674002888,
18-
"Step2.soma.AP_width": 2.6208617289330496,
19-
"Step1.soma.mean_frequency": 8.463461042316647,
20-
"Step1.soma.time_to_first_spike": 0.39320541048962065,
21-
"Step3.soma.time_to_first_spike": 0.9558823528730145,
22-
"bAP.soma.AP_width": 2.1999999999995907,
23-
"Step2.soma.AHP_slow_time": 0.47443372402028544,
24-
"Step2.soma.ISI_CV": 0.2645049648938316,
25-
"Step2.soma.AHP_depth_abs_slow": 9.368412779266553,
3+
"bAP.soma.AP_width": 1.9999999999995453,
4+
"bAP.soma.AP_height": 2.50384474984601,
265
"bAP.soma.Spikecount": 0.0,
27-
"Step3.soma.doublet_ISI": 1.92028985507415,
28-
"Step3.soma.adaptation_index2": 2.127232785945305,
29-
"Step3.soma.mean_frequency": 10.737513170460161,
30-
"Step2.soma.time_to_first_spike": 0.4343897692192053,
31-
"Step1.soma.AHP_depth_abs_slow": 7.357253814743192,
32-
"Step3.soma.AHP_slow_time": 1.49339094905374,
33-
"bAP.soma.AP_height": 3.909125166063487,
34-
"Step2.soma.AHP_depth_abs": 9.889050492297098,
35-
"bAP.dend2.AP_amplitude_from_voltagebase": 250.0,
36-
"Step3.soma.AP_width": 3.0637145057952795,
37-
"Step3.soma.AHP_depth_abs_slow": 6.765953222119169
6+
"bAP.dend1.AP_amplitude_from_voltagebase": 0.8267263765251129,
7+
"bAP.dend2.AP_amplitude_from_voltagebase": 0.5795372919702172,
8+
"Step3.soma.AP_height": 0.9933359179333321,
9+
"Step3.soma.AHP_slow_time": 1.7605122073692951,
10+
"Step3.soma.ISI_CV": 0.8718173723988226,
11+
"Step3.soma.doublet_ISI": 0.39855072463652236,
12+
"Step3.soma.adaptation_index2": 1.1379787461057103,
13+
"Step3.soma.mean_frequency": 1.7684352065813025,
14+
"Step3.soma.AHP_depth_abs_slow": 2.24354209144176,
15+
"Step3.soma.AP_width": 3.044293354575099,
16+
"Step3.soma.time_to_first_spike": 0.07352941183310188,
17+
"Step3.soma.AHP_depth_abs": 0.8314513271562025,
18+
"Step2.soma.AP_height": 0.40331820266634766,
19+
"Step2.soma.AHP_slow_time": 0.5635329569575162,
20+
"Step2.soma.ISI_CV": 0.4167583130087039,
21+
"Step2.soma.doublet_ISI": 0.08411961809835558,
22+
"Step2.soma.adaptation_index2": 0.9608331502738571,
23+
"Step2.soma.mean_frequency": 0.3526065669686068,
24+
"Step2.soma.AHP_depth_abs_slow": 0.3002832227214548,
25+
"Step2.soma.AP_width": 2.5539797463199387,
26+
"Step2.soma.time_to_first_spike": 1.1294134000889067,
27+
"Step2.soma.AHP_depth_abs": 0.47825588583451795,
28+
"Step1.soma.AP_height": 1.193221084786481,
29+
"Step1.soma.AHP_slow_time": 0.4051335332920494,
30+
"Step1.soma.ISI_CV": 0.6241490491551318,
31+
"Step1.soma.doublet_ISI": 0.4396536563682781,
32+
"Step1.soma.adaptation_index2": 0.1682382448448352,
33+
"Step1.soma.mean_frequency": 0.9054156314648848,
34+
"Step1.soma.AHP_depth_abs_slow": 0.48627438571478304,
35+
"Step1.soma.AP_width": 3.062383612663639,
36+
"Step1.soma.time_to_first_spike": 1.0572856593789417,
37+
"Step1.soma.AHP_depth_abs": 0.770012863966287
3838
}
39-
}
39+
}

bluepyopt/tests/test_bluepyopt.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@
2121

2222
# pylint:disable=W0612
2323

24-
from nose.plugins.attrib import attr
24+
import pytest
25+
import numpy
2526

2627

27-
@attr('unit')
28+
@pytest.mark.unit
2829
def test_import():
2930
"""bluepyopt: test importing bluepyopt"""
3031
import bluepyopt # NOQA

bluepyopt/tests/test_deapext/__init__.py

Whitespace-only changes.

bluepyopt/tests/test_deapext/test_algorithms.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@
66
import deap.creator
77
import deap.benchmarks
88

9-
import nose.tools as nt
109

1110
import bluepyopt.deapext.algorithms
1211

13-
from nose.plugins.attrib import attr
12+
import pytest
1413

1514

16-
@attr('unit')
15+
@pytest.mark.unit
1716
def test_eaAlphaMuPlusLambdaCheckpoint():
1817
"""deapext.algorithms: Testing eaAlphaMuPlusLambdaCheckpoint"""
1918

@@ -48,13 +47,13 @@ def test_eaAlphaMuPlusLambdaCheckpoint():
4847
cp_filename=None,
4948
continue_cp=False)
5049

51-
nt.assert_true(isinstance(population, list))
52-
nt.assert_equal(len(population), 20)
53-
nt.assert_true(isinstance(logbook, deap.tools.support.Logbook))
54-
nt.assert_true(isinstance(history, deap.tools.support.History))
50+
assert isinstance(population, list)
51+
assert len(population) == 20
52+
assert isinstance(logbook, deap.tools.support.Logbook)
53+
assert isinstance(history, deap.tools.support.History)
5554

5655

57-
@attr('unit')
56+
@pytest.mark.unit
5857
def test_eaAlphaMuPlusLambdaCheckpoint_with_checkpoint():
5958
"""deapext.algorithms: Testing eaAlphaMuPlusLambdaCheckpoint"""
6059

@@ -115,4 +114,4 @@ def test_eaAlphaMuPlusLambdaCheckpoint_with_checkpoint():
115114
cp_filename='cp_test',
116115
continue_cp=True)
117116
for ind1, ind2 in zip(new_population, population):
118-
nt.assert_equal(list(ind1), list(ind2))
117+
assert list(ind1) == list(ind2)

0 commit comments

Comments
 (0)