Пример #1
0
def test_channel_segment_add_upstream_node():
    segment = ChannelSegment([0, 1])
    upstream = ChannelSegment([5, 6])
    assert len(segment.upstream) == 0
    assert upstream.downstream is None

    segment.add_upstream(upstream)

    assert upstream in segment.upstream
    assert upstream.downstream is segment
Пример #2
0
def test_reindex_segment_nodes_with_downstream(nodes, last_node):
    root = ChannelSegment([0, 1])
    segment = ChannelSegment(nodes)
    root.add_upstream(segment)

    reindex = SegmentNodeReindexer(nodes=[last_node])
    reindex(segment)

    assert segment.nodes[0] == root.nodes[-1]
    assert segment.nodes[1:] == list(range(last_node + 1, last_node + len(nodes)))
Пример #3
0
def test_create_links_with_downstream(nodes):
    root = ChannelSegment([0, 1])
    segment = ChannelSegment(nodes)
    root.add_upstream(segment)

    collect_links = SegmentLinkCollector()
    collect_links(segment)
    links = collect_links.links

    assert len(links) == len(segment) - 1
    assert links[0] == (root.nodes[-1], segment.nodes[1])

    if len(links) > 1:
        heads, tails = zip(*links[1:])
        assert list(heads) == nodes[1:-1]
        assert list(tails) == nodes[2:]