Skip to content

Commit ac59615

Browse files
authored
Merge pull request #2757 from med-ayssar/test_set_start_stop_origin
Convert test-set-start-stop-origin.sli to pytest.
2 parents 509f3f8 + aa8b807 commit ac59615

File tree

2 files changed

+128
-174
lines changed

2 files changed

+128
-174
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# test_set_start_stop_origin.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+
Test if `start`, `stop` and `origin` are set properly.
24+
For all models (i.e, Devices) having `start`, `stop`, and `origin` parameters, this test
25+
checks the following:
26+
- Default values can be set successfully.
27+
- Nodes are created with correct default values.
28+
- Nodes can be created with correct default values from the command line.
29+
- Parameters can be set via SetStatus.
30+
"""
31+
32+
import nest
33+
import numpy as np
34+
import pytest
35+
36+
37+
@pytest.fixture(autouse=True)
38+
def reset():
39+
nest.ResetKernel()
40+
41+
42+
def device_attributes():
43+
return set(["start", "stop", "origin"])
44+
45+
46+
def get_devices():
47+
all_models = nest.node_models
48+
models = [m for m in all_models if len(device_attributes().intersection(nest.GetDefaults(m).keys())) > 0]
49+
return models
50+
51+
52+
@pytest.mark.parametrize("device", get_devices())
53+
def test_one_attr_implies_all_attr(device):
54+
"""Check that any model that has one of the attributes `start`, ``stop` or `origin`, it must have all"""
55+
56+
model_defaults = nest.GetDefaults(device)
57+
required_all_attr = device_attributes()
58+
59+
actual = len(required_all_attr.intersection(model_defaults.keys()))
60+
excepted = len(required_all_attr)
61+
62+
assert actual == excepted
63+
64+
65+
@pytest.mark.parametrize("device", get_devices())
66+
def test_initial_default_value(device):
67+
"""Ensure that no default value is equal to test value."""
68+
69+
model_defaults = nest.GetDefaults(device, device_attributes())
70+
71+
unexpected_value = 1234.0 * 42
72+
assert np.all(model_defaults != unexpected_value)
73+
74+
75+
@pytest.mark.parametrize("device", get_devices())
76+
@pytest.mark.parametrize("attr", device_attributes())
77+
def test_setting_new_default_value(device, attr):
78+
"""Check that default value of each attribute can be set."""
79+
80+
value = 1234.0 * 42
81+
nest.SetDefaults(device, {attr: value})
82+
83+
actual = nest.GetDefaults(device, attr)
84+
85+
assert actual == value
86+
87+
88+
@pytest.mark.parametrize("device", get_devices())
89+
@pytest.mark.parametrize("attr", device_attributes())
90+
def test_inheriting_new_default_on_instance(device, attr):
91+
"""Check that default value of each attribute are transferred to the model instance."""
92+
93+
value = 1234.0 * 42
94+
95+
nest.SetDefaults(device, {attr: value})
96+
97+
actual = nest.Create(device).get(attr)
98+
99+
assert actual == value
100+
101+
102+
@pytest.mark.parametrize("device", get_devices())
103+
@pytest.mark.parametrize("attr", device_attributes())
104+
def test_setting_new_value_on_create(device, attr):
105+
"""Check that values can be set on creation."""
106+
107+
value = 1234.0 * 42
108+
109+
device_instance = nest.Create(device, params={attr: value})
110+
111+
actual = device_instance.get(attr)
112+
113+
assert actual == value
114+
115+
116+
@pytest.mark.parametrize("device", get_devices())
117+
@pytest.mark.parametrize("attr", device_attributes())
118+
def test_setting_new_value_after_create(device, attr):
119+
"""Check that values can be set on model instances."""
120+
121+
value = 1234.0 * 42
122+
123+
device_instance = nest.Create(device)
124+
device_instance.set({attr: value})
125+
126+
actual = device_instance.get(attr)
127+
128+
assert actual == value

testsuite/unittests/test_set_start_stop_origin.sli

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

0 commit comments

Comments
 (0)