def test_container_get_entity_by_meta(container): """Test for method get entity by meta of coresponding Node Args: (list): meta_filter (top-entity): Top entity Return: (list): list of Entity """ top_entity = container.top_entities[0] meta = Meta('Geo', 'Country') entities = container.get_entities_by_meta(meta, top_entity) expected = ['Ukraine'].sort() actual = [entity._node.name for entity in entities].sort() assert expected == actual top_entity = container.top_entities[0] meta = Meta('Geo', 'Region') entities = container.get_entities_by_meta(meta, top_entity) expected = ['Kiev', 'Odessa'].sort() actual = [entity._node.name for entity in entities].sort() assert expected == actual top_entity = container.top_entities[0] meta = Meta('Food', 'Delicios') entities = container.get_entities_by_meta(meta, top_entity) expected = ['Candy'].sort() actual = [entity._node.name for entity in entities].sort() assert expected == actual
def get_parent_by_meta(meta_filter, id): meta_filter = Meta(meta_filter[0], meta_filter[1]) root_node = Node('root', (None, None)) encode_list_of_pathes_into_node(root_node, list_of_pathes, description) default_node = LIST_OF_NODES[id] output_node = default_node.get_parent_by_meta(meta_filter) return output_node
def get_children_by_meta(meta, nodes_ids): root_node = Node('root', (None, None)) encode_list_of_pathes_into_node(root_node, list_of_pathes, description) node_ids = [] meta_filter = Meta(meta[0], meta[1]) output_node = root_node.get_children_by_meta(meta_filter, node_ids) return node_ids
def add_child(name): depth = len(list_of_pathes) - 2 tree = list_of_pathes[:-1] root_node = Node('root', (None, None)) encode_list_of_pathes_into_node(root_node, list_of_pathes[:-1], description) last_node = LIST_OF_NODES[depth] last_node.add_child(name, Meta(description[name][0], description[name][1])) last_node.children[-1].id = depth + 1 return root_node
def test_container_get_entity_by_meta_raise_exception_wrong_value(container): """Test for method get entity by meta of coresponding Node Check raising exception on wrong value Args: (list): meta_filter (top-entity): Top entity Return: (list): list of Entity """ top_entity = container.top_entities[0] meta = Meta('Ukraine', 'Kiev') expected = [] actual = container.get_entities_by_meta(meta, top_entity)
def __init__(self, name, meta): """Initialisation of Node object Args: (sting): name - name of node (list ot tuple): meta - meta data for node, (dimension, level) Attributed: id: identification for node name: node's name meta: node's meta data paretn: list of node's parent on highes level children: list of node's children on bottom level """ self.id = 0 self.name = name self.meta = Meta(meta[0], meta[1]) self.parents = [] self.children = []
def encode_list_of_pathes_into_node(root_node, list_of_pathes, description): """Function serialise json list of pathes into Node object root_node :param root_node: root node :param list_of_pathes: list of pathes in graph :param description: meta data of each node :return: """ for path in list_of_pathes: new_nodes = [] depth = 0 metas = [] for node_name in path: metas.append( Meta(description[node_name][0], description[node_name][1])) new_node = root_node.add_node_by_path(path, metas, depth, new_nodes) new_node.id = list_of_pathes.index(path) LIST_OF_NODES[new_node.id] = new_node return list_of_pathes