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

Side by Side Diff: Tools/Scripts/webkitpy/thirdparty/unittest2/result.py

Issue 20652002: Fix trailing whitespace in scripts and misc. files (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Don't change literal diff. Created 7 years, 5 months 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
OLDNEW
1 """Test result object""" 1 """Test result object"""
2 2
3 import sys 3 import sys
4 import traceback 4 import traceback
5 import unittest 5 import unittest
6 6
7 from StringIO import StringIO 7 from StringIO import StringIO
8 8
9 from unittest2 import util 9 from unittest2 import util
10 from unittest2.compatibility import wraps 10 from unittest2.compatibility import wraps
(...skipping 18 matching lines...) Expand all
29 Test results are automatically managed by the TestCase and TestSuite 29 Test results are automatically managed by the TestCase and TestSuite
30 classes, and do not need to be explicitly manipulated by writers of tests. 30 classes, and do not need to be explicitly manipulated by writers of tests.
31 31
32 Each instance holds the total number of tests run, and collections of 32 Each instance holds the total number of tests run, and collections of
33 failures and errors that occurred among those test runs. The collections 33 failures and errors that occurred among those test runs. The collections
34 contain tuples of (testcase, exceptioninfo), where exceptioninfo is the 34 contain tuples of (testcase, exceptioninfo), where exceptioninfo is the
35 formatted traceback of the error that occurred. 35 formatted traceback of the error that occurred.
36 """ 36 """
37 _previousTestClass = None 37 _previousTestClass = None
38 _moduleSetUpFailed = False 38 _moduleSetUpFailed = False
39 39
40 def __init__(self): 40 def __init__(self):
41 self.failfast = False 41 self.failfast = False
42 self.failures = [] 42 self.failures = []
43 self.errors = [] 43 self.errors = []
44 self.testsRun = 0 44 self.testsRun = 0
45 self.skipped = [] 45 self.skipped = []
46 self.expectedFailures = [] 46 self.expectedFailures = []
47 self.unexpectedSuccesses = [] 47 self.unexpectedSuccesses = []
48 self.shouldStop = False 48 self.shouldStop = False
49 self.buffer = False 49 self.buffer = False
50 self._stdout_buffer = None 50 self._stdout_buffer = None
51 self._stderr_buffer = None 51 self._stderr_buffer = None
52 self._original_stdout = sys.stdout 52 self._original_stdout = sys.stdout
53 self._original_stderr = sys.stderr 53 self._original_stderr = sys.stderr
54 self._mirrorOutput = False 54 self._mirrorOutput = False
55 55
56 def startTest(self, test): 56 def startTest(self, test):
57 "Called when the given test is about to be run" 57 "Called when the given test is about to be run"
58 self.testsRun += 1 58 self.testsRun += 1
59 self._mirrorOutput = False 59 self._mirrorOutput = False
60 if self.buffer: 60 if self.buffer:
61 if self._stderr_buffer is None: 61 if self._stderr_buffer is None:
62 self._stderr_buffer = StringIO() 62 self._stderr_buffer = StringIO()
63 self._stdout_buffer = StringIO() 63 self._stdout_buffer = StringIO()
64 sys.stdout = self._stdout_buffer 64 sys.stdout = self._stdout_buffer
65 sys.stderr = self._stderr_buffer 65 sys.stderr = self._stderr_buffer
(...skipping 11 matching lines...) Expand all
77 output = sys.stdout.getvalue() 77 output = sys.stdout.getvalue()
78 error = sys.stderr.getvalue() 78 error = sys.stderr.getvalue()
79 if output: 79 if output:
80 if not output.endswith('\n'): 80 if not output.endswith('\n'):
81 output += '\n' 81 output += '\n'
82 self._original_stdout.write(STDOUT_LINE % output) 82 self._original_stdout.write(STDOUT_LINE % output)
83 if error: 83 if error:
84 if not error.endswith('\n'): 84 if not error.endswith('\n'):
85 error += '\n' 85 error += '\n'
86 self._original_stderr.write(STDERR_LINE % error) 86 self._original_stderr.write(STDERR_LINE % error)
87 87
88 sys.stdout = self._original_stdout 88 sys.stdout = self._original_stdout
89 sys.stderr = self._original_stderr 89 sys.stderr = self._original_stderr
90 self._stdout_buffer.seek(0) 90 self._stdout_buffer.seek(0)
91 self._stdout_buffer.truncate() 91 self._stdout_buffer.truncate()
92 self._stderr_buffer.seek(0) 92 self._stderr_buffer.seek(0)
93 self._stderr_buffer.truncate() 93 self._stderr_buffer.truncate()
94 self._mirrorOutput = False 94 self._mirrorOutput = False
95 95
96 96
97 def stopTestRun(self): 97 def stopTestRun(self):
98 """Called once after all tests are executed. 98 """Called once after all tests are executed.
99 99
100 See stopTest for a method called after each test. 100 See stopTest for a method called after each test.
101 """ 101 """
102 102
103 @failfast 103 @failfast
104 def addError(self, test, err): 104 def addError(self, test, err):
105 """Called when an error has occurred. 'err' is a tuple of values as 105 """Called when an error has occurred. 'err' is a tuple of values as
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 exctype, value, tb = err 146 exctype, value, tb = err
147 # Skip test runner traceback levels 147 # Skip test runner traceback levels
148 while tb and self._is_relevant_tb_level(tb): 148 while tb and self._is_relevant_tb_level(tb):
149 tb = tb.tb_next 149 tb = tb.tb_next
150 if exctype is test.failureException: 150 if exctype is test.failureException:
151 # Skip assert*() traceback levels 151 # Skip assert*() traceback levels
152 length = self._count_relevant_tb_levels(tb) 152 length = self._count_relevant_tb_levels(tb)
153 msgLines = traceback.format_exception(exctype, value, tb, length) 153 msgLines = traceback.format_exception(exctype, value, tb, length)
154 else: 154 else:
155 msgLines = traceback.format_exception(exctype, value, tb) 155 msgLines = traceback.format_exception(exctype, value, tb)
156 156
157 if self.buffer: 157 if self.buffer:
158 output = sys.stdout.getvalue() 158 output = sys.stdout.getvalue()
159 error = sys.stderr.getvalue() 159 error = sys.stderr.getvalue()
160 if output: 160 if output:
161 if not output.endswith('\n'): 161 if not output.endswith('\n'):
162 output += '\n' 162 output += '\n'
163 msgLines.append(STDOUT_LINE % output) 163 msgLines.append(STDOUT_LINE % output)
164 if error: 164 if error:
165 if not error.endswith('\n'): 165 if not error.endswith('\n'):
166 error += '\n' 166 error += '\n'
167 msgLines.append(STDERR_LINE % error) 167 msgLines.append(STDERR_LINE % error)
168 return ''.join(msgLines) 168 return ''.join(msgLines)
169 169
170 def _is_relevant_tb_level(self, tb): 170 def _is_relevant_tb_level(self, tb):
171 return '__unittest' in tb.tb_frame.f_globals 171 return '__unittest' in tb.tb_frame.f_globals
172 172
173 def _count_relevant_tb_levels(self, tb): 173 def _count_relevant_tb_levels(self, tb):
174 length = 0 174 length = 0
175 while tb and not self._is_relevant_tb_level(tb): 175 while tb and not self._is_relevant_tb_level(tb):
176 length += 1 176 length += 1
177 tb = tb.tb_next 177 tb = tb.tb_next
178 return length 178 return length
179 179
180 def __repr__(self): 180 def __repr__(self):
181 return "<%s run=%i errors=%i failures=%i>" % \ 181 return "<%s run=%i errors=%i failures=%i>" % \
182 (util.strclass(self.__class__), self.testsRun, len(self.errors), 182 (util.strclass(self.__class__), self.testsRun, len(self.errors),
183 len(self.failures)) 183 len(self.failures))
OLDNEW
« no previous file with comments | « Tools/Scripts/webkitpy/thirdparty/unittest2/main.py ('k') | Tools/Scripts/webkitpy/thirdparty/unittest2/runner.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698