]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-109864: Make test_gettext tests order independent (GH-109866)
authorSerhiy Storchaka <storchaka@gmail.com>
Sat, 7 Oct 2023 13:00:28 +0000 (16:00 +0300)
committerGitHub <noreply@github.com>
Sat, 7 Oct 2023 13:00:28 +0000 (16:00 +0300)
Lib/test/test_gettext.py

index 8430fc234d00eebc95f6c0188b68ff0d1c4c1639..2650ce501c309d759f24b85b76e3b8acc211749a 100644 (file)
@@ -115,6 +115,12 @@ UMOFILE = os.path.join(LOCALEDIR, 'ugettext.mo')
 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])
@@ -132,7 +138,8 @@ class GettextBaseTest(unittest.TestCase):
             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'''\
@@ -312,6 +319,10 @@ trggrkg zrffntr pngnybt yvoenel.''')
 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):
@@ -355,7 +366,7 @@ class PluralFormsTestCase(GettextBaseTest):
         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