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

Commit 0d0f5db

Browse files
author
Jaquier Aurélien Tristan
committed
lint fix and mark extra_features_utils tests as unit tests
1 parent 166c783 commit 0d0f5db

File tree

10 files changed

+84
-38
lines changed

10 files changed

+84
-38
lines changed

bluepyopt/ephys/objectives.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def __str__(self):
8585
"""String representation"""
8686

8787
return '( %s )' % self.features[0]
88-
88+
8989

9090
class SingletonWeightObjective(EFeatureObjective):
9191

bluepyopt/ephys/parameters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ class NrnPointProcessParameter(NrnParameter, DictMixin):
252252

253253
"""Parameter of a section"""
254254
SERIALIZED_FIELDS = ('name', 'value', 'frozen', 'bounds', 'param_name',
255-
'value_scaler', 'locations', 'param_name',
255+
'value_scaler', 'locations', 'param_name',
256256
'param_dependancies')
257257

258258
def __init__(

bluepyopt/ephys/parameterscalers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def __str__(self):
9292
class NrnSegmentSectionDistanceScaler(ParameterScaler, DictMixin):
9393

9494
"""Scaler based on distance from soma"""
95-
SERIALIZED_FIELDS = ('name', 'comment', 'distribution',
95+
SERIALIZED_FIELDS = ('name', 'comment', 'distribution',
9696
"distribution", "dist_param_names",
9797
"ref_sec", "ref_location",)
9898

bluepyopt/tests/test_ephys/test_extra_features_utils.py

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@
1616
waveform = numpy.array([waveforms[0]])
1717
sampling_freq = 10000
1818

19+
20+
@pytest.mark.unit
1921
def test_peak_to_valley():
2022
"""ephys.extra_features_utils: Test peak_to_valley"""
2123
ptv = ephys.extra_features_utils.peak_to_valley(waveform, sampling_freq)
2224
assert len(ptv) == 1
2325
assert ptv[0] == pytest.approx(0.0013)
2426

2527

28+
@pytest.mark.unit
2629
def test_peak_trough_ratio():
2730
"""ephys.extra_features_utils: Test peak_trough_ratio"""
2831
ptratio = ephys.extra_features_utils.peak_trough_ratio(waveform)
@@ -31,6 +34,7 @@ def test_peak_trough_ratio():
3134
assert ptratio[0] == pytest.approx(0.53804035)
3235

3336

37+
@pytest.mark.unit
3438
def test_halfwidth():
3539
"""ephys.extra_features_utils: Test halfwidth"""
3640
ret = ephys.extra_features_utils.halfwidth(waveform, sampling_freq, True)
@@ -41,66 +45,95 @@ def test_halfwidth():
4145
assert hw[0] == pytest.approx(0.0015)
4246

4347

48+
@pytest.mark.unit
4449
def test_repolarization_slope():
4550
"""ephys.extra_features_utils: Test repolarization_slope"""
46-
ret = ephys.extra_features_utils.repolarization_slope(waveform, sampling_freq, True)
51+
ret = ephys.extra_features_utils.repolarization_slope(
52+
waveform, sampling_freq, True
53+
)
4754
assert len(ret) == 2
4855

49-
rslope = ephys.extra_features_utils.repolarization_slope(waveform, sampling_freq)
56+
rslope = ephys.extra_features_utils.repolarization_slope(
57+
waveform, sampling_freq
58+
)
5059
assert len(rslope) == 1
5160
assert rslope[0] == pytest.approx(73.12572131)
5261

5362

63+
@pytest.mark.unit
5464
def test_recovery_slope():
5565
"""ephys.extra_features_utils: Test recovery_slope"""
56-
window=0.7
57-
rslope = ephys.extra_features_utils.recovery_slope(waveform, sampling_freq, window=window)
66+
window = 0.7
67+
rslope = ephys.extra_features_utils.recovery_slope(
68+
waveform, sampling_freq, window=window
69+
)
5870
assert len(rslope) == 1
5971
assert rslope[0] == pytest.approx(-3.63355521)
6072

6173

74+
@pytest.mark.unit
6275
def test_peak_image():
6376
"""ephys.extra_features_utils: Test peak_image"""
64-
rel_peaks = ephys.extra_features_utils.peak_image(waveforms, sign="negative")
77+
rel_peaks = ephys.extra_features_utils.peak_image(
78+
waveforms, sign="negative"
79+
)
6580
assert len(rel_peaks) == 209
6681
assert rel_peaks[0] == pytest.approx(0.06084468)
6782

68-
rel_peaks = ephys.extra_features_utils.peak_image(waveforms, sign="positive")
83+
rel_peaks = ephys.extra_features_utils.peak_image(
84+
waveforms, sign="positive"
85+
)
6986
assert len(rel_peaks) == 209
7087
assert rel_peaks[0] == pytest.approx(0.10850117)
7188

7289

90+
@pytest.mark.unit
7391
def test_relative_amplitude():
7492
"""ephys.extra_features_utils: Test relative_amplitude"""
75-
rel_amp = ephys.extra_features_utils.relative_amplitude(waveforms, sign="negative")
93+
rel_amp = ephys.extra_features_utils.relative_amplitude(
94+
waveforms, sign="negative"
95+
)
7696
assert len(rel_amp) == 209
7797
assert rel_amp[0] == pytest.approx(0.09513392)
7898

79-
rel_amp = ephys.extra_features_utils.relative_amplitude(waveforms, sign="positive")
99+
rel_amp = ephys.extra_features_utils.relative_amplitude(
100+
waveforms, sign="positive"
101+
)
80102
assert len(rel_amp) == 209
81103
assert rel_amp[0] == pytest.approx(0.2135929)
82104

83105

106+
@pytest.mark.unit
84107
def test_peak_time_diff():
85108
"""ephys.extra_features_utils: Test peak_time_diff"""
86-
peak_t = ephys.extra_features_utils.peak_time_diff(waveforms, sampling_freq, sign="negative")
109+
peak_t = ephys.extra_features_utils.peak_time_diff(
110+
waveforms, sampling_freq, sign="negative"
111+
)
87112
assert len(peak_t) == 209
88113
assert peak_t[0] == pytest.approx(0.0009)
89114

90-
peak_t = ephys.extra_features_utils.peak_time_diff(waveforms, sampling_freq, sign="positive")
115+
peak_t = ephys.extra_features_utils.peak_time_diff(
116+
waveforms, sampling_freq, sign="positive"
117+
)
91118
assert len(peak_t) == 209
92119
assert peak_t[0] == pytest.approx(0.0007)
93120

94121

122+
@pytest.mark.unit
95123
def test__get_trough_and_peak_idx():
96124
"""ephys.extra_features_utils: Test _get_trough_and_peak_idx"""
97-
t_idx, p_idx = ephys.extra_features_utils._get_trough_and_peak_idx(waveform)
125+
t_idx, p_idx = ephys.extra_features_utils._get_trough_and_peak_idx(
126+
waveform
127+
)
98128
assert t_idx == 102
99129
assert p_idx == 115
100130

101131

132+
@pytest.mark.unit
102133
def test_calculate_features():
103134
"""ephys.extra_features_utils: Test calculate_features"""
104-
feats = ephys.extra_features_utils.calculate_features(waveforms, sampling_freq)
135+
feats = ephys.extra_features_utils.calculate_features(
136+
waveforms, sampling_freq
137+
)
105138
for feature_name in ephys.extra_features_utils.all_1D_features:
106-
assert feature_name in feats
139+
assert feature_name in feats

bluepyopt/tests/test_ephys/test_features.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ def test_extraFELFeature():
260260
name = 'test_extraFELFeature'
261261
stim_start = 400
262262
stim_end = 1750
263-
fs = 10 # sampling freq (kHz)
263+
fs = 10
264264
ms_cut = [10, 25]
265265

266266
# load responses from file
@@ -288,11 +288,10 @@ def test_extraFELFeature():
288288
fs=fs,
289289
ms_cut=ms_cut
290290
)
291-
291+
292292
ret = efeature.calculate_feature(responses, raise_warnings=True)
293293
assert len(ret) == 209
294294

295-
296295
# compute for 1 electrode
297296
efeature = efeatures.extraFELFeature(
298297
name=name,

bluepyopt/tests/test_ephys/test_models.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,9 @@ def test_CellModel_destroy():
184184
def test_lfpy_create_empty_template():
185185
"""ephys.models: Test creation of lfpy empty template"""
186186
template_name = 'FakeTemplate'
187-
hoc_template = ephys.models.LFPyCellModel.create_empty_template(template_name)
187+
hoc_template = ephys.models.LFPyCellModel.create_empty_template(
188+
template_name
189+
)
188190
sim.neuron.h(hoc_template)
189191
assert hasattr(sim.neuron.h, template_name)
190192

@@ -225,7 +227,9 @@ def test_load_lfpy_hoc_template():
225227
"""ephys.models: Test loading of hoc template with lfpy cell"""
226228

227229
template_name = 'test_load_hoc'
228-
hoc_string = ephys.models.LFPyCellModel.create_empty_template(template_name)
230+
hoc_string = ephys.models.LFPyCellModel.create_empty_template(
231+
template_name
232+
)
229233
ephys.models.HocCellModel.load_hoc_template(sim, hoc_string)
230234
assert hasattr(sim.neuron.h, template_name)
231235

@@ -245,12 +249,15 @@ def test_LFPyCellModel_create_hoc():
245249

246250
morph0 = ephys.morphologies.NrnFileMorphology(
247251
simple_morphology_path,
248-
do_replace_axon=True)
252+
do_replace_axon=True
253+
)
249254

250-
cell_model = ephys.models.LFPyCellModel('LFPyCellModel',
251-
morph=morph0,
252-
mechs=[],
253-
params=[])
255+
cell_model = ephys.models.LFPyCellModel(
256+
'LFPyCellModel',
257+
morph=morph0,
258+
mechs=[],
259+
params=[]
260+
)
254261

255262
hoc_string = cell_model.create_hoc({})
256263
assert 'begintemplate LFPyCellModel' in hoc_string

bluepyopt/tests/test_ephys/test_parameterscalers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def test_NrnSegmentSomaDistanceScaler_dist_params():
3838

3939
@pytest.mark.unit
4040
def test_NrnSegmentSectionDistanceScaler_eval_dist_with_dict():
41-
"""ephys.parameterscalers: eval_dist of NrnSegmentSectionDistanceScaler with dict as values"""
41+
"""ephys.parameterscalers: eval_dist of NrnSegmentSectionDistanceScaler"""
4242

4343
dist = '{param1_somatic} + (1 - (abs({distance} - 8) / 4)) * {value}'
4444

bluepyopt/tests/test_ephys/test_recordings.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ def test_lfprecording_instantiate():
100100
test_morph = ephys.morphologies.NrnFileMorphology(simple_morphology_path)
101101

102102
recording = ephys.recordings.LFPRecording()
103-
lfpy_cell = ephys.models.LFPyCellModel(name="lfpy_cell", morph=test_morph, mechs=[])
103+
lfpy_cell = ephys.models.LFPyCellModel(
104+
name="lfpy_cell", morph=test_morph, mechs=[]
105+
)
104106
neuron_sim = ephys.simulators.LFPySimulator(LFPyCellModel=lfpy_cell)
105107
lfpy_cell.instantiate(sim=neuron_sim)
106108

@@ -111,4 +113,3 @@ def test_lfprecording_instantiate():
111113
assert recording.instantiated
112114

113115
lfpy_cell.destroy(sim=neuron_sim)
114-

bluepyopt/tests/test_ephys/test_simulators.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def test_lfpyimulator_init_windows():
169169

170170
@pytest.mark.unit
171171
def test__lfpysimulator_neuron_import():
172-
"""ephys.simulators: test if neuron import from LFPySimulator was successful"""
172+
"""ephys.simulators: test neuron import from LFPySimulator"""
173173
from bluepyopt import ephys # NOQA
174174
empty_cell = ephys.models.LFPyCellModel(name="empty_cell")
175175
neuron_sim = ephys.simulators.LFPySimulator(LFPyCellModel=empty_cell)
@@ -178,7 +178,7 @@ def test__lfpysimulator_neuron_import():
178178

179179
@pytest.mark.unit
180180
def test_lfpysim_run_cvodeactive_dt_exception():
181-
"""ephys.simulators: test if LFPySimulator run returns exception cvode and dt both used"""
181+
"""ephys.simulators: test if LFPySimulator run returns exception"""
182182

183183
from bluepyopt import ephys # NOQA
184184
TESTDATA_DIR = os.path.join(
@@ -187,13 +187,20 @@ def test_lfpysim_run_cvodeactive_dt_exception():
187187
simple_morphology_path = os.path.join(TESTDATA_DIR, 'simple.swc')
188188
test_morph = ephys.morphologies.NrnFileMorphology(simple_morphology_path)
189189

190-
lfpy_cell = ephys.models.LFPyCellModel(name="lfpy_cell", morph=test_morph, mechs=[])
190+
lfpy_cell = ephys.models.LFPyCellModel(
191+
name="lfpy_cell", morph=test_morph, mechs=[]
192+
)
191193
neuron_sim = ephys.simulators.LFPySimulator(LFPyCellModel=lfpy_cell)
192194
lfpy_cell.instantiate(sim=neuron_sim)
193195

194-
with pytest.raises(ValueError, match=('NrnSimulator: '
195-
'Impossible to combine the dt argument when '
196-
'cvode_active is True in the NrnSimulator run method')):
196+
with pytest.raises(
197+
ValueError,
198+
match=(
199+
'NrnSimulator: '
200+
'Impossible to combine the dt argument when '
201+
'cvode_active is True in the NrnSimulator run method'
202+
),
203+
):
197204
neuron_sim.run(10, dt=0.1, cvode_active=True)
198205

199206
lfpy_cell.destroy(sim=neuron_sim)
@@ -202,7 +209,7 @@ def test_lfpysim_run_cvodeactive_dt_exception():
202209
@pytest.mark.unit
203210
@mock.patch('glob.glob')
204211
def test_lfpysimulator_disable_banner_exception(mock_glob):
205-
"""ephys.simulators: test if LFPySimulator disable_banner raises exception"""
212+
"""ephys.simulators: test LFPySimulator disable_banner raises exception"""
206213
mock_glob.return_value = []
207214

208215
import warnings

bluepyopt/tests/test_ephys/testmodels/dummycells.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ def destroy(self, sim=None):
6060
self.persistent = []
6161

6262

63-
6463
class DummyLFPyCellModel1(ephys.models.Model):
6564

6665
"""Dummy LFPy cell model 1"""
@@ -126,4 +125,4 @@ def __init__(self):
126125
def destroy(self, sim=None):
127126
"""Destroy cell from simulator"""
128127

129-
self.persistent = []
128+
self.persistent = []

0 commit comments

Comments
 (0)