Skip to content

Commit 08bc8d7

Browse files
committed
In test_msgfmt move data files to the data folder.
Data used by test_msgfmt.Test_multi_input are now stored as files inside the msgfmt_data directory.
1 parent 9cb9395 commit 08bc8d7

File tree

7 files changed

+82
-146
lines changed

7 files changed

+82
-146
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
file1_fr.po eol=crlf
2+
file2_fr.po eol=lf
566 Bytes
Binary file not shown.
486 Bytes
Binary file not shown.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# French translations for python package.
2+
# Copyright (C) 2018 THE python\'S COPYRIGHT HOLDER
3+
# This file is distributed under the same license as the python package.
4+
# s-ball <[email protected]>, 2018.
5+
#
6+
msgid ""
7+
msgstr ""
8+
"Project-Id-Version: python 3.8\n"
9+
"Report-Msgid-Bugs-To: \n"
10+
"POT-Creation-Date: 2018-11-30 23:46+0100\n"
11+
"PO-Revision-Date: 2018-11-30 23:47+0100\n"
12+
"Last-Translator: s-ball <[email protected]>\n"
13+
"Language-Team: French\n"
14+
"Language: fr\n"
15+
"MIME-Version: 1.0\n"
16+
"Content-Type: text/plain; charset=UTF-8\n"
17+
"Content-Transfer-Encoding: 8bit\n"
18+
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
19+
20+
#: file1.py:6
21+
msgid "Hello!"
22+
msgstr "Bonjour !"
23+
24+
#: file1.py:7
25+
#, python-brace-format
26+
msgid "{n} horse"
27+
msgid_plural "{n} horses"
28+
msgstr[0] "{n} cheval"
29+
msgstr[1] "{n} chevaux"
473 Bytes
Binary file not shown.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# French translations for python package.
2+
# Copyright (C) 2018 THE python'S COPYRIGHT HOLDER
3+
# This file is distributed under the same license as the python package.
4+
# s-ball <[email protected]>, 2018.
5+
#
6+
msgid ""
7+
msgstr ""
8+
"Project-Id-Version: python 3.8\n"
9+
"Report-Msgid-Bugs-To: \n"
10+
"POT-Creation-Date: 2018-11-30 23:57+0100\n"
11+
"PO-Revision-Date: 2018-11-30 23:57+0100\n"
12+
"Last-Translator: s-ball <[email protected]>\n"
13+
"Language-Team: French\n"
14+
"Language: fr\n"
15+
"MIME-Version: 1.0\n"
16+
"Content-Type: text/plain; charset=UTF-8\n"
17+
"Content-Transfer-Encoding: 8bit\n"
18+
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
19+
20+
#: file2.py:6
21+
msgid "It's over."
22+
msgstr "C'est terminé."
23+
24+
#: file2.py:7
25+
msgid "Bye..."
26+
msgstr "Au revoir ..."

Lib/test/test_tools/test_msgfmt.py

Lines changed: 25 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Tests for the Tools/i18n/msgfmt.py tool."""
2-
2+
import filecmp
33
import os
4+
import shutil
45
import sys
56
import unittest
67
from gettext import GNUTranslations
@@ -131,126 +132,6 @@ class Test_multi_input(unittest.TestCase):
131132

132133
script = os.path.join(toolsdir, 'i18n', 'msgfmt.py')
133134

134-
# binary contents of tiny po files
135-
# windows end of lines for first one
136-
file1_fr_po = b'''# French translations for python package.\r
137-
# Copyright (C) 2018 THE python\'S COPYRIGHT HOLDER\r
138-
# This file is distributed under the same license as the python package.\r
139-
# s-ball <[email protected]>, 2018.\r
140-
#\r
141-
msgid ""\r
142-
msgstr ""\r
143-
"Project-Id-Version: python 3.8\\n"\r
144-
"Report-Msgid-Bugs-To: \\n"\r
145-
"POT-Creation-Date: 2018-11-30 23:46+0100\\n"\r
146-
"PO-Revision-Date: 2018-11-30 23:47+0100\\n"\r
147-
"Last-Translator: s-ball <[email protected]>\\n"\r
148-
"Language-Team: French\\n"\r\n"Language: fr\\n"\r
149-
"MIME-Version: 1.0\\n"\r
150-
"Content-Type: text/plain; charset=UTF-8\\n"\r
151-
"Content-Transfer-Encoding: 8bit\\n"\r
152-
"Plural-Forms: nplurals=2; plural=(n > 1);\\n"\r
153-
\r
154-
#: file1.py:6\r
155-
msgid "Hello!"\r
156-
msgstr "Bonjour !"\r
157-
\r
158-
#: file1.py:7\r
159-
#, python-brace-format\r
160-
msgid "{n} horse"\r
161-
msgid_plural "{n} horses"\r
162-
msgstr[0] "{n} cheval"\r
163-
msgstr[1] "{n} chevaux"\r
164-
'''
165-
166-
# Unix end of file and a non ascii character for second one
167-
file2_fr_po = rb'''# French translations for python package.
168-
# Copyright (C) 2018 THE python'S COPYRIGHT HOLDER
169-
# This file is distributed under the same license as the python package.
170-
# s-ball <[email protected]>, 2018.
171-
#
172-
msgid ""
173-
msgstr ""
174-
"Project-Id-Version: python 3.8\n"
175-
"Report-Msgid-Bugs-To: \n"
176-
"POT-Creation-Date: 2018-11-30 23:57+0100\n"
177-
"PO-Revision-Date: 2018-11-30 23:57+0100\n"
178-
"Last-Translator: s-ball <[email protected]>\n"
179-
"Language-Team: French\n"
180-
"Language: fr\n"
181-
"MIME-Version: 1.0\n"
182-
"Content-Type: text/plain; charset=UTF-8\n"
183-
"Content-Transfer-Encoding: 8bit\n"
184-
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
185-
186-
#: file2.py:6
187-
msgid "It's over."
188-
msgstr "C'est termin\xc3\xa9."
189-
190-
#: file2.py:7
191-
msgid "Bye..."
192-
msgstr "Au revoir ..."
193-
'''
194-
195-
# binary contents of corresponding compiled mo files
196-
file1_fr_mo = (
197-
b'\xde\x12\x04\x95\x00\x00\x00\x00\x03\x00\x00\x00\x1c'
198-
b'\x00\x00\x004\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
199-
b'\x00\x00\x00\x00\x00L\x00\x00\x00\x06\x00\x00\x00M'
200-
b'\x00\x00\x00\x14\x00\x00\x00T\x00\x00\x00[\x01\x00'
201-
b'\x00i\x00\x00\x00\t\x00\x00\x00\xc5\x01\x00\x00\x16'
202-
b'\x00\x00\x00\xcf\x01\x00\x00\x00Hello!\x00{n} horse'
203-
b'\x00{n} horses\x00Project-Id-Version: python 3.8\n'
204-
b'Report-Msgid-Bugs-To: \nPOT-Creation-Date: 2018-11-30 '
205-
b'23:46+0100\nPO-Revision-Date: 2018-11-30 23:47+0100\n'
206-
b'Last-Translator: s-ball <[email protected]>\n'
207-
b'Language-Team: French\nLanguage: fr\nMIME-Version: 1.0'
208-
b'\nContent-Type: text/plain; charset=UTF-8\nContent-'
209-
b'Transfer-Encoding: 8bit\nPlural-Forms: nplurals=2'
210-
b'; plural=(n > 1);\n\x00Bonjour !\x00{n} cheval\x00{n'
211-
b'} chevaux\x00'
212-
)
213-
file2_fr_mo = (
214-
b"\xde\x12\x04\x95\x00\x00\x00\x00\x03\x00\x00\x00"
215-
b"\x1c\x00\x00\x004\x00\x00\x00\x00\x00\x00\x00\x00"
216-
b"\x00\x00\x00\x00\x00\x00\x00L\x00\x00\x00\x06\x00"
217-
b"\x00\x00M\x00\x00\x00\n\x00\x00\x00T\x00\x00\x00["
218-
b"\x01\x00\x00_\x00\x00\x00\r\x00\x00\x00\xbb\x01"
219-
b"\x00\x00\x0f\x00\x00\x00\xc9\x01\x00\x00\x00Bye.."
220-
b".\x00It's over.\x00Project-Id-Version: python 3.8"
221-
b"\nReport-Msgid-Bugs-To: \nPOT-Creation-Date: 2018"
222-
b"-11-30 23:57+0100\nPO-Revision-Date: 2018-11-30 2"
223-
b"3:57+0100\nLast-Translator: s-ball <s-ball@lapost"
224-
b"e.net>\nLanguage-Team: French\nLanguage: fr\nMIME"
225-
b"-Version: 1.0\nContent-Type: text/plain; charset="
226-
b"UTF-8\nContent-Transfer-Encoding: 8bit\nPlural-Fo"
227-
b"rms: nplurals=2; plural=(n > 1);\n\x00Au revoir ."
228-
b"..\x00C'est termin\xc3\xa9.\x00"
229-
)
230-
231-
# content of merging both po files keeping second header
232-
file12_fr_mo = (
233-
b"\xde\x12\x04\x95\x00\x00\x00\x00\x05\x00\x00\x00"
234-
b"\x1c\x00\x00\x00D\x00\x00\x00\x00\x00\x00\x00\x00"
235-
b"\x00\x00\x00\x00\x00\x00\x00l\x00\x00\x00\x06\x00"
236-
b"\x00\x00m\x00\x00\x00\x06\x00\x00\x00t\x00\x00\x00"
237-
b"\n\x00\x00\x00{\x00\x00\x00\x14\x00\x00\x00\x86"
238-
b"\x00\x00\x00[\x01\x00\x00\x9b\x00\x00\x00\r\x00"
239-
b"\x00\x00\xf7\x01\x00\x00\t\x00\x00\x00\x05\x02\x00"
240-
b"\x00\x0f\x00\x00\x00\x0f\x02\x00\x00\x16\x00\x00"
241-
b"\x00\x1f\x02\x00\x00\x00Bye...\x00Hello!\x00It's "
242-
b"over.\x00{n} horse\x00{n} horses\x00Project-Id-Ver"
243-
b"sion: python 3.8\nReport-Msgid-Bugs-To: \nPOT-Crea"
244-
b"tion-Date: 2018-11-30 23:57+0100\nPO-Revision-Date"
245-
b": 2018-11-30 23:57+0100\nLast-Translator: s-ball <"
246-
b"[email protected]>\nLanguage-Team: French\nLangua"
247-
b"ge: fr\nMIME-Version: 1.0\nContent-Type: text/plai"
248-
b"n; charset=UTF-8\nContent-Transfer-Encoding: 8bit"
249-
b"\nPlural-Forms: nplurals=2; plural=(n > 1);\n\x00A"
250-
b"u revoir ...\x00Bonjour !\x00C'est termin\xc3\xa9."
251-
b"\x00{n} cheval\x00{n} chevaux\x00"
252-
)
253-
254135
def imp(self):
255136
i18ndir = os.path.join(toolsdir, 'i18n')
256137
sys.path.append(i18ndir)
@@ -279,50 +160,48 @@ def test_wrong(self):
279160
def test_outputfile(self):
280161
"""Test script with -o option - 1 single file, Windows EOL"""
281162
with temp_cwd(None):
282-
with open("file1_fr.po", "wb") as out:
283-
out.write(self.file1_fr_po)
284-
assert_python_ok(self.script, '-o', 'file1.mo', 'file1_fr.po')
285-
with open('file1.mo', 'rb') as fin:
286-
self.assertEqual(self.file1_fr_mo, fin.read())
163+
assert_python_ok(self.script, '-o', 'file1.mo',
164+
data_dir / 'file1_fr.po')
165+
self.assertTrue(
166+
filecmp.cmp(data_dir / 'file1_fr.mo', 'file1.mo'),
167+
'Wrong compiled file1_fr.mo')
287168

288169
def test_no_outputfile(self):
289170
"""Test script without -o option - 1 single file, Unix EOL"""
290171
with temp_cwd(None):
291-
with open("file2_fr.po", "wb") as out:
292-
out.write(self.file2_fr_po)
172+
shutil.copy(data_dir / 'file2_fr.po', '.')
293173
assert_python_ok(self.script, 'file2_fr.po')
294-
with open('file2_fr.mo', 'rb') as fin:
295-
self.assertEqual(self.file2_fr_mo, fin.read())
174+
self.assertTrue(
175+
filecmp.cmp(data_dir / 'file2_fr.mo', 'file2_fr.mo'),
176+
'Wrong compiled file2_fr.mo')
296177

297178
def test_both_with_outputfile(self):
298179
"""Test script with -o option and 2 input files"""
299180
# msgfmt.py version 1.2 behaviour is to correctly merge the input
300181
# files and to keep last entry when same entry occurs in more than
301182
# one file
302183
with temp_cwd(None):
303-
with open("file1_fr.po", "wb") as out:
304-
out.write(self.file1_fr_po)
305-
with open("file2_fr.po", "wb") as out:
306-
out.write(self.file2_fr_po)
307-
assert_python_ok(self.script, '-o', 'file1.mo',
308-
'file1_fr.po', 'file2_fr.po')
309-
with open('file1.mo', 'rb') as fin:
310-
self.assertEqual(self.file12_fr_mo, fin.read())
184+
assert_python_ok(self.script, '-o', 'file12.mo',
185+
data_dir / 'file1_fr.po',
186+
data_dir / 'file2_fr.po')
187+
self.assertTrue(
188+
filecmp.cmp(data_dir / 'file12_fr.mo', 'file12.mo'),
189+
'Wrong compiled file12.mo')
311190

312191
def test_both_without_outputfile(self):
313192
"""Test script without -o option and 2 input files"""
314193
# msgfmt.py version 1.2 behaviour was that second mo file
315194
# also merged previous po files
316195
with temp_cwd(None):
317-
with open("file1_fr.po", "wb") as out:
318-
out.write(self.file1_fr_po)
319-
with open("file2_fr.po", "wb") as out:
320-
out.write(self.file2_fr_po)
196+
shutil.copy(data_dir /'file1_fr.po', '.')
197+
shutil.copy(data_dir /'file2_fr.po', '.')
321198
assert_python_ok(self.script, 'file1_fr.po', 'file2_fr.po')
322-
with open('file1_fr.mo', 'rb') as fin:
323-
self.assertEqual(self.file1_fr_mo, fin.read())
324-
with open('file2_fr.mo', 'rb') as fin:
325-
self.assertEqual(self.file2_fr_mo, fin.read())
199+
self.assertTrue(
200+
filecmp.cmp(data_dir / 'file1_fr.mo', 'file1_fr.mo'),
201+
'Wrong compiled file1_fr.mo')
202+
self.assertTrue(
203+
filecmp.cmp(data_dir / 'file2_fr.mo', 'file2_fr.mo'),
204+
'Wrong compiled file2_fr.mo')
326205

327206
def test_consecutive_make_calls(self):
328207
"""Directly calls make twice to prove bpo-9741 is fixed"""

0 commit comments

Comments
 (0)