コード例 #1
0
 def test_node_records(self):
     graph = Graph()
     (graph.add_node_record('struct1', '<f0> left|<f1> middle|<f2> right').
      add_node_record('struct2', '<f0> one|<f1> two').add_node_record(
          'struct3',
          'hello&#92;nworld |{ b |{c|<here> d|e}| f}| g | h').add_edge(
              'struct1:f1', 'struct2:f0').add_edge('struct1:f2',
                                                   'struct3:here'))
     graph_dot = Graph_Dot(graph)
     (graph_dot.set_layout_engine_dot().render_svg_to_file(self.svg_file))
     graph_dot.print_dot_code()
コード例 #2
0
    def test_from_gs_graph(self):
        graph = Graph()
        #graph_name = 'graph_QIN'  # (SOW-18 128 nodes)
        #graph_name = 'graph_YXT' # person-42 (manages, 43 nodes)
        #graph_name = 'graph_CXJ'   # Playbook-2 (103 nodes)
        graph_name = 'graph_SCE'  # PERSON-4 (8 nodes)

        graph_dot = Lambda_Graph().get_graph_dot(graph_name)

        (graph_dot.set_layout_engine_dot().render_svg_to_file(self.svg_file))
コード例 #3
0
ファイル: Lambda_Graph.py プロジェクト: filetrust/OSBot-jira
 def get_graph(self, graph_name):
     graph_data = self.get_graph_data(graph_name)
     nodes = graph_data.get('nodes').keys()
     edges = graph_data.get('edges')
     return Graph().add_nodes(nodes)     \
                   .add_edges(edges)
コード例 #4
0
 def setUp(self):
     self.graph = Graph()
     self.result = None
コード例 #5
0
class test_Graph(TestCase):
    def setUp(self):
        self.graph = Graph()
        self.result = None

    def tearDown(self) -> None:
        if self.result is not None:
            Dev.pprint(self.result)

    def test_add_edges(self):
        assert self.graph.add_edges([('a', 'b')]).edges() == [{
            'from': 'a',
            'label': None,
            'to': 'b'
        }]
        assert self.graph.add_edges([('a', 'b'),
                                     ('a', 'b', 'c')]).edges() == [{
                                         'from': 'a',
                                         'label': None,
                                         'to': 'b'
                                     }, {
                                         'from': 'a',
                                         'label': 'b',
                                         'to': 'c'
                                     }]

    def test_edges(self):
        self.graph.add_edge_with_label('key_1', 'an label', 'key_2')
        self.graph.add_edge('key_1', 'key_2', params={'a': 42})
        assert self.graph._edges == {
            'key_1__None__key_2': {
                'from': 'key_1',
                'label': None,
                'to': 'key_2',
                'params': {
                    'a': 42
                }
            },
            'key_1__an label__key_2': {
                'from': 'key_1',
                'label': 'an label',
                'to': 'key_2'
            }
        }

        assert self.graph.edges() == [{
            'from': 'key_1',
            'label': 'an label',
            'to': 'key_2'
        }, {
            'from': 'key_1',
            'label': None,
            'to': 'key_2',
            'params': {
                'a': 42
            }
        }]

        assert self.graph.edges(group_by='from') == {
            'key_1': [{
                'from': 'key_1',
                'label': 'an label',
                'to': 'key_2'
            }, {
                'from': 'key_1',
                'label': None,
                'params': {
                    'a': 42
                },
                'to': 'key_2'
            }]
        }

    def test_nodes(self):
        self.graph.add_node('key_1')
        self.graph.add_node('key_2', 'an value')
        self.graph.add_node('key_3', {'a:': 'an value'})

        assert self.graph._nodes == {
            'key_1': {
                'key': 'key_1',
                'value': 'key_1'
            },
            'key_2': {
                'key': 'key_2',
                'value': 'an value'
            },
            'key_3': {
                'a:': 'an value',
                'value': 'key_3',
                'key': 'key_3'
            }
        }

        assert self.graph.nodes() == [{
            'key': 'key_1',
            'value': 'key_1'
        }, {
            'key': 'key_2',
            'value': 'an value'
        }, {
            'a:': 'an value',
            'key': 'key_3',
            'value': 'key_3'
        }]

        assert self.graph.nodes(index_by='key') == self.graph._nodes
コード例 #6
0
ファイル: Sample_Graphs.py プロジェクト: filetrust/OSBot-jira
 def simple_dot_file():
     graph = Graph()
     graph.add_nodes(['a0','a1', 'a3', 'b2', 'b3','end'])
     graph.add_edges([('a1','b3'), ('b3','end'), ('b2','a3'), ('a3','end'), ('a3','a0')])
     return graph
コード例 #7
0
 def __init__(self, graph=None, graph_name='G', graph_type='digraph'):
     self.graph = graph or Graph()
     self.layout_engine = 'fdp'
     self.sub_graphs = []
     self.render = Graph_Dot_Render(self.graph, self.sub_graphs, graph_name,
                                    graph_type)
コード例 #8
0
 def graph(self):
     return Graph().add_nodes(self.nodes) \
                   .add_edges(self.edges)