-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
80 lines (65 loc) · 2.14 KB
/
conftest.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import ivy
import pytest
import shutil
import os
import sys
TARGET_FRAMEWORKS = ["numpy", "jax", "tensorflow", "torch"]
S2S_TARGET_FRAMEWORKS = ["tensorflow"]
BACKEND_COMPILE = False
TARGET = "all"
S2S = False
def _clear_translated_directory(directory: str):
to_delete = []
for key in sys.modules.keys():
if directory in key:
to_delete.append(key)
for key in to_delete:
del sys.modules[key]
@pytest.fixture(autouse=True)
def run_around_tests():
ivy.unset_backend()
directory = "ivy_transpiled_outputs/"
# check if the directory exists and remove it
if os.path.exists(directory):
shutil.rmtree(directory)
_clear_translated_directory(directory.replace("/",""))
def pytest_addoption(parser):
parser.addoption(
"--backend-compile",
action="store_true",
help="Whether to use backend compilation (such as jax.jit) during testing",
)
parser.addoption(
"--target",
action="store",
default="all",
help="Target for the transpilation tests",
)
parser.addoption(
"--source-to-source",
action="store_true",
help="Whether to run the tests on the source-to-source translator or functional transpiler",
)
def pytest_configure(config):
getopt = config.getoption
global BACKEND_COMPILE
BACKEND_COMPILE = getopt("--backend-compile")
global TARGET
TARGET = getopt("--target")
global S2S
S2S = getopt("--source-to-source")
def pytest_generate_tests(metafunc):
configs = list()
if S2S:
if TARGET != "all":
configs.append((TARGET, "s2s", BACKEND_COMPILE))
else:
for target in S2S_TARGET_FRAMEWORKS:
configs.append((target, "s2s", BACKEND_COMPILE))
elif TARGET not in ["jax", "numpy", "tensorflow", "torch"]:
for target in TARGET_FRAMEWORKS:
configs.append((target, "transpile", BACKEND_COMPILE))
configs.append(("torch", "trace", BACKEND_COMPILE))
else:
configs.append((TARGET, "transpile", BACKEND_COMPILE))
metafunc.parametrize("target_framework,mode,backend_compile", configs)