summaryrefslogtreecommitdiff
path: root/openstackclient
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-06-08 04:30:57 +0000
committerGerrit Code Review <review@openstack.org>2016-06-08 04:30:58 +0000
commitc272476b7bbfe5eefa84d25475d7b8d85fa4d9b9 (patch)
treeb437d185ca78d5fe797a007f94249c076c1121b7 /openstackclient
parent4c331bd5f9ba2e9174b7e2ab17df2c3800d24caa (diff)
parentcf122397733b8795530577b7824aeae305719658 (diff)
downloadpython-openstackclient-c272476b7bbfe5eefa84d25475d7b8d85fa4d9b9.tar.gz
Merge "Error handling for KeyValueAction class."
Diffstat (limited to 'openstackclient')
-rw-r--r--openstackclient/common/parseractions.py4
-rw-r--r--openstackclient/tests/common/test_parseractions.py17
2 files changed, 10 insertions, 11 deletions
diff --git a/openstackclient/common/parseractions.py b/openstackclient/common/parseractions.py
index c535b4f3..1e92dc46 100644
--- a/openstackclient/common/parseractions.py
+++ b/openstackclient/common/parseractions.py
@@ -35,7 +35,9 @@ class KeyValueAction(argparse.Action):
if '=' in values:
getattr(namespace, self.dest, {}).update([values.split('=', 1)])
else:
- getattr(namespace, self.dest, {}).pop(values, None)
+ msg = _("Expected 'key=value' type, "
+ "but got: %s") % (str(values))
+ raise argparse.ArgumentTypeError(msg)
class MultiKeyValueAction(argparse.Action):
diff --git a/openstackclient/tests/common/test_parseractions.py b/openstackclient/tests/common/test_parseractions.py
index 5c5ca3d3..894b224c 100644
--- a/openstackclient/tests/common/test_parseractions.py
+++ b/openstackclient/tests/common/test_parseractions.py
@@ -49,16 +49,13 @@ class TestKeyValueAction(utils.TestCase):
self.assertDictEqual(expect, actual)
def test_error_values(self):
- results = self.parser.parse_args([
- '--property', 'red',
- '--property', 'green=100%',
- '--property', 'blue',
- ])
-
- actual = getattr(results, 'property', {})
- # There should be no red or blue
- expect = {'green': '100%', 'format': '#rgb'}
- self.assertDictEqual(expect, actual)
+ self.assertRaises(
+ argparse.ArgumentTypeError,
+ self.parser.parse_args,
+ [
+ '--property', 'red',
+ ]
+ )
class TestMultiKeyValueAction(utils.TestCase):