def test_ancestor_classes(): import re class A: pass class B: pass class C(A): pass class D(C): pass class E(B,A): pass a_anc = ancestor_classes(A) d_anc = set(ancestor_classes(D)) e_anc = set(ancestor_classes(E)) if a_anc != []: print 'ancestor_classes failed empty ancestors test.' print "\t" + str(a_anc) + ' should be empty' if d_anc != set([A,C]): print 'ancestor_classes failed grand-parent test.' print "\t" + str(d_anc) + ' should be ' + str([A,C]) if e_anc != set([A,B]): print 'ancestor_classes failed dual inheritance test.' print "\t" + str(e_anc) + ' should be ' + str([A,B])
def initiate_mockdb(config): clses = classes_list(config) mockdb={} for cls in clses: pro_cs = progenitor_classes(cls) if len(pro_cs) > 1: continue if not KeyedObject in pro_cs: continue anc_cs = ancestor_classes(cls) if NumberedObject in anc_cs: mockdb[cls.__name__] = SetOfNumberedObjects(cls=cls) else: mockdb[cls.__name__] = SetOfKeyedObjects(cls=cls) mockdb[cls.__name__].__load__(config) return mockdb
def __max_key__(self,config): keys = self.objects.keys() #Load database and children databases to get #access to their keys other = self.__class__(cls=self.cls) other.__load__(config,no_children=False) keys += other.objects.keys() anc_clses = ancestor_classes(self.cls) #Load ancestor databases to get #access to their keys for cls in anc_clses: other = SetOfNumberedObjects(cls=cls) other.__load__(config) keys += other.objects.keys() if keys == []: return 0 keys.sort(key=int) return keys[-1]