8000 GH-127488: Add tests for the file - msgfmt.py file in Tools/i18n/msgfmt · srinivasreddy/cpython@99af7e6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 99af7e6

Browse files
committed
pythonGH-127488: Add tests for the file - msgfmt.py file in Tools/i18n/msgfmt
1 parent 1f8267b commit 99af7e6

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

Tools/i18n/tests/__init__.py

Whitespace-only changes.

Tools/i18n/tests/test_msgfmt.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import unittest
2+
import os
3+
import tempfile
4+
from ..msgfmt import make
5+
6+
class TestMsgfmt(unittest.TestCase):
7+
8+
def setUp(self):
9+
self.test_dir = tempfile.TemporaryDirectory()
10+
self.addCleanup(self.test_dir.cleanup)
11+
12+
def create_po_file(self, content):
13+
po_file_path = os.path.join(self.test_dir.name, 'test.po')
14+
with open(po_file_path, 'w', encoding='utf-8') as f:
15+
f.write(content)
16+
return po_file_path
17+
18+
def test_make_creates_mo_file(self):
19+
po_content = '''
20+
msgid ""
21+
msgstr ""
22+
"Content-Type: text/plain; charset=UTF-8\\n"
23+
24+
msgid "Hello"
25+
msgstr "Bonjour"
26+
'''
27+
po_file = self.create_po_file(po_content)
28+
mo_file = os.path.splitext(po_file)[0] + '.mo'
29+
30+
make(po_file, mo_file)
31+
32+
self.assertTrue(os.path.exists(mo_file))
33+
34+
def test_make_handles_fuzzy(self):
35+
po_content = '''
< D79A code>36+
msgid ""
37+
msgstr ""
38+
"Content-Type: text/plain; charset=UTF-8\\n"
39+
40+
#, fuzzy
41+
msgid "Hello"
42+
msgstr "Bonjour"
43+
'''
44+
po_file = self.create_po_file(po_content)
45+
mo_file = os.path.splitext(po_file)[0] + '.mo'
46+
47+
make(po_file, mo_file)
48+
49+
self.assertTrue(os.path.exists(mo_file))
50+
51+
def test_make_invalid_po_file(self):
52+
po_content = '''
53+
msgid "Hello"
54+
msgstr "Bonjour"
55+
msgid_plural "Hellos"
56+
'''
57+
po_file = self.create_po_file(po_content)
58+
mo_file = os.path.splitext(po_file)[0] + '.mo'
59+
60+
with self.assertRaises(SystemExit):
61+
make(po_file, mo_file)
62+
63+
if __name__ == '__main__':
64+
unittest.main()

0 commit comments

Comments
 (0)
0