Skip to content

Commit d45039c

Browse files
committed
Generate json files for MultiInputTest data files.
1 parent 3760851 commit d45039c

File tree

4 files changed

+95
-38
lines changed

4 files changed

+95
-38
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[
2+
[
3+
"",
4+
"Project-Id-Version: PACKAGE VERSION\nReport-Msgid-Bugs-To: \nPOT-Creation-Date: 2018-11-30 23:57+0100\nPO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\nLast-Translator: FULL NAME <EMAIL@ADDRESS>\nLanguage-Team: French\nLanguage: fr\nMIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8\nContent-Transfer-Encoding: 8bit\nPlural-Forms: nplurals=2; plural=(n > 1);\n"
5+
],
6+
[
7+
"Bye...",
8+
"Au revoir ..."
9+
],
10+
[
11+
"Hello!",
12+
"Bonjour !"
13+
],
14+
[
15+
"It's over.",
16+
"C'est termin\u00e9."
17+
],
18+
[
19+
[
20+
"{n} horse",
21+
0
22+
],
23+
"{n} cheval"
24+
],
25+
[
26+
[
27+
"{n} horse",
28+
1
29+
],
30+
"{n} chevaux"
31+
]
32+
]
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[
2+
[
3+
"",
4+
"Project-Id-Version: PACKAGE VERSION\nReport-Msgid-Bugs-To: \nPOT-Creation-Date: 2018-11-30 23:46+0100\nPO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\nLast-Translator: FULL NAME <EMAIL@ADDRESS>\nLanguage-Team: French\nLanguage: fr\nMIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8\nContent-Transfer-Encoding: 8bit\nPlural-Forms: nplurals=2; plural=(n > 1);\n"
5+
],
6+
[
7+
"Hello!",
8+
"Bonjour !"
9+
],
10+
[
11+
[
12+
"{n} horse",
13+
0
14+
],
15+
"{n} cheval"
16+
],
17+
[
18+
[
19+
"{n} horse",
20+
1
21+
],
22+
"{n} chevaux"
23+
]
24+
]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[
2+
[
3+
"",
4+
"Project-Id-Version: PACKAGE VERSION\nReport-Msgid-Bugs-To: \nPOT-Creation-Date: 2018-11-30 23:57+0100\nPO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\nLast-Translator: FULL NAME <EMAIL@ADDRESS>\nLanguage-Team: French\nLanguage: fr\nMIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8\nContent-Transfer-Encoding: 8bit\nPlural-Forms: nplurals=2; plural=(n > 1);\n"
5+
],
6+
[
7+
"Bye...",
8+
"Au revoir ..."
9+
],
10+
[
11+
"It's over.",
12+
"C'est termin\u00e9."
13+
]
14+
]

Lib/test/test_tools/test_msgfmt.py

Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import filecmp
1212
import json
13-
import os
1413
import shutil
1514
import sys
1615
import unittest
@@ -21,7 +20,6 @@
2120
from test.support.script_helper import assert_python_failure, assert_python_ok
2221
from test.test_tools import skip_if_missing, toolsdir
2322

24-
2523
skip_if_missing('i18n')
2624

2725
data_dir = (Path(__file__).parent / 'msgfmt_data').resolve()
@@ -62,16 +60,10 @@ def test_translations(self):
6260
self.assertEqual(t.gettext('Multilinestring'), 'Multilinetranslation')
6361
self.assertEqual(t.gettext('"escapes"'), '"translated"')
6462
self.assertEqual(t.gettext('\n newlines \n'), '\n translated \n')
65-
self.assertEqual(t.ngettext('One email sent.', '%d emails sent.', 1),
66-
'One email sent.')
67-
self.assertEqual(t.ngettext('One email sent.', '%d emails sent.', 2),
68-
'%d emails sent.')
69-
self.assertEqual(t.npgettext('abc', 'One email sent.',
70-
'%d emails sent.', 1),
71-
'One email sent.')
72-
self.assertEqual(t.npgettext('abc', 'One email sent.',
73-
'%d emails sent.', 2),
74-
'%d emails sent.')
63+
self.assertEqual(t.ngettext('One email sent.', '%d emails sent.', 1), 'One email sent.')
64+
self.assertEqual(t.ngettext('One email sent.', '%d emails sent.', 2), '%d emails sent.')
65+
self.assertEqual(t.npgettext('abc', 'One email sent.', '%d emails sent.', 1), 'One email sent.')
66+
self.assertEqual(t.npgettext('abc', 'One email sent.', '%d emails sent.', 2), '%d emails sent.')
7567

7668
def test_po_with_bom(self):
7769
with temp_cwd():
@@ -165,9 +157,7 @@ def test_no_outputfile(self):
165157
with temp_cwd(None):
166158
shutil.copy(data_dir / 'file2_fr_lf.po', '.')
167159
assert_python_ok(msgfmt, 'file2_fr_lf.po')
168-
self.assertTrue(
169-
filecmp.cmp(data_dir / 'file2_fr_lf.mo', 'file2_fr_lf.mo'),
170-
'Wrong compiled file2_fr_lf.mo')
160+
self.assertTrue(filecmp.cmp(data_dir / 'file2_fr_lf.mo', 'file2_fr_lf.mo'), 'Wrong compiled file2_fr_lf.mo')
171161

172162
def test_both_with_outputfile(self):
173163
"""Test script with -o option and 2 input files
@@ -179,11 +169,8 @@ def test_both_with_outputfile(self):
179169
Unix endings (lf)
180170
"""
181171
with temp_cwd(None):
182-
assert_python_ok(msgfmt, '-o', 'file12.mo',
183-
data_dir / 'file1_fr_crlf.po',
184-
data_dir / 'file2_fr_lf.po')
185-
self.assertTrue(
186-
filecmp.cmp(data_dir / 'file12_fr.mo', 'file12.mo'))
172+
assert_python_ok(msgfmt, '-o', 'file12.mo', data_dir / 'file1_fr_crlf.po', data_dir / 'file2_fr_lf.po')
173+
self.assertTrue(filecmp.cmp(data_dir / 'file12_fr.mo', 'file12.mo'))
187174

188175
def test_both_without_outputfile(self):
189176
"""Test script without -o option and 2 input files"""
@@ -192,30 +179,30 @@ def test_both_without_outputfile(self):
192179
shutil.copy(data_dir / 'file1_fr_crlf.po', '.')
193180
shutil.copy(data_dir / 'file2_fr_lf.po', '.')
194181
assert_python_ok(msgfmt, 'file1_fr_crlf.po', 'file2_fr_lf.po')
195-
self.assertTrue(
196-
filecmp.cmp(data_dir / 'file1_fr_crlf.mo', 'file1_fr_crlf.mo'))
197-
self.assertTrue(
198-
filecmp.cmp(data_dir / 'file2_fr_lf.mo', 'file2_fr_lf.mo'))
182+
self.assertTrue(filecmp.cmp(data_dir / 'file1_fr_crlf.mo', 'file1_fr_crlf.mo'))
183+
self.assertTrue(filecmp.cmp(data_dir / 'file2_fr_lf.mo', 'file2_fr_lf.mo'))
184+
185+
186+
def make_message_files(mo_file, *po_files):
187+
compile_messages(mo_file, *po_files)
188+
# Create a human-readable JSON file which is
189+
# easier to review than the binary .mo file.
190+
with open(mo_file, 'rb') as f:
191+
translations = GNUTranslations(f)
192+
catalog_file = mo_file.with_suffix('.json')
193+
with open(catalog_file, 'w') as f:
194+
data = translations._catalog.items()
195+
data = sorted(data, key=lambda x: (isinstance(x[0], tuple), x[0]))
196+
json.dump(data, f, indent=4)
197+
f.write('\n')
199198

200199

201200
def update_catalog_snapshots():
202201
for po_file in data_dir.glob('*.po'):
203202
mo_file = po_file.with_suffix('.mo')
204-
compile_messages(mo_file, po_file)
205-
# Create a human-readable JSON file which is
206-
# easier to review than the binary .mo file.
207-
with open(mo_file, 'rb') as f:
208-
translations = GNUTranslations(f)
209-
catalog_file = po_file.with_suffix('.json')
210-
with open(catalog_file, 'w') as f:
211-
data = translations._catalog.items()
212-
data = sorted(data, key=lambda x: (isinstance(x[0], tuple), x[0]))
213-
json.dump(data, f, indent=4)
214-
f.write('\n')
203+
make_message_files(mo_file, po_file)
215204
# special processing for file12_fr.mo which results from 2 input files
216-
compile_messages(data_dir / 'file12_fr.mo',
217-
data_dir / 'file1_fr_crlf.po',
218-
data_dir / 'file2_fr_lf.po')
205+
make_message_files(data_dir / 'file12_fr.mo', data_dir / 'file1_fr_crlf.po', data_dir / 'file2_fr_lf.po')
219206

220207

221208
if __name__ == '__main__':

0 commit comments

Comments
 (0)