Author: Armin Rigo <[email protected]>
Branch:
Changeset: r90365:740872e8e466
Date: 2017-02-26 18:05 +0100
http://bitbucket.org/pypy/pypy/changeset/740872e8e466/
Log: (stevie, arigo)
Test and fix: outdentation errors (only!) were missing a 'filename'
diff --git a/pypy/interpreter/astcompiler/test/test_compiler.py
b/pypy/interpreter/astcompiler/test/test_compiler.py
--- a/pypy/interpreter/astcompiler/test/test_compiler.py
+++ b/pypy/interpreter/astcompiler/test/test_compiler.py
@@ -725,6 +725,19 @@
else:
raise Exception("DID NOT RAISE")
+ def test_indent_error_filename(self):
+ source = py.code.Source("""
+ def f():
+ x
+ y
+ """)
+ try:
+ self.simple_test(source, None, None)
+ except IndentationError as e:
+ assert e.filename == '<test>'
+ else:
+ raise Exception("DID NOT RAISE")
+
def test_kwargs_last(self):
py.test.raises(SyntaxError, self.simple_test, "int(base=10, '2')",
None, None)
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
@@ -167,6 +167,9 @@
except error.TokenError as e:
e.filename = compile_info.filename
raise
+ except error.TokenIndentationError as e:
+ e.filename = compile_info.filename
+ raise
except parser.ParseError as e:
# Catch parse errors, pretty them up and reraise them as a
# SyntaxError.
diff --git a/pypy/interpreter/test/test_compiler.py
b/pypy/interpreter/test/test_compiler.py
--- a/pypy/interpreter/test/test_compiler.py
+++ b/pypy/interpreter/test/test_compiler.py
@@ -77,7 +77,7 @@
""")
assert self.space.unwrap(w_args) == (
'unindent does not match any outer indentation level',
- (None, 3, 0, ' y\n'))
+ ('<string>', 3, 0, ' y\n'))
def test_getcodeflags(self):
code = self.compiler.compile('from __future__ import division\n',
@@ -1032,6 +1032,18 @@
else:
raise Exception("DID NOT RAISE")
+ def test_outdentation_error_filename(self):
+ source = """if 1:
+ x
+ y
+ """
+ try:
+ exec(source)
+ except IndentationError as e:
+ assert e.filename == '<string>'
+ else:
+ raise Exception("DID NOT RAISE")
+
def test_repr_vs_str(self):
source1 = "x = (\n"
source2 = "x = (\n\n"
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit