diff options
author | tmblweed <tmblweed@users.noreply.github.com> | 2019-08-02 04:57:13 (GMT) |
---|---|---|
committer | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-08-02 04:57:13 (GMT) |
commit | 4b3e97592376d5f8a3b75192b399a2da1be642cb (patch) | |
tree | eba27853c200ae6a4196410b5770871222265bac /Lib/test/test_argparse.py | |
parent | 2491134029b195d3159a489e1803ee22a7839b41 (diff) | |
download | cpython-4b3e97592376d5f8a3b75192b399a2da1be642cb.zip cpython-4b3e97592376d5f8a3b75192b399a2da1be642cb.tar.gz cpython-4b3e97592376d5f8a3b75192b399a2da1be642cb.tar.bz2 |
bpo-16970: Adding error message for invalid args (GH-14844)
BPO -16970: Adding error message for invalid args
Applied the patch argparse-v2 patch issue 16970, ran patch check and the test suite, test_argparse with 0 errors
https://bugs.python.org/issue16970
Diffstat (limited to 'Lib/test/test_argparse.py')
-rw-r--r-- | Lib/test/test_argparse.py | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py index 5128dc5..d6d1609 100644 --- a/Lib/test/test_argparse.py +++ b/Lib/test/test_argparse.py @@ -4263,7 +4263,6 @@ class TestHelpSubparsersWithHelpOrdering(HelpTestCase): class TestHelpMetavarTypeFormatter(HelpTestCase): - """""" def custom_type(string): return string @@ -5150,6 +5149,35 @@ class TestAddArgumentMetavar(TestCase): def test_nargs_3_metavar_length3(self): self.do_test_no_exception(nargs=3, metavar=("1", "2", "3")) + +class TestInvalidNargs(TestCase): + + EXPECTED_INVALID_MESSAGE = "invalid nargs value" + EXPECTED_RANGE_MESSAGE = ("nargs for store actions must be != 0; if you " + "have nothing to store, actions such as store " + "true or store const may be more appropriate") + + def do_test_range_exception(self, nargs): + parser = argparse.ArgumentParser() + with self.assertRaises(ValueError) as cm: + parser.add_argument("--foo", nargs=nargs) + self.assertEqual(cm.exception.args[0], self.EXPECTED_RANGE_MESSAGE) + + def do_test_invalid_exception(self, nargs): + parser = argparse.ArgumentParser() + with self.assertRaises(ValueError) as cm: + parser.add_argument("--foo", nargs=nargs) + self.assertEqual(cm.exception.args[0], self.EXPECTED_INVALID_MESSAGE) + + # Unit tests for different values of nargs + + def test_nargs_alphabetic(self): + self.do_test_invalid_exception(nargs='a') + self.do_test_invalid_exception(nargs="abcd") + + def test_nargs_zero(self): + self.do_test_range_exception(nargs=0) + # ============================ # from argparse import * tests # ============================ |