示例#1
0
def test_path_deserialisation():
    db = Memgraph()
    db.execute("create (:Person {id: 1, name: 'person'});")
    db.execute("create (:Alice {id: 8, name: 'alice'});")
    db.execute("match (a:Alice) match(b:Person) create (a)-[:FRIENDS]->(b);")
    result = list(db.execute_and_fetch("MATCH p = ()-[*1]-() RETURN p"))
    path = result[0]["p"]
    assert isinstance(path, Path)
    assert len(path._nodes) == 2
    assert len(path._relationships) == 1
    db.drop_database()
示例#2
0
def populated_memgraph(dataset_file: str) -> Memgraph:
    memgraph = Memgraph()
    memgraph.ensure_indexes([])
    memgraph.ensure_constraints([])
    memgraph.drop_database()
    with get_data_dir().joinpath(dataset_file).open("r") as dataset:
        for query in dataset:
            memgraph.execute(query)

    yield memgraph

    memgraph.drop_database()
示例#3
0
def test_automatic_deserialisation_from_database():
    db = Memgraph()

    db.execute("create (:Person {id: 1, name: 'person'});")
    db.execute("create (:Alice {id: 8, name: 'alice'});")
    db.execute("match (a:Alice) match(b:Person) create (a)-[:FRIENDS]->(b);")

    result = list(db.execute_and_fetch("match (a)-[r]->(b) return a, r, b"))
    for node in result:
        a = node["a"]
        assert isinstance(a, Alice)
        assert a.id == 8
        assert a.name == "alice"
        assert a._node_labels == {"Alice"}
        assert isinstance(a._node_id, int)
        assert a._properties == {"id": 8, "name": "alice"}
        assert isinstance(a._id, int)

        r = node["r"]
        assert isinstance(r, Friends)
        assert r._type == "FRIENDS"
        assert isinstance(r._relationship_id, int)
        assert isinstance(r._start_node_id, int)
        assert isinstance(r._end_node_id, int)
        assert r._properties == {}
        assert isinstance(r._id, int)

        b = node["b"]
        assert isinstance(b, Person)
        assert b.id == 1
        assert b.name == "person"
        assert b._node_labels == {"Person"}
        assert isinstance(b._node_id, int)
        assert b._properties == {"id": 1, "name": "person"}
        assert isinstance(b._id, int)

    db.drop_database()
示例#4
0
def clear_db():
    db = Memgraph()
    db.drop_database()
    on_disk_db = SQLitePropertyDatabase("./tests/on_disk_storage.db")
    on_disk_db.drop_database()
示例#5
0
def clear_db():
    db = Memgraph()
    db.drop_database()
示例#6
0
def memgraph() -> Memgraph:
    memgraph = Memgraph()
    memgraph.ensure_indexes([])
    memgraph.ensure_constraints([])
    memgraph.drop_database()
    return memgraph