Skip to content

Commit

Permalink
Add check
Browse files Browse the repository at this point in the history
  • Loading branch information
eleftherioszisis committed Apr 25, 2024
1 parent f5f92d2 commit 2132da8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions neurom/core/morphology.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
from neurom.core.soma import make_soma
from neurom.core.types import NeuriteIter, NeuriteType
from neurom.utils import flatten
from neurom.exceptions import NeuroMError


class Section:
Expand Down Expand Up @@ -546,6 +547,12 @@ def __init__(self, morphio_morph, name=None, process_subtrees=False):
name (str): an optional morphology name
process_subtrees (bool): enable mixed tree processing if set to True
"""
if not isinstance(morphio_morph, (morphio.Morphology, morphio.mut.Morphology)):
raise NeuroMError(
f"Expected morphio Morphology object but got: {morphio_morph}.\n"
f"Use neurom.load_morphology() to load from file."
)

self._morphio_morph = morphio_morph

self.name = name if name else 'Morphology'
Expand Down
7 changes: 7 additions & 0 deletions tests/core/test_neuron.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@
from copy import copy, deepcopy
from pathlib import Path

import pytest
import neurom as nm
import numpy as np
import morphio
from neurom.core.morphology import Morphology, graft_morphology, iter_segments
from numpy.testing import assert_array_equal
from neurom.exceptions import NeuroMError

SWC_PATH = Path(__file__).parent.parent / 'data/swc/'

Expand Down Expand Up @@ -137,3 +139,8 @@ def test_str():
n = nm.load_morphology(SWC_PATH / 'simple.swc')
assert 'Morphology' in str(n)
assert 'Section' in str(n.neurites[0].root_node)


def test_morphology_raises_wrong_argument():
with pytest.raises(NeuroMError, match="Expected morphio Morphology object but got: my-path"):
Morphology("my-path")

0 comments on commit 2132da8

Please sign in to comment.