Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(709)

Side by Side Diff: install_test/run_install_tests.py

Issue 11553041: Remove pyautolib dependency (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/chrome/test/
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Runs install and update tests. 6 """Runs install and update tests.
7 7
8 Install tests are performed using a single Chrome build, whereas two or more 8 Install tests are performed using a single Chrome build, whereas two or more
9 builds are needed for Update tests. There are separate command arguments for 9 builds are needed for Update tests. There are separate command arguments for
10 the builds that will be used for each of the tests. If a test file contains 10 the builds that will be used for each of the tests. If a test file contains
11 both types of tests(install and update), both arguments should be specified. 11 both types of tests(install and update), both arguments should be specified.
12 Otherwise, specify only the command argument that is required for the test. 12 Otherwise, specify only the command argument that is required for the test.
13 To run a test with this script, append the module name to the _TEST_MODULES 13 To run a test with this script, append the module name to the _TEST_MODULES
14 list. Modules added to the list must be in the same directory or in a sub- 14 list. Modules added to the list must be in the same directory or in a sub-
15 directory that's in the same location as this script. 15 directory that's in the same location as this script.
16 16
17 Example: 17 Example:
18 $ python run_install_test.py --url=<chrome_builds_url> --filter=* \ 18 $ python run_install_test.py --url=<chrome_builds_url> --filter=* \
19 --install-build=24.0.1290.0 --update-builds=24.0.1289.0,24.0.1290.0 19 --install-build=24.0.1290.0 --update-builds=24.0.1289.0,24.0.1290.0
20 """ 20 """
21 21
22 import fnmatch
23 import logging 22 import logging
24 import optparse 23 import optparse
25 import os 24 import os
26 import re 25 import re
27 import sys 26 import sys
28 import unittest 27 import unittest
29 28
30 import chrome_installer_win 29 import chrome_installer_win
31 from install_test import InstallTest 30 from install_test import InstallTest
32 31
33 _DIRECTORY = os.path.dirname(os.path.abspath(__file__)) 32 from common import unittest_util
34 sys.path.append(os.path.join(os.path.dirname(_DIRECTORY), 'pyautolib')) 33 from common import util
35
36 import pyauto_utils
37 34
38 # To run tests from a module, append the module name to this list. 35 # To run tests from a module, append the module name to this list.
39 _TEST_MODULES = ['sample_updater'] 36 _TEST_MODULES = ['sample_updater']
40 37
41 for module in _TEST_MODULES: 38 for module in _TEST_MODULES:
42 __import__(module) 39 __import__(module)
43 40
44 41
45 class Main(object): 42 class Main(object):
46 """Main program for running 'Fresh Install' and 'Updater' tests.""" 43 """Main program for running 'Fresh Install' and 'Updater' tests."""
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 """ 86 """
90 builds = [] 87 builds = []
91 if self._opts.install_build: 88 if self._opts.install_build:
92 builds.append(self._opts.install_build) 89 builds.append(self._opts.install_build)
93 if self._opts.update_builds: 90 if self._opts.update_builds:
94 builds.extend(self._opts.update_builds.split(',')) 91 builds.extend(self._opts.update_builds.split(','))
95 builds = list(frozenset(builds)) 92 builds = list(frozenset(builds))
96 for build in builds: 93 for build in builds:
97 if not re.match('\d+\.\d+\.\d+\.\d+', build): 94 if not re.match('\d+\.\d+\.\d+\.\d+', build):
98 raise RuntimeError('Invalid build number: %s' % build) 95 raise RuntimeError('Invalid build number: %s' % build)
99 if not pyauto_utils.DoesUrlExist('%s/%s/' % (self._opts.url, build)): 96 if not util.DoesUrlExist('%s/%s/' % (self._opts.url, build)):
100 raise RuntimeError('Could not locate build no. %s' % build) 97 raise RuntimeError('Could not locate build no. %s' % build)
101 98
102 def _SetLoggingConfiguration(self): 99 def _SetLoggingConfiguration(self):
103 """Sets the basic logging configuration.""" 100 """Sets the basic logging configuration."""
104 log_format = '%(asctime)s %(levelname)-8s %(message)s' 101 log_format = '%(asctime)s %(levelname)-8s %(message)s'
105 logging.basicConfig(level=logging.INFO, format=log_format) 102 logging.basicConfig(level=logging.INFO, format=log_format)
106 103
107 def _GetTestsFromSuite(self, suite):
108 """Returns all the tests from a given test suite.
109
110 Args:
111 suite: A unittest.TestSuite object.
112
113 Returns:
114 A list that contains all the tests found in the suite.
115 """
116 tests = []
117 for test in suite:
118 if isinstance(test, unittest.TestSuite):
119 tests += self._GetTestsFromSuite(test)
120 else:
121 tests += [test]
122 return tests
123
124 def _GetTestName(self, test):
125 """Gets the test name of the given unittest test.
126
127 Args:
128 test: A unittest test.
129
130 Returns:
131 A string representing the full test name.
132 """
133 return '.'.join([test.__module__, test.__class__.__name__,
134 test._testMethodName])
135
136 def _FilterTestSuite(self, suite, gtest_filter):
137 """Returns a new filtered test suite based on the given gtest filter.
138
139 See http://code.google.com/p/googletest/wiki/AdvancedGuide for
140 gtest_filter specification.
141
142 Args:
143 suite: A unittest.TestSuite object, which can be obtained by calling
144 |unittest.defaultTestLoader.loadTestsFromName|.
145 gtest_filter: The gtest filter to use. Filter can be passed as follows:
146 --filter=*className* or --filter=*testcaseName.
147
148 Returns:
149 A unittest.TestSuite object that contains tests that match the gtest
150 filter.
151 """
152 return unittest.TestSuite(
153 self._FilterTests(self._GetTestsFromSuite(suite), gtest_filter))
154
155 def _FilterTests(self, all_tests, gtest_filter):
156 """Returns a filtered list of tests based on the given gtest filter.
157
158 Args:
159 all_tests: A list that contains all unittests in a given suite. This
160 list must be obtained by calling |_GetTestsFromSuite|.
161 gtest_filter: The gtest filter to use. Filter can be passed as follows:
162 *className* or *testcaseName.
163
164 Returns:
165 A list that contains all tests that match the given gtest filter.
166 """
167 pattern_groups = gtest_filter.split('-')
168 positive_patterns = pattern_groups[0].split(':')
169 negative_patterns = None
170 if len(pattern_groups) > 1:
171 negative_patterns = pattern_groups[1].split(':')
172 tests = []
173 for test in all_tests:
174 test_name = self._GetTestName(test)
175 # Test name must by matched by one positive pattern.
176 for pattern in positive_patterns:
177 if fnmatch.fnmatch(test_name, pattern):
178 break
179 else:
180 continue
181 # Test name must not be matched by any negative patterns.
182 for pattern in negative_patterns or []:
183 if fnmatch.fnmatch(test_name, pattern):
184 break
185 else:
186 tests += [test]
187 return tests
188
189 def _Run(self): 104 def _Run(self):
190 """Runs the unit tests.""" 105 """Runs the unit tests."""
191 all_tests = unittest.defaultTestLoader.loadTestsFromNames(_TEST_MODULES) 106 all_tests = unittest.defaultTestLoader.loadTestsFromNames(_TEST_MODULES)
192 tests = self._FilterTestSuite(all_tests, self._opts.filter) 107 tests = unittest_util.FilterTestSuite(all_tests, self._opts.filter)
193 result = pyauto_utils.GTestTextTestRunner(verbosity=1).run(tests) 108 result = unittest_util.TextTestRunner(verbosity=1).run(tests)
194 # Run tests again if installation type is 'both'(i.e., user and system). 109 # Run tests again if installation type is 'both'(i.e., user and system).
195 if self._opts.install_type == 'both': 110 if self._opts.install_type == 'both':
196 # Load the tests again so test parameters can be reinitialized. 111 # Load the tests again so test parameters can be reinitialized.
197 all_tests = unittest.defaultTestLoader.loadTestsFromNames(_TEST_MODULES) 112 all_tests = unittest.defaultTestLoader.loadTestsFromNames(_TEST_MODULES)
198 tests = self._FilterTestSuite(all_tests, self._opts.filter) 113 tests = unittest_util.FilterTestSuite(all_tests, self._opts.filter)
199 InstallTest.SetInstallType(chrome_installer_win.InstallationType.SYSTEM) 114 InstallTest.SetInstallType(chrome_installer_win.InstallationType.SYSTEM)
200 result = pyauto_utils.GTestTextTestRunner(verbosity=1).run(tests) 115 result = unittest_util.TextTestRunner(verbosity=1).run(tests)
201 del(tests) 116 del(tests)
202 if not result.wasSuccessful(): 117 if not result.wasSuccessful():
203 print >>sys.stderr, ('Not all tests were successful.') 118 print >>sys.stderr, ('Not all tests were successful.')
204 sys.exit(1) 119 sys.exit(1)
205 sys.exit(0) 120 sys.exit(0)
206 121
207 122
208 if __name__ == '__main__': 123 if __name__ == '__main__':
209 Main() 124 Main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698