Skip to content

Commit

Permalink
Add tests for net.add_electrode
Browse files Browse the repository at this point in the history
  • Loading branch information
ntolley committed Apr 2, 2021
1 parent 8cbf05d commit 055962e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
5 changes: 3 additions & 2 deletions hnn_core/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -1058,9 +1058,10 @@ def add_electrode(self, electrode_pos, sigma=3.0, method='psa'):
'psa' (default), i.e., point source approximation or line source
approximation, i.e., 'lsa'
"""
_validate_type(electrode_pos, (list, tuple))
_validate_type(sigma, (float, int))
_validate_type(electrode_pos, (list, tuple), 'electrode_pos')
_validate_type(sigma, (float, int), 'sigma')
assert sigma > 0.0
_validate_type(method, str, 'method')
_check_option('method', method, ['psa', 'lsa'])
if isinstance(electrode_pos, tuple):
electrode_pos = [electrode_pos]
Expand Down
34 changes: 34 additions & 0 deletions hnn_core/tests/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,40 @@ def test_network():
net.clear_connectivity()
assert len(net.connectivity) == 0

# Test LFP electrodes
kwargs_default = {
'electrode_pos': (2, 2, 400),
'sigma': 3.0, 'method': 'psa'}
net.add_electrode(**kwargs_default)
kwargs_default['electrode_pos'] = [(2, 2, 400), (6, 6, 800)]
net.add_electrode(**kwargs_default)
assert len(net.lfp) == 3
with pytest.raises(AssertionError):
kwargs = kwargs_default.copy()
kwargs['electrode_pos'] = [(2, 2), (6, 6, 800)]
net.add_electrode(**kwargs)
with pytest.raises(AssertionError):
kwargs = kwargs_default.copy()
kwargs['sigma'] = -1.0
net.add_electrode(**kwargs)

match = "Invalid value for the 'method' parameter"
with pytest.raises(ValueError, match=match):
kwargs = kwargs_default.copy()
kwargs['method'] = 'LSA'
net.add_electrode(**kwargs)

bad_kwargs = [
('electrode_pos', '[(2, 2, 400), (6, 6, 800)]'),
('electrode_pos', (2, '2', 400)),
('sigma', '3.0'), ('method', 3.0)]
for arg, item in bad_kwargs:
kwargs = kwargs_default.copy()
kwargs[arg] = item
match = 'must be an instance of'
with pytest.raises(TypeError, match=match):
net.add_electrode(**kwargs)


def test_tonic_biases():
"""Test tonic biases."""
Expand Down

0 comments on commit 055962e

Please sign in to comment.