-
-
Notifications
You must be signed in to change notification settings - Fork 32k
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
base: main
Are you sure you want to change the base?
Conversation
Lib/test/test_gettext.py
Outdated
return mofile | ||
|
||
def test_dgettext_found_translation(self): | ||
"""Test dgettext finds translation in specified domain.""" |
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.
Avoid using docstrings for test_*
methods as it will be shown upon failure.
Lib/test/test_gettext.py
Outdated
|
||
def setUp(self): | ||
"""Set up a specific test domain and environment for dgettext tests.""" | ||
self.localedir = tempfile.mkdtemp() |
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.
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)
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) |
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.
Prefer using os_helper.rmtree
over shutil.rmtree
ecaa9d1
to
c4fb7ac
Compare
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.
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.
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) |
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.
This could just be a for loop combining these cases.
add tests for dgettext
dgettext
#134593gettext
#130655