[pypy-commit] pypy stdlib-2.7.6: fix compile error message case
bdkearns
noreply at buildbot.pypy.org
Sun Mar 2 02:45:35 CET 2014
Author: Brian Kearns <bdkearns at gmail.com>
Branch: stdlib-2.7.6
Changeset: r69592:2dd986a2c9d0
Date: 2014-03-01 20:40 -0500
http://bitbucket.org/pypy/pypy/changeset/2dd986a2c9d0/
Log: fix compile error message case
diff --git a/pypy/interpreter/pyparser/pyparse.py b/pypy/interpreter/pyparser/pyparse.py
--- a/pypy/interpreter/pyparser/pyparse.py
+++ b/pypy/interpreter/pyparser/pyparse.py
@@ -108,7 +108,7 @@
# If an encoding is explicitly given check that it is utf-8.
decl_enc = _check_for_encoding(textsrc)
if decl_enc and decl_enc != "utf-8":
- raise error.SyntaxError("UTF-8 BOM with non-utf8 coding cookie",
+ raise error.SyntaxError("UTF-8 BOM with %s coding cookie" % decl_enc,
filename=compile_info.filename)
elif compile_info.flags & consts.PyCF_SOURCE_IS_UTF8:
enc = 'utf-8'
diff --git a/pypy/interpreter/pyparser/test/test_pyparse.py b/pypy/interpreter/pyparser/test/test_pyparse.py
--- a/pypy/interpreter/pyparser/test/test_pyparse.py
+++ b/pypy/interpreter/pyparser/test/test_pyparse.py
@@ -55,7 +55,7 @@
assert exc.msg == "coding declaration in unicode string"
input = "\xEF\xBB\xBF# coding: latin-1\nx"
exc = py.test.raises(SyntaxError, self.parse, input).value
- assert exc.msg == "UTF-8 BOM with non-utf8 coding cookie"
+ assert exc.msg == "UTF-8 BOM with latin-1 coding cookie"
input = "# coding: not-here"
exc = py.test.raises(SyntaxError, self.parse, input).value
assert exc.msg == "Unknown encoding: not-here"
diff --git a/pypy/module/__builtin__/test/test_builtin.py b/pypy/module/__builtin__/test/test_builtin.py
--- a/pypy/module/__builtin__/test/test_builtin.py
+++ b/pypy/module/__builtin__/test/test_builtin.py
@@ -486,6 +486,23 @@
raises(ValueError, compile, "\n", "<string>", "exec", 0xff)
raises(TypeError, compile, '1+2', 12, 34)
+ def test_compile_error_message(self):
+ import re
+ compile('# -*- coding: iso-8859-15 -*-\n', 'dummy', 'exec')
+ compile('\xef\xbb\xbf\n', 'dummy', 'exec')
+ compile('\xef\xbb\xbf# -*- coding: utf-8 -*-\n', 'dummy', 'exec')
+ exc = raises(SyntaxError, compile,
+ '# -*- coding: fake -*-\n', 'dummy', 'exec')
+ assert 'fake' in exc.value[0]
+ exc = raises(SyntaxError, compile,
+ '\xef\xbb\xbf# -*- coding: iso-8859-15 -*-\n', 'dummy', 'exec')
+ assert 'iso-8859-15' in exc.value[0]
+ assert 'BOM' in exc.value[0]
+ exc = raises(SyntaxError, compile,
+ '\xef\xbb\xbf# -*- coding: fake -*-\n', 'dummy', 'exec')
+ assert 'fake' in exc.value[0]
+ assert 'BOM' in exc.value[0]
+
def test_unicode_compile(self):
try:
compile(u'-', '?', 'eval')
More information about the pypy-commit
mailing list