diff options
author | Hai Shi <shihai1992@gmail.com> | 2019-09-12 10:56:05 (GMT) |
---|---|---|
committer | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-09-12 10:56:05 (GMT) |
commit | f545638b5701652ffbe1774989533cdf5bc6631e (patch) | |
tree | 27c90f441b2aa84cf770ff3782550947b4ab36af /Lib/test/test_argparse.py | |
parent | 2d32bf1ef23c9e468b2e8afab3c24e7a2047ac36 (diff) | |
download | cpython-f545638b5701652ffbe1774989533cdf5bc6631e.zip cpython-f545638b5701652ffbe1774989533cdf5bc6631e.tar.gz cpython-f545638b5701652ffbe1774989533cdf5bc6631e.tar.bz2 |
bpo-9938: Add optional keyword argument exit_on_error to argparse.ArgumentParser (GH-15362)
Co-Authored-by: Xuanji Li <xuanji@gmail.com>
https://bugs.python.org/issue9938
Automerge-Triggered-By: @matrixise
Diffstat (limited to 'Lib/test/test_argparse.py')
-rw-r--r-- | Lib/test/test_argparse.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py index 86ec6cc..464db29 100644 --- a/Lib/test/test_argparse.py +++ b/Lib/test/test_argparse.py @@ -5262,6 +5262,21 @@ class TestWrappingMetavar(TestCase): ''')) +class TestExitOnError(TestCase): + + def setUp(self): + self.parser = argparse.ArgumentParser(exit_on_error=False) + self.parser.add_argument('--integers', metavar='N', type=int) + + def test_exit_on_error_with_good_args(self): + ns = self.parser.parse_args('--integers 4'.split()) + self.assertEqual(ns, argparse.Namespace(integers=4)) + + def test_exit_on_error_with_bad_args(self): + with self.assertRaises(argparse.ArgumentError): + self.parser.parse_args('--integers a'.split()) + + def test_main(): support.run_unittest(__name__) # Remove global references to avoid looking like we have refleaks. |