Boolean options: use strict checking

Boolean options (such as "--protected" for glance md-namespace-update)
should accept a limited amount of valid values, rather than assuming an
"invalid" value means "False".

The following values (no matter the case) will now be interpreted as
True: ‘t’,’true’, ‘on’, ‘y’, ‘yes’, or ‘1’.

The following values (no matter the case) will now be interpreted as
False: ‘f’, ‘false’, ‘off’, ‘n’, ‘no’, or ‘0’.

Change-Id: I0e7942045d883ac398bab4a7a85f2b4ac9b1ed8c
Closes-Bug: #1607317
This commit is contained in:
Cyril Roelandt
2022-09-21 19:38:24 +02:00
parent 9e8fcdb92e
commit 88e3b0ad98
4 changed files with 26 additions and 1 deletions
+8
View File
@@ -229,6 +229,14 @@ class TestUtils(testtools.TestCase):
self.assertEqual(encodeutils.safe_decode, opts['type'])
self.assertIn('None, opt-1, opt-2', opts['help'])
# Make sure we use strict checking for boolean values.
decorated = utils.schema_args(schema_getter('boolean'))(dummy_func)
arg, opts = decorated.__dict__['arguments'][0]
type_function = opts['type']
self.assertEqual(type_function('False'), False)
self.assertEqual(type_function('True'), True)
self.assertRaises(ValueError, type_function, 'foo')
def test_iterable_closes(self):
# Regression test for bug 1461678.
def _iterate(i):