forked from python/cpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pythonGH-127488: Add tests for the file - msgfmt.py file in Tools/i18…
…n/msgfmt
- Loading branch information
1 parent
1f8267b
commit 095a567
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import unittest | ||
import os | ||
import tempfile | ||
from Tools.i18n.msgfmt import make | ||
|
||
class TestMsgfmt(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.test_dir = tempfile.TemporaryDirectory() | ||
self.addCleanup(self.test_dir.cleanup) | ||
|
||
def create_po_file(self, content): | ||
po_file_path = os.path.join(self.test_dir.name, 'test.po') | ||
with open(po_file_path, 'w', encoding='utf-8') as f: | ||
f.write(content) | ||
return po_file_path | ||
|
||
def test_make_creates_mo_file(self): | ||
po_content = ''' | ||
msgid "" | ||
msgstr "" | ||
"Content-Type: text/plain; charset=UTF-8\\n" | ||
msgid "Hello" | ||
msgstr "Bonjour" | ||
''' | ||
po_file = self.create_po_file(po_content) | ||
mo_file = os.path.splitext(po_file)[0] + '.mo' | ||
|
||
make(po_file, mo_file) | ||
|
||
self.assertTrue(os.path.exists(mo_file)) | ||
|
||
def test_make_handles_fuzzy(self): | ||
po_content = ''' | ||
msgid "" | ||
msgstr "" | ||
"Content-Type: text/plain; charset=UTF-8\\n" | ||
#, fuzzy | ||
msgid "Hello" | ||
msgstr "Bonjour" | ||
''' | ||
po_file = self.create_po_file(po_content) | ||
mo_file = os.path.splitext(po_file)[0] + '.mo' | ||
|
||
make(po_file, mo_file) | ||
|
||
self.assertTrue(os.path.exists(mo_file)) | ||
|
||
def test_make_invalid_po_file(self): | ||
po_content = ''' | ||
msgid "Hello" | ||
msgstr "Bonjour" | ||
msgid_plural "Hellos" | ||
''' | ||
po_file = self.create_po_file(po_content) | ||
mo_file = os.path.splitext(po_file)[0] + '.mo' | ||
|
||
with self.assertRaises(SystemExit): | ||
make(po_file, mo_file) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |