From 0d6e9cbd254b8f9911a0d6aad1edb913e95fff45 Mon Sep 17 00:00:00 2001 From: Kevin Van Brunt Date: Tue, 19 Nov 2019 23:45:56 -0500 Subject: Added unit test for overriding default parser --- tests/test_argparse_custom.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'tests/test_argparse_custom.py') diff --git a/tests/test_argparse_custom.py b/tests/test_argparse_custom.py index 65cbc8da..ce789f8e 100644 --- a/tests/test_argparse_custom.py +++ b/tests/test_argparse_custom.py @@ -242,3 +242,20 @@ def test_apcustom_required_options(): parser = Cmd2ArgumentParser() parser.add_argument('--required_flag', required=True) assert 'required arguments' in parser.format_help() + + +def test_override_parser(): + import importlib + from cmd2 import DEFAULT_ARGUMENT_PARSER + + # The standard parser is Cmd2ArgumentParser + assert DEFAULT_ARGUMENT_PARSER == Cmd2ArgumentParser + + # Set our parser module and force a reload of cmd2 so it loads the module + argparse.cmd2_parser_module = 'examples.custom_parser' + importlib.reload(cmd2) + from cmd2 import DEFAULT_ARGUMENT_PARSER + + # Verify DEFAULT_ARGUMENT_PARSER is now our CustomParser + from examples.custom_parser import CustomParser + assert DEFAULT_ARGUMENT_PARSER == CustomParser -- cgit v1.2.1