FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-130655: add tests for dgettext by alex-semenyuk · Pull Request #134594 · python/cpython · GitHub

Repository navigation

gh-130655: add tests for dgettext - #134594

Closed
alex-semenyuk wants to merge 4 commits into
python:mainfrom
alex-semenyuk:add_dgettext_tests
Closed

alex-semenyuk wants to merge 4 commits into
python:mainfrom
alex-semenyuk:add_dgettext_tests

Conversation

alex-semenyuk commented May 23, 2025 •
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Contributor

bedevere-app Bot added the tests Tests in the Lib/test dir label May 23, 2025
Comment thread Lib/test/test_gettext.py Outdated
return mofile

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Comment thread Lib/test/test_gettext.py Outdated

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Comment thread Lib/test/test_gettext.py Outdated
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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Prefer using os_helper.rmtree over shutil.rmtree

StanFromIreland left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Comment thread Lib/test/test_gettext.py Outdated
picnixz changed the title gh-134593: add tests for dgettext gh-130655: add tests for dgettext May 23, 2025
picnixz added needs backport to 3.13 only security fixes needs backport to 3.14 bugs and security fixes labels May 23, 2025
alex-semenyuk requested a review from picnixz May 25, 2025 10:56

StanFromIreland left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Comment thread Lib/test/test_gettext.py


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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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 thread Lib/test/test_gettext.py Outdated
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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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 two test_dgettext_translation for organization

Comment thread Lib/test/test_gettext.py Outdated
Comment on lines +958 to +961
if domain == '':
expected = gettext.gettext(message)
else:
expected = message

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Comment thread Lib/test/test_gettext.py Outdated
GettextBaseTest.setUp(self)
gettext.bindtextdomain('gettext', os.curdir)

def test_dgettext_found_translation(self):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

picnixz requested review from picnixz and tomasr8 and removed request for picnixz May 25, 2025 22:55

tomasr8 commented May 26, 2025

Copy link
Copy Markdown
Member

Thanks for the PR @alex-semenyuk! Would you mind measuring 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!

Comment thread Lib/test/test_gettext.py Outdated
class DGettextTest(GettextBaseTest):

def setUp(self):
GettextBaseTest.setUp(self)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
Suggested change
GettextBaseTest.setUp(self)
super().setUp()

Comment thread Lib/test/test_gettext.py

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Don't we need to tearDown this one?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Seems reset_gettext() resets the state from GettextBaseTest is enough

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 25, 2026

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 90 days with no activity.

github-actions Bot added the stale Stale PR or inactive for long period of time. label Sep 3, 2026

ambv commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

This PR is superseded by #154006, a newer open pull request for the same issue (gh-130655), and it no longer merges cleanly. Closing to cull the number of open pull requests. Do not reopen this pull request without getting a go-ahead from a triager or core developer.

ambv closed this Oct 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review needs backport to 3.13 only security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes skip news stale Stale PR or inactive for long period of time. tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants


Back | FazBrowse Home | New Git URL