diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2007-09-04 14:19:28 +0000 |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2007-09-04 14:19:28 +0000 |
commit | a5136196bce72c51c79a5f961223b4645c90255c (patch) | |
tree | 552aefbadb426b866df79421bb0e7e953dec47c9 /Lib/test/test_compiler.py | |
parent | 58bd49f5fec11751806d869a8479f59e13d2d558 (diff) | |
download | cpython-git-a5136196bce72c51c79a5f961223b4645c90255c.tar.gz |
Patch #1031213: Decode source line in SyntaxErrors back to its original
source encoding. Will backport to 2.5.
Diffstat (limited to 'Lib/test/test_compiler.py')
-rw-r--r-- | Lib/test/test_compiler.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/Lib/test/test_compiler.py b/Lib/test/test_compiler.py index 229d8a370f..606ed700df 100644 --- a/Lib/test/test_compiler.py +++ b/Lib/test/test_compiler.py @@ -155,6 +155,32 @@ class CompilerTest(unittest.TestCase): self.assertEquals(dct.get('result'), 1) + def _testErrEnc(self, src, text, offset): + try: + compile(src, "", "exec") + except SyntaxError, e: + self.assertEquals(e.offset, offset) + self.assertEquals(e.text, text) + + def testSourceCodeEncodingsError(self): + # Test SyntaxError with encoding definition + sjis = "print '\x83\x70\x83\x43\x83\x5c\x83\x93', '\n" + ascii = "print '12345678', '\n" + encdef = "#! -*- coding: ShiftJIS -*-\n" + + # ascii source without encdef + self._testErrEnc(ascii, ascii, 19) + + # ascii source with encdef + self._testErrEnc(encdef+ascii, ascii, 19) + + # non-ascii source with encdef + self._testErrEnc(encdef+sjis, sjis, 19) + + # ShiftJIS source without encdef + self._testErrEnc(sjis, sjis, 19) + + NOLINENO = (compiler.ast.Module, compiler.ast.Stmt, compiler.ast.Discard) ############################################################################### |