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

Side by Side Diff: chrome/test/install_test/install_test.py

Issue 11262040: Revert 164090 - Moved Main class to a new file called run_install_tests.py and modified it by addin… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 1 month 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
« no previous file with comments | « no previous file | chrome/test/install_test/run_install_tests.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Test fixture for tests involving installing/updating Chrome. 5 """Test fixture for tests involving installing/updating Chrome.
6 6
7 Provides an interface to install or update chrome from within a testcase, and 7 Provides an interface to install or update chrome from within a testcase, and
8 allows users to run tests using installed version of Chrome. User and system 8 allows users to run tests using installed version of Chrome. User and system
9 level installations are supported, and either one can be used for running the 9 level installations are supported, and either one can be used for running the
10 tests. Currently the only platform it supports is Windows. 10 tests. Currently the only platform it supports is Windows.
11 """ 11 """
12 12
13 import atexit 13 import atexit
14 import logging
15 import optparse
14 import os 16 import os
15 import platform 17 import platform
18 import re
19 import shutil
16 import stat 20 import stat
17 import sys 21 import sys
18 import tempfile 22 import tempfile
19 import unittest 23 import unittest
20 import urllib 24 import urllib
21 25
22 import chrome_installer_win 26 import chrome_installer_win
23 27
24 _DIRECTORY = os.path.dirname(os.path.abspath(__file__)) 28 _DIRECTORY = os.path.dirname(os.path.abspath(__file__))
25 sys.path.append(os.path.join(os.path.dirname(_DIRECTORY), 'pyautolib')) 29 sys.path.append(os.path.join(os.path.dirname(_DIRECTORY), 'pyautolib'))
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 builds = list(frozenset(builds)) 215 builds = list(frozenset(builds))
212 for build in builds: 216 for build in builds:
213 url = '%s%s/%s/mini_installer.exe' % (base_url, build, system) 217 url = '%s%s/%s/mini_installer.exe' % (base_url, build, system)
214 installer_path = os.path.join(tempdir, 'mini_installer_%s.exe' % build) 218 installer_path = os.path.join(tempdir, 'mini_installer_%s.exe' % build)
215 InstallTest._installer_paths[build] = installer_path 219 InstallTest._installer_paths[build] = installer_path
216 InstallTest._Download(url, installer_path) 220 InstallTest._Download(url, installer_path)
217 InstallTest._chrome_driver = os.path.join(tempdir, 'chromedriver.exe') 221 InstallTest._chrome_driver = os.path.join(tempdir, 'chromedriver.exe')
218 url = '%s%s/%s/%s/chromedriver.exe' % (base_url, build, system, 222 url = '%s%s/%s/%s/chromedriver.exe' % (base_url, build, system,
219 'chrome-win32.test') 223 'chrome-win32.test')
220 InstallTest._Download(url, InstallTest._chrome_driver) 224 InstallTest._Download(url, InstallTest._chrome_driver)
225
226
227 class Main(object):
228 """Main program for running Updater tests."""
229
230 def __init__(self):
231 self._SetLoggingConfiguration()
232 self._ParseArgs()
233 self._Run()
234
235 def _ParseArgs(self):
236 """Parses command line arguments."""
237 parser = optparse.OptionParser()
238 parser.add_option(
239 '-u', '--url', type='string', default='', dest='url',
240 help='Specifies the build url, without the build number.')
241 parser.add_option(
242 '-o', '--options', type='string', default='',
243 help='Specifies any additional Chrome options (i.e. --system-level).')
244 parser.add_option(
245 '--install-build', type='string', default='', dest='install_build',
246 help='Specifies the build to be used for fresh install testing.')
247 parser.add_option(
248 '--update-builds', type='string', default='', dest='update_builds',
249 help='Specifies the builds to be used for updater testing.')
250 parser.add_option(
251 '--install-type', type='string', default='user', dest='install_type',
252 help='Type of installation (i.e., user, system, or both)')
253 self._opts, self._args = parser.parse_args()
254 self._ValidateArgs()
255 if(self._opts.install_type == 'system' or
256 self._opts.install_type == 'user'):
257 install_type = ({
258 'system' : chrome_installer_win.InstallationType.SYSTEM,
259 'user' : chrome_installer_win.InstallationType.USER}).get(
260 self._opts.install_type)
261 InstallTest.SetInstallType(install_type)
262 update_builds = (self._opts.update_builds.split(',') if
263 self._opts.update_builds else [])
264 options = self._opts.options.split(',') if self._opts.options else []
265 InstallTest.InitTestFixture(self._opts.install_build,
266 update_builds,
267 self._opts.url,
268 options)
269
270 def _ValidateArgs(self):
271 """Verifies the sanity of the command arguments.
272
273 Confirms that all specified builds have a valid version number, and the
274 build urls are valid.
275 """
276 builds = []
277 if self._opts.install_build:
278 builds.append(self._opts.install_build)
279 if self._opts.update_builds:
280 builds.extend(self._opts.update_builds.split(','))
281 builds = list(frozenset(builds))
282 for build in builds:
283 if not re.match('\d+\.\d+\.\d+\.\d+', build):
284 raise RuntimeError('Invalid build number: %s' % build)
285 if not pyauto_utils.DoesUrlExist('%s/%s/' % (self._opts.url, build)):
286 raise RuntimeError('Could not locate build no. %s' % build)
287
288 def _SetLoggingConfiguration(self):
289 """Sets the basic logging configuration."""
290 log_format = '%(asctime)s %(levelname)-8s %(message)s'
291 logging.basicConfig(level=logging.INFO, format=log_format)
292
293 def _GetTests(self):
294 """Returns a list of unittests from the calling script."""
295 mod_name = [os.path.splitext(os.path.basename(sys.argv[0]))[0]]
296 if os.path.dirname(sys.argv[0]) not in sys.path:
297 sys.path.append(os.path.dirname(sys.argv[0]))
298 return unittest.defaultTestLoader.loadTestsFromNames(mod_name)
299
300 def _Run(self):
301 """Runs the unit tests."""
302 tests = self._GetTests()
303 result = pyauto_utils.GTestTextTestRunner(verbosity=1).run(tests)
304 del(tests)
305 if not result.wasSuccessful():
306 print >>sys.stderr, ('Not all tests were successful.')
307 sys.exit(1)
308 sys.exit(0)
OLDNEW
« no previous file with comments | « no previous file | chrome/test/install_test/run_install_tests.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698