FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-85012: Properly reset `msgctxt` when compiling messages with `msgfmt` by tomasr8 · Pull Request #130525 · python/cpython · GitHub

Repository navigation

Prev Previous commit
Next Next commit
Add regression tests
  • Loading branch information
tomasr8 committed Feb 25, 2025
commit 97d0a0fe05579fa8a8e8bdd58a5ea8d5772cef1f
22 changes: 22 additions & 0 deletions Lib/test/test_tools/test_msgfmt.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,28 @@ def test_compilation(self):

self.assertDictEqual(actual._catalog, expected._catalog)

def test_translations(self):
with open(data_dir / 'general.mo', 'rb') as f:
t = GNUTranslations(f)

self.assertEqual(t.gettext('foo'), 'foo')
self.assertEqual(t.gettext('bar'), 'baz')
self.assertEqual(t.pgettext('abc', 'foo'), 'bar')
self.assertEqual(t.pgettext('xyz', 'foo'), 'bar')
self.assertEqual(t.gettext('Multilinestring'), 'Multilinetranslation')
self.assertEqual(t.gettext('"escapes"'), '"translated"')
self.assertEqual(t.gettext('\n newlines \n'), '\n translated \n')
self.assertEqual(t.ngettext('One email sent.', '%d emails sent.', 1),
'One email sent.')
self.assertEqual(t.ngettext('One email sent.', '%d emails sent.', 2),
'%d emails sent.')
self.assertEqual(t.npgettext('abc', 'One email sent.',
'%d emails sent.', 1),
'One email sent.')
self.assertEqual(t.npgettext('abc', 'One email sent.',
'%d emails sent.', 2),
'%d emails sent.')

def test_invalid_msgid_plural(self):
with temp_cwd():
Path('invalid.po').write_text('''\
Expand Down

Back | FazBrowse Home | New Git URL