예제 #1
0
def test_docnetdb_init_with_nothing(tmp_path):
    """Test if the DocNetDB init doesn't create vertices or edges.

    If there's no file.
    """
    path = tmp_path / "not_existing_file.db"
    db = DocNetDB(path)
    assert len(db) == 0
    assert len(list(db.edges())) == 0
예제 #2
0
def test_colorededge_load(db_2_vertices):
    """Test if this Edge keeps its type when saved and loaded."""
    db, v1, v2 = db_2_vertices
    path = db.path
    edge = ColoredEdge(v1, v2, color="blue")
    db.insert_edge(edge)
    db.save()

    db2 = DocNetDB(path, edge_creation_callable=ColoredEdge.from_pack)
    edge = next(db2.edges())
    assert isinstance(edge, ColoredEdge)
    assert edge.color == "blue"
    assert edge.start is db2[1]
    assert edge.end is db2[2]
예제 #3
0
def test_docnetdb_edges(tmp_path):
    """Test if the DocNetDB edges method returns all the contained edges.

    In an Iterable.
    """
    db = DocNetDB(tmp_path / "db.db")
    db.insert(Vertex())
    db.insert(Vertex())
    db.insert(Vertex())
    db.insert_edge(Edge(db[1], db[2]))
    db.insert_edge(Edge(db[2], db[3]))

    edges = db.edges()

    # Test if the type is right
    assert isinstance(edges, Iterator) is True

    # Test if the content is right
    assert list(edges) == [Edge(db[1], db[2]), Edge(db[2], db[3])]