This repository has been archived by the owner on Jul 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy path.travis-runner.py
executable file
·75 lines (61 loc) · 1.99 KB
/
.travis-runner.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
#!/usr/bin/env python
#
# Test runner for Travis
#
from __future__ import print_function
import sys
import argparse
if sys.version_info[0] < 3:
import unittest2 as unittest
else:
import unittest
def get_args_parser():
"""Build the command line argument parser
"""
parser = argparse.ArgumentParser(
description='Load GAE and run the test modules '
'found in the target directory.'
)
parser.add_argument(
'start_dir',
nargs='?',
default='./tests',
help='directory to find test modules from (default to "./tests").'
)
parser.add_argument(
'--gae-lib-root', '-l',
default='/usr/local/google_appengine',
help='directory where to find Google App Engine SDK '
'(default to "/usr/local/google_appengine")'
)
return parser
def setup_gae(gae_lib_root):
"""Try to load Google App Engine SDK on Python 2.7.
It shouldn't try to import to load it with Pyhton 2.6;
dev_appserver exit on load with any other version than 2.7.
setup_gae will fail quietly if it can't find the SDK.
"""
if sys.version_info[0:2] != (2, 7,):
return
try:
sys.path.insert(0, gae_lib_root)
import dev_appserver
except ImportError:
print("Failed to load Google App Engine SDK.")
print("Google App Engine related tests will be skipped.")
else:
dev_appserver.fix_sys_path()
def main(gae_lib_root, start_dir):
"""Try to load Google App Engine SDK and then to run any tests found with
unittest2 discovery feature.
If a test fail, it will exit with a status code of 1.
"""
setup_gae(gae_lib_root)
suite = unittest.loader.TestLoader().discover(start_dir)
results = unittest.TextTestRunner(verbosity=2, buffer=True).run(suite)
if not results.wasSuccessful():
sys.exit(1)
if __name__ == '__main__':
parser = get_args_parser()
args = parser.parse_args()
main(args.gae_lib_root, args.start_dir)