def test_load_attr_as_list_of_on_list_mixed_none(self): with self.assertRaises(TypeError): info = Info({'sub_info_data': [None, { 'test': 'test' }]}, preserve_data=True) info._load_attr_as_list_of('sub_info_data', Info)
def test_load_attr_on_invalid_name(self): info = Info({'1': 1}, preserve_data=True) info._load_attr('1') self.assertEqual(info['1'], 1)
def test_subscriptable(self): info = Info({}) setattr(info, 'test', 1) self.assertEqual(info['test'], 1)
def test_load_attr_on_missing_key(self): info = Info({}, preserve_data=True) info._load_attr('test') self.assertEqual(info.test, None)
def test_load_attr(self): info = Info({'test': 'test'}, preserve_data=True) info._load_attr('test') self.assertEqual(info.test, 'test')
def __init__(self, dictionary, parent=None, **kwargs): if self.__validate_parent(parent): self.parent = parent Info.__init__(self, dictionary, **kwargs)
def test_load_attr_as_list_of_on_list_mixed_none(self): with self.assertRaises(TypeError): info = Info({'sub_info_data': [None, {'test':'test'}]}, preserve_data=True) info._load_attr_as_list_of('sub_info_data', Info)
def test_load_attr_as(self): info = Info({'subinfo': {'test':True}}, preserve_data=True) info._load_attr_as('subinfo', Info, preserve_data=True) info.subinfo._load_attr('test') self.assertEqual(info.subinfo.test, True)
def test_load_attr_as_list_of_on_none(self): info = Info({'test': None}, preserve_data=True) info._load_attr_as_list_of('test', Info) self.assertEqual(info.test, [])
def test_load_attr_as(self): info = Info({'subinfo': {'test': True}}, preserve_data=True) info._load_attr_as('subinfo', Info, preserve_data=True) info.subinfo._load_attr('test') self.assertEqual(info.subinfo.test, True)
def test_load_attr_as_list_of_on_string(self): with self.assertRaises(TypeError): info = Info({'sub_info_data': 'test'}, preserve_data=True) info._load_attr_as_list_of('sub_info_data', Info)
def test_data_deleted_by_default(self): info = Info({'test': None}) with self.assertRaises(AttributeError): info._data
def test_data_not_deleted_with_preserve_data(self): info = Info({'test': None}, preserve_data=True) self.assertEqual(info._data, {'test': None})
def __init__(self, dictionary, **kwargs): Info.__init__(self, dictionary, **kwargs)