From 06ab8a681764afca353eb5ad9301568bd8c2e08d Mon Sep 17 00:00:00 2001 From: Mushkan Rana Date: Sat, 28 Mar 2026 10:08:49 +0000 Subject: [PATCH 1/2] test:add cython synapses regression coverage for #1769 --- brian2/tests/test_synapses.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/brian2/tests/test_synapses.py b/brian2/tests/test_synapses.py index cabfaf94d..41d146db4 100644 --- a/brian2/tests/test_synapses.py +++ b/brian2/tests/test_synapses.py @@ -3730,6 +3730,34 @@ def test_setting_from_weight_matrix(): assert all(syn.w[i, j] == weights[i, j]) +def test_synapses_cython_codegen_target_runs(): + from brian2 import prefs, start_scope, run, ms, NeuronGroup, Synapses + + old_target = prefs.codegen.target + prefs.codegen.target = "cython" + + try: + start_scope() + + G = NeuronGroup( + 2, + "v : 1", + threshold="v > 1", + reset="v = 0", + ) + + S = Synapses(G, G, on_pre="v_post += 1") + S.connect(i=0, j=1) + + G.v = [2, 0] + run(1 * ms) + + assert G.v[0] == pytest.approx(0) + assert G.v[1] == pytest.approx(1) + finally: + prefs.codegen.target = old_target + + if __name__ == "__main__": SANITY_CHECK_PERMUTATION_ANALYSIS_EXAMPLE = True # prefs.codegen.target = 'numpy' @@ -3832,5 +3860,6 @@ def test_setting_from_weight_matrix(): test_synaptic_subgroups() test_incorrect_connect_N_incoming_outgoing() test_setting_from_weight_matrix() + test_synapses_cython_codegen_target_runs() print("Tests took", time.time() - start) From 9d3cc382a1e9d024512f4fc8805ab2605bd3c5f3 Mon Sep 17 00:00:00 2001 From: Mushkan Rana Date: Sun, 29 Mar 2026 10:05:53 +0530 Subject: [PATCH 2/2] test: remove direct test call from synapses regression test --- brian2/tests/test_synapses.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/brian2/tests/test_synapses.py b/brian2/tests/test_synapses.py index 41d146db4..397fa1806 100644 --- a/brian2/tests/test_synapses.py +++ b/brian2/tests/test_synapses.py @@ -3731,7 +3731,6 @@ def test_setting_from_weight_matrix(): def test_synapses_cython_codegen_target_runs(): - from brian2 import prefs, start_scope, run, ms, NeuronGroup, Synapses old_target = prefs.codegen.target prefs.codegen.target = "cython" @@ -3752,8 +3751,7 @@ def test_synapses_cython_codegen_target_runs(): G.v = [2, 0] run(1 * ms) - assert G.v[0] == pytest.approx(0) - assert G.v[1] == pytest.approx(1) + assert_allclose(G.v[:], [0, 1]) finally: prefs.codegen.target = old_target @@ -3860,6 +3858,6 @@ def test_synapses_cython_codegen_target_runs(): test_synaptic_subgroups() test_incorrect_connect_N_incoming_outgoing() test_setting_from_weight_matrix() - test_synapses_cython_codegen_target_runs() + print("Tests took", time.time() - start)