-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
gh-124295: Add translation tests for argparse #124803
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
Conversation
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. Thank you, @tomasr8.
Since argparse is currently actively fixed, there are some conflicts. After fixing them I'll merge this PR.
I will wait for the 3.13 release before merging this PR because it will conflict with many backports waiting for 3.13. It would be easier to resolve conflicts in this PR (just move |
Ok! Let me know if I can help with anything :) |
Don't worry, I'll merge this PR when the time comes. |
Github was complaining about some merge conflicts so I just wanted to update the branch ;) |
This avoids having to turn tests into packages.
On Serhiy's suggestion, I moved the translation data into a separate folder and merged the new tests with the existing ones to avoid turning the tests into a package. |
Thanks @tomasr8 for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13. |
Sorry, @tomasr8 and @serhiy-storchaka, I could not cleanly backport this to
|
Sorry, @tomasr8 and @serhiy-storchaka, I could not cleanly backport this to
|
GH-126046 is a backport of this pull request to the 3.13 branch. |
There seems to be a buildbot failure related to this PR: https://buildbot.python.org/#/builders/1244/builds/3363 Edit: maybe something like this? @requires_subprocess()
+ @requires_tool('i18n')
class TestTranslations(unittest.TestCase): with this helper function in def requires_tool(tool=None):
exists = True
try:
skip_if_missing(tool)
except unittest.SkipTest:
exists = False
return unittest.skipUnless(exists, f'{tool} not available') |
Do you mind to create a PR? I paused backporting. Simply call |
On it :) |
PR is here: #126051 |
…thonGH-124803) (pythonGH-126046) (cherry picked from commit 0922a4a) (cherry picked from commit ff044ed) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Tomas R. <tomas.roun8@gmail.com>
This uses
Tools/i18n/pygettext.py
to extract all translatable messages fromargparse.py
. The messages are kept in a snapshot file in the test folder. The test extracts the current messages and compares them against this snapshot.The snapshot can be updated using
./python Lib/test/test_argparse/test_translations.py --snapshot-update
.There is currently no way to read a PO file using the stdlib (gettext only reads MO files, maybe it should be able to do both?) so I just use a simple regex to get the
msgid
s out of the PO file.Feedback welcome!