Skip to content

gh-130655: add tests for dgettext #134594

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Conversation

alex-semenyuk
Copy link
Contributor

@alex-semenyuk alex-semenyuk commented May 23, 2025

@bedevere-app bedevere-app bot added the tests Tests in the Lib/test dir label May 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 for test_* 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 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)

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 using os_helper.rmtree over shutil.rmtree

Copy link
Contributor

@StanFromIreland StanFromIreland 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 from GettextBaseTest and avail of the mo files. You can then use the messages in the files to test it works properly.

Comment on lines +965 to +972
def test_dgettext_non_existent_domain(self):
result = gettext.dgettext('nonexistent_domain', 'test message')
self.assertEqual(result, 'test message')

def test_dgettext_empty_domain(self):
result = gettext.dgettext('', 'test message')
expected = gettext.gettext('test message')
self.assertEqual(result, expected)
Copy link
Contributor

Choose a reason for hiding this comment

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

This could just be a for loop combining these cases.

@picnixz picnixz changed the title gh-134593: add tests for dgettext gh-130655: add tests for dgettext May 23, 2025
@picnixz picnixz added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels May 23, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
awaiting review needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes skip news tests Tests in the Lib/test dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants