Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-130655: add tests for dgettext#134594

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
alex-semenyuk wants to merge3 commits intopython:main
base:main
Choose a base branch
Loading
fromalex-semenyuk:add_dgettext_tests

Conversation

alex-semenyuk
Copy link
Contributor

@alex-semenyukalex-semenyuk commentedMay 23, 2025
edited by bedevere-appbot
Loading

tomasr8 reacted with thumbs up emoji
@bedevere-appbedevere-appbot added the testsTests in the Lib/test dir labelMay 23, 2025
return mofile

def test_dgettext_found_translation(self):
"""Test dgettext finds translation in specified domain."""
Copy link
Member

Choose a reason for hiding this comment

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

Avoid using docstrings fortest_* methods as it will be shown upon failure.


def setUp(self):
"""Set up a specific test domain and environment for dgettext tests."""
self.localedir = tempfile.mkdtemp()
Copy link
Member

Choose a reason for hiding this comment

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

Instead of usingmkdtemp which would create something inside/tmp, usetest.support.temp_dir (I think, check the name) which creates something inside the build folder (it's easier to cleanup)

def setUp(self):
"""Set up a specific test domain and environment for dgettext tests."""
self.localedir = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, self.localedir)
Copy link
Member

Choose a reason for hiding this comment

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

Prefer usingos_helper.rmtree overshutil.rmtree

Copy link
Contributor

@StanFromIrelandStanFromIreland left a comment

Choose a reason for hiding this comment

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

We can inherit fromGettextBaseTest and avail of the mo files. You can then use the messages in the files to test it works properly.

alex-semenyuk reacted with thumbs up emoji
@picnixzpicnixz changed the titlegh-134593: add tests for dgettextgh-130655: add tests for dgettextMay 23, 2025
@picnixzpicnixz added needs backport to 3.13bugs and security fixes needs backport to 3.14bugs and security fixes labelsMay 23, 2025
Copy link
Contributor

@StanFromIrelandStanFromIreland left a comment

Choose a reason for hiding this comment

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

We can still simply them a lot, you have to remember dgettext is really just a wrapper.

@@ -11,7 +11,6 @@


# TODO:
# - Add new tests, for example for "dgettext"
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's keep the TODO, since it is still valid (the first part).

It can be updated with the issue number if you wish.

Comment on lines +964 to +972
def test_dgettext_luxury_yacht_translation(self):
result = gettext.dgettext('gettext', 'Raymond Luxury Yach-t')
self.assertEqual(result, 'Throatwobbler Mangrove')

def test_dgettext_nudge_nudge_translation(self):
result = gettext.dgettext('gettext', 'nudge nudge')
self.assertEqual(result, 'wink wink')

def test_dgettext_multiline_translation(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need these these anyway, it's long and pretty much identical to the previous two. dgettext is a pretty simple wrapper. Maybe merge the first twotest_dgettext_translation for organization

Comment on lines +958 to +961
if domain == '':
expected = gettext.gettext(message)
else:
expected = message
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just store the expected, it is clearer. And this part is made simpler.

GettextBaseTest.setUp(self)
gettext.bindtextdomain('gettext', os.curdir)

def test_dgettext_found_translation(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Join this one with the other two, these all test the exact same thing (which is well tested above too).

@picnixzpicnixz requested review fromtomasr8 andpicnixz and removed request forpicnixzMay 25, 2025 22:55
@tomasr8
Copy link
Member

Thanks for the PR@alex-semenyuk! Would you mindmeasuring the test coverage before and after this change and sharing the results here? (after you address the review comments)
Just to make sure we covered everything 🙂 Thanks!

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@StanFromIrelandStanFromIrelandStanFromIreland left review comments

@tomasr8tomasr8Awaiting requested review from tomasr8

@picnixzpicnixzAwaiting requested review from picnixz

Assignees
No one assigned
Labels
awaiting reviewneeds backport to 3.13bugs and security fixesneeds backport to 3.14bugs and security fixesskip newstestsTests in the Lib/test dir
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@alex-semenyuk@tomasr8@picnixz@StanFromIreland

[8]ページ先頭

©2009-2025 Movatter.jp