def check_description(self, obj, target, description): annotations = annotated_references(obj) self.assertIn( target, annotations, msg="{} not found in referents of {}".format(target, obj), ) self.assertIn(description, annotations[target])
def check_completeness(self, obj): # Check that all referents of obj are annotated. annotations = annotated_references(obj) referents = gc.get_referents(obj) for ref in referents: if not annotations[ref]: self.fail( "Didn't find annotation from {} to {}".format(obj, ref) ) annotations[ref].pop()
def annotated(self): """ Annotate this graph, returning an AnnotatedGraph object with the same structure. """ # Build up dictionary of edge annotations. edge_annotations = {} for edge in self.edges: if edge not in edge_annotations: # We annotate all edges from a given object at once. referrer = self._tail[edge] known_refs = annotated_references(referrer) for out_edge in self._out_edges[referrer]: referent = self._head[out_edge] if known_refs[referent]: annotation = known_refs[referent].pop() else: annotation = None edge_annotations[out_edge] = annotation annotated_vertices = [ AnnotatedVertex( id=id(vertex), annotation=object_annotation(vertex), ) for vertex in self.vertices ] annotated_edges = [ AnnotatedEdge( id=edge, annotation=edge_annotations[edge], head=id(self._head[edge]), tail=id(self._tail[edge]), ) for edge in self.edges ] return AnnotatedGraph( vertices=annotated_vertices, edges=annotated_edges, )