Bug 1257476 - Ensure Marionette error classes use correct inheritance. r=ato,automatedtester
authorHenrik Skupin <mail@hskupin.info>
Fri, 22 Jul 2016 14:35:55 +0200
changeset 306802 928a0bdcea4c62fa1d192815199051281fd2c49f
parent 306801 efc0b2d797abeb7624071731e6cb25704b502bae
child 306803 aadff7c91cd6aa6a1a75108129af3a0bce00f4d4
push id79943
push usercbook@mozilla.com
push dateWed, 27 Jul 2016 14:39:03 +0000
treeherdermozilla-inbound@950a962b75ea [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato, automatedtester
bugs1257476
milestone50.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1257476 - Ensure Marionette error classes use correct inheritance. r=ato,automatedtester Custom Marionette error classes should not re-invent the message property which already exists in the Exception class. This is fixed by calling constructor appropriately. MozReview-Commit-ID: 1oWjg7MnrSe
testing/marionette/client/marionette_driver/errors.py
testing/marionette/harness/marionette/tests/unit/single_finger_functions.py
testing/marionette/harness/marionette/tests/unit/test_errors.py
testing/marionette/harness/marionette/tests/unit/test_execute_script.py
testing/marionette/harness/marionette/tests/unit/test_proxy.py
testing/marionette/harness/marionette/tests/unit/test_switch_frame.py
testing/marionette/harness/marionette/tests/unit/test_switch_frame_chrome.py
--- a/testing/marionette/client/marionette_driver/errors.py
+++ b/testing/marionette/client/marionette_driver/errors.py
@@ -25,36 +25,36 @@ class MarionetteException(Exception):
             information about the root exception cause.  Expected
             tuple values are (type, value, traceback).
 
         :param stacktrace: Optional string containing a stacktrace
             (typically from a failed JavaScript execution) that will
             be displayed in the exception's string representation.
 
         """
-
-        self.msg = message
         self.cause = cause
         self.stacktrace = stacktrace
 
+        super(MarionetteException, self).__init__(message)
+
     def __str__(self):
-        msg = str(self.msg)
+        msg = str(self.message)
         tb = None
 
         if self.cause:
             if type(self.cause) is tuple:
                 msg += ", caused by %r" % self.cause[0]
                 tb = self.cause[2]
             else:
                 msg += ", caused by %s" % self.cause
         if self.stacktrace:
             st = "".join(["\t%s\n" % x for x in self.stacktrace.splitlines()])
             msg += "\nstacktrace:\n%s" % st
 
-        return "".join(traceback.format_exception(self.__class__, msg, tb))
+        return "".join(traceback.format_exception(self.__class__, msg, tb)).strip()
 
 
 class ElementNotSelectableException(MarionetteException):
     status = "element not selectable"
 
 
 class InvalidArgumentException(MarionetteException):
     status = "invalid argument"
--- a/testing/marionette/harness/marionette/tests/unit/single_finger_functions.py
+++ b/testing/marionette/harness/marionette/tests/unit/single_finger_functions.py
@@ -2,17 +2,18 @@ from marionette_driver.marionette import
 from marionette_driver.errors import TimeoutException
 from marionette_driver.by import By
 
 
 def wait_for_condition_else_raise(marionette, wait_for_condition, expected, script):
     try:
         wait_for_condition(lambda m: expected in m.execute_script(script))
     except TimeoutException as e:
-        raise TimeoutException(e.msg + " got %s instead of %s" % (marionette.execute_script(script), expected))
+        raise TimeoutException("{0} got {1} instead of {2}".format(
+            e.message, marionette.execute_script(script), expected))
 
 def press_release(marionette, times, wait_for_condition, expected):
     testAction = marionette.absolute_url("testAction.html")
     marionette.navigate(testAction)
     action = Actions(marionette)
     button = marionette.find_element(By.ID, "button1")
     action.press(button).release()
     # Insert wait between each press and release chain.
--- a/testing/marionette/harness/marionette/tests/unit/test_errors.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_errors.py
@@ -15,34 +15,34 @@ def fake_cause():
 
 message = "foo"
 cause = fake_cause()
 stacktrace = "first\nsecond"
 
 class TestErrors(marionette_test.MarionetteTestCase):
     def test_defaults(self):
         exc = errors.MarionetteException()
-        self.assertIsNone(exc.msg)
+        self.assertIsNone(exc.message)
         self.assertIsNone(exc.cause)
         self.assertIsNone(exc.stacktrace)
 
     def test_construction(self):
         exc = errors.MarionetteException(
             message=message, cause=cause, stacktrace=stacktrace)
-        self.assertEquals(exc.msg, message)
+        self.assertEquals(exc.message, message)
         self.assertEquals(exc.cause, cause)
         self.assertEquals(exc.stacktrace, stacktrace)
 
     def test_str(self):
         exc = errors.MarionetteException(
             message=message, cause=cause, stacktrace=stacktrace)
         r = str(exc)
         self.assertIn(message, r)
         self.assertIn(", caused by %r" % cause[0], r)
-        self.assertIn("\nstacktrace:\n\tfirst\n\tsecond\n", r)
+        self.assertIn("\nstacktrace:\n\tfirst\n\tsecond", r)
         self.assertIn("MarionetteException:", r)
 
     def test_cause_string(self):
         exc = errors.MarionetteException(cause="foo")
         self.assertEqual(exc.cause, "foo")
         r = str(exc)
         self.assertIn(", caused by foo", r)
 
--- a/testing/marionette/harness/marionette/tests/unit/test_execute_script.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_execute_script.py
@@ -31,17 +31,17 @@ class TestExecuteSimpleTestContent(Mario
     def test_stack_trace(self):
         try:
             self.marionette.execute_js_script("""
                 let a = 1;
                 throwHere();
                 """, filename="file.js")
             self.assertFalse(True)
         except errors.JavascriptException as e:
-            self.assertIn("throwHere is not defined", e.msg)
+            self.assertIn("throwHere is not defined", e.message)
             self.assertIn("@file.js:2", e.stacktrace)
 
 
 class TestExecuteContent(MarionetteTestCase):
     def test_return_number(self):
         self.assertEqual(1, self.marionette.execute_script("return 1"))
         self.assertEqual(1.5, self.marionette.execute_script("return 1.5"))
 
@@ -133,17 +133,17 @@ class TestExecuteContent(MarionetteTestC
     def test_stacktrace(self):
         try:
             self.marionette.execute_script("return b")
             self.assertFalse(True)
         except errors.JavascriptException as e:
             # by default execute_script pass the name of the python file
             self.assertIn(
                 os.path.basename(__file__.replace(".pyc", ".py")), e.stacktrace)
-            self.assertIn("b is not defined", e.msg)
+            self.assertIn("b is not defined", e.message)
             self.assertIn("return b", e.stacktrace)
 
     def test_permission(self):
         with self.assertRaises(errors.JavascriptException):
             self.marionette.execute_script("""
                 let prefs = Components.classes["@mozilla.org/preferences-service;1"]
                     .getService(Components.interfaces.nsIPrefBranch)""")
 
--- a/testing/marionette/harness/marionette/tests/unit/test_proxy.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_proxy.py
@@ -220,17 +220,17 @@ class TestProxy(MarionetteTestCase):
                                     {
                                     "proxy":"I really should be a dictionary"
                                     }
                             }
         try:
             self.marionette.start_session(capabilities)
             self.fail("We should have started a session because proxy should be a dict")
         except InvalidArgumentException as e:
-            assert e.msg == "Value of 'proxy' should be an object"
+            assert e.message == "Value of 'proxy' should be an object"
 
     def test_proxy_is_passed_in_with_no_proxy_doesnt_set_it(self):
         capabilities = {"requiredCapabilities":
             {
                 "proxy": {"proxyType": "NOPROXY"},
             }
         }
         self.marionette.start_session(capabilities)
--- a/testing/marionette/harness/marionette/tests/unit/test_switch_frame.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_switch_frame.py
@@ -66,17 +66,17 @@ class TestSwitchFrame(MarionetteTestCase
         self.marionette.switch_to_frame()
         self.assertEqual(verify_title, self.marionette.title)
         self.marionette.switch_to_frame(inner_frame_element)
         self.assertTrue(start_url in self.marionette.get_url())
 
         try:
             self.marionette.execute_async_script("foo();")
         except JavascriptException as e:
-            self.assertTrue("foo" in e.msg)
+            self.assertTrue("foo" in e.message)
 
     def test_should_be_able_to_carry_on_working_if_the_frame_is_deleted_from_under_us(self):
         test_html = self.marionette.absolute_url("deletingFrame.html")
         self.marionette.navigate(test_html)
 
         self.marionette.switch_to_frame(self.marionette.find_element(By.ID,
                                                                      'iframe1'))
         killIframe = self.marionette.find_element(By.ID, "killIframe")
--- a/testing/marionette/harness/marionette/tests/unit/test_switch_frame_chrome.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_switch_frame_chrome.py
@@ -42,9 +42,9 @@ class TestSwitchFrameChrome(MarionetteTe
 
     def test_stack_trace(self):
         self.assertIn("test.xul", self.marionette.get_url(), "Initial navigation has failed")
         self.marionette.switch_to_frame(0)
         self.assertRaises(JavascriptException, self.marionette.execute_async_script, "foo();")
         try:
             self.marionette.execute_async_script("foo();")
         except JavascriptException as e:
-            self.assertIn("foo", e.msg)
+            self.assertIn("foo", e.message)