Exemplo n.º 1
0
    def get_attribute_dict(self):
        """
           :return: map of all the block's native attributes (from the source file),
           combined with the attributes generated by the module builder.
           If the attributes are not a primitive type, they are converted to strings.
           """
        base_attributes = self.get_base_attributes()
        self.get_origin_attributes(base_attributes)

        if self.changed_attributes:
            # add changed attributes only for calculating the hash
            changed_attributes_keys = list(self.changed_attributes.keys())
            changed_attributes_keys.sort()
            base_attributes['changed_attributes'] = changed_attributes_keys

        if self.breadcrumbs:
            sorted_breadcrumbs = dict(sorted(self.breadcrumbs.items()))
            base_attributes[CustomAttributes.RENDERING_BREADCRUMBS] = sorted_breadcrumbs

        if self.encode:
            for attribute in base_attributes:
                value_to_encode = base_attributes[attribute]
                encoded_value = utils.encode_graph_property_value(value_to_encode)
                base_attributes[attribute] = encoded_value

        base_attributes[CustomAttributes.HASH] = calculate_hash(base_attributes)

        if base_attributes.get('changed_attributes'):
            # removed changed attributes if it was added previously for calculating hash.
            del base_attributes['changed_attributes']

        return base_attributes
Exemplo n.º 2
0
 def group_edges_by_origin_and_label(edges: List[Edge]) -> List[List[Edge]]:
     edge_groups: Dict[str, List[Edge]] = {}
     for edge in edges:
         origin_and_label_hash = calculate_hash(f"{edge.origin}{edge.label}")
         if not edge_groups.get(origin_and_label_hash):
             edge_groups[origin_and_label_hash] = []
         edge_groups[origin_and_label_hash].append(edge)
     return list(edge_groups.values())
Exemplo n.º 3
0
 def group_edges_by_origin_and_label(edges):
     edge_groups = {}
     for edge in edges:
         origin_and_label_hash = calculate_hash(f'{edge.origin}{edge.label}')
         if not edge_groups.get(origin_and_label_hash):
             edge_groups[origin_and_label_hash] = []
         edge_groups[origin_and_label_hash].append(edge)
     return list(edge_groups.values())
Exemplo n.º 4
0
 def order_edges_by_hash_codes(self):
     edges = {}
     for edge in self.edges:
         edge_data = {'edge_label': edge.label,
                      'from_vertex_hash': self.get_vertex_hash_by_index(vertex_index=edge.origin),
                      'to_vertex_hash': self.get_vertex_hash_by_index(vertex_index=edge.dest),
                      }
         edge_hash = calculate_hash(edge_data)
         edges[edge_hash] = edge
     return edges
Exemplo n.º 5
0
 def order_edges_by_hash_codes(self) -> Dict[str, Edge]:
     edges = {}
     for edge in self.edges:
         edge_data = {
             "edge_label":
             edge.label,
             "from_vertex_hash":
             self.get_vertex_hash_by_index(vertex_index=edge.origin),
             "to_vertex_hash":
             self.get_vertex_hash_by_index(vertex_index=edge.dest),
         }
         edge_hash = calculate_hash(edge_data)
         edges[edge_hash] = edge
     return edges
Exemplo n.º 6
0
    def test_single_edge_with_same_label(self):
        resources_dir = os.path.realpath(
            os.path.join(TEST_DIRNAME, '../resources/k8_service'))

        graph_manager = GraphManager(NetworkxConnector())
        local_graph, _ = graph_manager.build_graph_from_source_directory(resources_dir,
                                                                          render_variables=True)
        edges_hash = []
        for e in local_graph.edges:
            edge_hash = calculate_hash({"origin": e.origin, "dest": e.dest, "label": e.label})
            if edge_hash in edges_hash:
                origin = local_graph.vertices[e.origin]
                dest = local_graph.vertices[e.dest]
                self.fail(f'edge {e} == [{origin} - {e.label} -> {dest}] appears more than once in the graph')
            else:
                edges_hash.append(edge_hash)