Skip to content

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 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 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Lib/test/test_gettext.py
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,28 @@ def test_lazy_import(self):
ensure_lazy_imports("gettext", {"re", "warnings", "locale"})


class DGettextTest(GettextBaseTest):

def setUp(self):
super().setUp()
gettext.bindtextdomain('gettext', os.curdir)
Copy link
Member

Choose a reason for hiding this comment

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

Don't we need to tearDown this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems reset_gettext() resets the state from GettextBaseTest is enough


def test_dgettext_translation(self):
translation_cases = [
('gettext', 'mullusk', 'bacon'),
('gettext', 'Raymond Luxury Yach-t', 'Throatwobbler Mangrove'),
('gettext', 'nudge nudge', 'wink wink'),

('gettext', 'missing message', 'missing message'),
('nonexistent_domain', 'mullusk', 'mullusk'),
('', 'mullusk', gettext.gettext('mullusk')),
]
for domain, msgid, expected in translation_cases:
with self.subTest(domain=domain, msgid=msgid):
result = gettext.dgettext(domain, msgid)
self.assertEqual(result, expected)


if __name__ == '__main__':
unittest.main()

Expand Down
Loading