forked from oughtinc/ice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_primer_recipes.py
44 lines (35 loc) · 1.27 KB
/
test_primer_recipes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from importlib import import_module
from inspect import signature
from pathlib import Path
import pytest
from faker import Faker
from ice.paper import Paper
from ice.recipe import FunctionBasedRecipe
from ice.recipe import recipe
from ice.trace import enable_trace
Faker.seed(0)
fake = Faker()
root_dir = Path(__file__).parent.parent
recipe.all_recipes = []
primer_recipes_dir = root_dir / "ice" / "recipes" / "primer"
for path in primer_recipes_dir.glob("**/*.py"):
relative_path = path.relative_to(primer_recipes_dir)
module_name = ".".join(relative_path.parts[:-1] + (relative_path.stem,))
import_module(f"ice.recipes.primer.{module_name}")
paper = Paper.load(Path(root_dir / "papers" / "keenan-2018-tiny.txt"))
@pytest.mark.parametrize("main", recipe.all_recipes)
@pytest.mark.anyio
async def test_all_primer_recipes(main: FunctionBasedRecipe):
kwargs = {}
for p in signature(main).parameters.values():
if p.default is not p.empty:
value = p.default
elif issubclass(p.annotation, str):
value = fake.sentence()
elif issubclass(p.annotation, Paper):
value = paper
else:
raise ValueError(f"Cannot handle parameter {p}")
kwargs[p.name] = value
enable_trace()
await main(**kwargs)