forked from pytorch/builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_all.py
executable file
·47 lines (33 loc) · 1.21 KB
/
run_all.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
#!/usr/bin/env python3
import os.path
import unittest
import subprocess
import sys
import os
TIMEOUT = 2 * 60 * 60 # 2 hours
def run(command, timeout=None):
"""
Returns (return-code, stdout, stderr)
"""
completed = subprocess.run(command, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, shell=True,
encoding="utf8", timeout=timeout)
return completed.returncode, completed.stdout, completed.stderr
class TestRepos(unittest.TestCase):
pass
def _test(cls, directory):
command = os.path.join(directory, "run.sh")
(rc, out, err) = run(command, TIMEOUT)
cls.assertEqual(rc, 0, "Ran {}\nstdout:\n{}\nstderr:\n{}".format(
command, out, err))
def generate_test_objects(target_directory):
"""
Generate the tests, one for each repo
"""
repos = sorted([os.path.normpath(os.path.join(target_directory, o)) for o in os.listdir(target_directory) if os.path.isdir(os.path.join(target_directory, o))])
for f in repos:
print("found {}".format(f))
setattr(TestRepos, "test_" + f, lambda cls, f=f: _test(cls, f))
if __name__ == '__main__':
generate_test_objects('examples')
unittest.main()