@@ -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 \x00 4\x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 ' \
591- b'\x00 \x00 \x00 \x00 \x00 L\x00 \x00 \x00 \x06 \x00 \x00 \x00 M' \
592- b'\x00 \x00 \x00 \x14 \x00 \x00 \x00 T\x00 \x00 \x00 [\x01 \x00 ' \
593- b'\x00 i\x00 \x00 \x00 \t \x00 \x00 \x00 \xc5 \x01 \x00 \x00 \x16 ' \
594- b'\x00 \x00 \x00 \xcf \x01 \x00 \x00 \x00 Hello!\x00 {n} horse' \
595- b'\x00 {n} horses\x00 Project-Id-Version: python 3.8\n ' \
596- b'Report-Msgid-Bugs-To: \n POT-Creation-Date: 2018-11-30 ' \
597- b'23:46+0100\n PO-Revision-Date: 2018-11-30 23:47+0100\n ' \
598- b'Last-Translator: s-ball <[email protected] >\n ' \
599- b'Language-Team: French\n Language: fr\n MIME-Version: 1.0' \
600- b'\n Content-Type: text/plain; charset=UTF-8\n Content-' \
601- b'Transfer-Encoding: 8bit\n Plural-Forms: nplurals=2' \
602- b'; plural=(n > 1);\n \x00 Bonjour !\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 \x00 4\x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 " \
606- b"\x00 \x00 \x00 \x00 \x00 \x00 \x00 L\x00 \x00 \x00 \x06 \x00 " \
607- b"\x00 \x00 M\x00 \x00 \x00 \n \x00 \x00 \x00 T\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 \x00 Bye.." \
610- b".\x00 It's over.\x00 Project-Id-Version: python 3.8" \
611- b"\n Report-Msgid-Bugs-To: \n POT-Creation-Date: 2018" \
612- b"-11-30 23:57+0100\n PO-Revision-Date: 2018-11-30 2" \
613- b"3:57+0100\n Last-Translator: s-ball <s-ball@lapost" \
614- b"e.net>\n Language-Team: French\n Language: fr\n MIME" \
615- b"-Version: 1.0\n Content-Type: text/plain; charset=" \
616- b"UTF-8\n Content-Transfer-Encoding: 8bit\n Plural-Fo" \
617- b"rms: nplurals=2; plural=(n > 1);\n \x00 Au revoir ." \
618- b"..\x00 C'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 \x00 D\x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 " \
623- b"\x00 \x00 \x00 \x00 \x00 \x00 \x00 l\x00 \x00 \x00 \x06 \x00 " \
624- b"\x00 \x00 m\x00 \x00 \x00 \x06 \x00 \x00 \x00 t\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 \x00 Bye...\x00 Hello!\x00 It's " \
630- b"over.\x00 {n} horse\x00 {n} horses\x00 Project-Id-Ver" \
631- b"sion: python 3.8\n Report-Msgid-Bugs-To: \n POT-Crea" \
632- b"tion-Date: 2018-11-30 23:57+0100\n PO-Revision-Date" \
633- b": 2018-11-30 23:57+0100\n Last-Translator: s-ball <" \
634- b"[email protected] >\n Language-Team: French\n Langua" \
635- b"ge: fr\n MIME-Version: 1.0\n Content-Type: text/plai" \
636- b"n; charset=UTF-8\n Content-Transfer-Encoding: 8bit" \
637- b"\n Plural-Forms: nplurals=2; plural=(n > 1);\n \x00 A" \
638- b"u revoir ...\x00 Bonjour !\x00 C'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-
731520def extract_from_snapshots ():
732521 snapshots = {
733522 'messages.py' : (),
0 commit comments