Пример #1
0
def fixture():
    no_args = node.Node()
    no_props = node.Node(node_id=1, alias="alias", label="l")
    props_only = node.Node(properties={"a": "a", "b": 10})
    no_label = node.Node(node_id=1, alias="alias", properties={"a": "a"})
    multi_label = node.Node(node_id=1, alias="alias", label=["l", "ll"])
    return no_args, no_props, props_only, no_label, multi_label
Пример #2
0
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))
Пример #3
0
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)
Пример #4
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 == ""
Пример #5
0
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})
Пример #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]
    )
Пример #7
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)
Пример #8
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()
Пример #9
0
def test_comparision(fixture):
    no_args, no_props, props_only, no_label, multi_label = fixture

    assert node.Node() == node.Node()
    assert node.Node(node_id=1) == node.Node(node_id=1)
    assert node.Node(node_id=1) != node.Node(node_id=2)
    assert node.Node(node_id=1, alias="a") == node.Node(node_id=1, alias="b")
    assert node.Node(node_id=1, alias="a") == node.Node(node_id=1, alias="a")
    assert node.Node(node_id=1, label="a") == node.Node(node_id=1, label="a")
    assert node.Node(node_id=1, label="a") != node.Node(node_id=1, label="b")
    assert node.Node(node_id=1, alias="a", label="l") == node.Node(
        node_id=1, alias="a", label="l"
    )
    assert node.Node(alias="a", label="l") != node.Node(alias="a", label="l1")
    assert node.Node(properties={"a": 10}) == node.Node(properties={"a": 10})
    assert node.Node() != node.Node(properties={"a": 10})