Skip to content

Commit

Permalink
warning to log in serialized_sections #176 (#178)
Browse files Browse the repository at this point in the history
* warning to log in serialized_sections  #176

* update test_serialized_sections

* format
  • Loading branch information
anilbey authored May 6, 2024
1 parent 8a134f3 commit d3d6d3d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
8 changes: 3 additions & 5 deletions bluecellulab/cell/serialized_sections.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,14 @@
index."""
from __future__ import annotations
import logging
import warnings
import neuron
from bluecellulab.type_aliases import HocObjectType, NeuronSection


logger = logging.getLogger(__name__)
warnings.filterwarnings("once", category=UserWarning, module=__name__)


class SerializedSections:

def __init__(self, cell: HocObjectType) -> None:
self.isec2sec: dict[int, NeuronSection] = {}
n = cell.nSecAll
Expand All @@ -37,7 +34,8 @@ def __init__(self, cell: HocObjectType) -> None:
raise ValueError("Error: failure in mk2_isec2sec()")

if v_value < 0:
warnings.warn(
f"[Warning] SerializedSections: v(0.0001) < 0. index={index} v()={v_value}")
logging.debug(
f"[Warning] SerializedSections: v(0.0001) < 0. index={index} v()={v_value}"
)
else:
self.isec2sec[int(v_value)] = neuron.h.SectionRef(sec=sec)
11 changes: 7 additions & 4 deletions tests/test_cell/test_serialized_sections.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Unit tests for serialized_sections module."""
import logging
from pathlib import Path

import pytest
Expand All @@ -11,11 +12,12 @@


@pytest.mark.v5
def test_serialized_sections():
def test_serialized_sections(caplog):
"""Test the SerializedSections class."""
cell = Cell(
"%s/examples/cell_example1/test_cell.hoc" % script_dir,
"%s/examples/cell_example1" % script_dir)
"%s/examples/cell_example1" % script_dir,
)

serialized_sections = SerializedSections(cell.cell.getCell())
assert len(serialized_sections.isec2sec) == 135
Expand All @@ -32,8 +34,9 @@ def test_serialized_sections():
section_list = modified_cell.all
first_section = next(iter(section_list))
first_section(0.0001).v = -2
with pytest.warns(UserWarning):
SerializedSections(modified_cell)
caplog.set_level(logging.DEBUG)
SerializedSections(modified_cell)
assert "[Warning] SerializedSections: v(0.0001) < 0" in caplog.text

modified_cell.nSecAll = -1
with pytest.raises(ValueError):
Expand Down

0 comments on commit d3d6d3d

Please sign in to comment.