summaryrefslogtreecommitdiff
path: root/tests/test_argparse_custom.py
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2019-11-22 21:57:25 -0500
committerGitHub <noreply@github.com>2019-11-22 21:57:25 -0500
commit1cad8d92b87a227b331c0e86ddbbee25a6742650 (patch)
tree473f2e533aa34f2b4811a01bf18746aaf8471c0c /tests/test_argparse_custom.py
parent8c00d342ee3967e09cce436d76208238307d1cd4 (diff)
parent0d6e9cbd254b8f9911a0d6aad1edb913e95fff45 (diff)
downloadcmd2-git-1cad8d92b87a227b331c0e86ddbbee25a6742650.tar.gz
Merge pull request #812 from python-cmd2/custom_parser
Custom parser
Diffstat (limited to 'tests/test_argparse_custom.py')
-rw-r--r--tests/test_argparse_custom.py17
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