| OLD | NEW | 
|---|
| 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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 134     TestCaseUtils.tearDown(self) | 134     TestCaseUtils.tearDown(self) | 
| 135     mox.MoxTestBase.tearDown(self) | 135     mox.MoxTestBase.tearDown(self) | 
| 136 | 136 | 
| 137   def MockList(self, parent, items_to_mock): | 137   def MockList(self, parent, items_to_mock): | 
| 138     for item in items_to_mock: | 138     for item in items_to_mock: | 
| 139       # Skip over items not present because of OS-specific implementation, | 139       # Skip over items not present because of OS-specific implementation, | 
| 140       # implemented only in later python version, etc. | 140       # implemented only in later python version, etc. | 
| 141       if hasattr(parent, item): | 141       if hasattr(parent, item): | 
| 142         try: | 142         try: | 
| 143           self.mox.StubOutWithMock(parent, item) | 143           self.mox.StubOutWithMock(parent, item) | 
| 144         except TypeError: | 144         except TypeError, e: | 
| 145           raise TypeError('Couldn\'t mock %s in %s' % (item, parent.__name__)) | 145           raise TypeError( | 
|  | 146               'Couldn\'t mock %s in %s: %s' % (item, parent.__name__, e)) | 
| 146 | 147 | 
| 147   def UnMock(self, obj, name): | 148   def UnMock(self, obj, name): | 
| 148     """Restore an object inside a test.""" | 149     """Restore an object inside a test.""" | 
| 149     for (parent, old_child, child_name) in self.mox.stubs.cache: | 150     for (parent, old_child, child_name) in self.mox.stubs.cache: | 
| 150       if parent == obj and child_name == name: | 151       if parent == obj and child_name == name: | 
| 151         setattr(parent, child_name, old_child) | 152         setattr(parent, child_name, old_child) | 
| 152         break | 153         break | 
| OLD | NEW | 
|---|