Revision: 3174
Author: janne.t.harkonen
Date: Wed May  5 03:26:53 2010
Log: handle long error messages with multiple execution failures
http://code.google.com/p/robotframework/source/detail?r=3174

Modified:
 /trunk/src/robot/errors.py
 /trunk/src/robot/utils/error.py

=======================================
--- /trunk/src/robot/errors.py  Tue May  4 06:39:19 2010
+++ /trunk/src/robot/errors.py  Wed May  5 03:26:53 2010
@@ -12,6 +12,7 @@
 #  See the License for the specific language governing permissions and
 #  limitations under the License.

+import utils

 # Return codes from Robot and Rebot.
 # RC below 250 is the number of failed critical tests and exactly 250
@@ -27,6 +28,13 @@

     Do not raise this method but use more specific errors instead.
     """
+    def __init__(self, message=''):
+        Exception.__init__(self, message)
+
+    def __unicode__(self):
+        """This is required because of Python 2.5"""
+        return unicode(self.args[0])
+

 class FrameworkError(RobotError):
     """Can be used when the core framework goes to unexpected state
@@ -49,7 +57,7 @@

     def __init__(self, message, timeout=False, exit=False, cont=False,
                  syntax=False):
-        RobotError.__init__(self, message)
+        RobotError.__init__(self, utils.cut_long_message(message))
         self.timeout = timeout
         self.exit = exit
         self.cont = cont
@@ -58,9 +66,6 @@
     def get_errors(self):
         return [self]

-    def __unicode__(self):
-        return unicode(self.args[0])
-

 class ExecutionFailures(ExecutionFailed):

@@ -70,17 +75,17 @@
         self.timeout = any(err.timeout for err in errors)
         self.syntax = any(err.syntax for err in errors)
         self._errors = errors
-        RobotError.__init__(self, unicode(self))
-
-    def get_errors(self):
-        return self._errors
-
-    def __unicode__(self):
+        RobotError.__init__(self, self._get_message())
+
+    def _get_message(self):
         if len(self._errors) == 1:
             return unicode(self._errors[0])
         lines = ['Several failures occurred:'] \
+ ['%d) %s' % (i+1, unicode(err)) for i, err in enumerate(self._errors)]
-        return '\n\n'.join(lines)
+        return utils.cut_long_message('\n\n'.join(lines))
+
+    def get_errors(self):
+        return self._errors


 class TimeoutError(RobotError):
=======================================
--- /trunk/src/robot/utils/error.py     Tue May  4 06:50:22 2010
+++ /trunk/src/robot/utils/error.py     Wed May  5 03:26:53 2010
@@ -19,7 +19,6 @@
 import traceback

 from robottypes import is_str
-from text import cut_long_message
 from unic import unic
from robot.errors import DataError, TimeoutError, RemoteError, ExecutionFailed

@@ -80,8 +79,8 @@
     exit = bool(getattr(exc_value, 'ROBOT_EXIT_ON_FAILURE', False))
     cont = bool(getattr(exc_value, 'ROBOT_CONTINUE_ON_FAILURE', False))
     syntax = isinstance(exc_value, DataError)
-    return message, details, ExecutionFailed(cut_long_message(message),
-                                             timeout, exit, cont, syntax)
+    return message, details, ExecutionFailed(message, timeout, exit, cont,
+                                             syntax)


 def _is_java_exception(exc):

Reply via email to