Skip to content

Commit 033e1ef

Browse files
committed
Make test robust against changes in synapse reordering and invalidation of SynapseCollection
1 parent fa86018 commit 033e1ef

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

testsuite/pytests/test_get_connections.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import pandas as pd
3232
import pandas.testing as pdtest
3333
import pytest
34+
from testutil import expected_synapse_counts, synapse_counts
3435

3536

3637
@pytest.fixture(autouse=True)
@@ -60,15 +61,10 @@ def test_get_connections_with_node_collection_step():
6061
nodes = nest.Create("iaf_psc_alpha", 3)
6162
nest.Connect(nodes, nodes)
6263

63-
conns = nest.GetConnections(nodes[::2])
64-
actual_sources = conns.get("source")
65-
actual_targets = conns.get("target")
66-
67-
expected_sources = [1, 1, 1, 3, 3, 3]
68-
expected_targets = [1, 2, 3, 1, 2, 3]
64+
actual = synapse_counts(nest.GetConnections(nodes[::2]), criteria=["source", "target"])
65+
expected = expected_synapse_counts(sources=[1, 1, 1, 3, 3, 3], targets=[1, 2, 3, 1, 2, 3])
6966

70-
assert actual_sources == expected_sources
71-
assert actual_targets == expected_targets
67+
assert actual == expected
7268

7369

7470
def test_get_connections_with_sliced_node_collection():
@@ -77,11 +73,10 @@ def test_get_connections_with_sliced_node_collection():
7773
nodes = nest.Create("iaf_psc_alpha", 11)
7874
nest.Connect(nodes, nodes)
7975

80-
conns = nest.GetConnections(nodes[1:9:3])
81-
actual_sources = conns.get("source")
76+
actual = synapse_counts(nest.GetConnections(nodes[1:9:3]), criteria=["source"])
77+
expected = expected_synapse_counts(sources=[2] * 11 + [5] * 11 + [8] * 11)
8278

83-
expected_sources = [2] * 11 + [5] * 11 + [8] * 11
84-
assert actual_sources == expected_sources
79+
assert actual == expected
8580

8681

8782
def test_get_connections_with_sliced_node_collection_2():
@@ -91,11 +86,10 @@ def test_get_connections_with_sliced_node_collection_2():
9186
nest.Connect(nodes, nodes)
9287

9388
# ([ 2 3 4 ] + [ 8 9 10 11 ])[::3] -> [2 8 11]
94-
conns = nest.GetConnections((nodes[1:4] + nodes[7:])[::3])
95-
actual_sources = conns.get("source")
89+
actual = synapse_counts(nest.GetConnections((nodes[1:4] + nodes[7:])[::3]), criteria=["source"])
90+
expected = expected_synapse_counts(sources=[2] * 11 + [8] * 11 + [11] * 11)
9691

97-
expected_sources = [2] * 11 + [8] * 11 + [11] * 11
98-
assert actual_sources == expected_sources
92+
assert actual == expected
9993

10094

10195
def test_get_connections_bad_source_raises():
@@ -111,11 +105,17 @@ def test_get_connections_bad_source_raises():
111105
def test_get_connections_correct_table_with_node_collection_step():
112106
"""
113107
Test that ``GetConnections`` table from ``NodeCollection`` sliced in step match expectations.
108+
109+
This test is for internal testing also of the synapse sorting process. It therefore requires
110+
that the connection infrastructure has been updated before connections are read out.
114111
"""
115112

116113
nodes = nest.Create("iaf_psc_alpha", 3)
117114
nest.Connect(nodes, nodes)
118115

116+
# Force synapse sorting
117+
nest.Simulate(0.1)
118+
119119
conns = nest.GetConnections(nodes[::2])
120120
actual_row = [
121121
conns.get("source")[3],
@@ -134,11 +134,17 @@ def test_get_connections_correct_table_with_node_collection_step():
134134
def test_get_connections_correct_table_with_node_collection_index():
135135
"""
136136
Test that ``GetConnections`` table from ``NodeCollection`` index match expectations.
137+
138+
This test is for internal testing also of the synapse sorting process. It therefore requires
139+
that the connection infrastructure has been updated before connections are read out.
137140
"""
138141

139142
nodes = nest.Create("iaf_psc_alpha", 3)
140143
nest.Connect(nodes, nodes)
141144

145+
# Force synapse sorting
146+
nest.Simulate(0.1)
147+
142148
actual_conns = pd.DataFrame(
143149
nest.GetConnections(nodes[0]).get(["source", "target", "target_thread", "synapse_id", "port"])
144150
)

0 commit comments

Comments
 (0)