Exemple #1
0
 def test_unicode(self):
     """
     If a L{FlattenerError} is created with a unicode root, up to around 40
     characters from that string are included in the string representation
     of the exception.
     """
     # the response includes the output of repr(), which differs between
     # Python 2 and 3
     u = {'u': ''} if _PY3 else {'u': 'u'}
     self.assertEqual(
         str(
             error.FlattenerError(RuntimeError("reason"),
                                  [u'abc\N{SNOWMAN}xyz'], [])),
         "Exception while flattening:\n"
         "  %(u)s'abc\\u2603xyz'\n"  # Codepoint for SNOWMAN
         "RuntimeError: reason\n" % u)
     self.assertEqual(
         str(
             error.FlattenerError(RuntimeError("reason"),
                                  [u'01234567\N{SNOWMAN}9' * 10], [])),
         "Exception while flattening:\n"
         "  %(u)s'01234567\\u2603901234567\\u26039"
         "<...>01234567\\u2603901234567"
         "\\u26039'\n"
         "RuntimeError: reason\n" % u)
Exemple #2
0
 def test_unicode(self):
     """
     If a L{FlattenerError} is created with a unicode root, up to around 40
     characters from that string are included in the string representation
     of the exception.
     """
     self.assertEqual(
         str(
             error.FlattenerError(RuntimeError("reason"), ["abc\N{SNOWMAN}xyz"], [])
         ),
         "Exception while flattening:\n"
         "  'abc\\u2603xyz'\n"  # Codepoint for SNOWMAN
         "RuntimeError: reason\n",
     )
     self.assertEqual(
         str(
             error.FlattenerError(
                 RuntimeError("reason"), ["01234567\N{SNOWMAN}9" * 10], []
             )
         ),
         "Exception while flattening:\n"
         "  '01234567\\u2603901234567\\u26039"
         "<...>01234567\\u2603901234567"
         "\\u26039'\n"
         "RuntimeError: reason\n",
     )
Exemple #3
0
 def test_string(self):
     """
     If a L{FlattenerError} is created with a string root, up to around 40
     bytes from that string are included in the string representation of the
     exception.
     """
     self.assertEqual(
         str(error.FlattenerError(RuntimeError("reason"), ["abc123xyz"], [])),
         "Exception while flattening:\n" "  'abc123xyz'\n" "RuntimeError: reason\n",
     )
     self.assertEqual(
         str(error.FlattenerError(RuntimeError("reason"), ["0123456789" * 10], [])),
         "Exception while flattening:\n"
         "  '01234567890123456789"
         "<...>01234567890123456789'\n"  # TODO: re-add 0
         "RuntimeError: reason\n",
     )
Exemple #4
0
 def test_reprWithoutRootsAndWithoutTraceback(self):
     """
     The representation of a L{FlattenerError} initialized without roots but
     with a traceback contains a formatted traceback but no roots.
     """
     e = error.FlattenerError(RuntimeError("oh noes"), [], None)
     self.assertTrue(
         re.match(
             'Exception while flattening:\n'
             'RuntimeError: oh noes\n$', repr(e), re.M | re.S), repr(e))
Exemple #5
0
 def makeFlattenerError(self, roots=[]):
     try:
         raise RuntimeError("oh noes")
     except Exception as e:
         tb = traceback.extract_tb(sys.exc_info()[2])
         return error.FlattenerError(e, roots, tb)