Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adjust lineno
  • Loading branch information
sobolevn committed Sep 18, 2023
commit 35a3a3de02f824b1e6069013cf2cd54752638fba
26 changes: 13 additions & 13 deletions Lib/test/test_future_stmt/test_future.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ def assertSyntaxError(self, code,
lineno,
message=TOP_LEVEL_MSG, offset=1,
parametrize_docstring=True):
code = dedent(code)
code = dedent(code.lstrip('\n'))
for trim_docstring in ([False, True] if parametrize_docstring else [False]):
with self.subTest(code=code, trim_docstring=trim_docstring):
if trim_docstring:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last question: instead of copy/paste '''Docstring''' in each test. Would it make sense to add it here instead? I'm waiting for your opinion to decide if we merge the change like that, or you prefer to remove docstrings in tests and add it here instead.

code = os.linesep.join(code.splitlines()[2:])
lineno -= 2
code = os.linesep.join(code.splitlines()[1:])
lineno -= 1
with self.assertRaises(SyntaxError) as cm:
exec(code)
self.check_syntax_error(cm.exception, "<string>",
Expand Down Expand Up @@ -88,7 +88,7 @@ def test_unknown_future_flag(self):
from __future__ import rested_snopes # typo error here: nested => rested
"""
self.assertSyntaxError(
code, lineno=4,
code, lineno=3,
message='future feature rested_snopes is not defined',
)

Expand All @@ -98,30 +98,30 @@ def test_future_import_not_on_top(self):
import some_module
from __future__ import annotations
"""
self.assertSyntaxError(code, lineno=4)
self.assertSyntaxError(code, lineno=3)

code = """
'''Docstring'''
import __future__
from __future__ import annotations
"""
self.assertSyntaxError(code, lineno=4)
self.assertSyntaxError(code, lineno=3)

code = """
'''Docstring'''
from __future__ import absolute_import
"spam, bar, blah"
from __future__ import print_function
"""
self.assertSyntaxError(code, lineno=5)
self.assertSyntaxError(code, lineno=4)

def test_future_import_with_extra_string(self):
code = """
'''Docstring'''
"this isn't a doc string"
from __future__ import nested_scopes
"""
self.assertSyntaxError(code, lineno=4, parametrize_docstring=False)
self.assertSyntaxError(code, lineno=3, parametrize_docstring=False)

def test_multiple_import_statements_on_same_line(self):
# With `\`:
Expand All @@ -130,22 +130,22 @@ def test_multiple_import_statements_on_same_line(self):
from __future__ import nested_scopes; import string; from __future__ import \
nested_scopes
"""
self.assertSyntaxError(code, lineno=3, offset=54)
self.assertSyntaxError(code, lineno=2, offset=54)

# Without `\`:
code = """
'''Docstring'''
from __future__ import nested_scopes; import string; from __future__ import nested_scopes
"""
self.assertSyntaxError(code, lineno=3, offset=54)
self.assertSyntaxError(code, lineno=2, offset=54)

def test_future_import_star(self):
Comment thread
vstinner marked this conversation as resolved.
code = """
'''Docstring'''
from __future__ import *
"""
self.assertSyntaxError(
code, lineno=3,
code, lineno=2,
message='future feature * is not defined',
)

Expand All @@ -155,13 +155,13 @@ def test_future_import_braces(self):
from __future__ import braces
"""
# Congrats, you found an easter egg!
self.assertSyntaxError(code, lineno=3, message='not a chance')
self.assertSyntaxError(code, lineno=2, message='not a chance')

code = """
'''Docstring'''
from __future__ import nested_scopes, braces
"""
self.assertSyntaxError(code, lineno=3, message='not a chance')
self.assertSyntaxError(code, lineno=2, message='not a chance')

def test_module_with_future_import_not_on_top(self):
with self.assertRaises(SyntaxError) as cm:
Expand Down