forked from materialsproject/pymatgen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_circle.py
57 lines (43 loc) · 1.5 KB
/
run_circle.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
from __future__ import division
"""
Script to wrap around nosetests to only run on files modified in the past 10
commits as well as 10% of all files.
"""
import os
import sys
import subprocess
import random
run_ratio = 1/10
try:
output = subprocess.check_output(["git", "diff", "--name-only", "HEAD~20"])
files_changed = [f for f in output.decode("utf-8").split("\n")
if f.startswith("pymatgen")]
except subprocess.CalledProcessError:
print("Can't get changed_files... Setting run_ratio to 100%")
run_ratio = 1
files_changed = []
must_run = []
for f in files_changed:
d = os.path.dirname(f)
b = os.path.basename(f)
testname = os.path.join(d, "tests", "test_" + b)
if os.path.exists(testname):
must_run.append(testname)
can_run = []
for parent, subdir, files in os.walk("pymatgen"):
for f in files:
if (parent.endswith("tests") and f.startswith("test_")
and f.endswith(".py") and f not in must_run):
can_run.append(os.path.join(parent, f))
print("%d test files must be run..." % len(must_run))
print(must_run)
print("%d possible test files can be run..." % len(can_run))
nrun = int(run_ratio * len(can_run))
if random.randint(1, 20) % 20 == 0:
# One in fifty times, we will run a full test.
to_run = must_run + can_run
else:
to_run = list(set(random.sample(can_run, nrun) + must_run))
print("%d test files will be run..." % len(to_run))
status = subprocess.call(["nosetests", "-v"] + to_run)
sys.exit(status)