From 35c73c9f232436fc5598a4f10a481c28e6908554 Mon Sep 17 00:00:00 2001 From: Marcel Stimberg Date: Mon, 24 Jun 2024 11:42:41 +0200 Subject: [PATCH] Add a test for soma compartments not at start --- brian2/tests/test_morphology.py | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/brian2/tests/test_morphology.py b/brian2/tests/test_morphology.py index 0fc99d13f..e287aaf1a 100644 --- a/brian2/tests/test_morphology.py +++ b/brian2/tests/test_morphology.py @@ -8,6 +8,7 @@ from brian2.spatialneuron import * from brian2.tests.utils import assert_allclose from brian2.units import DimensionMismatchError, cm, second, um +from brian2.utils.logger import catch_logs @pytest.mark.codegen_independent @@ -718,6 +719,39 @@ def test_tree_soma_from_points_3_point_soma_incorrect(): Morphology.from_points(points) +@pytest.mark.codegen_independent +def test_tree_soma_from_points_somas_not_at_start(): + # A single soma in the middle (ununusal but possible) + points = [ # dendrite + (1, "dend", 100, 0, 0, 10, -1), + (2, "dend", 100, 0, 0, 10, 1), + (3, "dend", 100, 0, 0, 10, 2), + (4, "soma", 100, 0, 0, 30, 3), + (5, "dend2", 130, 0, 0, 10, 4), + (6, "dend2", 160, 0, 0, 10, 5), + ] + morpho = Morphology.from_points(points) + assert morpho.total_sections == 3 + assert morpho.total_compartments == 5 + + # Several somata (probably an error) + points = [ # dendrite + (1, "dend", 0, 0, 0, 10, -1), + (2, "dend", 30, 0, 0, 10, 1), + (3, "dend", 60, 0, 0, 10, 2), + (4, "soma", 90, 0, 0, 30, 3), + (5, "dend2", 120, 70, 0, 10, 4), + (6, "dend2", 150, 70, 0, 10, 5), + (7, "soma", 180, 40, 0, 30, 6), + ] + with catch_logs() as logs: + morpho = Morphology.from_points(points) + assert len(logs) == 1 + assert logs[0][1].endswith("soma_compartments") + assert morpho.total_sections == 4 + assert morpho.total_compartments == 6 + + @pytest.mark.codegen_independent def test_tree_soma_from_swc(): swc_content = """