def test_retrieve_values_by_key_method(): class TestLoadClass(KeyedObject): def __init__(self,key='dummy',attr1='a1',attr2='a2'): KeyedObject.__init__(self,key=key) self.attr1 = attr1 self.attr2 = attr2 set_of_keyed_objects = SetOfKeyedObjects(TestLoadClass) set_of_keyed_objects.__load__(base_dir=os.path.join(os.getcwd(),'mockdb/test_data'),no_children=True) d = set_of_keyed_objects.__retrieve_values_by_key__('attr1')
def test_save(): class TestLoadClass(KeyedObject): def __init__(self,key='dummy',attr1='a1',attr2='a2'): KeyedObject.__init__(self,key=key) self.attr1 = attr1 self.attr2 = attr2 set_of_keyed_objects = SetOfKeyedObjects(TestLoadClass) instance = set_of_keyed_objects.cls(key='2') set_of_keyed_objects.objects['2'] = instance set_of_keyed_objects.__save__(base_dir=os.path.join(os.getcwd(),'mockdb/test_data'))
def test_class_set_method(): class TestLoadClass(KeyedObject): def __init__(self,key='dummy',attr1='a1',attr2='a2'): KeyedObject.__init__(self,key=key) self.attr1 = attr1 self.attr2 = attr2 set_of_keyed_objects = SetOfKeyedObjects(TestLoadClass) instance = set_of_keyed_objects.cls(key='2') set_of_keyed_objects.objects['2'] = instance clses = set_of_keyed_objects.__class_set__() if clses != set([set_of_keyed_objects.cls]): print "class_set_method failed."
def test_load_set(): class TestLoadClass(KeyedObject): def __init__(self,key='dummy',attr1='a1',attr2='a2'): KeyedObject.__init__(self,key=key) self.attr1 = attr1 self.attr2 = attr2 set_of_keyed_objects = SetOfKeyedObjects(TestLoadClass) set_of_keyed_objects.__load__(base_dir=os.path.join(os.getcwd(),'mockdb/test_data'),no_children=True,key=1) try: if set_of_keyed_objects.objects['1'].attr1 != 'attribute1': print 'load did not load the correct attributes.' except KeyError: print 'Specifying the key in load did not work.' try: if set_of_keyed_objects.objects['2'].attr1 != 'attribute1': "More keys than specified were loaded." except KeyError: pass