forked from ivy-llc/ivy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_tests.py
146 lines (130 loc) · 4.81 KB
/
run_tests.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# Run Tests
import os
import sys
from pymongo import MongoClient
submodules = (
"test_functional",
"test_experimental",
"test_stateful",
"test_tensorflow",
"test_torch",
"test_jax",
"test_numpy",
"test_misc",
)
db_dict = {
"test_functional/test_core": ["core", 10],
"test_experimental/test_core": ["exp_core", 11],
"test_functional/test_nn": ["nn", 12],
"test_experimental/test_nn": ["exp_nn", 13],
"test_stateful": ["stateful", 14],
"test_torch": ["torch", 15],
"test_jax": ["jax", 16],
"test_tensorflow": ["tensorflow", 17],
"test_numpy": ["numpy", 18],
"test_misc": ["misc", 19],
}
result_config = {
"success": "https://img.shields.io/badge/-success-success",
"failure": "https://img.shields.io/badge/-failure-red",
}
def make_clickable(url, name):
return '<a href="{}" rel="noopener noreferrer" '.format(
url
) + 'target="_blank"><img src={}></a>'.format(name)
def get_submodule(test_path):
test_path = test_path.split("/")
for name in submodules:
if name in test_path:
if name == "test_functional":
coll = db_dict["test_functional/" + test_path[-2]]
elif name == "test_experimental":
coll = db_dict["test_experimental/" + test_path[-2]]
else:
coll = db_dict[name]
submod_test = test_path[-1]
submod, test_fn = submod_test.split("::")
submod = submod.replace("test_", "").replace(".py", "")
return coll, submod, test_fn
def update_individual_test_results(collection, id, submod, backend, test, result):
collection.update_one(
{"_id": id},
{"$set": {submod + "." + backend + "." + test: result}},
upsert=True,
)
return
def remove_from_db(collection, id, submod, backend, test):
collection.update_one(
{"_id": id},
{"$unset": {submod + "." + backend + ".": test}},
)
return
def run_multiversion_testing(failed):
with open("tests_to_run", "r") as f:
for line in f:
test, frontend, backend = line.split(",")
frontend, backend = frontend.split("=")[1], backend.split("=")[1].replace(
":", ","
)
print(test, frontend, backend)
ret = os.system(
f'docker run --rm -v "$(pwd)":/ivy -v "$(pwd)"/.hypothesis:/.hypothesis unifyai/multiversion /opt/miniconda/envs/multienv/bin/python -m pytest --tb=short {test} --frontend={frontend} --backend={backend}' # noqa
)
if ret != 0:
exit(1)
else:
exit(0)
if __name__ == "__main__":
redis_url = sys.argv[1]
redis_pass = sys.argv[2]
mongo_key = sys.argv[3]
version_flag = sys.argv[4]
workflow_id = sys.argv[5]
if len(sys.argv) > 6:
print(f"Job URL available -: {sys.argv}")
run_id = sys.argv[6]
else:
run_id = "https://github.com/unifyai/ivy/actions/runs/" + workflow_id
failed = False
# multiversion testing
if version_flag == "true":
run_multiversion_testing(failed)
cluster = MongoClient(
f"mongodb+srv://deep-ivy:{mongo_key}@cluster0.qdvf8q3.mongodb.net/?retryWrites=true&w=majority" # noqa
)
db = cluster["Ivy_tests"]
with open("tests_to_run", "r") as f:
for line in f:
test, backend = line.split(",")
coll, submod, test_fn = get_submodule(test)
print(coll, submod, test_fn)
if len(sys.argv) > 2:
ret = os.system(
f'docker run --rm --env REDIS_URL={redis_url} --env REDIS_PASSWD={redis_pass} -v "$(pwd)":/ivy -v "$(pwd)"/.hypothesis:/.hypothesis unifyai/ivy:latest python3 -m pytest --tb=short {test} --backend {backend}' # noqa
)
else:
ret = os.system(
f'docker run --rm -v "$(pwd)":/ivy -v "$(pwd)"/.hypothesis:/.hypothesis unifyai/ivy:latest python3 -m pytest --tb=short {test} --backend {backend}' # noqa
)
if ret != 0:
res = make_clickable(run_id, result_config["failure"])
update_individual_test_results(
db[coll[0]], coll[1], submod, backend, test_fn, res
)
failed = True
else:
res = make_clickable(run_id, result_config["success"])
update_individual_test_results(
db[coll[0]], coll[1], submod, backend, test_fn, res
)
try:
with open("tests_to_remove", "r") as f:
for line in f:
test, backend = line.split(",")
coll, submod, test_fn = get_submodule(test)
print(coll, submod, test_fn)
remove_from_db(db[coll[0]], coll[1], submod, backend, test_fn)
except Exception:
pass
if failed:
exit(1)