OLD | NEW |
---|---|
(Empty) | |
1 # Copyright 2017 The Chromium Authors. All rights reserved. | |
2 # Use of this source code is governed by a BSD-style license that can be | |
3 # found in the LICENSE file. | |
4 | |
5 import os | |
6 import re | |
7 import sys | |
8 import time | |
9 import unittest | |
10 | |
11 import common | |
12 | |
13 ################################################################################ | |
14 # EDIT BETWEEN THESE LINES | |
RyanSturm
2017/04/27 21:46:39
Remove these comments.
Robert Ogden
2017/04/28 15:48:46
Done.
| |
15 | |
16 combinations = [ | |
17 # One object for each set of tests to run with the given variations. | |
18 { | |
19 'tests': [ | |
RyanSturm
2017/04/27 21:46:39
Would it make sense to give a name to each test co
Robert Ogden
2017/04/28 15:48:46
I think that's a great idea. It gives some documen
| |
20 # Of the form <file_name>.<class_name>.<method_name> | |
21 # Also accepts wildcard (*) as matching anything. | |
22 "lite_page.LitePage.testLitePage", | |
23 "lite_page.LitePage.testLitePageFallback", | |
24 "quic*" | |
25 ], | |
26 'variations': [ | |
27 "DataReductionProxyUseQuic/Enabled", | |
28 "DataCompressionProxyLoFi/Enabled_Preview", | |
29 "DataCompressionProxyLitePageFallback/Enabled" | |
30 ], | |
31 'variations-params': [ | |
32 "DataCompressionProxyLoFi.Enabled_Preview:effective_connection_type/4G" | |
RyanSturm
2017/04/27 21:46:39
These seem fine as a dummy example.
Robert Ogden
2017/04/28 15:48:46
Acknowledged.
| |
33 ] | |
34 } | |
35 ] | |
36 ################################################################################ | |
37 | |
38 | |
39 def GetAllTestsFromRegexList(test_list, test_suite_iter): | |
40 """A helper function to make a test suite from tests matching the given list. | |
41 | |
42 Args: | |
43 test_list: a string list of all tests to run, allowing for simple regex | |
44 test_suite_iter: An iterator of all test suites to search | |
45 Returns: | |
46 a test suite with all the tests specified by the test_list | |
47 """ | |
48 id_to_test_map = {} | |
49 for test_suite in test_suite_iter: | |
50 for test_case in test_suite: | |
51 for test_method in test_case: | |
52 id_to_test_map[test_method.id()] = test_method | |
53 my_test_suite = unittest.TestSuite() | |
54 for test_spec in test_list: | |
55 regex = re.compile('^' + test_spec.replace('.', '\\.').replace('*', '.*') | |
56 + '$') | |
57 for test_id in sorted(id_to_test_map): | |
58 if regex.match(test_id): | |
59 my_test_suite.addTest(id_to_test_map[test_id]) | |
60 return my_test_suite | |
61 | |
62 def ParseFlagsWithExtraBrowserArgs(extra_args): | |
63 """Generates a function to override common.ParseFlags. | |
64 | |
65 The returned function will honor everything in the original ParseFlags(), but | |
66 adds on additional browser_args. | |
67 | |
68 Args: | |
69 extra_args: The extra browser agruments to add. | |
70 Returns: | |
71 A function to override common.ParseFlags with additional browser_args. | |
72 """ | |
73 original_flags = common.ParseFlags() | |
74 def AddExtraBrowserArgs(): | |
75 original_flags.browser_args = ((original_flags.browser_args if | |
76 original_flags.browser_args else '') + ' ' + extra_args) | |
77 return original_flags | |
78 return AddExtraBrowserArgs | |
79 | |
80 def main(): | |
81 """Runs each set of tests against its set of variations. | |
82 | |
83 For each test combination, the above variation specifications will be used to | |
84 setup the browser arguments for each test given above that will be run. | |
85 """ | |
86 flags = common.ParseFlags() | |
87 for variation_test in combinations: | |
88 # Set browser arguments to use the given variations. | |
89 extra_args = '--force-fieldtrials=' + '/'.join(variation_test['variations']) | |
90 extra_args += ' --force-fieldtrial-params=' + ','.join( | |
91 variation_test['variations-params']) | |
92 common.ParseFlags = ParseFlagsWithExtraBrowserArgs(extra_args) | |
93 # Run the given tests. | |
94 loader = unittest.TestLoader() | |
95 test_suite_iter = loader.discover(os.path.dirname(__file__), pattern='*.py') | |
96 my_test_suite = GetAllTestsFromRegexList(variation_test['tests'], | |
97 test_suite_iter) | |
98 testRunner = unittest.runner.TextTestRunner(verbosity=2, | |
99 failfast=flags.failfast, buffer=(not flags.disable_buffer)) | |
100 testRunner.run(my_test_suite) | |
101 | |
102 if __name__ == '__main__': | |
103 main() | |
OLD | NEW |