Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-79516: allow msgfmt.py to compile multiple input po files#10875

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
s-ball wants to merge68 commits intopython:main
base:main
Choose a base branch
Loading
froms-ball:multi_inputs
Open
Changes from1 commit
Commits
Show all changes
68 commits
Select commitHold shift + click to select a range
73b5ac8
Add test for current behaviour of msgfmt.py
s-ballDec 2, 2018
5fb1575
Final fix for bpo-9741, with tests proving it.
s-ballDec 2, 2018
b1968e9
Update docstrings for the script and make function
s-ballDec 2, 2018
0bc4ad3
Give make a simpler and more consistent interface.
s-ballDec 4, 2018
a9e67b4
Add a Misc/NEWS.d entry.
s-ballDec 5, 2018
6c59d6c
Merge branch 'multi_inputs' of https://github.com/s-ball/cpython into…
s-ballDec 5, 2018
1ce22c0
Merge branch 'main' into multi_inputs
s-ballJan 23, 2025
863bd97
Merge branch 'main' into multi_inputs
s-ballJan 23, 2025
4390ede
Fix an import error in test_i18n.py .
s-ballJan 23, 2025
008ea27
Fix another import error.
s-ballJan 23, 2025
8744743
Merge branch 'main' into multi_inputs
s-ballJan 23, 2025
93a6eb7
Merge branch 'main' into multi_inputs
s-ballFeb 23, 2025
ba26b80
Revert version number to 1.2
s-ballFeb 23, 2025
150cea1
Merge branch 'main' into multi_inputs
s-ballFeb 23, 2025
d9afabb
Merge branch 'main' into multi_inputs
s-ballFeb 24, 2025
9004387
Merge branch 'main' into multi_inputs
s-ballFeb 24, 2025
7556f79
Merge branch 'multi_inputs' of https://github.com/s-ball/cpython into…
s-ballFeb 27, 2025
80947d1
Merge branch 'main' into multi_inputs
s-ballFeb 27, 2025
12acb83
Merge branch 'main' into multi_inputs
s-ballFeb 27, 2025
1ecc1f3
Fix a merge error
s-ballFeb 27, 2025
e59ba68
Merge branch 'multi_inputs' of https://github.com/s-ball/cpython into…
s-ballFeb 27, 2025
4ffd20a
Merge branch 'main' into multi_inputs
s-ballFeb 27, 2025
7505f2b
Merge branch 'main' into multi_inputs
s-ballFeb 28, 2025
2c27120
Merge branch 'main' into multi_inputs
s-ballFeb 28, 2025
1f4e5ac
fix details
merwokFeb 28, 2025
4170796
Merge branch 'main' into multi_inputs
s-ballMar 1, 2025
46c08c5
Move tests for the gh-79516 issue to test_msgfmt.py
s-ballMar 1, 2025
24d89a6
Cosmetic improvements after review.
s-ballMar 1, 2025
17b4e05
Fix an import error
s-ballMar 1, 2025
bfc8a44
Merge branch 'main' into multi_inputs
s-ballMar 1, 2025
106dd40
Apply suggestions from code review
s-ballMar 2, 2025
9cb9395
Cosmetic improvements after review.
s-ballMar 2, 2025
08bc8d7
In test_msgfmt move data files to the data folder.
s-ballMar 2, 2025
9d992cd
Remove duplicate tests from test_msgfmt.
s-ballMar 2, 2025
31fd434
Merge branch 'main' into multi_inputs
s-ballMar 2, 2025
916aec7
Merge branch 'main' into multi_inputs
s-ballMar 2, 2025
51fcf09
Rename data files for test_msgfmt.Test_multi_input
s-ballMar 3, 2025
d51ad50
Apply suggestions from code review
s-ballMar 3, 2025
677f720
Cosmetic improvements after review.
s-ballMar 3, 2025
b4ea80a
compile_messages now accepts several input files
s-ballMar 4, 2025
3120add
whitespace nit
merwokMar 4, 2025
d642923
Merge branch 'main' into multi_inputs
s-ballMar 4, 2025
9d91f12
Make explicit how mo files can be re-generated.
s-ballMar 4, 2025
4d83cb7
Merge branch 'multi_inputs' of https://github.com/s-ball/cpython into…
s-ballMar 4, 2025
421272b
Apply suggestions from code review
s-ballMar 4, 2025
09b97d9
Update Lib/test/test_tools/test_msgfmt.py
s-ballMar 4, 2025
12cae51
Merge branch 'main' into multi_inputs
s-ballMar 5, 2025
3760851
Merge branch 'main' into multi_inputs
s-ballMar 15, 2025
d45039c
Generate json files for MultiInputTest data files.
s-ballMar 16, 2025
dde5ef1
Apply suggestions from code review
s-ballMar 16, 2025
bb6e0c5
Cosmetic improvements (long lines...)
s-ballMar 16, 2025
797990a
Merge branch 'multi_inputs' of https://github.com/s-ball/cpython into…
s-ballMar 16, 2025
c95af16
Merge branch 'main' into multi_inputs
s-ballMar 17, 2025
905ec70
Revert an unwanted change.
s-ballMar 17, 2025
b7a7c48
Simplifies the general logic of msgfmt.py
s-ballMar 18, 2025
1b3b73e
Update Tools/i18n/msgfmt.py
s-ballMar 18, 2025
1db2c66
Changes per review.
s-ballMar 18, 2025
3a6e1ef
Merge branch 'multi_inputs' of https://github.com/s-ball/cpython into…
s-ballMar 18, 2025
743bdc5
Removes the now unused get_names function.
s-ballMar 19, 2025
50e7145
Tests for extension corner cases for msgfmt.py
s-ballMar 19, 2025
caa8955
Merge branch 'main' into multi_inputs
s-ballApr 4, 2025
a4f1769
Fix a parameter inversion in test_msgfmt.py
s-ballApr 4, 2025
11f6e69
Merge branch 'main' into multi_inputs
s-ballApr 4, 2025
0ed3107
Merge branch 'main' into multi_inputs
s-ballApr 8, 2025
d1e0a26
Merge branch 'main' into multi_inputs
s-ballApr 8, 2025
213afcb
Merge branch 'main' into multi_inputs
s-ballMay 20, 2025
4d54e50
Merge main into multi_inputs
s-ballMay 22, 2025
ab97edd
Merge branch 'main' into multi_inputs
s-ballMay 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
NextNext commit
Add test for current behaviour of msgfmt.py
Test option processing, and conversion of one single file with orwithout the -o option.Also test the little documented behaviour of merging two input fileswith -o option.
  • Loading branch information
@s-ball
s-ball committedDec 2, 2018
commit73b5ac88202e6560b01cf37c82f03d51996746a8
185 changes: 183 additions & 2 deletionsLib/test/test_tools/test_i18n.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,9 +5,9 @@
import unittest
from textwrap import dedent

from test.support.script_helper import assert_python_ok
from test.support.script_helper import assert_python_ok, assert_python_failure
from test.test_tools import skip_if_missing, toolsdir
from test.support import temp_cwd, temp_dir
from test.support import temp_cwd, temp_dir, unload, change_cwd


skip_if_missing()
Expand DownExpand Up@@ -243,3 +243,184 @@ def test_files_list(self):
self.assertIn(f'msgid "{text1}"', data)
self.assertIn(f'msgid "{text2}"', data)
self.assertNotIn(text3, data)


class Test_msgfmt(unittest.TestCase):
"""Tests for the msgfmt.py tool
bpo-35335 - bpo-9741
"""

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

# binary images of tiny po files
# windows end of lines for first one
file1_fr_po = b'''# French translations for python package.\r
# Copyright (C) 2018 THE python\'S COPYRIGHT HOLDER\r
# This file is distributed under the same license as the python package.\r
# s-ball <s-ball@laposte.net>, 2018.\r
#\r
msgid ""\r
msgstr ""\r
"Project-Id-Version: python 3.8\\n"\r
"Report-Msgid-Bugs-To: \\n"\r
"POT-Creation-Date: 2018-11-30 23:46+0100\\n"\r
"PO-Revision-Date: 2018-11-30 23:47+0100\\n"\r
"Last-Translator: s-ball <s-ball@laposte.net>\\n"\r
"Language-Team: French\\n"\r\n"Language: fr\\n"\r
"MIME-Version: 1.0\\n"\r
"Content-Type: text/plain; charset=UTF-8\\n"\r
"Content-Transfer-Encoding: 8bit\\n"\r
"Plural-Forms: nplurals=2; plural=(n > 1);\\n"\r
\r
#: file1.py:6\r
msgid "Hello!"\r
msgstr "Bonjour !"\r
\r
#: file1.py:7\r
#, python-brace-format\r
msgid "{n} horse"\r
msgid_plural "{n} horses"\r
msgstr[0] "{n} cheval"\r
msgstr[1] "{n} chevaux"\r
'''

# Unix end of file and a non ascii character for second one
file2_fr_po = rb'''# French translations for python package.
# Copyright (C) 2018 THE python'S COPYRIGHT HOLDER
# This file is distributed under the same license as the python package.
# s-ball <s-ball@laposte.net>, 2018.
#
msgid ""
msgstr ""
"Project-Id-Version: python 3.8\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-11-30 23:57+0100\n"
"PO-Revision-Date: 2018-11-30 23:57+0100\n"
"Last-Translator: s-ball <s-ball@laposte.net>\n"
"Language-Team: French\n"
"Language: fr\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"

#: file2.py:6
msgid "It's over."
msgstr "C'est termin\xc3\xa9."

#: file2.py:7
msgid "Bye..."
msgstr "Au revoir ..."
'''

# binary images of corresponding compiled mo files
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

images?

file1_fr_mo = b'\xde\x12\x04\x95\x00\x00\x00\x00\x03\x00\x00\x00\x1c' \
b'\x00\x00\x004\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Not very important: escaping newlines with backslashes is not recommended, better use parens. This also gives more room per line:

file1_fr_mo= (b'bytes bytes bytes bytes etc to 80 columns')

b'\x00\x00\x00\x00\x00L\x00\x00\x00\x06\x00\x00\x00M' \
b'\x00\x00\x00\x14\x00\x00\x00T\x00\x00\x00[\x01\x00' \
b'\x00i\x00\x00\x00\t\x00\x00\x00\xc5\x01\x00\x00\x16' \
b'\x00\x00\x00\xcf\x01\x00\x00\x00Hello!\x00{n} horse' \
b'\x00{n} horses\x00Project-Id-Version: python 3.8\n' \
b'Report-Msgid-Bugs-To: \nPOT-Creation-Date: 2018-11-30 ' \
b'23:46+0100\nPO-Revision-Date: 2018-11-30 23:47+0100\n'\
b'Last-Translator: s-ball <s-ball@laposte.net>\n' \
b'Language-Team: French\nLanguage: fr\nMIME-Version: 1.0' \
b'\nContent-Type: text/plain; charset=UTF-8\nContent-' \
b'Transfer-Encoding: 8bit\nPlural-Forms: nplurals=2' \
b'; plural=(n > 1);\n\x00Bonjour !\x00{n} cheval\x00{n' \
b'} chevaux\x00'
file2_fr_mo = b"\xde\x12\x04\x95\x00\x00\x00\x00\x03\x00\x00\x00" \
b"\x1c\x00\x00\x004\x00\x00\x00\x00\x00\x00\x00\x00" \
b"\x00\x00\x00\x00\x00\x00\x00L\x00\x00\x00\x06\x00" \
b"\x00\x00M\x00\x00\x00\n\x00\x00\x00T\x00\x00\x00[" \
b"\x01\x00\x00_\x00\x00\x00\r\x00\x00\x00\xbb\x01" \
b"\x00\x00\x0f\x00\x00\x00\xc9\x01\x00\x00\x00Bye.." \
b".\x00It's over.\x00Project-Id-Version: python 3.8" \
b"\nReport-Msgid-Bugs-To: \nPOT-Creation-Date: 2018" \
b"-11-30 23:57+0100\nPO-Revision-Date: 2018-11-30 2" \
b"3:57+0100\nLast-Translator: s-ball <s-ball@lapost" \
b"e.net>\nLanguage-Team: French\nLanguage: fr\nMIME" \
b"-Version: 1.0\nContent-Type: text/plain; charset=" \
b"UTF-8\nContent-Transfer-Encoding: 8bit\nPlural-Fo" \
b"rms: nplurals=2; plural=(n > 1);\n\x00Au revoir ." \
b"..\x00C'est termin\xc3\xa9.\x00"

# image of merging both po files keeping second header
file12_fr_mo = b"\xde\x12\x04\x95\x00\x00\x00\x00\x05\x00\x00\x00" \
b"\x1c\x00\x00\x00D\x00\x00\x00\x00\x00\x00\x00\x00" \
b"\x00\x00\x00\x00\x00\x00\x00l\x00\x00\x00\x06\x00" \
b"\x00\x00m\x00\x00\x00\x06\x00\x00\x00t\x00\x00\x00" \
b"\n\x00\x00\x00{\x00\x00\x00\x14\x00\x00\x00\x86" \
b"\x00\x00\x00[\x01\x00\x00\x9b\x00\x00\x00\r\x00" \
b"\x00\x00\xf7\x01\x00\x00\t\x00\x00\x00\x05\x02\x00" \
b"\x00\x0f\x00\x00\x00\x0f\x02\x00\x00\x16\x00\x00" \
b"\x00\x1f\x02\x00\x00\x00Bye...\x00Hello!\x00It's " \
b"over.\x00{n} horse\x00{n} horses\x00Project-Id-Ver" \
b"sion: python 3.8\nReport-Msgid-Bugs-To: \nPOT-Crea" \
b"tion-Date: 2018-11-30 23:57+0100\nPO-Revision-Date" \
b": 2018-11-30 23:57+0100\nLast-Translator: s-ball <" \
b"s-ball@laposte.net>\nLanguage-Team: French\nLangua" \
b"ge: fr\nMIME-Version: 1.0\nContent-Type: text/plai" \
b"n; charset=UTF-8\nContent-Transfer-Encoding: 8bit" \
b"\nPlural-Forms: nplurals=2; plural=(n > 1);\n\x00A" \
b"u revoir ...\x00Bonjour !\x00C'est termin\xc3\xa9." \
b"\x00{n} cheval\x00{n} chevaux\x00"
def imp(self):
i18ndir = os.path.join(toolsdir, 'i18n')
sys.path.append(i18ndir)
import msgfmt
sys.path.remove(i18ndir)
return msgfmt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Is it really necessary to import the script as a module? I thought it was only a command-line tool.


def test_help(self):
"""Test option -h"""
rc, stdout, stderr = assert_python_ok(self.script, '-h')
self.assertEqual(0, rc)
self.assertTrue(stderr.startswith(
b'Generate binary message catalog from textual'
b' translation description.'
)
)

def test_wrong(self):
"""Test wrong option"""
rc, stdout, stderr = assert_python_failure(self.script, '-x')
self.assertEqual(1, rc)
self.assertTrue(stderr.startswith(
b'Generate binary message catalog from textual'
b' translation description.'
)
)

def test_outputfile(self):
"""Test script with -o option - 1 single file, Windows EOL"""
with temp_cwd(None):
with open("file1_fr.po", "wb") as out:
out.write(self.file1_fr_po)
assert_python_ok(self.script, '-o', 'file1.mo', 'file1_fr.po')
with open('file1.mo', 'rb') as fin:
self.assertEqual(self.file1_fr_mo, fin.read())

def test_no_outputfile(self):
"""Test script without -o option - 1 single file, Unix EOL"""
with temp_cwd(None):
with open("file2_fr.po", "wb") as out:
out.write(self.file2_fr_po)
assert_python_ok(self.script, 'file2_fr.po')
with open('file2_fr.mo', 'rb') as fin:
self.assertEqual(self.file2_fr_mo, fin.read())

def test_both_with_outputfile(self):
"""Test script with -o option and 2 input files"""
# msgfmt.py version 1.2 behaviour is to correctly merge the input
# files and to keep last entry when same entry occurs in more than
# one file
with temp_cwd(None):
with open("file1_fr.po", "wb") as out:
out.write(self.file1_fr_po)
with open("file2_fr.po", "wb") as out:
out.write(self.file2_fr_po)
assert_python_ok(self.script, '-o', 'file1.mo',
'file1_fr.po', 'file2_fr.po')
with open('file1.mo', 'rb') as fin:
self.assertEqual(self.file12_fr_mo, fin.read())

[8]ページ先頭

©2009-2025 Movatter.jp