@@ -237,3 +237,151 @@ def test_more_than(self):
237237 with open (self .output_file , 'r' ) as f :
238238 actual_content = f .read ()
239239 assert expected_content == actual_content
240+
241+
242+ class MergeMessagesTestCase (unittest .TestCase ):
243+
244+ @freeze_time ("1994-11-11" )
245+ def setUp (self ):
246+ self .olddir = os .getcwd ()
247+ os .chdir (data_dir )
248+
249+ self .dist = Distribution (TEST_PROJECT_DISTRIBUTION_DATA )
250+ self .cmd = frontend .MessageMerge (self .dist )
251+ self .cmd .initialize_options ()
252+
253+ self .temp_def = f'{ i18n_dir } /msgmerge_def.po'
254+ self .temp_ref = f'{ i18n_dir } /msgmerge_ref.pot'
255+ self .compendium = f'{ i18n_dir } /compenidum.po'
256+ self .output_file = f'{ i18n_dir } /msgmerge.po'
257+
258+ with open (self .temp_ref , 'wb' ) as file :
259+ catalog = Catalog ()
260+ for word in ['word1' , 'word2' , 'word3' , 'word4' ]:
261+ catalog .add (word )
262+ pofile .write_po (file , catalog )
263+
264+ with open (self .temp_def , 'wb' ) as file :
265+ catalog = Catalog ()
266+ catalog .add ('word1' , string = 'Word 1' )
267+ catalog .add ('word2' , string = 'Word 2' )
268+ catalog .add ('word3' )
269+ pofile .write_po (file , catalog )
270+
271+ with open (self .compendium , 'wb' ) as file :
272+ catalog = Catalog ()
273+ catalog .add ('word4' , string = 'Word 4' )
274+ catalog .add ('word5' , string = 'Word 5' )
275+ pofile .write_po (file , catalog )
276+
277+ def tearDown (self ):
278+ for file in [self .temp_def , self .temp_ref , self .compendium , self .output_file ]:
279+ if os .path .isfile (file ):
280+ os .unlink (file )
281+
282+ def test_no_input_files (self ):
283+ with pytest .raises (OptionError ):
284+ self .cmd .finalize_options ()
285+
286+ with pytest .raises (OptionError ):
287+ self .cmd .input_files = ['1' ]
288+ self .cmd .finalize_options ()
289+
290+ with pytest .raises (OptionError ):
291+ self .cmd .input_files = ['1' , '2' , '3' ]
292+ self .cmd .finalize_options ()
293+
294+ def test_no_output_file (self ):
295+ self .cmd .input_files = ['1' , '2' ]
296+ with pytest .raises (OptionError ):
297+ self .cmd .finalize_options ()
298+
299+ @freeze_time ("1994-11-11" )
300+ def test_default (self ):
301+ self .cmd .input_files = [self .temp_def , self .temp_ref ]
302+ self .cmd .output_file = self .output_file
303+ self .cmd .finalize_options ()
304+ self .cmd .run ()
305+
306+ date = format_datetime (datetime (1994 , 11 , 11 , 00 , 00 ), 'yyyy-MM-dd HH:mmZ' , tzinfo = LOCALTZ , locale = 'en' )
307+ expected_content = fr"""# Translations template for PROJECT.
308+ # Copyright (C) 1994 ORGANIZATION
309+ # This file is distributed under the same license as the PROJECT project.
310+ # FIRST AUTHOR <EMAIL@ADDRESS>, 1994.
311+ #
312+ msgid ""
313+ msgstr ""
314+ "Project-Id-Version: PROJECT VERSION\n"
315+ "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
316+ "POT-Creation-Date: { date } \n"
317+ "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
318+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
319+ "Language-Team: LANGUAGE <LL@li.org>\n"
320+ "MIME-Version: 1.0\n"
321+ "Content-Type: text/plain; charset=utf-8\n"
322+ "Content-Transfer-Encoding: 8bit\n"
323+ "Generated-By: Babel { VERSION } \n"
324+
325+ msgid "word1"
326+ msgstr "Word 1"
327+
328+ msgid "word2"
329+ msgstr "Word 2"
330+
331+ msgid "word3"
332+ msgstr ""
333+
334+ #, fuzzy
335+ msgid "word4"
336+ msgstr "Word 2"
337+
338+ """
339+
340+ with open (self .output_file , 'r' ) as f :
341+ actual_content = f .read ()
342+ assert expected_content == actual_content
343+
344+ @freeze_time ("1994-11-11" )
345+ def test_compenidum (self ):
346+ self .cmd .input_files = [self .temp_def , self .temp_ref ]
347+ self .cmd .output_file = self .output_file
348+ self .cmd .compendium = self .compendium
349+ self .cmd .finalize_options ()
350+ self .cmd .run ()
351+
352+ date = format_datetime (datetime (1994 , 11 , 11 , 00 , 00 ), 'yyyy-MM-dd HH:mmZ' , tzinfo = LOCALTZ , locale = 'en' )
353+ expected_content = fr"""# Translations template for PROJECT.
354+ # Copyright (C) 1994 ORGANIZATION
355+ # This file is distributed under the same license as the PROJECT project.
356+ # FIRST AUTHOR <EMAIL@ADDRESS>, 1994.
357+ #
358+ msgid ""
359+ msgstr ""
360+ "Project-Id-Version: PROJECT VERSION\n"
361+ "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
362+ "POT-Creation-Date: { date } \n"
363+ "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
364+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
365+ "Language-Team: LANGUAGE <LL@li.org>\n"
366+ "MIME-Version: 1.0\n"
367+ "Content-Type: text/plain; charset=utf-8\n"
368+ "Content-Transfer-Encoding: 8bit\n"
369+ "Generated-By: Babel { VERSION } \n"
370+
371+ msgid "word1"
372+ msgstr "Word 1"
373+
374+ msgid "word2"
375+ msgstr "Word 2"
376+
377+ msgid "word3"
378+ msgstr ""
379+
380+ msgid "word4"
381+ msgstr "Word 4"
382+
383+ """
384+
385+ with open (self .output_file , 'r' ) as f :
386+ actual_content = f .read ()
387+ assert expected_content == actual_content
0 commit comments