Exemplo n.º 1
0
def test_remove_node():
    G = LayeredGraph()
    G.add_edges_from([('a', 'b'), ('a', 'c'), ('b', 'd')])
    G.ordering = Ordering([['a'], ['b', 'c'], ['d']])
    assert sorted(G.nodes()) == ['a', 'b', 'c', 'd']

    G.remove_node('c')
    assert sorted(G.nodes()) == ['a', 'b', 'd']
    assert G.ordering == Ordering([['a'], ['b'], ['d']])
Exemplo n.º 2
0
def test_dummy_nodes_merge_bundles():
    G = LayeredGraph()
    G.add_node('a', node=ProcessGroup())
    G.add_node('b', node=ProcessGroup())
    G.ordering = Ordering([[['a']], [['b']]])

    G = add_dummy_nodes(G, 'a', 'b', bundle_key=1)
    assert G['a']['b']['bundles'] == [1]

    G = add_dummy_nodes(G, 'a', 'b', bundle_key=2)
    assert G['a']['b']['bundles'] == [1, 2]

    assert set(G.nodes()) == {'a', 'b'}
    assert set(G.edges()) == {('a', 'b')}
    assert G.ordering == Ordering([[['a']], [['b']]])
def test_augment_waypoint_alignment():
    # j -- a -- x
    #      b
    # k -- c -- y
    #
    # should insert "from b" betwen x and y
    # and "to b" between j and k
    G = LayeredGraph()
    G.add_nodes_from([
        ('a', {'node': ProcessGroup()}),
        ('b', {'node': ProcessGroup(selection=['b1'])}),
        ('c', {'node': ProcessGroup()}),
        ('x', {'node': ProcessGroup()}),
        ('y', {'node': ProcessGroup()}),
        ('j', {'node': ProcessGroup()}),
        ('k', {'node': ProcessGroup()}),
    ])
    G.add_edges_from([
        ('a', 'x', {'bundles': [2]}),
        ('k', 'c', {'bundles': [1]}),
        ('j', 'a', {'bundles': [0]}),
        ('c', 'y', {'bundles': [3]}),
    ])
    G.ordering = Ordering([[['j', 'k']], [['a', 'b', 'c']], [['x', 'y']]])

    new_waypoints = {
        'from b': Waypoint(),
        'to b': Waypoint(),
    }
    new_bundles = {
        'b>': Bundle('b', Elsewhere, waypoints=['from b']),
        '>b': Bundle(Elsewhere, 'b', waypoints=['to b']),
    }

    G2 = augment(G, new_waypoints, new_bundles)

    assert set(G2.nodes()).difference(G.nodes()) == {'from b', 'to b'}
    assert G2.ordering == Ordering([
        [['j', 'to b', 'k']], [['a', 'b', 'c']], [['x', 'from b', 'y']]
    ])