Skip to content

Commit 6430ca5

Browse files
[3.12] gh-109864: Make test_gettext tests order independent (GH-109866) (GH-110502)
(cherry picked from commit 1aad4fc) Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent 2465fe0 commit 6430ca5

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

Lib/test/test_gettext.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@
115115
MMOFILE = os.path.join(LOCALEDIR, 'metadata.mo')
116116

117117

118+
def reset_gettext():
119+
gettext._localedirs.clear()
120+
gettext._current_domain = 'messages'
121+
gettext._translations.clear()
122+
123+
118124
class GettextBaseTest(unittest.TestCase):
119125
def setUp(self):
120126
self.addCleanup(os_helper.rmtree, os.path.split(LOCALEDIR)[0])
@@ -132,7 +138,8 @@ def setUp(self):
132138
fp.write(base64.decodebytes(MMO_DATA))
133139
self.env = self.enterContext(os_helper.EnvironmentVarGuard())
134140
self.env['LANGUAGE'] = 'xx'
135-
gettext._translations.clear()
141+
reset_gettext()
142+
self.addCleanup(reset_gettext)
136143

137144

138145
GNU_MO_DATA_ISSUE_17898 = b'''\
@@ -312,6 +319,10 @@ def test_multiline_strings(self):
312319
class PluralFormsTestCase(GettextBaseTest):
313320
def setUp(self):
314321
GettextBaseTest.setUp(self)
322+
self.localedir = os.curdir
323+
# Set up the bindings
324+
gettext.bindtextdomain('gettext', self.localedir)
325+
gettext.textdomain('gettext')
315326
self.mofile = MOFILE
316327

317328
def test_plural_forms1(self):
@@ -355,7 +366,7 @@ def test_plural_context_forms2(self):
355366
x = t.npgettext('With context',
356367
'There is %s file', 'There are %s files', 2)
357368
eq(x, 'Hay %s ficheros (context)')
358-
x = gettext.pgettext('With context', 'There is %s file')
369+
x = t.pgettext('With context', 'There is %s file')
359370
eq(x, 'Hay %s fichero (context)')
360371

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

0 commit comments

Comments
 (0)