diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-11-19 23:45:56 -0500 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-11-19 23:45:56 -0500 |
commit | 0d6e9cbd254b8f9911a0d6aad1edb913e95fff45 (patch) | |
tree | 473f2e533aa34f2b4811a01bf18746aaf8471c0c | |
parent | eee6bf15805fa8ed3ca713a4c6e8edfd9ebc5d4e (diff) | |
download | cmd2-git-0d6e9cbd254b8f9911a0d6aad1edb913e95fff45.tar.gz |
Added unit test for overriding default parser
-rw-r--r-- | tests/test_argparse_custom.py | 17 |
1 files changed, 17 insertions, 0 deletions
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 |