Ejemplo n.º 1
0
def _setup_connected(g: Graph):
    n1 = Node(value="ABC")
    n2 = Node(value="BCD")
    g.upsert_node(n1)
    g.upsert_node(n2)
    e = Edge(src="ABC", tgt="BCD", edge_value=0)
    g.add_edge(e)
    g.save()
Ejemplo n.º 2
0
def test_graph_basics_nodes(g: Graph):
    expected = ["ABC", "BCE", "CEF"]
    expected = set(Node(value=v) for v in expected)
    for node in expected:
        g.upsert_node(node)
    # We assume the backing store might change ordering and only care for the
    # node values
    assert set(n.value for n in g.nodes) == set(ne.value for ne in expected)
Ejemplo n.º 3
0
def _setup_connected_distant(g: Graph):
    n1 = Node(value="ABC")
    n2 = Node(value="BCD")
    n3 = Node(value="CDE")
    g.upsert_node(n1)
    g.upsert_node(n2)
    g.upsert_node(n3)
    e1 = Edge(src="ABC", tgt="BCD", edge_value=0)
    g.add_edge(e1)
    e2 = Edge(src="BCD", tgt="CDE", edge_value=1)
    g.add_edge(e2)
    g.save()
Ejemplo n.º 4
0
def _setup_connected_shortcut(g: Graph):
    n1 = Node(value="ABC")
    n2 = Node(value="BCD")
    n3 = Node(value="CDE")
    g.upsert_node(n1)
    g.upsert_node(n2)
    g.upsert_node(n3)
    e1 = Edge(src="ABC", tgt="BCD", edge_type="path1", edge_value=0)
    g.add_edge(e1)
    e2 = Edge(src="BCD", tgt="CDE", edge_type="path1", edge_value=1)
    g.add_edge(e2)
    e1_short = Edge(src="ABC", tgt="CDE", edge_type="path2", edge_value=0)
    g.add_edge(e1_short)
    g.save()
Ejemplo n.º 5
0
def test_graph_connected_repeats_one_middle_path(g: Graph):
    n1 = Node(value="ABC")
    n2 = Node(value="BCD")
    n3 = Node(value="CDE")
    g.upsert_node(n1)
    g.upsert_node(n2)
    g.upsert_node(n3)
    e1 = Edge(src="ABC", tgt="BCD", edge_value=0)
    g.add_edge(e1)
    e2 = Edge(src="BCD", tgt="BCD", edge_value=1)
    g.add_edge(e2)
    e3 = Edge(src="BCD", tgt="CDE", edge_value=2)
    g.add_edge(e3)
    g.save()

    paths, _ = g.path('ABC', 'CDE')
    assert len(paths) == 1
Ejemplo n.º 6
0
def test_graph_connected_repeats_full_path(g: Graph):
    n1 = Node(value="ABC")
    n2 = Node(value="BCD")
    n3 = Node(value="CDE")
    g.upsert_node(n1)
    g.upsert_node(n2)
    g.upsert_node(n3)
    e1 = Edge(src="ABC", tgt="BCD", edge_value=0)
    g.add_edge(e1)
    e2 = Edge(src="BCD", tgt="CDE", edge_value=1)
    g.add_edge(e2)
    e3 = Edge(src="CDE", tgt="ABC", edge_value=2)
    g.add_edge(e3)
    e4 = Edge(src="ABC", tgt="BCD", edge_value=3)
    g.add_edge(e4)
    e5 = Edge(src="BCD", tgt="CDE", edge_value=4)
    g.add_edge(e5)
    g.save()

    try:
        paths, _ = g.path('ABC', 'CDE')
    except:
        raise GraphException(g)

    assert len(paths) == 3

    c = 0
    for path in paths:
        assert path[0].value == "ABC"
        assert path[-1].value == "CDE"
        if len(path) == 3:
            assert path[1].value == "BCD"
            # There are 2 copies of this
            c += 1
        elif len(path) == 6:
            assert path[1].value == "BCD"
            assert path[2].value == "CDE"
            assert path[3].value == "ABC"
            assert path[4].value == "BCD"
            assert path[5].value == "CDE"

    assert c == 2
Ejemplo n.º 7
0
def test_graph_node_labels(g: Graph):
    # TODO: we dont support node labels yet for our Dgraph backend
    if isinstance(g, Dgraph):
        return
    expected = [
        Node(value="ABC", labels={"species": "dog"}),
        Node(value="BCE", labels={"species": "cat"})
    ]
    for node in expected:
        g.upsert_node(node)

    assert len(g.nodes) == 2

    for node in g.nodes:
        if node.value == "ABC":
            assert node.labels == expected[0].labels
        elif node.value == "BCE":
            assert node.labels == expected[1].labels
        else:
            # Something went wrong
            assert False
Ejemplo n.º 8
0
def _setup_connected_multiple(g: Graph):
    n1 = Node(value="ABC")
    n2 = Node(value="BCD")
    n2_alt = Node(value="XYZ")
    n3 = Node(value="CDE")
    g.upsert_node(n1)
    g.upsert_node(n2)
    g.upsert_node(n3)
    g.upsert_node(n2_alt)
    e1 = Edge(src="ABC", tgt="BCD", edge_type="path1", edge_value=0)
    g.add_edge(e1)
    e2 = Edge(src="BCD", tgt="CDE", edge_type="path1", edge_value=1)
    g.add_edge(e2)
    e1_alt = Edge(src="ABC", tgt="XYZ", edge_type="path2", edge_value=0)
    g.add_edge(e1_alt)
    e2_alt = Edge(src="XYZ", tgt="CDE", edge_type="path2", edge_value=1)
    g.add_edge(e2_alt)
    g.save()
Ejemplo n.º 9
0
def _setup_connected_no_node(g: Graph):
    n1 = Node(value="ABC")
    g.upsert_node(n1)
    g.save()
Ejemplo n.º 10
0
def _setup_not_connected(g: Graph):
    n1 = Node(value="ABC")
    n2 = Node(value="BCD")
    g.upsert_node(n1)
    g.upsert_node(n2)
    g.save()