diff options
author | nkang@chromium.org <nkang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-14 18:35:03 +0000 |
---|---|---|
committer | nkang@chromium.org <nkang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-14 18:35:03 +0000 |
commit | af275c58611add67b9fa1e6efa90733dc79c2303 (patch) | |
tree | d567d7379e80359d9bd52affdc2a516d82f82ca5 /chrome/test/install_test | |
parent | e9ef692967ffc7e5da31cfe8b031d4eabb6133e6 (diff) | |
download | chromium_src-af275c58611add67b9fa1e6efa90733dc79c2303.zip chromium_src-af275c58611add67b9fa1e6efa90733dc79c2303.tar.gz chromium_src-af275c58611add67b9fa1e6efa90733dc79c2303.tar.bz2 |
Removed 'pyautolib' dependencies from install_test and removed some common code from run_install_test.py. Also, modified util.py and copied DoesUrlExist to it, so install_test doesn't have to depend on 'pyautolib.pyauto_utils'.
BUG=163708,163718
NOTRY=true
Review URL: https://chromiumcodereview.appspot.com/11553041
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@173176 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/install_test')
-rw-r--r-- | chrome/test/install_test/install_test.py | 47 | ||||
-rwxr-xr-x | chrome/test/install_test/run_install_tests.py | 99 |
2 files changed, 13 insertions, 133 deletions
diff --git a/chrome/test/install_test/install_test.py b/chrome/test/install_test/install_test.py index d80a620..280b6a0 100644 --- a/chrome/test/install_test/install_test.py +++ b/chrome/test/install_test/install_test.py @@ -10,22 +10,18 @@ level installations are supported, and either one can be used for running the tests. Currently the only platform it supports is Windows. """ -import atexit import os -import platform -import stat import sys -import tempfile import unittest import urllib import chrome_installer_win _DIRECTORY = os.path.dirname(os.path.abspath(__file__)) -sys.path.append(os.path.join(os.path.dirname(_DIRECTORY), 'pyautolib')) sys.path.append(os.path.join(_DIRECTORY, os.path.pardir, os.path.pardir, os.path.pardir, 'third_party', 'webdriver', 'pylib')) +sys.path.append(os.path.join(_DIRECTORY, os.path.pardir, 'pylib')) # This import should go after sys.path is set appropriately. from chrome import Chrome @@ -33,36 +29,7 @@ from selenium import webdriver import selenium.webdriver.chrome.service as service from selenium.webdriver.chrome.service import WebDriverException -import pyauto_utils - - -def MakeTempDir(parent_dir=None): - """Creates a temporary directory and returns an absolute path to it. - - The temporary directory is automatically deleted when the python interpreter - exits normally. - - Args: - parent_dir: the directory to create the temp dir in. If None, the system - temp dir is used. - - Returns: - The absolute path to the temporary directory. - """ - path = tempfile.mkdtemp(dir=parent_dir) - def DeleteDir(): - # Don't use shutil.rmtree because it can't delete read-only files on Win. - for root, dirs, files in os.walk(path, topdown=False): - for name in files: - filename = os.path.join(root, name) - os.chmod(filename, stat.S_IWRITE) - os.remove(filename) - for name in dirs: - os.rmdir(os.path.join(root, name)) - # Delete parent directory after its contents have been removed. - os.rmdir(path) - atexit.register(DeleteDir) - return path +from common import util class InstallTest(unittest.TestCase): @@ -154,7 +121,7 @@ class InstallTest(unittest.TestCase): if self._install_type == chrome_installer_win.InstallationType.SYSTEM: options.append('--system-level') if master_pref: - options.append('--installerdata="%s"' % master_pref) + options.append('--installerdata=%s' % master_pref) self._installation = chrome_installer_win.Install( self._installer_paths[build], self._install_type, @@ -177,7 +144,7 @@ class InstallTest(unittest.TestCase): url: URL where the file is located. path: Location where file will be downloaded. """ - if not pyauto_utils.DoesUrlExist(url): + if not util.DoesUrlExist(url): raise RuntimeError('Either the URL or the file name is invalid.') urllib.urlretrieve(url, path) @@ -209,13 +176,11 @@ class InstallTest(unittest.TestCase): base_url: Base url of the 'official chrome builds' page. options: A list that contains options to be passed to Chrome installer. """ - system = ({'Windows': 'win', - 'Darwin': 'mac', - 'Linux': 'linux'}).get(platform.system()) + system = util.GetPlatformName() InstallTest._install_build = install_build InstallTest._update_builds = update_builds InstallTest._installer_options = options - tempdir = MakeTempDir() + tempdir = util.MakeTempDir() builds = [] if InstallTest._install_build: builds.append(InstallTest._install_build) diff --git a/chrome/test/install_test/run_install_tests.py b/chrome/test/install_test/run_install_tests.py index 2ee88f8..162c823 100755 --- a/chrome/test/install_test/run_install_tests.py +++ b/chrome/test/install_test/run_install_tests.py @@ -19,7 +19,6 @@ Example: --install-build=24.0.1290.0 --update-builds=24.0.1289.0,24.0.1290.0 """ -import fnmatch import logging import optparse import os @@ -30,10 +29,8 @@ import unittest import chrome_installer_win from install_test import InstallTest -_DIRECTORY = os.path.dirname(os.path.abspath(__file__)) -sys.path.append(os.path.join(os.path.dirname(_DIRECTORY), 'pyautolib')) - -import pyauto_utils +from common import unittest_util +from common import util # To run tests from a module, append the module name to this list. _TEST_MODULES = ['sample_updater'] @@ -96,7 +93,7 @@ class Main(object): for build in builds: if not re.match('\d+\.\d+\.\d+\.\d+', build): raise RuntimeError('Invalid build number: %s' % build) - if not pyauto_utils.DoesUrlExist('%s/%s/' % (self._opts.url, build)): + if not util.DoesUrlExist('%s/%s/' % (self._opts.url, build)): raise RuntimeError('Could not locate build no. %s' % build) def _SetLoggingConfiguration(self): @@ -104,100 +101,18 @@ class Main(object): log_format = '%(asctime)s %(levelname)-8s %(message)s' logging.basicConfig(level=logging.INFO, format=log_format) - def _GetTestsFromSuite(self, suite): - """Returns all the tests from a given test suite. - - Args: - suite: A unittest.TestSuite object. - - Returns: - A list that contains all the tests found in the suite. - """ - tests = [] - for test in suite: - if isinstance(test, unittest.TestSuite): - tests += self._GetTestsFromSuite(test) - else: - tests += [test] - return tests - - def _GetTestName(self, test): - """Gets the test name of the given unittest test. - - Args: - test: A unittest test. - - Returns: - A string representing the full test name. - """ - return '.'.join([test.__module__, test.__class__.__name__, - test._testMethodName]) - - def _FilterTestSuite(self, suite, gtest_filter): - """Returns a new filtered test suite based on the given gtest filter. - - See http://code.google.com/p/googletest/wiki/AdvancedGuide for - gtest_filter specification. - - Args: - suite: A unittest.TestSuite object, which can be obtained by calling - |unittest.defaultTestLoader.loadTestsFromName|. - gtest_filter: The gtest filter to use. Filter can be passed as follows: - --filter=*className* or --filter=*testcaseName. - - Returns: - A unittest.TestSuite object that contains tests that match the gtest - filter. - """ - return unittest.TestSuite( - self._FilterTests(self._GetTestsFromSuite(suite), gtest_filter)) - - def _FilterTests(self, all_tests, gtest_filter): - """Returns a filtered list of tests based on the given gtest filter. - - Args: - all_tests: A list that contains all unittests in a given suite. This - list must be obtained by calling |_GetTestsFromSuite|. - gtest_filter: The gtest filter to use. Filter can be passed as follows: - *className* or *testcaseName. - - Returns: - A list that contains all tests that match the given gtest filter. - """ - pattern_groups = gtest_filter.split('-') - positive_patterns = pattern_groups[0].split(':') - negative_patterns = None - if len(pattern_groups) > 1: - negative_patterns = pattern_groups[1].split(':') - tests = [] - for test in all_tests: - test_name = self._GetTestName(test) - # Test name must by matched by one positive pattern. - for pattern in positive_patterns: - if fnmatch.fnmatch(test_name, pattern): - break - else: - continue - # Test name must not be matched by any negative patterns. - for pattern in negative_patterns or []: - if fnmatch.fnmatch(test_name, pattern): - break - else: - tests += [test] - return tests - def _Run(self): """Runs the unit tests.""" all_tests = unittest.defaultTestLoader.loadTestsFromNames(_TEST_MODULES) - tests = self._FilterTestSuite(all_tests, self._opts.filter) - result = pyauto_utils.GTestTextTestRunner(verbosity=1).run(tests) + tests = unittest_util.FilterTestSuite(all_tests, self._opts.filter) + result = unittest_util.TextTestRunner(verbosity=1).run(tests) # Run tests again if installation type is 'both'(i.e., user and system). if self._opts.install_type == 'both': # Load the tests again so test parameters can be reinitialized. all_tests = unittest.defaultTestLoader.loadTestsFromNames(_TEST_MODULES) - tests = self._FilterTestSuite(all_tests, self._opts.filter) + tests = unittest_util.FilterTestSuite(all_tests, self._opts.filter) InstallTest.SetInstallType(chrome_installer_win.InstallationType.SYSTEM) - result = pyauto_utils.GTestTextTestRunner(verbosity=1).run(tests) + result = unittest_util.TextTestRunner(verbosity=1).run(tests) del(tests) if not result.wasSuccessful(): print >>sys.stderr, ('Not all tests were successful.') |