[pypy-svn] pypy default: Add tests for continuation lines being acceptable before __future__

vincentlegoll commits-noreply at bitbucket.org
Tue Mar 1 05:03:40 CET 2011


Author: Vincent Legoll <vincent.legoll at gmail.com>
Branch: 
Changeset: r42359:63ae44cc20d2
Date: 2011-03-01 01:14 +0100
http://bitbucket.org/pypy/pypy/changeset/63ae44cc20d2/

Log:	Add tests for continuation lines being acceptable before __future__
	imports. CPython 2.7 allows them. One test is disabled as it's a
	cpython behaviour we probably don't want to emulate. Those tests
	currently fail.

diff --git a/pypy/interpreter/pyparser/test/test_futureautomaton.py b/pypy/interpreter/pyparser/test/test_futureautomaton.py
--- a/pypy/interpreter/pyparser/test/test_futureautomaton.py
+++ b/pypy/interpreter/pyparser/test/test_futureautomaton.py
@@ -204,5 +204,37 @@
     f = run(s)
     assert f.pos == len(s)
     assert f.flags == fut.CO_FUTURE_WITH_STATEMENT
+
+def test_continuation_line():
+    s = "\\\nfrom __future__ import with_statement\n"
+    f = run(s)
+    assert f.pos == len(s)
+    assert f.flags == fut.CO_FUTURE_WITH_STATEMENT
     assert f.lineno == 2
     assert f.col_offset == 0
+
+def test_continuation_lines():
+    s = "\\\n  \t\\\nfrom __future__ import with_statement\n"
+    f = run(s)
+    assert f.pos == len(s)
+    assert f.flags == fut.CO_FUTURE_WITH_STATEMENT
+    assert f.lineno == 3
+    assert f.col_offset == 0
+
+# This looks like a bug in cpython parser
+# and would require extensive modifications
+# to future.py in order to emulate the same behaviour
+def __test_continuation_lines_raise():
+    s = "   \\\n  \t\\\nfrom __future__ import with_statement\n"
+    try:
+        f = run(s)
+    except IndentationError, e:
+        assert e.args == 'unexpected indent'
+        assert f.pos == len(s)
+        assert f.flags == 0
+        assert f.lineno == -1
+        assert f.col_offset == 0
+    else:
+        raise AssertionError('IndentationError not raised')
+    assert f.lineno == 2
+    assert f.col_offset == 0


More information about the Pypy-commit mailing list