@@ -926,6 +926,154 @@ def test_more_than(self):
926926 assert expected_content == actual_content
927927
928928
929+ class MergeMessagesTestCase (unittest .TestCase ):
930+
931+ @freeze_time ("1994-11-11" )
932+ def setUp (self ):
933+ self .olddir = os .getcwd ()
934+ os .chdir (data_dir )
935+
936+ self .dist = Distribution (TEST_PROJECT_DISTRIBUTION_DATA )
937+ self .cmd = frontend .MessageMerge (self .dist )
938+ self .cmd .initialize_options ()
939+
940+ self .temp_def = f'{ i18n_dir } /msgmerge_def.po'
941+ self .temp_ref = f'{ i18n_dir } /msgmerge_ref.pot'
942+ self .compendium = f'{ i18n_dir } /compenidum.po'
943+ self .output_file = f'{ i18n_dir } /msgmerge.po'
944+
945+ with open (self .temp_ref , 'wb' ) as file :
946+ catalog = Catalog ()
947+ for word in ['word1' , 'word2' , 'word3' , 'word4' ]:
948+ catalog .add (word )
949+ pofile .write_po (file , catalog )
950+
951+ with open (self .temp_def , 'wb' ) as file :
952+ catalog = Catalog ()
953+ catalog .add ('word1' , string = 'Word 1' )
954+ catalog .add ('word2' , string = 'Word 2' )
955+ catalog .add ('word3' )
956+ pofile .write_po (file , catalog )
957+
958+ with open (self .compendium , 'wb' ) as file :
959+ catalog = Catalog ()
960+ catalog .add ('word4' , string = 'Word 4' )
961+ catalog .add ('word5' , string = 'Word 5' )
962+ pofile .write_po (file , catalog )
963+
964+ def tearDown (self ):
965+ for file in [self .temp_def , self .temp_ref , self .compendium , self .output_file ]:
966+ if os .path .isfile (file ):
967+ os .unlink (file )
968+
969+ def test_no_input_files (self ):
970+ with pytest .raises (OptionError ):
971+ self .cmd .finalize_options ()
972+
973+ with pytest .raises (OptionError ):
974+ self .cmd .input_files = ['1' ]
975+ self .cmd .finalize_options ()
976+
977+ with pytest .raises (OptionError ):
978+ self .cmd .input_files = ['1' , '2' , '3' ]
979+ self .cmd .finalize_options ()
980+
981+ def test_no_output_file (self ):
982+ self .cmd .input_files = ['1' , '2' ]
983+ with pytest .raises (OptionError ):
984+ self .cmd .finalize_options ()
985+
986+ @freeze_time ("1994-11-11" )
987+ def test_default (self ):
988+ self .cmd .input_files = [self .temp_def , self .temp_ref ]
989+ self .cmd .output_file = self .output_file
990+ self .cmd .finalize_options ()
991+ self .cmd .run ()
992+
993+ date = format_datetime (datetime (1994 , 11 , 11 , 00 , 00 ), 'yyyy-MM-dd HH:mmZ' , tzinfo = LOCALTZ , locale = 'en' )
994+ expected_content = fr"""# Translations template for PROJECT.
995+ # Copyright (C) 1994 ORGANIZATION
996+ # This file is distributed under the same license as the PROJECT project.
997+ # FIRST AUTHOR <EMAIL@ADDRESS>, 1994.
998+ #
999+ msgid ""
1000+ msgstr ""
1001+ "Project-Id-Version: PROJECT VERSION\n"
1002+ "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
1003+ "POT-Creation-Date: { date } \n"
1004+ "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1005+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1006+ "Language-Team: LANGUAGE <LL@li.org>\n"
1007+ "MIME-Version: 1.0\n"
1008+ "Content-Type: text/plain; charset=utf-8\n"
1009+ "Content-Transfer-Encoding: 8bit\n"
1010+ "Generated-By: Babel { VERSION } \n"
1011+
1012+ msgid "word1"
1013+ msgstr "Word 1"
1014+
1015+ msgid "word2"
1016+ msgstr "Word 2"
1017+
1018+ msgid "word3"
1019+ msgstr ""
1020+
1021+ #, fuzzy
1022+ msgid "word4"
1023+ msgstr "Word 2"
1024+
1025+ """
1026+
1027+ with open (self .output_file , 'r' ) as f :
1028+ actual_content = f .read ()
1029+ assert expected_content == actual_content
1030+
1031+ @freeze_time ("1994-11-11" )
1032+ def test_compenidum (self ):
1033+ self .cmd .input_files = [self .temp_def , self .temp_ref ]
1034+ self .cmd .output_file = self .output_file
1035+ self .cmd .compendium = self .compendium
1036+ self .cmd .finalize_options ()
1037+ self .cmd .run ()
1038+
1039+ date = format_datetime (datetime (1994 , 11 , 11 , 00 , 00 ), 'yyyy-MM-dd HH:mmZ' , tzinfo = LOCALTZ , locale = 'en' )
1040+ expected_content = fr"""# Translations template for PROJECT.
1041+ # Copyright (C) 1994 ORGANIZATION
1042+ # This file is distributed under the same license as the PROJECT project.
1043+ # FIRST AUTHOR <EMAIL@ADDRESS>, 1994.
1044+ #
1045+ msgid ""
1046+ msgstr ""
1047+ "Project-Id-Version: PROJECT VERSION\n"
1048+ "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
1049+ "POT-Creation-Date: { date } \n"
1050+ "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1051+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1052+ "Language-Team: LANGUAGE <LL@li.org>\n"
1053+ "MIME-Version: 1.0\n"
1054+ "Content-Type: text/plain; charset=utf-8\n"
1055+ "Content-Transfer-Encoding: 8bit\n"
1056+ "Generated-By: Babel { VERSION } \n"
1057+
1058+ msgid "word1"
1059+ msgstr "Word 1"
1060+
1061+ msgid "word2"
1062+ msgstr "Word 2"
1063+
1064+ msgid "word3"
1065+ msgstr ""
1066+
1067+ msgid "word4"
1068+ msgstr "Word 4"
1069+
1070+ """
1071+
1072+ with open (self .output_file , 'r' ) as f :
1073+ actual_content = f .read ()
1074+ assert expected_content == actual_content
1075+
1076+
9291077class CommandLineInterfaceTestCase (unittest .TestCase ):
9301078
9311079 def setUp (self ):
0 commit comments