Ejemplo n.º 1
0
    def test_argument_unaltered(self):
        match = nx.MultiDiGraph()
        match.add_node('a')
        mapping = {1: 'a'}
        replacement = nx.MultiDiGraph()
        replacement.add_nodes_from([1, 2])
        expected = (len(GRAPH), len(GRAPH.edges()))

        replace_subgraph(GRAPH, match, mapping, replacement)
        result = (len(GRAPH), len(GRAPH.edges()))

        self.assertEqual(expected, result)
Ejemplo n.º 2
0
    def test_empty_replace(self):
        match = nx.MultiDiGraph()
        mapping = {}
        replacement = nx.MultiDiGraph()

        result = replace_subgraph(GRAPH, match, mapping, replacement)

        self.assertGraphEqual(GRAPH, result)
Ejemplo n.º 3
0
    def test_remove_node(self):
        match = nx.MultiDiGraph()
        match.add_node('a')
        mapping = {1: 'a'}
        replacement = nx.MultiDiGraph()

        result = replace_subgraph(GRAPH, match, mapping, replacement)
        expected = nx.MultiDiGraph()
        expected.add_node('b')

        self.assertGraphEqual(expected, result)
Ejemplo n.º 4
0
    def test_remove_edge(self):
        match = nx.MultiDiGraph()
        match.add_edge('a', 'b', key='s')
        mapping = {1: 'a', 2: 'b'}
        replacement = nx.MultiDiGraph()
        replacement.add_nodes_from([1, 2])

        result = replace_subgraph(GRAPH, match, mapping, replacement)
        expected = nx.MultiDiGraph()
        expected.add_edge('a', 'b', key='t')

        self.assertGraphEqual(expected, result)
Ejemplo n.º 5
0
    def test_add_identity_edge(self):
        match = nx.MultiDiGraph()
        match.add_node('a')
        mapping = {1: 'a'}
        replacement = nx.MultiDiGraph()
        replacement.add_edge(1, 1, key='id')

        result = replace_subgraph(GRAPH, match, mapping, replacement)
        expected = nx.MultiDiGraph()
        expected.add_edge('a', 'b', key='s')
        expected.add_edge('a', 'b', key='t')
        expected.add_edge('a', 'a', key='id')

        self.assertGraphEqual(expected, result)
Ejemplo n.º 6
0
    def test_add_node_and_edge(self):
        match = nx.MultiDiGraph()
        match.add_node('a')
        mapping = {1: 'a'}
        replacement = nx.MultiDiGraph()
        replacement.add_edge(2, 1, key='u')

        result = replace_subgraph(GRAPH, match, mapping, replacement)
        expected = nx.MultiDiGraph()
        expected.add_edge('a', 'b', key='s')
        expected.add_edge('a', 'b', key='t')
        expected.add_edge(MockSymbol(), 'a', key='u')

        self.assertSymbolGraphEqual(expected, result)
Ejemplo n.º 7
0
def _apply_expression_substitutions(graph, expression, substitutions):
    for subgraph, mapping in find_all_subgraphs(graph, expression):
        for substitution in substitutions:
            yield replace_subgraph(graph, subgraph, mapping, substitution)