Skip to content
Snippets Groups Projects
Verified Commit 2448a5bd authored by Yoann Schneider's avatar Yoann Schneider :tennis:
Browse files

Correctly handle null values for arguments

parent bfabe321
No related branches found
No related tags found
1 merge request!22Correctly handle null values for arguments
Pipeline #202624 passed
......@@ -95,9 +95,8 @@ class ConfigParser:
for name in data:
if name not in self.options:
errors[name] = "This option does not exist"
for name, option in self.options.items():
if name in data:
if data.get(name) is not None:
value = data[name]
elif option.default is UNSET:
errors[name] = "This option is required"
......
......@@ -82,3 +82,24 @@ class TestConfigParser(TestCase):
"unknownthing": "This option does not exist",
},
)
def test_parse_null_no_default(self):
parser = ConfigParser()
parser.add_option("something", type=str)
with self.assertRaises(ConfigurationError) as context:
parser.parse_data({"something": None})
self.assertDictEqual(
context.exception.errors,
{
"something": "This option is required",
},
)
def test_parse_null_with_default(self):
parser = ConfigParser()
parser.add_option("something", type=str, default=None)
self.assertDictEqual(
parser.parse_data({"something": None}),
{"something": None},
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment