Mercurial > cpython-lru_cache-weakref
diff Lib/test/test_traceback.py @ 39163:89e090fef985 legacy-trunk
Patch #1515343: Fix printing of deprecated string exceptions with a
value in the traceback module.
| author | Georg Brandl <georg@python.org> |
|---|---|
| date | Mon, 24 Jul 2006 14:09:56 +0000 |
| parents | bb3e0c889632 |
| children | 07cee01a4fcc |
line wrap: on
line diff
--- a/Lib/test/test_traceback.py Mon Jul 24 13:46:47 2006 +0000 +++ b/Lib/test/test_traceback.py Mon Jul 24 14:09:56 2006 +0000 @@ -31,8 +31,9 @@ err = self.get_exception_format(self.syntax_error_with_caret, SyntaxError) self.assert_(len(err) == 4) + self.assert_(err[1].strip() == "return x!") self.assert_("^" in err[2]) # third line has caret - self.assert_(err[1].strip() == "return x!") + self.assert_(err[1].find("!") == err[2].find("^")) # in the right place def test_nocaret(self): if is_jython: @@ -47,8 +48,9 @@ err = self.get_exception_format(self.syntax_error_bad_indentation, IndentationError) self.assert_(len(err) == 4) + self.assert_(err[1].strip() == "print 2") self.assert_("^" in err[2]) - self.assert_(err[1].strip() == "print 2") + self.assert_(err[1].find("2") == err[2].find("^")) def test_bug737473(self): import sys, os, tempfile, time @@ -109,6 +111,36 @@ lst = traceback.format_exception_only(e.__class__, e) self.assertEqual(lst, ['KeyboardInterrupt\n']) + # String exceptions are deprecated, but legal. The quirky form with + # separate "type" and "value" tends to break things, because + # not isinstance(value, type) + # and a string cannot be the first argument to issubclass. + # + # Note that sys.last_type and sys.last_value do not get set if an + # exception is caught, so we sort of cheat and just emulate them. + # + # test_string_exception1 is equivalent to + # + # >>> raise "String Exception" + # + # test_string_exception2 is equivalent to + # + # >>> raise "String Exception", "String Value" + # + def test_string_exception1(self): + str_type = "String Exception" + err = traceback.format_exception_only(str_type, None) + self.assert_(len(err) == 1) + self.assert_(err[0] == str_type + '\n') + + def test_string_exception2(self): + str_type = "String Exception" + str_value = "String Value" + err = traceback.format_exception_only(str_type, str_value) + self.assert_(len(err) == 1) + self.assert_(err[0] == str_type + ': ' + str_value + '\n') + + def test_main(): run_unittest(TracebackCases)
