-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
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
gh-108303: Move test_future
into its own subdir
#109368
Conversation
Yeap, they are executed: https://github.com/python/cpython/actions/runs/6170416321/job/16746672105?pr=109368 |
I see that the change doesn't remove tests, but adds one test method (29 => 30 tests in total). Before:
After:
Oh, there is an additional test AFTER:
It's this test: def test_future4(self):
with import_helper.CleanImport('test.test_future_import.test_future4'):
from test.test_future_import import test_future4 I don't understand the design of these tests. |
I'm not sure about
|
Yes, it was missing, I've decided to add it. All other tests were imported like this, except this one. I also a bit confused about the design of these tests, but I don't see any harm in them as well.
Indeed, thanks for the suggestion! |
Ok. I wasn't directly a remark about this change, but more the test in general. In case of doubt, I prefer to leave it this way. |
The documentation calls it "Future statement definitions": https://docs.python.org/dev/library/__future__.html It's more a statement than a module, even if a real module exists. Maybe use |
I've created a new issue to fix |
👍 |
Honestly, the test filenames are not very helpful :-( While we are moving code and renaming files anyway, would it be possible to come up with better names?
|
How about these names?
|
These names are different from each others and look more useful, thanks! Can you update your PR please? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
The tests could be enhanced to have a better name and description (documentation/comment/docstring) than just... a counter: test1, test2, test3, ...
Maybe using inline code rather than loading file would help to make tests more explicit.
I don't want to hold this PR further. Enhancing the test can be done later.
@@ -25,57 +25,71 @@ def check_syntax_error(self, err, basename, lineno, offset=1): | |||
self.assertEqual(err.offset, offset) | |||
|
|||
def test_future1(self): |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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( | ||
"test.test_future_stmt.test_future_multiple_features", | ||
): | ||
from test.test_future_stmt import test_future_multiple_features | ||
|
||
def test_badfuture3(self): |
There was a problem hiding this comment.
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
|
||
def test_badfuture3(self): | ||
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): |
There was a problem hiding this comment.
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
self.check_syntax_error(cm.exception, "badsyntax_future3", 3) | ||
|
||
def test_badfuture4(self): | ||
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): |
There was a problem hiding this comment.
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.
self.check_syntax_error(cm.exception, "badsyntax_future4", 3) | ||
|
||
def test_badfuture5(self): | ||
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): |
There was a problem hiding this comment.
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.
self.check_syntax_error(cm.exception, "badsyntax_future5", 4) | ||
|
||
def test_badfuture6(self): | ||
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): |
There was a problem hiding this comment.
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()).
Merged, thanks for this nice change! Feel free to ignore my remarks on finding better name/doc for tests ;-) |
I will open a PR with better names later today :) |
Sorry, @sobolevn and @vstinner, I could not cleanly backport this to |
Sorry, @sobolevn and @vstinner, I could not cleanly backport this to |
…dir (python#109368) (cherry picked from commit 82505dc)
GH-109679 is a backport of this pull request to the 3.12 branch. |
…dir (python#109368) (cherry picked from commit 82505dc)
GH-109680 is a backport of this pull request to the 3.11 branch. |
Two important notes:
test
:» ./python.exe Lib/test/test_future_import/test_future.py ........................ ---------------------------------------------------------------------- Ran 24 tests in 0.087s OK