Skip to content

gh-130197: Improve test coverage of msgfmt.py part 2 #133309

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

tomasr8
Copy link
Member

@tomasr8 tomasr8 commented May 2, 2025

This is a followup to #133048

This PR adds more tests to msgfmt.py:

  • general syntax error tests (mainly unclosed strings and invalid plural syntax)
  • semantic errors such incorrect ordering of msgid/msgstr etc.., invalid plural indices and duplicate entries.

I verified that these are rejected by GNU's msgfmt.

Note that some tests are commented out. That is because msgfmt.py is currently accepting these as valid.
In a followup PR, I am planning to fix its parser and then we'll be able to uncomment all of theses cases.

@bedevere-app bedevere-app bot added the tests Tests in the Lib/test dir label May 2, 2025
@bedevere-app bedevere-app bot mentioned this pull request May 2, 2025
18 tasks
@tomasr8 tomasr8 requested a review from serhiy-storchaka May 2, 2025 17:30
msgfmt.MESSAGES.clear()
with self.assertRaises((SystemExit, UnboundLocalError,
IndexError, SyntaxError)):
msgfmt.make('messages.po', 'messages.mo')
Copy link
Member

Choose a reason for hiding this comment

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

It prints errors on stderr. They should be silenced. Instead, it would be nice to check the output against the expected error message.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated to capture the output and check error messages :)

'[0]',

# unclosed string
'''
Copy link
Member

Choose a reason for hiding this comment

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

You could use textwrap.dedent() and strip the initial newlines. It's up to you, but perhaps the indented code would look better.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added, I think it reads better with textwrap.dedent()

# invalid plural index
# invalid but currently accepted
# '''
# msgid "foo"
Copy link
Member

Choose a reason for hiding this comment

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

I do not think that it is worth to add such large blocks of the commented out code. It only increases the diff, in this PR, and in the future ones.

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed, I'll add them back (uncommented) when I fix the parser

@tomasr8 tomasr8 requested a review from serhiy-storchaka May 4, 2025 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting review skip news tests Tests in the Lib/test dir
3 participants
X