Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit093c587

Browse files
miss-islingtonStanFromIrelandtomasr8
authored
[3.13]gh-130655: Add tests forgettext.find() (GH-130691) (#132084)
gh-130655: Add tests for `gettext.find()` (GH-130691)(cherry picked from commit3118693)Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>Co-authored-by: Tomas R. <tomas.roun8@gmail.com>
1 parent0c0ffbe commit093c587

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

‎Lib/test/test_gettext.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,76 @@ def test_expand_lang(self):
768768
self.assertEqual(gettext._expand_lang(locale),expanded)
769769

770770

771+
classFindTestCase(unittest.TestCase):
772+
773+
defsetUp(self):
774+
self.env=self.enterContext(os_helper.EnvironmentVarGuard())
775+
self.tempdir=self.enterContext(os_helper.temp_cwd())
776+
777+
forkeyin ('LANGUAGE','LC_ALL','LC_MESSAGES','LANG'):
778+
self.env.unset(key)
779+
780+
defcreate_mo_file(self,lang):
781+
locale_dir=os.path.join(self.tempdir,"locale")
782+
mofile_dir=os.path.join(locale_dir,lang,"LC_MESSAGES")
783+
os.makedirs(mofile_dir)
784+
mo_file=os.path.join(mofile_dir,"mofile.mo")
785+
withopen(mo_file,"wb")asf:
786+
f.write(GNU_MO_DATA)
787+
returnmo_file
788+
789+
deftest_find_with_env_vars(self):
790+
# test that find correctly finds the environment variables
791+
# when languages are not supplied
792+
mo_file=self.create_mo_file("ga_IE")
793+
forvarin ('LANGUAGE','LC_ALL','LC_MESSAGES','LANG'):
794+
self.env.set(var,'ga_IE')
795+
result=gettext.find("mofile",
796+
localedir=os.path.join(self.tempdir,"locale"))
797+
self.assertEqual(result,mo_file)
798+
self.env.unset(var)
799+
800+
deftest_find_with_languages(self):
801+
# test that passed languages are used
802+
self.env.set('LANGUAGE','pt_BR')
803+
mo_file=self.create_mo_file("ga_IE")
804+
805+
result=gettext.find("mofile",
806+
localedir=os.path.join(self.tempdir,"locale"),
807+
languages=['ga_IE'])
808+
self.assertEqual(result,mo_file)
809+
810+
@unittest.mock.patch('gettext._expand_lang')
811+
deftest_find_with_no_lang(self,patch_expand_lang):
812+
# no language can be found
813+
gettext.find('foo')
814+
patch_expand_lang.assert_called_with('C')
815+
816+
@unittest.mock.patch('gettext._expand_lang')
817+
deftest_find_with_c(self,patch_expand_lang):
818+
# 'C' is already in languages
819+
self.env.set('LANGUAGE','C')
820+
gettext.find('foo')
821+
patch_expand_lang.assert_called_with('C')
822+
823+
deftest_find_all(self):
824+
# test that all are returned when all is set
825+
paths= []
826+
forlangin ["ga_IE","es_ES"]:
827+
paths.append(self.create_mo_file(lang))
828+
result=gettext.find('mofile',
829+
localedir=os.path.join(self.tempdir,"locale"),
830+
languages=["ga_IE","es_ES"],all=True)
831+
self.assertEqual(sorted(result),sorted(paths))
832+
833+
deftest_find_deduplication(self):
834+
# test that find removes duplicate languages
835+
mo_file= [self.create_mo_file('ga_IE')]
836+
result=gettext.find("mofile",localedir=os.path.join(self.tempdir,"locale"),
837+
languages=['ga_IE','ga_IE'],all=True)
838+
self.assertEqual(result,mo_file)
839+
840+
771841
classMiscTestCase(unittest.TestCase):
772842
deftest__all__(self):
773843
support.check__all__(self,gettext,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp