Skip to content

Conversation

@sobolevn
Copy link
Member

@sobolevn sobolevn commented Sep 16, 2023

I've also enabled docstring parametrization, because tests must works the same way with and without docstrings most of the time.

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

Would it be possible to check for the error message in assertSyntaxError?

self.assertSyntaxError(code, 3)

def test_badfuture10(self):
def test_bad_future_as_module(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 name is not clear. The expected error is:

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

@sobolevn
Copy link
Member Author

With error messages it should be much better!

lineno,
message=TOP_LEVEL_MSG, offset=1,
parametrize_docstring=True):
code = dedent(code)
Copy link
Member

Choose a reason for hiding this comment

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

It seems like code first line is always empty. I suggest using:

Suggested change
code = dedent(code)
code = dedent(code.lstrip())

And adapt lineno -= 2 and other references to lineno below.

For example, for me, test_unknown_future_flag() code has only 3 lines and expect an error on the 4th line, it's strange.

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks! It's way way more readable now! The test methods have better name, it's easier to understand the purpose of the test, and you added many checks!

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
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.

@brettcannon brettcannon removed their request for review September 18, 2023 18:07
@vstinner vstinner merged commit 94c95d4 into python:main Sep 19, 2023
@vstinner
Copy link
Member

Thanks a lot @sobolevn, it's way better! I edited the final message.

csm10495 pushed a commit to csm10495/cpython that referenced this pull request Sep 28, 2023
)

Add assertSyntaxError() which run tests with an additional docstring
and without docstring, and checks for the error message.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants