Skip to content

Commit cfc9b43

Browse files
authored
Merge pull request #2963 from nicolossus/port_test_wfr_settings
Port `test_wfr_settings.sli` to Pytest
2 parents 739357e + 2404a19 commit cfc9b43

File tree

2 files changed

+109
-144
lines changed

2 files changed

+109
-144
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# test_wfr_settings.py
4+
#
5+
# This file is part of NEST.
6+
#
7+
# Copyright (C) 2004 The NEST Initiative
8+
#
9+
# NEST is free software: you can redistribute it and/or modify
10+
# it under the terms of the GNU General Public License as published by
11+
# the Free Software Foundation, either version 2 of the License, or
12+
# (at your option) any later version.
13+
#
14+
# NEST is distributed in the hope that it will be useful,
15+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
# GNU General Public License for more details.
18+
#
19+
# You should have received a copy of the GNU General Public License
20+
# along with NEST. If not, see <http://www.gnu.org/licenses/>.
21+
22+
23+
"""
24+
This set of tests checks the possible settings for the waveform relaxation method.
25+
26+
The waveform relaxation method is used for iterative solution when connections
27+
without delay are present (e.g. gap junctions).
28+
"""
29+
30+
import nest
31+
import pytest
32+
33+
34+
@pytest.fixture(autouse=True)
35+
def reset():
36+
nest.ResetKernel()
37+
38+
39+
@pytest.mark.parametrize("use_wfr", [False, True])
40+
def test_set_wfr(use_wfr):
41+
"""Test that ``use_wfr`` can be set."""
42+
43+
nest.set(use_wfr=use_wfr)
44+
45+
46+
def test_set_wfr_after_node_creation_raises():
47+
"""Ensure that ``use_wfr`` cannot be set after nodes are created."""
48+
49+
nest.Create("iaf_psc_alpha")
50+
51+
with pytest.raises(nest.kernel.NESTErrors.KernelException):
52+
nest.set(use_wfr=True)
53+
54+
55+
def test_wfr_comm_interval_lower_than_resolution_raises():
56+
"""Ensure that ``wfr_comm_interval`` cannot be set lower than the resolution."""
57+
58+
with pytest.raises(nest.kernel.NESTErrors.KernelException):
59+
nest.set(resolution=0.1, wfr_comm_interval=0.05)
60+
61+
62+
def test_wfr_comm_interval_cannot_be_set_when_use_wfr_false():
63+
"""Ensure that ``wfr_comm_interval`` cannot be set if ``use_wfr=False``."""
64+
65+
with pytest.raises(nest.kernel.NESTErrors.KernelException):
66+
nest.set(use_wfr=False, wfr_comm_interval=0.5)
67+
68+
69+
def test_wfr_comm_interval_set_to_resolution_after_disabling_use_wfr():
70+
"""Ensure that ``wfr_comm_interval`` is set to and updated with resolution when disabling ``use_wfr``."""
71+
72+
nest.set(use_wfr=True, wfr_comm_interval=0.5)
73+
74+
# Disable use_wfr
75+
nest.set(resolution=0.1, use_wfr=False)
76+
77+
assert nest.resolution == 0.1
78+
assert nest.wfr_comm_interval == nest.resolution
79+
80+
# Ensure that wfr_comm_interval is updated with the resolution
81+
nest.set(resolution=0.2)
82+
83+
assert nest.resolution == 0.2
84+
assert nest.wfr_comm_interval == nest.resolution
85+
86+
87+
def test_wfr_comm_interval_not_updated_with_resolution_when_use_wfr_true():
88+
"""Ensure that ``wfr_comm_interval`` is not updated with resolution if ``use_wfr=True``."""
89+
90+
nest.set(use_wfr=True, wfr_comm_interval=2.0)
91+
nest.set(resolution=0.1)
92+
assert nest.wfr_comm_interval == 2.0
93+
94+
95+
@pytest.mark.skipif_missing_gsl
96+
@pytest.mark.parametrize("use_wfr", [False, True])
97+
def test_use_wfr_set_correctly_in_created_node(use_wfr):
98+
"""
99+
Test correct set of ``use_wfr`` in created node.
100+
101+
The test verifies both the case with ``use_wfr`` off and on.
102+
"""
103+
104+
nest.set(use_wfr=use_wfr)
105+
106+
nrn_gap = nest.Create("hh_psc_alpha_gap")
107+
nest.Simulate(5.0)
108+
109+
assert nrn_gap.node_uses_wfr == use_wfr

testsuite/unittests/test_wfr_settings.sli

Lines changed: 0 additions & 144 deletions
This file was deleted.

0 commit comments

Comments
 (0)