def test_stringify():
    john = node.Node(
        alias="a",
        label="person",
        properties={
            "name": "John Doe",
            "age": 33,
            "someArray": [1, 2, 3]
        },
    )
    japan = node.Node(alias="b", label="country", properties={"name": "Japan"})
    edge_with_relation = edge.Edge(john,
                                   "visited",
                                   japan,
                                   properties={"purpose": "pleasure"})
    assert ('(a:person{age:33,name:"John Doe",someArray:[1, 2, 3]})'
            '-[:visited{purpose:"pleasure"}]->'
            '(b:country{name:"Japan"})' == str(edge_with_relation))

    edge_no_relation_no_props = edge.Edge(japan, "", john)
    assert ('(b:country{name:"Japan"})'
            "-[]->"
            '(a:person{age:33,name:"John Doe",someArray:[1, 2, 3]})' == str(
                edge_no_relation_no_props))

    edge_only_props = edge.Edge(john, "", japan, properties={"a": "b", "c": 3})
    assert ('(a:person{age:33,name:"John Doe",someArray:[1, 2, 3]})'
            '-[{a:"b",c:3}]->'
            '(b:country{name:"Japan"})' == str(edge_only_props))
def test_init():

    with pytest.raises(AssertionError):
        edge.Edge(None, None, None)
        edge.Edge(node.Node(), None, None)
        edge.Edge(None, None, node.Node())

    assert isinstance(
        edge.Edge(node.Node(node_id=1), None, node.Node(node_id=2)), edge.Edge)
Example #3
0
def test_to_string():
    props_result = edge.Edge(
        node.Node(), None, node.Node(), properties={"a": "a", "b": 10}
    ).to_string()
    assert props_result == '{a:"a",b:10}'

    no_props_result = edge.Edge(
        node.Node(), None, node.Node(), properties={}
    ).to_string()
    assert no_props_result == ""
Example #4
0
def test_wrong_flows():
    node_1 = node.Node(node_id=1)
    node_2 = node.Node(node_id=2)
    node_3 = node.Node(node_id=3)

    edge_1 = edge.Edge(node_1, None, node_2)
    edge_2 = edge.Edge(node_1, None, node_3)

    p = path.Path.new_empty_path()
    with pytest.raises(AssertionError):
        p.add_edge(edge_1)

    p.add_node(node_1)
    with pytest.raises(AssertionError):
        p.add_node(node_2)

    p.add_edge(edge_1)
    with pytest.raises(AssertionError):
        p.add_edge(edge_2)
def test_comparision():
    node1 = node.Node(node_id=1)
    node2 = node.Node(node_id=2)
    node3 = node.Node(node_id=3)

    edge1 = edge.Edge(node1, None, node2)
    assert edge1 == edge.Edge(node1, None, node2)
    assert edge1 != edge.Edge(node1, "bla", node2)
    assert edge1 != edge.Edge(node1, None, node3)
    assert edge1 != edge.Edge(node3, None, node2)
    assert edge1 != edge.Edge(node2, None, node1)
    assert edge1 != edge.Edge(node1, None, node2, properties={"a": 10})
Example #6
0
def test_compare():
    node_1 = node.Node(node_id=1)
    node_2 = node.Node(node_id=2)
    edge_1 = edge.Edge(node_1, None, node_2)

    assert path.Path.new_empty_path() == path.Path.new_empty_path()
    assert path.Path(nodes=[node_1, node_2], edges=[edge_1]) == path.Path(
        nodes=[node_1, node_2], edges=[edge_1]
    )
    assert path.Path(nodes=[node_1], edges=[]) != path.Path(nodes=[], edges=[])
    assert path.Path(nodes=[node_1], edges=[]) != path.Path(nodes=[], edges=[])
    assert path.Path(nodes=[node_1], edges=[]) != path.Path(nodes=[node_2], edges=[])
    assert path.Path(nodes=[node_1], edges=[edge_1]) != path.Path(
        nodes=[node_1], edges=[]
    )
    assert path.Path(nodes=[node_1], edges=[edge_1]) != path.Path(
        nodes=[node_2], edges=[edge_1]
    )
Example #7
0
def test_nodes_and_edges():
    node_1 = node.Node(node_id=1)
    node_2 = node.Node(node_id=2)
    edge_1 = edge.Edge(node_1, None, node_2)

    p = path.Path.new_empty_path()
    assert p.nodes() == []
    p.add_node(node_1)
    assert [] == p.edges()
    assert 0 == p.edge_count()
    assert [node_1] == p.nodes()
    assert node_1 == p.get_node(0)
    assert node_1 == p.first_node()
    assert node_1 == p.last_node()
    assert 1 == p.nodes_count()
    p.add_edge(edge_1)
    assert [edge_1] == p.edges()
    assert 1 == p.edge_count()
    assert edge_1 == p.get_relationship(0)
    p.add_node(node_2)
    assert [node_1, node_2] == p.nodes()
    assert node_1 == p.first_node()
    assert node_2 == p.last_node()
    assert 2 == p.nodes_count()