def add_layer_to_tree(cls, tree, layer): parents = layer.__bases__ if not parents: err = "Invalid layer {0}: should at least inherit from `object`" raise exceptions.LoadTestsFailure(err.format(layer)) for parent in parents: if parent not in tree and parent is not object: raise MissingParentLayer() # if we reached that point, then all the parents are in the tree # if there are multiple parents, we first try to get the closest # to the current layer. for parent in parents: if not cls.get_parents_from_tree(parent, tree): cls.insert_layer(tree, layer, parent) return raise exceptions.LoadTestsFailure("Failed to add {0}".format(layer))
def insert_layer(cls, tree, layer, outer): if outer is object: outer = cls.insert_mixins(tree, layer, None) elif outer in tree: outer = cls.insert_mixins(tree, layer, outer) else: err = "{0} not found in {1}".format(outer, tree) raise exceptions.LoadTestsFailure(err) if outer is None: tree.setdefault(None, []).append(layer) else: tree[outer].append(layer) tree[layer] = []
def make_suite(self, suite, suiteClass): top_layer, layers_dict = self.get_layers_from_suite(suite, suiteClass) tree = {} unresolved_layers = self.update_layer_tree(tree, layers_dict.keys()) while unresolved_layers: remaining = self.update_layer_tree(tree, unresolved_layers) if len(remaining) == len(unresolved_layers): raise exceptions.LoadTestsFailure( "Could not resolve layer dependencies") unresolved_layers = remaining for layer in tree.keys(): if layer and layer not in layers_dict: layers_dict[layer] = LayerSuite(self.session, layer=layer) self.tree_to_suite(tree, None, top_layer, layers_dict) return top_layer