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