Skip to content

gh-108303: Move test_future into its own subdir #109368

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions Lib/test/libregrtest/findtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
SPLITTESTDIRS: set[TestName] = {
"test_asyncio",
"test_concurrent_futures",
"test_future_stmt",
"test_multiprocessing_fork",
"test_multiprocessing_forkserver",
"test_multiprocessing_spawn",
Expand Down
6 changes: 6 additions & 0 deletions Lib/test/test_future_stmt/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import os
from test import support


def load_tests(*args):
return support.load_package_tests(os.path.dirname(__file__), *args)
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -25,57 +25,71 @@ def check_syntax_error(self, err, basename, lineno, offset=1):
self.assertEqual(err.offset, offset)

def test_future1(self):
Copy link
Member

Choose a reason for hiding this comment

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

test_future1 has an interesting comment that you can copy there:

# Import the name nested_scopes twice to trigger SF bug #407394 (regression).

I suggest to rename the file and test to: test_import_nested_scope_twice. For the filename, just drop test_ prefix: import_nested_scope_twice.py?

with import_helper.CleanImport('future_test1'):
from test import future_test1
with import_helper.CleanImport('test.test_future_stmt.future_test1'):
from test.test_future_stmt import future_test1
self.assertEqual(future_test1.result, 6)

def test_future2(self):
Copy link
Member

Choose a reason for hiding this comment

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

I suggest to rename the file and test to: test_nested_scope.

with import_helper.CleanImport('future_test2'):
from test import future_test2
with import_helper.CleanImport('test.test_future_stmt.future_test2'):
from test.test_future_stmt import future_test2
self.assertEqual(future_test2.result, 6)

def test_future3(self):
with import_helper.CleanImport('test_future3'):
from test import test_future3
def test_future_single_import(self):
with import_helper.CleanImport(
'test.test_future_stmt.test_future_single_import',
):
from test.test_future_stmt import test_future_single_import

def test_future_multiple_imports(self):
with import_helper.CleanImport(
'test.test_future_stmt.test_future_multiple_imports',
):
from test.test_future_stmt import test_future_multiple_imports

def test_future_multiple_features(self):
with import_helper.CleanImport(
"test.test_future_stmt.test_future_multiple_features",
):
from test.test_future_stmt import test_future_multiple_features

def test_badfuture3(self):
Copy link
Member

Choose a reason for hiding this comment

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

This one tests that a typo is catched properly, that an invalid name raises SyntaxError: from __future__ import rested_snopes.

Maybe: test_unknown_feature. The doc calls __future__ names as "features": https://docs.python.org/dev/library/__future__.html

with self.assertRaises(SyntaxError) as cm:
from test import badsyntax_future3
from test.test_future_stmt import badsyntax_future3
self.check_syntax_error(cm.exception, "badsyntax_future3", 3)

def test_badfuture4(self):
Copy link
Member

Choose a reason for hiding this comment

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

$ python badsyntax_future4.py 
SyntaxError: from __future__ imports must occur at the beginning of the file

with self.assertRaises(SyntaxError) as cm:
from test import badsyntax_future4
from test.test_future_stmt import badsyntax_future4
self.check_syntax_error(cm.exception, "badsyntax_future4", 3)

def test_badfuture5(self):
Copy link
Member

Choose a reason for hiding this comment

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

SyntaxError: from __future__ imports must occur at the beginning of the file

import fails if done after another import.

with self.assertRaises(SyntaxError) as cm:
from test import badsyntax_future5
from test.test_future_stmt import badsyntax_future5
self.check_syntax_error(cm.exception, "badsyntax_future5", 4)

def test_badfuture6(self):
Copy link
Member

Choose a reason for hiding this comment

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

SyntaxError: from __future__ imports must occur at the beginning of the file

Import after a statement.

with self.assertRaises(SyntaxError) as cm:
from test import badsyntax_future6
from test.test_future_stmt import badsyntax_future6
self.check_syntax_error(cm.exception, "badsyntax_future6", 3)

def test_badfuture7(self):
Copy link
Member

Choose a reason for hiding this comment

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

... Maybe these tests would be more explicit if they would not use a file, but pass the code as a string (maybe use textwrap.dedent()).

with self.assertRaises(SyntaxError) as cm:
from test import badsyntax_future7
from test.test_future_stmt import badsyntax_future7
self.check_syntax_error(cm.exception, "badsyntax_future7", 3, 54)

def test_badfuture8(self):
with self.assertRaises(SyntaxError) as cm:
from test import badsyntax_future8
from test.test_future_stmt import badsyntax_future8
self.check_syntax_error(cm.exception, "badsyntax_future8", 3)

def test_badfuture9(self):
with self.assertRaises(SyntaxError) as cm:
from test import badsyntax_future9
from test.test_future_stmt import badsyntax_future9
self.check_syntax_error(cm.exception, "badsyntax_future9", 3)

def test_badfuture10(self):
with self.assertRaises(SyntaxError) as cm:
from test import badsyntax_future10
from test.test_future_stmt import badsyntax_future10
self.check_syntax_error(cm.exception, "badsyntax_future10", 3)

def test_ensure_flags_dont_clash(self):
Expand Down Expand Up @@ -113,10 +127,6 @@ def test_parserhack(self):
else:
self.fail("syntax error didn't occur")

def test_multiple_features(self):
with import_helper.CleanImport("test.test_future5"):
from test import test_future5

def test_unicode_literals_exec(self):
scope = {}
exec("from __future__ import unicode_literals; x = ''", {}, scope)
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -2160,6 +2160,7 @@ TESTSUBDIRS= idlelib/idle_test \
test/test_dataclasses \
test/test_email \
test/test_email/data \
test/test_future_stmt \
test/test_import \
test/test_import/data \
test/test_import/data/circular_imports \
Expand Down