3 new revisions:

Revision: 350e80437f15
Author:   Pekka Klärck
Date:     Mon Jan  2 04:08:53 2012
Log:      no emty rows in import error messages
http://code.google.com/p/robotframework/source/detail?r=350e80437f15

Revision: dca4d6fe0f89
Author:   Pekka Klärck
Date:     Mon Jan  2 05:49:37 2012
Log: cleaned up filtering non-robot entries from tracebacks -- this works a...
http://code.google.com/p/robotframework/source/detail?r=dca4d6fe0f89

Revision: 7ed7e6ec8496
Author:   Pekka Klärck
Date:     Mon Jan  2 05:51:20 2012
Log:      Automated merge with https://code.google.com/p/robotframework/
http://code.google.com/p/robotframework/source/detail?r=7ed7e6ec8496

==============================================================================
Revision: 350e80437f15
Author:   Pekka Klärck
Date:     Mon Jan  2 04:08:53 2012
Log:      no emty rows in import error messages
http://code.google.com/p/robotframework/source/detail?r=350e80437f15

Modified:
 /src/robot/utils/importer.py

=======================================
--- /src/robot/utils/importer.py        Mon Jan  2 02:08:11 2012
+++ /src/robot/utils/importer.py        Mon Jan  2 04:08:53 2012
@@ -93,7 +93,7 @@
msg = "Importing %s'%s' failed: %s" % (import_type, name, error.message)
         if not error.details:
             raise DataError(msg)
-        msg = [msg, '', error.details]
+        msg = [msg, error.details]
         msg.extend(self._get_items_in('PYTHONPATH', sys.path))
         if sys.platform.startswith('java'):
classpath = getProperty('java.class.path').split(os.path.pathsep)
@@ -109,7 +109,7 @@
                               % (import_type, item_type, name, location))

     def _get_items_in(self, type, items):
-        yield '\n%s:' % type
+        yield '%s:' % type
         for item in items:
             yield '  %s' % item


==============================================================================
Revision: dca4d6fe0f89
Author:   Pekka Klärck
Date:     Mon Jan  2 05:49:37 2012
Log: cleaned up filtering non-robot entries from tracebacks -- this works also with imports
http://code.google.com/p/robotframework/source/detail?r=dca4d6fe0f89

Modified:
 /src/robot/utils/error.py
 /utest/utils/test_error.py

=======================================
--- /src/robot/utils/error.py   Fri Dec 23 04:28:43 2011
+++ /src/robot/utils/error.py   Mon Jan  2 05:49:37 2012
@@ -108,7 +108,6 @@


 class PythonErrorDetails(_ErrorDetails):
- _ignore_trace_until = (os.path.join('robot','running','handlers.py'), '<lambda>')

     def _get_message(self):
# If exception is a "string exception" without a message exc_value is None
@@ -127,16 +126,14 @@
return 'Traceback (most recent call last):\n' + self._get_traceback()

     def _get_traceback(self):
-        tb = traceback.extract_tb(self._exc_traceback)
-        for row, (path, _, func, _) in enumerate(tb):
-            if self._include_rest_traceback(path, func):
-                tb = tb[row+1:]
-                break
-        return ''.join(traceback.format_list(tb)).rstrip()
-
-    def _include_rest_traceback(self, path, func):
-        return (path.endswith(self._ignore_trace_until[0]) and
-                func == self._ignore_trace_until[1])
+        tb = self._exc_traceback
+        while tb and self._is_excluded_traceback(tb):
+            tb = tb.tb_next
+        return ''.join(traceback.format_tb(tb)).rstrip() or '  None'
+
+    def _is_excluded_traceback(self, traceback):
+        module = traceback.tb_frame.f_globals['__name__']
+        return module.startswith('robot.')


 class JavaErrorDetails(_ErrorDetails):
=======================================
--- /utest/utils/test_error.py  Fri May 28 03:54:36 2010
+++ /utest/utils/test_error.py  Mon Jan  2 05:49:37 2012
@@ -1,24 +1,26 @@
 import unittest
-
-from robot.utils.asserts import *
+import sys
+import re
+
+from robot.utils.asserts import assert_equals, assert_true, assert_raises
 from robot import utils
 if utils.is_jython:
     import JavaExceptions
     java_exceptions = JavaExceptions()

-from robot.utils.error import get_error_details, get_error_message
+from robot.utils.error import get_error_details, get_error_message, PythonErrorDetails



-class TestError(unittest.TestCase):
-
+class TestGetErrorDetails(unittest.TestCase):
+
     def test_get_error_details_python(self):
         for exception, msg, exp_msg in [
                     (AssertionError, 'My Error', 'My Error'),
                     (AssertionError, None, 'AssertionError'),
                     (Exception, 'Another Error', 'Another Error'),
                     (Exception, None, 'Exception'),
-                    (ValueError, 'Something', 'ValueError: Something'),
+                    (ValueError, 'Something', 'ValueError: Something'),
                     (ValueError, None, 'ValueError'),
(AssertionError, 'Msg\nin 3\nlines', 'Msg\nin 3\nlines'),
                     (ValueError, '2\nlines', 'ValueError: 2\nlines')]:
@@ -27,31 +29,31 @@
             except:
                 message, details = get_error_details()
                 assert_equals(message, get_error_message())
-            assert_equal(message, exp_msg)
+            assert_equals(message, exp_msg)
             assert_true(details.startswith('Traceback'))
-            assert_false(exp_msg in details)
-
+            assert_true(exp_msg not in details)
+
     if utils.is_jython:
-
+
         def test_get_error_details_java(self):
             for exception, msg, expected in [
                     ('AssertionError', 'My Error', 'My Error'),
                     ('AssertionError', None, 'AssertionError'),
                     ('RuntimeException', 'Another Error', 'Another Error'),
                     ('RuntimeException', None, 'RuntimeException'),
- ('ArithmeticException', 'foo', 'ArithmeticException: foo'), + ('ArithmeticException', 'foo', 'ArithmeticException: foo'),
                     ('ArithmeticException', None, 'ArithmeticException'),
('AssertionError', 'Msg\nin 3\nlines', 'Msg\nin 3\nlines'),
                     ('IOException', '1\n2', 'IOException: 1\n2'),
                     ('RuntimeException', 'embedded', 'embedded'),
- ('IOException', 'IOException: emb', 'IOException: emb'), ]: + ('IOException', 'IOException: emb', 'IOException: emb')]:
                 try:
throw_method = getattr(java_exceptions, 'throw'+exception)
                     throw_method(msg)
                 except:
                     message, details = get_error_details()
                     assert_equals(message, get_error_message())
-                assert_equal(message, expected)
+                assert_equals(message, expected)
                 lines = details.splitlines()
                 assert_true(exception in lines[0])
                 for line in lines[1:]:
@@ -67,7 +69,47 @@
                 line1, line2 = details.splitlines()[0:2]
                 assert_equals('java.lang.RuntimeException: ', line1)
                 assert_true(line2.strip().startswith('at '))
-
+
+
+class TestRemoveRobotEntriesFromTraceback(unittest.TestCase):
+
+    def test_both_robot_and_non_robot_entries(self):
+        def raises():
+            raise Exception
+        self._verify_traceback('Traceback (most recent call last):\n'
+                               '  File "PATH", line X, in raises\n'
+                               '    raise Exception',
+                               assert_raises, AssertionError, raises)
+
+    def test_remove_entries_with_lambda_and_multiple_entries(self):
+        def raises():
+            1/0
+        raising_lambda = lambda: raises()
+        self._verify_traceback('Traceback (most recent call last):\n'
+                               '  File "PATH", line X, in <lambda>\n'
+                               '    raising_lambda = lambda: raises()\n'
+                               '  File "PATH", line X, in raises\n'
+                               '    1/0',
+ assert_raises, AssertionError, raising_lambda)
+
+    def test_only_robot_entries(self):
+        self._verify_traceback('Traceback (most recent call last):\n'
+                               '  None',
+                               assert_equals, 1, 2)
+
+    def _verify_traceback(self, expected, method, *args):
+        try:
+            method(*args)
+        except Exception:
+            type, value, tb = sys.exc_info()
+            # first tb entry originates from this file and must be excluded
+            details = PythonErrorDetails(type, value, tb.tb_next)
+        else:
+            raise AssertionError
+        traceback = re.sub('File ".*", line \d+', 'File "PATH", line X',
+                           details.traceback)
+        assert_equals(traceback, expected)
+

 if __name__ == "__main__":
     unittest.main()

==============================================================================
Revision: 7ed7e6ec8496
Author:   Pekka Klärck
Date:     Mon Jan  2 05:51:20 2012
Log:      Automated merge with https://code.google.com/p/robotframework/
http://code.google.com/p/robotframework/source/detail?r=7ed7e6ec8496


Reply via email to