summaryrefslogtreecommitdiff
path: root/openstackclient/tests/common
diff options
context:
space:
mode:
Diffstat (limited to 'openstackclient/tests/common')
-rw-r--r--openstackclient/tests/common/test_parseractions.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/openstackclient/tests/common/test_parseractions.py b/openstackclient/tests/common/test_parseractions.py
index 8afcb632..b75c4814 100644
--- a/openstackclient/tests/common/test_parseractions.py
+++ b/openstackclient/tests/common/test_parseractions.py
@@ -102,3 +102,58 @@ class TestKeyValueAction(utils.TestCase):
expect = {'green': '100%'}
self.assertDictEqual(expect, actual)
self.assertEqual(None, failhere)
+
+
+class TestNonNegativeAction(utils.TestCase):
+ def test_negative_values(self):
+ parser = argparse.ArgumentParser()
+
+ # Set up our typical usage
+ parser.add_argument(
+ '--foo',
+ metavar='<foo>',
+ type=int,
+ action=parseractions.NonNegativeAction,
+ )
+
+ self.assertRaises(
+ argparse.ArgumentTypeError,
+ parser.parse_args,
+ "--foo -1".split()
+ )
+
+ def test_zero_values(self):
+ parser = argparse.ArgumentParser()
+
+ # Set up our typical usage
+ parser.add_argument(
+ '--foo',
+ metavar='<foo>',
+ type=int,
+ action=parseractions.NonNegativeAction,
+ )
+
+ results = parser.parse_args(
+ '--foo 0'.split()
+ )
+
+ actual = getattr(results, 'foo', None)
+ self.assertEqual(actual, 0)
+
+ def test_positive_values(self):
+ parser = argparse.ArgumentParser()
+
+ # Set up our typical usage
+ parser.add_argument(
+ '--foo',
+ metavar='<foo>',
+ type=int,
+ action=parseractions.NonNegativeAction,
+ )
+
+ results = parser.parse_args(
+ '--foo 1'.split()
+ )
+
+ actual = getattr(results, 'foo', None)
+ self.assertEqual(actual, 1)