Skip to content

Commit f5cc917

Browse files
committed
test(csr): Check attribute and type errors are correctly raised
1 parent 17e7661 commit f5cc917

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

src/skan/test/test_csr.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from numpy.testing import assert_equal, assert_almost_equal
1111
import pandas as pd
1212
import pytest
13+
import scipy
1314
from skimage.draw import line
1415

1516
from skan import csr
@@ -523,7 +524,7 @@ def test_nx_to_skeleton(
523524

524525

525526
@pytest.mark.parametrize(
526-
'wrong_skeleton',
527+
('wrong_skeleton'),
527528
[
528529
pytest.param(skeleton0, id='Numpy Array.'),
529530
pytest.param(csr.Skeleton(skeleton0), id='Skeleton.'),
@@ -538,3 +539,36 @@ def test_nx_to_skeleton_attribute_error(wrong_skeleton: Any) -> None:
538539
"""Test various errors are raised by nx_to_skeleton()."""
539540
with pytest.raises(Exception):
540541
csr.nx_to_skeleton(wrong_skeleton)
542+
543+
544+
@pytest.mark.parametrize(
545+
('skeleton'),
546+
[
547+
pytest.param(skeleton0, id='Numpy Array'),
548+
pytest.param(csr.Skeleton(skeleton0), id='Skeleton'),
549+
pytest.param(nx_graph, id='NetworkX Graph without edges.'),
550+
],
551+
)
552+
def test_csr_to_nbgraph_attribute_error(skeleton: Any) -> None:
553+
"""Raise AttributeError if csr_to_nbgraph() passed incomplete objects."""
554+
with pytest.raises(AttributeError):
555+
csr.csr_to_nbgraph(skeleton)
556+
557+
558+
@pytest.mark.parametrize(
559+
('graph'),
560+
[
561+
pytest.param(
562+
scipy.sparse.csr_matrix(skeleton0),
563+
id='Sparse matrix directly from Numpy Array',
564+
),
565+
pytest.param(
566+
scipy.sparse.csr_matrix(csr.Skeleton(skeleton0)),
567+
id='Sparse matrix from csr.Skeleton',
568+
),
569+
],
570+
)
571+
def test_csr_to_nbgraph_type_error(graph: scipy.sparse.csr_matrix) -> None:
572+
"""Test TypeError is raised by csr_to_nbgraph() if wrong type is passed."""
573+
with pytest.raises(TypeError):
574+
csr.csr_to_nbgraph(graph)

0 commit comments

Comments
 (0)