| OLD | NEW |
| (Empty) | |
| 1 #!/usr/bin/env python |
| 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 |
| 4 # found in the LICENSE file. |
| 5 |
| 6 import sys |
| 7 import unittest |
| 8 |
| 9 |
| 10 class _GTestTextTestResult(unittest._TextTestResult): |
| 11 """A test result class that can print formatted text results to a stream. |
| 12 |
| 13 Results printed in conformance with gtest output format, like: |
| 14 [ RUN ] autofill.AutofillTest.testAutofillInvalid: "test desc." |
| 15 [ OK ] autofill.AutofillTest.testAutofillInvalid |
| 16 [ RUN ] autofill.AutofillTest.testFillProfile: "test desc." |
| 17 [ OK ] autofill.AutofillTest.testFillProfile |
| 18 [ RUN ] autofill.AutofillTest.testFillProfileCrazyCharacters: "Test." |
| 19 [ OK ] autofill.AutofillTest.testFillProfileCrazyCharacters |
| 20 """ |
| 21 |
| 22 def __init__(self, stream, descriptions, verbosity): |
| 23 unittest._TextTestResult.__init__(self, stream, descriptions, verbosity) |
| 24 |
| 25 def _GetTestURI(self, test): |
| 26 if sys.version_info[:2] <= (2, 4): |
| 27 return '%s.%s' % (unittest._strclass(test.__class__), |
| 28 test._TestCase__testMethodName) |
| 29 return '%s.%s' % (unittest._strclass(test.__class__), test._testMethodName) |
| 30 |
| 31 def getDescription(self, test): |
| 32 return '%s: "%s"' % (self._GetTestURI(test), test.shortDescription()) |
| 33 |
| 34 def startTest(self, test): |
| 35 unittest.TestResult.startTest(self, test) |
| 36 self.stream.writeln('[ RUN ] %s' % self.getDescription(test)) |
| 37 |
| 38 def addSuccess(self, test): |
| 39 unittest.TestResult.addSuccess(self, test) |
| 40 self.stream.writeln('[ OK ] %s' % self._GetTestURI(test)) |
| 41 |
| 42 def addError(self, test, err): |
| 43 unittest.TestResult.addError(self, test, err) |
| 44 self.stream.writeln('[ ERROR ] %s' % self._GetTestURI(test)) |
| 45 |
| 46 def addFailure(self, test, err): |
| 47 unittest.TestResult.addFailure(self, test, err) |
| 48 self.stream.writeln('[ FAILED ] %s' % self._GetTestURI(test)) |
| 49 |
| 50 |
| 51 class GTestTextTestRunner(unittest.TextTestRunner): |
| 52 """Test Runner for displaying test results in textual format. |
| 53 |
| 54 Results are displayed in conformance with gtest output. |
| 55 """ |
| 56 |
| 57 def __init__(self, verbosity=1): |
| 58 unittest.TextTestRunner.__init__(self, stream=sys.stderr, |
| 59 verbosity=verbosity) |
| 60 |
| 61 def _makeResult(self): |
| 62 return _GTestTextTestResult(self.stream, self.descriptions, self.verbosity) |
| OLD | NEW |