1
1
import pytest
2
+ from unittest .mock import patch , Mock
3
+ from siibra .commons import Species
2
4
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
5
6
6
7
7
8
@pytest .fixture
@@ -16,21 +17,22 @@ def fixture_teardown():
16
17
]
17
18
18
19
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" )]
22
24
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