44import struct
55import sys
66import unittest
7+ from contextlib import redirect_stderr
78from gettext import GNUTranslations
9+ from io import StringIO
810from pathlib import Path
11+ from textwrap import dedent
912
1013from test .support .os_helper import temp_cwd
1114from test .support .script_helper import assert_python_failure , assert_python_ok
1215from test .test_tools import imports_under_tool , skip_if_missing , toolsdir
13- from textwrap import dedent
1416
1517
1618skip_if_missing ('i18n' )
@@ -320,9 +322,10 @@ def test_general_syntax_errors(self):
320322 Path ('messages.po' ).write_text (invalid_po )
321323 # Reset the global MESSAGES dictionary
322324 msgfmt .MESSAGES .clear ()
323- with self .assertRaises ((SystemExit , UnboundLocalError ,
324- IndexError , SyntaxError )):
325- msgfmt .make ('messages.po' , 'messages.mo' )
325+ with redirect_stderr (StringIO ()) as output :
326+ with self .assertRaises ((SystemExit , UnboundLocalError ,
327+ IndexError , SyntaxError )):
328+ msgfmt .make ('messages.po' , 'messages.mo' )
326329
327330 def test_semantic_errors (self ):
328331 invalid_po_files = (
@@ -394,8 +397,9 @@ def test_semantic_errors(self):
394397 Path ('messages.po' ).write_text (invalid_po )
395398 # Reset the global MESSAGES dictionary
396399 msgfmt .MESSAGES .clear ()
397- with self .assertRaises ((SystemExit , UnboundLocalError )):
398- msgfmt .make ('messages.po' , 'messages.mo' )
400+ with redirect_stderr (StringIO ()) as output :
401+ with self .assertRaises ((SystemExit , UnboundLocalError )):
402+ msgfmt .make ('messages.po' , 'messages.mo' )
399403
400404 def test_msgstr_invalid_indices (self ):
401405 invalid_po_files = (
@@ -412,8 +416,9 @@ def test_msgstr_invalid_indices(self):
412416 Path ('messages.po' ).write_text (invalid_po )
413417 # Reset the global MESSAGES dictionary
414418 msgfmt .MESSAGES .clear ()
415- with self .assertRaises (SystemExit ):
416- msgfmt .make ('messages.po' , 'messages.mo' )
419+ with redirect_stderr (StringIO ()) as output :
420+ with self .assertRaises (SystemExit ):
421+ msgfmt .make ('messages.po' , 'messages.mo' )
417422
418423
419424class CLITest (unittest .TestCase ):
0 commit comments