1
1
import pytest
2
- import siibra
3
2
from typing import Union , List
3
+ from json import JSONDecodeError
4
+ from functools import wraps
5
+ import siibra
6
+
7
+
8
+ def skip_if_allen_api_unavailable (test_func ):
9
+ @wraps (test_func )
10
+ def wrapper (* args , ** kwargs ):
11
+ try :
12
+ return test_func (* args , ** kwargs )
13
+ except JSONDecodeError :
14
+ pytest .skip (
15
+ f"Skipping test { test_func .__name__ } due to JSONDecodeError since Allen API sent a malformed JSON"
16
+ )
17
+ except RuntimeError as e :
18
+ if str (e ) == "Allen institute site unavailable - please try again later." :
19
+ pytest .skip ("Skipping since Allen Institute API is unavailable." )
20
+ else :
21
+ raise e
22
+
23
+ return wrapper
24
+
4
25
5
26
test_params = [
6
27
("julich 2.9" , "hoc1 left" , "MAOA" ),
13
34
14
35
15
36
@pytest .mark .parametrize ("parc_spec, region_spec, gene" , test_params )
37
+ @skip_if_allen_api_unavailable
16
38
def test_genes (parc_spec : str , region_spec : str , gene : Union [str , List [str ]]):
17
39
parc = siibra .parcellations [parc_spec ]
18
40
region = parc .get_region (region_spec )
@@ -23,6 +45,7 @@ def test_genes(parc_spec: str, region_spec: str, gene: Union[str, List[str]]):
23
45
), "expecting all features to be of type GeneExpression"
24
46
25
47
48
+ @skip_if_allen_api_unavailable
26
49
def test_gene_exp_w_parent_structures ():
27
50
kwargs = {"gene" : "MAOA" }
28
51
features_grandparent_struct = siibra .features .get (
0 commit comments