Skip to content

Commit

Permalink
Allow None as option for ChoiceMeta
Browse files Browse the repository at this point in the history
  • Loading branch information
coretl committed Jul 13, 2016
1 parent d80f6f4 commit d9f9bb7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion malcolm/core/choicemeta.py
Expand Up @@ -36,7 +36,7 @@ def validate(self, value):
ValueError: If value not valid
"""

if value in self.choices:
if value is None or value in self.choices:
return value
else:
raise ValueError("%s is not a valid value" % value)
Expand Down
4 changes: 4 additions & 0 deletions tests/test_core/test_choicemeta.py
Expand Up @@ -36,6 +36,10 @@ def test_given_valid_value_then_return(self):
response = self.choice_meta.validate(1)
self.assertEqual(1, response)

def test_None_valid(self):
response = self.choice_meta.validate(None)
self.assertEqual(None, response)

def test_given_invalid_value_then_raises(self):
with self.assertRaises(ValueError):
self.choice_meta.validate(0)
Expand Down

0 comments on commit d9f9bb7

Please sign in to comment.