[Python-checkins] r84928 - in python/branches/py3k/Lib/test: badsyntax_nocaret.py test_traceback.py

benjamin.peterson python-checkins at python.org
Mon Sep 20 23:47:37 CEST 2010


Author: benjamin.peterson
Date: Mon Sep 20 23:47:37 2010
New Revision: 84928
Log:
rewrite nocaret test to not rely on a specific SyntaxError
Removed:
 python/branches/py3k/Lib/test/badsyntax_nocaret.py
Modified:
 python/branches/py3k/Lib/test/test_traceback.py
Deleted: python/branches/py3k/Lib/test/badsyntax_nocaret.py
==============================================================================
--- python/branches/py3k/Lib/test/badsyntax_nocaret.py	Mon Sep 20 23:47:37 2010
+++ (empty file)
@@ -1,2 +0,0 @@
-def f(x):
- [x for x in x] = x
Modified: python/branches/py3k/Lib/test/test_traceback.py
==============================================================================
--- python/branches/py3k/Lib/test/test_traceback.py	(original)
+++ python/branches/py3k/Lib/test/test_traceback.py	Mon Sep 20 23:47:37 2010
@@ -5,7 +5,7 @@
 import sys
 import unittest
 import re
-from test.support import run_unittest, is_jython, Error, captured_output
+from test.support import run_unittest, Error, captured_output
 from test.support import TESTFN, unlink
 
 import traceback
@@ -29,10 +29,6 @@
 def syntax_error_with_caret_2(self):
 compile("1 +\n", "?", "exec")
 
- def syntax_error_without_caret(self):
- # XXX why doesn't compile raise the same traceback?
- import test.badsyntax_nocaret
-
 def syntax_error_bad_indentation(self):
 compile("def spam():\n print(1)\n print(2)", "?", "exec")
 
@@ -51,13 +47,10 @@
 self.assertTrue(err[1].find("+") == err[2].find("^")) # in the right place
 
 def test_nocaret(self):
- if is_jython:
- # jython adds a caret in this case (why shouldn't it?)
- return
- err = self.get_exception_format(self.syntax_error_without_caret,
- SyntaxError)
+ exc = SyntaxError("error", ("x.py", 23, None, "bad syntax"))
+ err = traceback.format_exception_only(SyntaxError, exc)
 self.assertEqual(len(err), 3)
- self.assertTrue(err[1].strip() == "[x for x in x] = x")
+ self.assertEqual(err[1].strip(), "bad syntax")
 
 def test_bad_indentation(self):
 err = self.get_exception_format(self.syntax_error_bad_indentation,


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /