forked from materialsproject/pymatgen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_test.py
42 lines (32 loc) · 1.12 KB
/
run_test.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
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
output = subprocess.check_output(["git", "diff", "--name-only", "HEAD~10"])
files_changed = [f for f in output.decode("utf-8").split("\n") if f.startswith("pymatgen")]
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))
nrun = int(run_ratio * len(can_run))
if random.randint(1, 50) % 50 == 0:
#One in fifty times, we will run a full test.
to_run = must_run + can_run
else:
to_run = random.sample(can_run, nrun) + must_run
status = subprocess.call(["nosetests", "-v"] + to_run)
sys.exit(status)