Skip to content
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

gh-109864: Make test_gettext tests order independent #109866

Merged
merged 1 commit into from
Oct 7, 2023
Merged
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
15 changes: 13 additions & 2 deletions Lib/test/test_gettext.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@
MMOFILE = os.path.join(LOCALEDIR, 'metadata.mo')


def reset_gettext():
gettext._localedirs.clear()
gettext._current_domain = 'messages'
gettext._translations.clear()


class GettextBaseTest(unittest.TestCase):
def setUp(self):
self.addCleanup(os_helper.rmtree, os.path.split(LOCALEDIR)[0])
Expand All @@ -132,7 +138,8 @@ def setUp(self):
fp.write(base64.decodebytes(MMO_DATA))
self.env = self.enterContext(os_helper.EnvironmentVarGuard())
self.env['LANGUAGE'] = 'xx'
gettext._translations.clear()
reset_gettext()
self.addCleanup(reset_gettext)


GNU_MO_DATA_ISSUE_17898 = b'''\
Expand Down Expand Up @@ -312,6 +319,10 @@ def test_multiline_strings(self):
class PluralFormsTestCase(GettextBaseTest):
def setUp(self):
GettextBaseTest.setUp(self)
self.localedir = os.curdir
# Set up the bindings
gettext.bindtextdomain('gettext', self.localedir)
gettext.textdomain('gettext')
self.mofile = MOFILE

def test_plural_forms1(self):
Expand Down Expand Up @@ -355,7 +366,7 @@ def test_plural_context_forms2(self):
x = t.npgettext('With context',
'There is %s file', 'There are %s files', 2)
eq(x, 'Hay %s ficheros (context)')
x = gettext.pgettext('With context', 'There is %s file')
x = t.pgettext('With context', 'There is %s file')
eq(x, 'Hay %s fichero (context)')

# Examples from http://www.gnu.org/software/gettext/manual/gettext.html
Expand Down