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