Skip to content

gh-130197: Improve test coverage of msgfmt.py part 2 #133309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Silence error output
  • Loading branch information
tomasr8 committed May 4, 2025
commit 98917e53419c550ab4b9f35b8dc3c7435a12bdf2
21 changes: 13 additions & 8 deletions Lib/test/test_tools/test_msgfmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import struct
import sys
import unittest
from contextlib import redirect_stderr
from gettext import GNUTranslations
from io import StringIO
from pathlib import Path
from textwrap import dedent

from test.support.os_helper import temp_cwd
from test.support.script_helper import assert_python_failure, assert_python_ok
from test.test_tools import imports_under_tool, skip_if_missing, toolsdir
from textwrap import dedent


skip_if_missing('i18n')
Expand Down Expand Up @@ -320,9 +322,10 @@ def test_general_syntax_errors(self):
Path('messages.po').write_text(invalid_po)
# Reset the global MESSAGES dictionary
msgfmt.MESSAGES.clear()
with self.assertRaises((SystemExit, UnboundLocalError,
IndexError, SyntaxError)):
msgfmt.make('messages.po', 'messages.mo')
with redirect_stderr(StringIO()) as output:
with self.assertRaises((SystemExit, UnboundLocalError,
IndexError, SyntaxError)):
msgfmt.make('messages.po', 'messages.mo')

def test_semantic_errors(self):
invalid_po_files = (
Expand Down Expand Up @@ -394,8 +397,9 @@ def test_semantic_errors(self):
Path('messages.po').write_text(invalid_po)
# Reset the global MESSAGES dictionary
msgfmt.MESSAGES.clear()
with self.assertRaises((SystemExit, UnboundLocalError)):
msgfmt.make('messages.po', 'messages.mo')
with redirect_stderr(StringIO()) as output:
with self.assertRaises((SystemExit, UnboundLocalError)):
msgfmt.make('messages.po', 'messages.mo')

def test_msgstr_invalid_indices(self):
invalid_po_files = (
Expand All @@ -412,8 +416,9 @@ def test_msgstr_invalid_indices(self):
Path('messages.po').write_text(invalid_po)
# Reset the global MESSAGES dictionary
msgfmt.MESSAGES.clear()
with self.assertRaises(SystemExit):
msgfmt.make('messages.po', 'messages.mo')
with redirect_stderr(StringIO()) as output:
with self.assertRaises(SystemExit):
msgfmt.make('messages.po', 'messages.mo')


class CLITest(unittest.TestCase):
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy