forked from ga4gh/ga4gh-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_tests.py
More file actions
66 lines (52 loc) · 1.83 KB
/
run_tests.py
File metadata and controls
66 lines (52 loc) · 1.83 KB
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
"""
Script to imitate a Travis CI run
"""
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import glob
import shlex
import subprocess
import yaml
import utils
class TravisSimulator(object):
logStrPrefix = '***'
yamlFileLocation = '.travis.yml'
def parseTestCommands(self):
yamlFile = file(self.yamlFileLocation)
yamlData = yaml.load(yamlFile)
return yamlData['script']
def expandCommand(self, command):
# subprocess.check_call doesn't expand globs by default, unless
# shell=True is passed, which is a security hazzard.
# This gets around that limitation by implementing some shell features
# which should be enough for our purposes. See:
# https://docs.python.org/2/library/subprocess.html
# #frequently-used-arguments
if '*' not in command:
return command
splits = shlex.split(command)
expandedSplits = []
for split in splits:
if '*' in split:
files = glob.glob(split)
expandedSplits.extend(files)
else:
expandedSplits.append(split)
return ' '.join(expandedSplits)
def runTests(self):
testCommands = self.parseTestCommands()
for command in testCommands:
expandedCommand = self.expandCommand(command)
self.log('Running: "{0}"'.format(expandedCommand))
try:
utils.runCommand(expandedCommand)
except subprocess.CalledProcessError:
self.log('ERROR')
return
self.log('SUCCESS')
def log(self, logStr):
utils.log("{0} {1}".format(self.logStrPrefix, logStr))
if __name__ == '__main__':
travisSimulator = TravisSimulator()
travisSimulator.runTests()