| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 """ | 5 """ |
| 6 Unit tests for decorators.py. | 6 Unit tests for decorators.py. |
| 7 """ | 7 """ |
| 8 | 8 |
| 9 # pylint: disable=W0613 | 9 # pylint: disable=W0613 |
| 10 | 10 |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 raise device_errors.CommandFailedError('testCommand failed') | 216 raise device_errors.CommandFailedError('testCommand failed') |
| 217 | 217 |
| 218 # pylint: disable=no-self-use | 218 # pylint: disable=no-self-use |
| 219 | 219 |
| 220 @decorators.WithTimeoutAndRetriesFromInstance( | 220 @decorators.WithTimeoutAndRetriesFromInstance( |
| 221 'default_timeout', 'default_retries') | 221 'default_timeout', 'default_retries') |
| 222 def alwaysReturnsTimeout(self, timeout=None, retries=None): | 222 def alwaysReturnsTimeout(self, timeout=None, retries=None): |
| 223 return timeout | 223 return timeout |
| 224 | 224 |
| 225 @decorators.WithTimeoutAndRetriesFromInstance( | 225 @decorators.WithTimeoutAndRetriesFromInstance( |
| 226 'default_timeout', 'default_retries', min_default_timeout=100) |
| 227 def alwaysReturnsTimeoutWithMin(self, timeout=None, retries=None): |
| 228 return timeout |
| 229 |
| 230 @decorators.WithTimeoutAndRetriesFromInstance( |
| 226 'default_timeout', 'default_retries') | 231 'default_timeout', 'default_retries') |
| 227 def alwaysReturnsRetries(self, timeout=None, retries=None): | 232 def alwaysReturnsRetries(self, timeout=None, retries=None): |
| 228 return retries | 233 return retries |
| 229 | 234 |
| 230 @decorators.WithTimeoutAndRetriesFromInstance( | 235 @decorators.WithTimeoutAndRetriesFromInstance( |
| 231 'default_timeout', 'default_retries') | 236 'default_timeout', 'default_retries') |
| 232 def alwaysRaisesProvidedException(self, exception, timeout=None, | 237 def alwaysRaisesProvidedException(self, exception, timeout=None, |
| 233 retries=None): | 238 retries=None): |
| 234 raise exception | 239 raise exception |
| 235 | 240 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 264 | 269 |
| 265 def testMethodDecoratorPassesValues(self): | 270 def testMethodDecoratorPassesValues(self): |
| 266 """Tests that the method decorator passes timeout and retries kwargs.""" | 271 """Tests that the method decorator passes timeout and retries kwargs.""" |
| 267 test_obj = self._MethodDecoratorTestObject( | 272 test_obj = self._MethodDecoratorTestObject( |
| 268 self, default_timeout=42, default_retries=31) | 273 self, default_timeout=42, default_retries=31) |
| 269 self.assertEquals(42, test_obj.alwaysReturnsTimeout()) | 274 self.assertEquals(42, test_obj.alwaysReturnsTimeout()) |
| 270 self.assertEquals(41, test_obj.alwaysReturnsTimeout(timeout=41)) | 275 self.assertEquals(41, test_obj.alwaysReturnsTimeout(timeout=41)) |
| 271 self.assertEquals(31, test_obj.alwaysReturnsRetries()) | 276 self.assertEquals(31, test_obj.alwaysReturnsRetries()) |
| 272 self.assertEquals(32, test_obj.alwaysReturnsRetries(retries=32)) | 277 self.assertEquals(32, test_obj.alwaysReturnsRetries(retries=32)) |
| 273 | 278 |
| 279 def testMethodDecoratorUsesMiniumumTimeout(self): |
| 280 test_obj = self._MethodDecoratorTestObject( |
| 281 self, default_timeout=42, default_retries=31) |
| 282 self.assertEquals(100, test_obj.alwaysReturnsTimeoutWithMin()) |
| 283 self.assertEquals(41, test_obj.alwaysReturnsTimeoutWithMin(timeout=41)) |
| 284 |
| 274 def testMethodDecoratorTranslatesReraiserExceptions(self): | 285 def testMethodDecoratorTranslatesReraiserExceptions(self): |
| 275 test_obj = self._MethodDecoratorTestObject(self) | 286 test_obj = self._MethodDecoratorTestObject(self) |
| 276 | 287 |
| 277 exception_desc = 'Reraiser thread timeout error' | 288 exception_desc = 'Reraiser thread timeout error' |
| 278 with self.assertRaises(device_errors.CommandTimeoutError) as e: | 289 with self.assertRaises(device_errors.CommandTimeoutError) as e: |
| 279 test_obj.alwaysRaisesProvidedException( | 290 test_obj.alwaysRaisesProvidedException( |
| 280 reraiser_thread.TimeoutError(exception_desc)) | 291 reraiser_thread.TimeoutError(exception_desc)) |
| 281 self.assertEquals(exception_desc, str(e.exception)) | 292 self.assertEquals(exception_desc, str(e.exception)) |
| 282 | 293 |
| 283 if __name__ == '__main__': | 294 if __name__ == '__main__': |
| 284 unittest.main(verbosity=2) | 295 unittest.main(verbosity=2) |
| 285 | 296 |
| OLD | NEW |