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

Side by Side Diff: testing_support/super_mox.py

Issue 10828393: Fix depot_tools presubmit check for ubuntu 12.04. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 8 years, 4 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
« no previous file with comments | « no previous file | tests/presubmit_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Simplify unit tests based on pymox.""" 5 """Simplify unit tests based on pymox."""
6 6
7 import os 7 import os
8 import random 8 import random
9 import shutil 9 import shutil
10 import string 10 import string
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 # Override the mock with a StringIO, it's much less painful to test. 91 # Override the mock with a StringIO, it's much less painful to test.
92 self._old_stdout = sys.stdout 92 self._old_stdout = sys.stdout
93 stdout = StringIO.StringIO() 93 stdout = StringIO.StringIO()
94 stdout.flush = lambda: None 94 stdout.flush = lambda: None
95 sys.stdout = stdout 95 sys.stdout = stdout
96 96
97 def tearDown(self): 97 def tearDown(self):
98 try: 98 try:
99 # If sys.stdout was used, self.checkstdout() must be called. 99 # If sys.stdout was used, self.checkstdout() must be called.
100 # pylint: disable=E1101 100 # pylint: disable=E1101
101 self.assertEquals('', sys.stdout.getvalue()) 101 if not sys.stdout.closed:
102 self.assertEquals('', sys.stdout.getvalue())
102 except AttributeError: 103 except AttributeError:
103 pass 104 pass
104 sys.stdout = self._old_stdout 105 sys.stdout = self._old_stdout
105 106
106 def checkstdout(self, expected): 107 def checkstdout(self, expected):
107 value = sys.stdout.getvalue() 108 value = sys.stdout.getvalue()
108 sys.stdout.close() 109 sys.stdout.close()
109 # pylint: disable=E1101 110 # pylint: disable=E1101
110 self.assertEquals(expected, value) 111 self.assertEquals(expected, value)
111 112
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 except TypeError, e: 146 except TypeError, e:
146 raise TypeError( 147 raise TypeError(
147 'Couldn\'t mock %s in %s: %s' % (item, parent.__name__, e)) 148 'Couldn\'t mock %s in %s: %s' % (item, parent.__name__, e))
148 149
149 def UnMock(self, obj, name): 150 def UnMock(self, obj, name):
150 """Restore an object inside a test.""" 151 """Restore an object inside a test."""
151 for (parent, old_child, child_name) in self.mox.stubs.cache: 152 for (parent, old_child, child_name) in self.mox.stubs.cache:
152 if parent == obj and child_name == name: 153 if parent == obj and child_name == name:
153 setattr(parent, child_name, old_child) 154 setattr(parent, child_name, old_child)
154 break 155 break
OLDNEW
« no previous file with comments | « no previous file | tests/presubmit_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698