Merge "Boolean options: use strict checking"

This commit is contained in:
Zuul
2023-01-12 22:39:41 +00:00
committed by Gerrit Code Review
4 changed files with 26 additions and 1 deletions
+1 -1
View File
@@ -103,7 +103,7 @@ def schema_args(schema_getter, omit=None):
typemap = {
'string': encodeutils.safe_decode,
'integer': int,
'boolean': strutils.bool_from_string,
'boolean': lambda x: strutils.bool_from_string(x, strict=True),
'array': list
}
+8
View File
@@ -236,6 +236,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):