ATTR_NOT_SPECIFIED and None are singleton objects
When conducting "is in" against a list of objects, they are compared using
unequal unless they are the same object.
http://docs.python.org/2/reference/expressions.html#in
According to PEP8, they should be compared by their id not value
Therefore the is_attr_set logic has changed to:
return not (attribute is None or attribute is ATTR_NOT_SPECIFIED)
Wrote unittests for is_attr_set
Change-Id: I2ebdd29564e5627b9e33b13a744948e8c9c0b9ce
def is_attr_set(attribute):
- return attribute not in (None, ATTR_NOT_SPECIFIED)
+ return not (attribute is None or attribute is ATTR_NOT_SPECIFIED)
def _validate_boolean(data, valid_values=None):
class TestAttributes(unittest2.TestCase):
+ def test_is_attr_set(self):
+ mock_obj = attributes.ATTR_NOT_SPECIFIED
+ mock_none = None
+ mock_str = "I'm set"
+ self.assertIs(attributes.is_attr_set(mock_obj), False)
+ self.assertIs(attributes.is_attr_set(mock_none), False)
+ self.assertIs(attributes.is_attr_set(mock_str), True)
+
def test_booleans(self):
msg = attributes._validate_boolean(True)
self.assertIsNone(msg)