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

Unified Diff: build/android/pylib/device/decorators_test.py

Issue 1288993002: Revert of [Android] Remove android_commands and android_testrunner. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build/android/pylib/device/decorators.py ('k') | build/android/pylib/device/device_utils.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/pylib/device/decorators_test.py
diff --git a/build/android/pylib/device/decorators_test.py b/build/android/pylib/device/decorators_test.py
index ec167ae014a6759e4e539f4f223911c0bc1a48f4..b75618b09e60d3160869dfd4130fd70f5e795a95 100644
--- a/build/android/pylib/device/decorators_test.py
+++ b/build/android/pylib/device/decorators_test.py
@@ -18,6 +18,12 @@
from pylib.device import decorators
from pylib.device import device_errors
from pylib.utils import reraiser_thread
+
+# TODO(jbudorick) Remove once the DeviceUtils implementations are no longer
+# backed by AndroidCommands / android_testrunner.
+sys.path.append(os.path.join(constants.DIR_SOURCE_ROOT, 'third_party',
+ 'android_testrunner'))
+import errors as old_errors
_DEFAULT_TIMEOUT = 30
_DEFAULT_RETRIES = 3
@@ -72,6 +78,26 @@
self.assertEquals(expected_timeout, actual_timeout)
self.assertEquals(expected_retries, actual_retries)
+ def testFunctionDecoratorTranslatesOldExceptions(self):
+ """Tests that the explicit decorator translates old exceptions."""
+ @decorators.WithTimeoutAndRetries
+ def alwaysRaisesProvidedException(exception, timeout=None, retries=None):
+ raise exception
+
+ exception_desc = 'Old response timeout error'
+ with self.assertRaises(device_errors.CommandTimeoutError) as e:
+ alwaysRaisesProvidedException(
+ old_errors.WaitForResponseTimedOutError(exception_desc),
+ timeout=10, retries=1)
+ self.assertEquals(exception_desc, str(e.exception))
+
+ exception_desc = 'Old device error'
+ with self.assertRaises(device_errors.DeviceUnreachableError) as e:
+ alwaysRaisesProvidedException(
+ old_errors.DeviceUnresponsiveError(exception_desc),
+ timeout=10, retries=1)
+ self.assertEquals(exception_desc, str(e.exception))
+
def testFunctionDecoratorTranslatesReraiserExceptions(self):
"""Tests that the explicit decorator translates reraiser exceptions."""
@decorators.WithTimeoutAndRetries
@@ -140,6 +166,24 @@
self.assertEquals(10, alwaysReturnsRetries())
self.assertEquals(1, alwaysReturnsRetries(retries=1))
+ def testDefaultsFunctionDecoratorTranslatesOldExceptions(self):
+ """Tests that the explicit decorator translates old exceptions."""
+ @decorators.WithTimeoutAndRetriesDefaults(30, 10)
+ def alwaysRaisesProvidedException(exception, timeout=None, retries=None):
+ raise exception
+
+ exception_desc = 'Old response timeout error'
+ with self.assertRaises(device_errors.CommandTimeoutError) as e:
+ alwaysRaisesProvidedException(
+ old_errors.WaitForResponseTimedOutError(exception_desc))
+ self.assertEquals(exception_desc, str(e.exception))
+
+ exception_desc = 'Old device error'
+ with self.assertRaises(device_errors.DeviceUnreachableError) as e:
+ alwaysRaisesProvidedException(
+ old_errors.DeviceUnresponsiveError(exception_desc))
+ self.assertEquals(exception_desc, str(e.exception))
+
def testDefaultsFunctionDecoratorTranslatesReraiserExceptions(self):
"""Tests that the explicit decorator translates reraiser exceptions."""
@decorators.WithTimeoutAndRetriesDefaults(30, 10)
@@ -178,6 +222,24 @@
with self.assertRaises(device_errors.CommandFailedError):
alwaysRaisesCommandFailedError()
self.assertEquals(11, DecoratorsTest._decorated_function_called_count)
+
+ def testExplicitDecoratorTranslatesOldExceptions(self):
+ """Tests that the explicit decorator translates old exceptions."""
+ @decorators.WithExplicitTimeoutAndRetries(30, 10)
+ def alwaysRaisesProvidedException(exception):
+ raise exception
+
+ exception_desc = 'Old response timeout error'
+ with self.assertRaises(device_errors.CommandTimeoutError) as e:
+ alwaysRaisesProvidedException(
+ old_errors.WaitForResponseTimedOutError(exception_desc))
+ self.assertEquals(exception_desc, str(e.exception))
+
+ exception_desc = 'Old device error'
+ with self.assertRaises(device_errors.DeviceUnreachableError) as e:
+ alwaysRaisesProvidedException(
+ old_errors.DeviceUnresponsiveError(exception_desc))
+ self.assertEquals(exception_desc, str(e.exception))
def testExplicitDecoratorTranslatesReraiserExceptions(self):
"""Tests that the explicit decorator translates reraiser exceptions."""
@@ -274,6 +336,21 @@
self.assertEquals(31, test_obj.alwaysReturnsRetries())
self.assertEquals(32, test_obj.alwaysReturnsRetries(retries=32))
+ def testMethodDecoratorTranslatesOldExceptions(self):
+ test_obj = self._MethodDecoratorTestObject(self)
+
+ exception_desc = 'Old response timeout error'
+ with self.assertRaises(device_errors.CommandTimeoutError) as e:
+ test_obj.alwaysRaisesProvidedException(
+ old_errors.WaitForResponseTimedOutError(exception_desc))
+ self.assertEquals(exception_desc, str(e.exception))
+
+ exception_desc = 'Old device error'
+ with self.assertRaises(device_errors.DeviceUnreachableError) as e:
+ test_obj.alwaysRaisesProvidedException(
+ old_errors.DeviceUnresponsiveError(exception_desc))
+ self.assertEquals(exception_desc, str(e.exception))
+
def testMethodDecoratorTranslatesReraiserExceptions(self):
test_obj = self._MethodDecoratorTestObject(self)
« no previous file with comments | « build/android/pylib/device/decorators.py ('k') | build/android/pylib/device/device_utils.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698