def test_value_not_found(self): # None is returned if the collection does not contain the requested # item. item = _get_by_attr(self.collection, self.attr, '__does_not_exist__') self.assertIsNone(item)
def test_attr_not_found(self): # An AttributeError is raised if items in collection does not have the # required attribute. with self.assertRaises(AttributeError): _get_by_attr(self.collection, 'another_attr', 0)
def test_item_found(self): # Ensure an object instance is correctly returned if found in # the collection. item = _get_by_attr(self.collection, self.attr, 3) self.assertEqual(3, item.myattr)