forked from sanyaade-mobiledev/chromium.src
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[chromedriver] Flush stdout when printing buildbot annotations.
R=chrisgao@chromium.org Review URL: https://codereview.chromium.org/15926002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@201904 0039d316-1c4b-4281-b951-d872f2087c98
- Loading branch information
kkania@chromium.org
committed
May 23, 2013
1 parent
aa3030b
commit 307ef81
Showing
7 changed files
with
367 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Copyright (c) 2012 The Chromium Authors. All rights reserved. | ||
# Use of this source code is governed by a BSD-style license that can be | ||
# found in the LICENSE file. | ||
|
||
"""Paths to common resources in the Chrome repository.""" | ||
|
||
import os | ||
|
||
|
||
_THIS_DIR = os.path.abspath(os.path.dirname(__file__)) | ||
|
||
|
||
def GetSrc(): | ||
"""Returns the path to the root src directory.""" | ||
return os.path.join(_THIS_DIR, os.pardir, os.pardir, os.pardir) | ||
|
||
|
||
def GetTestData(): | ||
"""Returns the path to the src/chrome/test/data directory.""" | ||
return os.path.join(GetSrc(), 'chrome', 'test', 'data') | ||
|
||
|
||
def GetBuildDir(required_paths): | ||
"""Returns the preferred build directory that contains given paths.""" | ||
dirs = ['out', 'build', 'xcodebuild', 'sconsbuild'] | ||
rel_dirs = [os.path.join(x, 'Release') for x in dirs] | ||
debug_dirs = [os.path.join(x, 'Debug') for x in dirs] | ||
full_dirs = [os.path.join(GetSrc(), x) for x in rel_dirs + debug_dirs] | ||
for build_dir in full_dirs: | ||
for required_path in required_paths: | ||
if not os.path.exists(os.path.join(build_dir, required_path)): | ||
break | ||
else: | ||
return build_dir | ||
raise RuntimeError('Cannot find build directory containing ' + | ||
', '.join(required_paths)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
# Copyright (c) 2012 The Chromium Authors. All rights reserved. | ||
# Use of this source code is governed by a BSD-style license that can be | ||
# found in the LICENSE file. | ||
|
||
"""Utilities for dealing with the python unittest module.""" | ||
|
||
import fnmatch | ||
import sys | ||
import unittest | ||
|
||
|
||
class _TextTestResult(unittest._TextTestResult): | ||
"""A test result class that can print formatted text results to a stream. | ||
Results printed in conformance with gtest output format, like: | ||
[ RUN ] autofill.AutofillTest.testAutofillInvalid: "test desc." | ||
[ OK ] autofill.AutofillTest.testAutofillInvalid | ||
[ RUN ] autofill.AutofillTest.testFillProfile: "test desc." | ||
[ OK ] autofill.AutofillTest.testFillProfile | ||
[ RUN ] autofill.AutofillTest.testFillProfileCrazyCharacters: "Test." | ||
[ OK ] autofill.AutofillTest.testFillProfileCrazyCharacters | ||
""" | ||
def __init__(self, stream, descriptions, verbosity): | ||
unittest._TextTestResult.__init__(self, stream, descriptions, verbosity) | ||
self._fails = set() | ||
|
||
def _GetTestURI(self, test): | ||
return '%s.%s.%s' % (test.__class__.__module__, | ||
test.__class__.__name__, | ||
test._testMethodName) | ||
|
||
def getDescription(self, test): | ||
return '%s: "%s"' % (self._GetTestURI(test), test.shortDescription()) | ||
|
||
def startTest(self, test): | ||
unittest.TestResult.startTest(self, test) | ||
self.stream.writeln('[ RUN ] %s' % self.getDescription(test)) | ||
|
||
def addSuccess(self, test): | ||
unittest.TestResult.addSuccess(self, test) | ||
self.stream.writeln('[ OK ] %s' % self._GetTestURI(test)) | ||
|
||
def addError(self, test, err): | ||
unittest.TestResult.addError(self, test, err) | ||
self.stream.writeln('[ ERROR ] %s' % self._GetTestURI(test)) | ||
self._fails.add(self._GetTestURI(test)) | ||
|
||
def addFailure(self, test, err): | ||
unittest.TestResult.addFailure(self, test, err) | ||
self.stream.writeln('[ FAILED ] %s' % self._GetTestURI(test)) | ||
self._fails.add(self._GetTestURI(test)) | ||
|
||
def getRetestFilter(self): | ||
return ':'.join(self._fails) | ||
|
||
|
||
class TextTestRunner(unittest.TextTestRunner): | ||
"""Test Runner for displaying test results in textual format. | ||
Results are displayed in conformance with google test output. | ||
""" | ||
|
||
def __init__(self, verbosity=1): | ||
unittest.TextTestRunner.__init__(self, stream=sys.stderr, | ||
verbosity=verbosity) | ||
|
||
def _makeResult(self): | ||
return _TextTestResult(self.stream, self.descriptions, self.verbosity) | ||
|
||
|
||
def GetTestsFromSuite(suite): | ||
"""Returns all the tests from a given test suite.""" | ||
tests = [] | ||
for x in suite: | ||
if isinstance(x, unittest.TestSuite): | ||
tests += GetTestsFromSuite(x) | ||
else: | ||
tests += [x] | ||
return tests | ||
|
||
|
||
def GetTestNamesFromSuite(suite): | ||
"""Returns a list of every test name in the given suite.""" | ||
return map(lambda x: GetTestName(x), GetTestsFromSuite(suite)) | ||
|
||
|
||
def GetTestName(test): | ||
"""Gets the test name of the given unittest test.""" | ||
return '.'.join([test.__class__.__module__, | ||
test.__class__.__name__, | ||
test._testMethodName]) | ||
|
||
|
||
def FilterTestSuite(suite, gtest_filter): | ||
"""Returns a new filtered tests suite based on the given gtest filter. | ||
See http://code.google.com/p/googletest/wiki/AdvancedGuide | ||
for gtest_filter specification. | ||
""" | ||
return unittest.TestSuite(FilterTests(GetTestsFromSuite(suite), gtest_filter)) | ||
|
||
|
||
def FilterTests(all_tests, gtest_filter): | ||
"""Returns a filtered list of tests based on the given gtest filter. | ||
See http://code.google.com/p/googletest/wiki/AdvancedGuide | ||
for gtest_filter specification. | ||
""" | ||
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 = 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 |
Oops, something went wrong.