Skip to content

Commit 46c08c5

Browse files
committed
Move tests for the gh-79516 issue to test_msgfmt.py
Those tests used to be in the test_i18n.py file. But as msgfmt now has its own test file, they have to go there. The test class has been renamed Test_multi_inputs.
1 parent 4170796 commit 46c08c5

File tree

2 files changed

+211
-211
lines changed

2 files changed

+211
-211
lines changed

Lib/test/test_tools/test_i18n.py

Lines changed: 0 additions & 211 deletions
Original file line numberDiff line numberDiff line change
@@ -517,217 +517,6 @@ def test_parse_keyword_spec(self):
517517
self.assertEqual(str(cm.exception), message)
518518

519519

520-
class Test_msgfmt(unittest.TestCase):
521-
"""Tests for the msgfmt.py tool
522-
bpo-35335 - bpo-9741
523-
"""
524-
525-
script = os.path.join(toolsdir, 'i18n', 'msgfmt.py')
526-
527-
# binary images of tiny po files
528-
# windows end of lines for first one
529-
file1_fr_po = b'''# French translations for python package.\r
530-
# Copyright (C) 2018 THE python\'S COPYRIGHT HOLDER\r
531-
# This file is distributed under the same license as the python package.\r
532-
# s-ball <[email protected]>, 2018.\r
533-
#\r
534-
msgid ""\r
535-
msgstr ""\r
536-
"Project-Id-Version: python 3.8\\n"\r
537-
"Report-Msgid-Bugs-To: \\n"\r
538-
"POT-Creation-Date: 2018-11-30 23:46+0100\\n"\r
539-
"PO-Revision-Date: 2018-11-30 23:47+0100\\n"\r
540-
"Last-Translator: s-ball <[email protected]>\\n"\r
541-
"Language-Team: French\\n"\r\n"Language: fr\\n"\r
542-
"MIME-Version: 1.0\\n"\r
543-
"Content-Type: text/plain; charset=UTF-8\\n"\r
544-
"Content-Transfer-Encoding: 8bit\\n"\r
545-
"Plural-Forms: nplurals=2; plural=(n > 1);\\n"\r
546-
\r
547-
#: file1.py:6\r
548-
msgid "Hello!"\r
549-
msgstr "Bonjour !"\r
550-
\r
551-
#: file1.py:7\r
552-
#, python-brace-format\r
553-
msgid "{n} horse"\r
554-
msgid_plural "{n} horses"\r
555-
msgstr[0] "{n} cheval"\r
556-
msgstr[1] "{n} chevaux"\r
557-
'''
558-
559-
# Unix end of file and a non ascii character for second one
560-
file2_fr_po = rb'''# French translations for python package.
561-
# Copyright (C) 2018 THE python'S COPYRIGHT HOLDER
562-
# This file is distributed under the same license as the python package.
563-
# s-ball <[email protected]>, 2018.
564-
#
565-
msgid ""
566-
msgstr ""
567-
"Project-Id-Version: python 3.8\n"
568-
"Report-Msgid-Bugs-To: \n"
569-
"POT-Creation-Date: 2018-11-30 23:57+0100\n"
570-
"PO-Revision-Date: 2018-11-30 23:57+0100\n"
571-
"Last-Translator: s-ball <[email protected]>\n"
572-
"Language-Team: French\n"
573-
"Language: fr\n"
574-
"MIME-Version: 1.0\n"
575-
"Content-Type: text/plain; charset=UTF-8\n"
576-
"Content-Transfer-Encoding: 8bit\n"
577-
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
578-
579-
#: file2.py:6
580-
msgid "It's over."
581-
msgstr "C'est termin\xc3\xa9."
582-
583-
#: file2.py:7
584-
msgid "Bye..."
585-
msgstr "Au revoir ..."
586-
'''
587-
588-
# binary images of corresponding compiled mo files
589-
file1_fr_mo = b'\xde\x12\x04\x95\x00\x00\x00\x00\x03\x00\x00\x00\x1c' \
590-
b'\x00\x00\x004\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \
591-
b'\x00\x00\x00\x00\x00L\x00\x00\x00\x06\x00\x00\x00M' \
592-
b'\x00\x00\x00\x14\x00\x00\x00T\x00\x00\x00[\x01\x00' \
593-
b'\x00i\x00\x00\x00\t\x00\x00\x00\xc5\x01\x00\x00\x16' \
594-
b'\x00\x00\x00\xcf\x01\x00\x00\x00Hello!\x00{n} horse' \
595-
b'\x00{n} horses\x00Project-Id-Version: python 3.8\n' \
596-
b'Report-Msgid-Bugs-To: \nPOT-Creation-Date: 2018-11-30 ' \
597-
b'23:46+0100\nPO-Revision-Date: 2018-11-30 23:47+0100\n'\
598-
b'Last-Translator: s-ball <[email protected]>\n' \
599-
b'Language-Team: French\nLanguage: fr\nMIME-Version: 1.0' \
600-
b'\nContent-Type: text/plain; charset=UTF-8\nContent-' \
601-
b'Transfer-Encoding: 8bit\nPlural-Forms: nplurals=2' \
602-
b'; plural=(n > 1);\n\x00Bonjour !\x00{n} cheval\x00{n' \
603-
b'} chevaux\x00'
604-
file2_fr_mo = b"\xde\x12\x04\x95\x00\x00\x00\x00\x03\x00\x00\x00" \
605-
b"\x1c\x00\x00\x004\x00\x00\x00\x00\x00\x00\x00\x00" \
606-
b"\x00\x00\x00\x00\x00\x00\x00L\x00\x00\x00\x06\x00" \
607-
b"\x00\x00M\x00\x00\x00\n\x00\x00\x00T\x00\x00\x00[" \
608-
b"\x01\x00\x00_\x00\x00\x00\r\x00\x00\x00\xbb\x01" \
609-
b"\x00\x00\x0f\x00\x00\x00\xc9\x01\x00\x00\x00Bye.." \
610-
b".\x00It's over.\x00Project-Id-Version: python 3.8" \
611-
b"\nReport-Msgid-Bugs-To: \nPOT-Creation-Date: 2018" \
612-
b"-11-30 23:57+0100\nPO-Revision-Date: 2018-11-30 2" \
613-
b"3:57+0100\nLast-Translator: s-ball <s-ball@lapost" \
614-
b"e.net>\nLanguage-Team: French\nLanguage: fr\nMIME" \
615-
b"-Version: 1.0\nContent-Type: text/plain; charset=" \
616-
b"UTF-8\nContent-Transfer-Encoding: 8bit\nPlural-Fo" \
617-
b"rms: nplurals=2; plural=(n > 1);\n\x00Au revoir ." \
618-
b"..\x00C'est termin\xc3\xa9.\x00"
619-
620-
# image of merging both po files keeping second header
621-
file12_fr_mo = b"\xde\x12\x04\x95\x00\x00\x00\x00\x05\x00\x00\x00" \
622-
b"\x1c\x00\x00\x00D\x00\x00\x00\x00\x00\x00\x00\x00" \
623-
b"\x00\x00\x00\x00\x00\x00\x00l\x00\x00\x00\x06\x00" \
624-
b"\x00\x00m\x00\x00\x00\x06\x00\x00\x00t\x00\x00\x00" \
625-
b"\n\x00\x00\x00{\x00\x00\x00\x14\x00\x00\x00\x86" \
626-
b"\x00\x00\x00[\x01\x00\x00\x9b\x00\x00\x00\r\x00" \
627-
b"\x00\x00\xf7\x01\x00\x00\t\x00\x00\x00\x05\x02\x00" \
628-
b"\x00\x0f\x00\x00\x00\x0f\x02\x00\x00\x16\x00\x00" \
629-
b"\x00\x1f\x02\x00\x00\x00Bye...\x00Hello!\x00It's " \
630-
b"over.\x00{n} horse\x00{n} horses\x00Project-Id-Ver" \
631-
b"sion: python 3.8\nReport-Msgid-Bugs-To: \nPOT-Crea" \
632-
b"tion-Date: 2018-11-30 23:57+0100\nPO-Revision-Date" \
633-
b": 2018-11-30 23:57+0100\nLast-Translator: s-ball <" \
634-
b"[email protected]>\nLanguage-Team: French\nLangua" \
635-
b"ge: fr\nMIME-Version: 1.0\nContent-Type: text/plai" \
636-
b"n; charset=UTF-8\nContent-Transfer-Encoding: 8bit" \
637-
b"\nPlural-Forms: nplurals=2; plural=(n > 1);\n\x00A" \
638-
b"u revoir ...\x00Bonjour !\x00C'est termin\xc3\xa9." \
639-
b"\x00{n} cheval\x00{n} chevaux\x00"
640-
def imp(self):
641-
i18ndir = os.path.join(toolsdir, 'i18n')
642-
sys.path.append(i18ndir)
643-
import msgfmt
644-
sys.path.remove(i18ndir)
645-
return msgfmt
646-
647-
def test_help(self):
648-
"""Test option -h"""
649-
rc, stdout, stderr = assert_python_ok(self.script, '-h')
650-
self.assertEqual(0, rc)
651-
self.assertTrue(stderr.startswith(
652-
b'Generate binary message catalog from textual'
653-
b' translation description.'
654-
))
655-
656-
def test_wrong(self):
657-
"""Test wrong option"""
658-
rc, stdout, stderr = assert_python_failure(self.script, '-x')
659-
self.assertEqual(1, rc)
660-
self.assertTrue(stderr.startswith(
661-
b'Generate binary message catalog from textual'
662-
b' translation description.'
663-
))
664-
665-
def test_outputfile(self):
666-
"""Test script with -o option - 1 single file, Windows EOL"""
667-
with temp_cwd(None):
668-
with open("file1_fr.po", "wb") as out:
669-
out.write(self.file1_fr_po)
670-
assert_python_ok(self.script, '-o', 'file1.mo', 'file1_fr.po')
671-
with open('file1.mo', 'rb') as fin:
672-
self.assertEqual(self.file1_fr_mo, fin.read())
673-
674-
def test_no_outputfile(self):
675-
"""Test script without -o option - 1 single file, Unix EOL"""
676-
with temp_cwd(None):
677-
with open("file2_fr.po", "wb") as out:
678-
out.write(self.file2_fr_po)
679-
assert_python_ok(self.script, 'file2_fr.po')
680-
with open('file2_fr.mo', 'rb') as fin:
681-
self.assertEqual(self.file2_fr_mo, fin.read())
682-
683-
def test_both_with_outputfile(self):
684-
"""Test script with -o option and 2 input files"""
685-
# msgfmt.py version 1.2 behaviour is to correctly merge the input
686-
# files and to keep last entry when same entry occurs in more than
687-
# one file
688-
with temp_cwd(None):
689-
with open("file1_fr.po", "wb") as out:
690-
out.write(self.file1_fr_po)
691-
with open("file2_fr.po", "wb") as out:
692-
out.write(self.file2_fr_po)
693-
assert_python_ok(self.script, '-o', 'file1.mo',
694-
'file1_fr.po', 'file2_fr.po')
695-
with open('file1.mo', 'rb') as fin:
696-
self.assertEqual(self.file12_fr_mo, fin.read())
697-
698-
def test_both_without_outputfile(self):
699-
"""Test script without -o option and 2 input files"""
700-
# msgfmt.py version 1.2 behaviour was that second mo file
701-
# also merged previous po files
702-
with temp_cwd(None):
703-
with open("file1_fr.po", "wb") as out:
704-
out.write(self.file1_fr_po)
705-
with open("file2_fr.po", "wb") as out:
706-
out.write(self.file2_fr_po)
707-
assert_python_ok(self.script, 'file1_fr.po', 'file2_fr.po')
708-
with open('file1_fr.mo', 'rb') as fin:
709-
self.assertEqual(self.file1_fr_mo, fin.read())
710-
with open('file2_fr.mo', 'rb') as fin:
711-
self.assertEqual(self.file2_fr_mo, fin.read())
712-
713-
def test_consecutive_make_calls(self):
714-
"""Directly calls make twice to prove bpo-9741 is fixed"""
715-
sys.path.append(os.path.join(toolsdir,'i18n'))
716-
from msgfmt import make
717-
with temp_cwd(None):
718-
with open("file1_fr.po", "wb") as out:
719-
out.write(self.file1_fr_po)
720-
with open("file2_fr.po", "wb") as out:
721-
out.write(self.file2_fr_po)
722-
make("file1_fr.po", "file1_fr.mo")
723-
make("file2_fr.po", "file2_fr.mo")
724-
with open('file1_fr.mo', 'rb') as fin:
725-
self.assertEqual(self.file1_fr_mo, fin.read())
726-
with open('file2_fr.mo', 'rb') as fin:
727-
self.assertEqual(self.file2_fr_mo, fin.read())
728-
sys.path.pop()
729-
730-
731520
def extract_from_snapshots():
732521
snapshots = {
733522
'messages.py': (),

0 commit comments

Comments
 (0)