Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6823212

Browse filesBrowse files
[3.11] gh-109864: Make test_gettext tests order independent (GH-109866) (GH-110503)
(cherry picked from commit 1aad4fc) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parent 6a33529 commit 6823212
Copy full SHA for 6823212

File tree

1 file changed

+13
-2
lines changed
Filter options

1 file changed

+13
-2
lines changed

‎Lib/test/test_gettext.py

Copy file name to clipboardExpand all lines: Lib/test/test_gettext.py
+13-2Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.