Skip to content

Commit 83d4dee

Browse files
committed
test: fix anchor unit test
1 parent e076e00 commit 83d4dee

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

pytest.ini

+1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ testpaths =
1313
test/features/test_genes.py
1414
test/features/test_receptors.py
1515
test/features/test_voi.py
16+
test/features/test_anchor.py
1617
# eventually, only use the below ini
1718
# test/

test/features/test_anchor.py

+21-19
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import pytest
2+
from unittest.mock import patch, Mock
3+
from siibra.commons import Species
24
from siibra.core.region import Region
3-
from siibra.features.anchor import AnatomicalAnchor, Parcellation, Species
4-
from unittest.mock import patch
5+
from siibra.features.anchor import AnatomicalAnchor
56

67

78
@pytest.fixture
@@ -16,21 +17,22 @@ def fixture_teardown():
1617
]
1718

1819

19-
@pytest.mark.parametrize("region,teardown", region_specs)
20-
def test_region_region_spec(region, teardown):
21-
mock_found_regions = [Region("baz"), Region("hello world")]
20+
@pytest.mark.parametrize("region_spec,teardown", region_specs)
21+
@patch("siibra.features.anchor.find_regions")
22+
def test_region_region_spec(mock_find_regions: Mock, region_spec, teardown):
23+
mock_find_regions.return_value = [Region("baz"), Region("hello world")]
2224
species = Species.UNSPECIFIED_SPECIES
23-
with patch.object(
24-
Parcellation, "find_regions", return_value=mock_found_regions
25-
) as mock_find_regions:
26-
anchor = AnatomicalAnchor(species, region=region)
27-
assert isinstance(anchor.regions, dict)
28-
for _region in anchor.regions:
29-
assert isinstance(_region, Region)
30-
31-
if isinstance(region, Region):
32-
mock_find_regions.assert_not_called()
33-
elif isinstance(region, str):
34-
mock_find_regions.assert_called_once_with(region, species)
35-
else:
36-
assert False, "Cannot have region as neither str or Region"
25+
for r in mock_find_regions.return_value:
26+
r._species_cached = species
27+
28+
anchor = AnatomicalAnchor(species, region=region_spec)
29+
assert isinstance(anchor.regions, dict)
30+
for _region in anchor.regions:
31+
assert isinstance(_region, Region)
32+
33+
if isinstance(region_spec, Region):
34+
mock_find_regions.assert_not_called()
35+
elif isinstance(region_spec, str):
36+
mock_find_regions.assert_called_once_with(region_spec, filter_children=True, find_topmost=False)
37+
else:
38+
assert False, "Cannot have region as neither str or Region"

0 commit comments

Comments
 (0)