From d8e4563a7f2878efa13d442b1595bdb66e65865e Mon Sep 17 00:00:00 2001 From: boxydog Date: Fri, 31 May 2024 08:19:31 -0500 Subject: [PATCH] Change default of --fatal command line arg to terminate on error --- RELEASE.md | 3 +++ pelican/__init__.py | 10 +++++----- pelican/log.py | 2 +- pelican/tests/test_init.py | 20 ++++++++++++++++++++ 4 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 RELEASE.md create mode 100644 pelican/tests/test_init.py diff --git a/RELEASE.md b/RELEASE.md new file mode 100644 index 00000000..045cfad6 --- /dev/null +++ b/RELEASE.md @@ -0,0 +1,3 @@ +Release type: major + +Change default of `--fatal` command line switch to terminate on error. diff --git a/pelican/__init__.py b/pelican/__init__.py index ab6b0225..247be4f5 100644 --- a/pelican/__init__.py +++ b/pelican/__init__.py @@ -438,12 +438,12 @@ def parse_arguments(argv=None): parser.add_argument( "--fatal", - metavar="errors|warnings", - choices=("errors", "warnings"), - default="", + metavar="errors|warnings|ignore", + choices=("errors", "warnings", "ignore"), + default="errors", help=( "Exit the program with non-zero status if any " - "errors/warnings encountered." + "errors/warnings encountered, or ignore any errors." ), ) @@ -634,7 +634,7 @@ def main(argv=None): logs_dedup_min_level = getattr(logging, args.logs_dedup_min_level) init_logging( level=args.verbosity, - fatal=args.fatal, + fatal=args.fatal if args.fatal != "ignore" else "", name=__name__, handler=args.log_handler, logs_dedup_min_level=logs_dedup_min_level, diff --git a/pelican/log.py b/pelican/log.py index edf2f182..b60a1aef 100644 --- a/pelican/log.py +++ b/pelican/log.py @@ -131,7 +131,7 @@ DEFAULT_LOG_HANDLER = RichHandler(console=console) def init( level=None, - fatal="", + fatal="errors", handler=DEFAULT_LOG_HANDLER, name=None, logs_dedup_min_level=None, diff --git a/pelican/tests/test_init.py b/pelican/tests/test_init.py new file mode 100644 index 00000000..1f8e156b --- /dev/null +++ b/pelican/tests/test_init.py @@ -0,0 +1,20 @@ +import unittest +from unittest.mock import MagicMock, patch + +from pelican import DEFAULT_LOG_HANDLER, main + + +class TestLog(unittest.TestCase): + @patch("pelican.get_instance") + @patch("pelican.init_logging") + def test_main_fatal_default(self, init_logging_mock, get_instance): + get_instance.side_effect = lambda *args, **kwargs: (MagicMock(), MagicMock()) + main() + init_logging_mock.assert_called_once_with( + level=None, + # default is "errors" + fatal="errors", + name="pelican", + handler=DEFAULT_LOG_HANDLER, + logs_dedup_min_level=30, + )