From cc0423b4f6dca210a3ae0c60f5fa6bc3d9649235 Mon Sep 17 00:00:00 2001 From: Jay Bazuzi Date: Sun, 10 Nov 2024 11:38:36 -0800 Subject: [PATCH 1/2] - F move verify_argument_parser scrubber to caller --- approvaltests/approvals.py | 6 +----- tests/test_find_stale_approved_files.py | 5 ++++- tests/test_verify_argument_parser.py | 7 ++++++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/approvaltests/approvals.py b/approvaltests/approvals.py index 4630e7d..1a1009d 100644 --- a/approvaltests/approvals.py +++ b/approvaltests/approvals.py @@ -417,11 +417,7 @@ def verify_argument_parser( options: Optional[Options] = None, ) -> None: parser.formatter_class = lambda prog: argparse.HelpFormatter(prog, width=200) - options = options or Options() - scrubber = lambda t: t.replace("options:", ":").replace( - "optional arguments:", ":" - ) verify( parser.format_help(), - options=options.with_scrubber(scrubber), + options=options, ) diff --git a/tests/test_find_stale_approved_files.py b/tests/test_find_stale_approved_files.py index 3b8f60d..2e7d3dc 100644 --- a/tests/test_find_stale_approved_files.py +++ b/tests/test_find_stale_approved_files.py @@ -52,7 +52,10 @@ def execute_script(directory, log_file): def test_create_argument_parser(): - verify_argument_parser(create_argument_parser()) + scrubber = lambda t: t.replace("options:", ":").replace( + "optional arguments:", ":" + ) + verify_argument_parser(create_argument_parser(), options=Options().with_scrubber(scrubber)) def test_find_stale_approved_files(): diff --git a/tests/test_verify_argument_parser.py b/tests/test_verify_argument_parser.py index abe97cf..24b752e 100644 --- a/tests/test_verify_argument_parser.py +++ b/tests/test_verify_argument_parser.py @@ -3,6 +3,7 @@ from approvaltests import verify_argument_parser from tests.find_stale_approved_files import create_argument_parser +from approvaltests.core.options import Options def test_argument_parser(): @@ -13,4 +14,8 @@ def test_argument_parser(): parser.add_argument("1st_argument", help="1st argument help text") parser.add_argument("--optional_argument", help="An Optional Argument help text") parser.add_argument("long_argument", help=f"{'Very' * 100} Long message") - verify_argument_parser(parser) + + scrubber = lambda t: t.replace("options:", ":").replace( + "optional arguments:", ":" + ) + verify_argument_parser(parser, options=Options().with_scrubber(scrubber)) From 7c7706e1391daf524934342c0bf48dae1da24a5b Mon Sep 17 00:00:00 2001 From: Jay Bazuzi Date: Tue, 12 Nov 2024 11:52:40 -0800 Subject: [PATCH 2/2] - r clean up imports --- tests/test_verify_argument_parser.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/test_verify_argument_parser.py b/tests/test_verify_argument_parser.py index 24b752e..2787acf 100644 --- a/tests/test_verify_argument_parser.py +++ b/tests/test_verify_argument_parser.py @@ -1,9 +1,6 @@ import argparse -import os -from approvaltests import verify_argument_parser -from tests.find_stale_approved_files import create_argument_parser -from approvaltests.core.options import Options +from approvaltests import verify_argument_parser, Options def test_argument_parser():