Skip to content

Commit 8bc16bb

Browse files
committed
test: skip gene expression query tests if allen api is unavailable
1 parent 6e4b4c9 commit 8bc16bb

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

e2e/features/molecular/test_genes.py

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
11
import pytest
2-
import siibra
32
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+
425

526
test_params = [
627
("julich 2.9", "hoc1 left", "MAOA"),
@@ -13,6 +34,7 @@
1334

1435

1536
@pytest.mark.parametrize("parc_spec, region_spec, gene", test_params)
37+
@skip_if_allen_api_unavailable
1638
def test_genes(parc_spec: str, region_spec: str, gene: Union[str, List[str]]):
1739
parc = siibra.parcellations[parc_spec]
1840
region = parc.get_region(region_spec)
@@ -23,6 +45,7 @@ def test_genes(parc_spec: str, region_spec: str, gene: Union[str, List[str]]):
2345
), "expecting all features to be of type GeneExpression"
2446

2547

48+
@skip_if_allen_api_unavailable
2649
def test_gene_exp_w_parent_structures():
2750
kwargs = {"gene": "MAOA"}
2851
features_grandparent_struct = siibra.features.get(

0 commit comments

Comments
 (0)