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

Commit65a0103

Browse files
miss-islingtonStanFromIrelandtomasr8
authored
[3.12]gh-130655: Add tests forgettext.find() (GH-130691) (#132083)
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 parent10f73f7 commit65a0103

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
@@ -766,6 +766,76 @@ def test_expand_lang(self):
766766
self.assertEqual(gettext._expand_lang(locale),expanded)
767767

768768

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp