Skip to content

Commit 102dd0f

Browse files
committed
Re-purposing run_system_test.py to be more flexible.
Also using the re-purposed `run_module_tests` to get a basic `scripts/attempt_system_tests.py` to perform all four tests as is done in `scripts/run_system_tests.sh`.
1 parent 5fc0150 commit 102dd0f

2 files changed

Lines changed: 70 additions & 9 deletions

File tree

scripts/attempt_system_tests.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Copyright 2016 Google Inc. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Attempt to run system tests.
16+
17+
If the system tests are being run on Travis, no test need be run if
18+
the build is for a PR and not a merged commit.
19+
20+
If being run as part of a Travis build for a merged commit, the
21+
encrypted `key.json` file need be decrypted before running tests.
22+
"""
23+
24+
25+
from system_tests.run_system_test import run_module_tests
26+
27+
28+
MODULES = (
29+
'datastore',
30+
'storage',
31+
'pubsub',
32+
'bigquery',
33+
)
34+
35+
36+
def main():
37+
"""Run all the system tests.
38+
39+
Uses module objects to directly load test cases.
40+
"""
41+
for module in MODULES:
42+
run_module_tests(module)
43+
44+
45+
if __name__ == '__main__':
46+
main()

system_tests/run_system_test.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,25 @@
1818

1919
# This assumes the command is being run via tox hence the
2020
# repository root is the current directory.
21+
from system_tests import bigquery
22+
from system_tests import datastore
23+
from system_tests import pubsub
24+
from system_tests import storage
2125
from system_tests import system_test_utils
2226

27+
2328
REQUIREMENTS = {
2429
'datastore': ['dataset_id', 'credentials'],
2530
'storage': ['project', 'credentials'],
2631
'pubsub': ['project', 'credentials'],
2732
'bigquery': ['project', 'credentials'],
2833
}
34+
TEST_MODULES = {
35+
'datastore': datastore,
36+
'storage': storage,
37+
'pubsub': pubsub,
38+
'bigquery': bigquery,
39+
}
2940

3041

3142
def get_parser():
@@ -38,22 +49,26 @@ def get_parser():
3849

3950

4051
def run_module_tests(module_name):
52+
# Make sure environ is set before running test.
53+
requirements = REQUIREMENTS[module_name]
54+
system_test_utils.check_environ(*requirements)
55+
4156
suite = unittest2.TestSuite()
42-
tests = unittest2.defaultTestLoader.loadTestsFromName(module_name)
57+
test_mod = TEST_MODULES[module_name]
58+
tests = unittest2.defaultTestLoader.loadTestsFromModule(test_mod)
4359
suite.addTest(tests)
44-
return unittest2.TextTestRunner(verbosity=2).run(suite)
60+
61+
# Run tests.
62+
test_result = unittest2.TextTestRunner(verbosity=2).run(suite)
63+
# Exit if not successful.
64+
if not test_result.wasSuccessful():
65+
sys.exit(1)
4566

4667

4768
def main():
4869
parser = get_parser()
4970
args = parser.parse_args()
50-
# Make sure environ is set before running test.
51-
requirements = REQUIREMENTS[args.package]
52-
system_test_utils.check_environ(*requirements)
53-
54-
test_result = run_module_tests(args.package)
55-
if not test_result.wasSuccessful():
56-
sys.exit(1)
71+
run_module_tests(args.package)
5772

5873

5974
if __name__ == '__main__':

0 commit comments

Comments
 (0)