forked from ivy-llc/ivy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_tests.py
123 lines (109 loc) · 3.95 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
# 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
if __name__ == "__main__":
redis_url = sys.argv[1]
redis_pass = sys.argv[2]
mongo_key = sys.argv[3]
if len(sys.argv) > 3:
run_id = sys.argv[4]
else:
run_id = "https://github.com/unifyai/ivy/actions/"
failed = False
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)