Example #1
0
def test_docnetdb_load_place_reset(tmp_path):
    """Test if the DocNetDB load with a blank file reset _next_place."""
    db = DocNetDB(tmp_path / "db1.db")
    for __ in range(3):
        db.insert(Vertex())
    db.save()

    db.path = tmp_path / "db2.db"
    db.load()
    assert db.insert(Vertex()) == 1
Example #2
0
def test_docnetdb_load_place(tmp_path):
    """Test if the DocNetDB load restores the state of used places."""
    path = tmp_path / "db.db"
    db1 = DocNetDB(path)
    vertex1 = Vertex()
    db1.insert(vertex1)
    db1.remove(vertex1)
    db1.save()

    db2 = DocNetDB(path)
    assert db2.insert(Vertex()) == 2
Example #3
0
def test_intlistvertex_load(tmp_path):
    """Test if this Vertex keeps its type when saved and loaded."""
    db = DocNetDB(tmp_path / "db.db")
    v = IntListVertex()
    v.append(12)
    db.insert(v)
    db.save()

    db2 = DocNetDB(tmp_path / "db.db",
                   vertex_creation_callable=IntListVertex.from_pack)
    assert isinstance(db2[1], IntListVertex)
    assert db2[1].list == [12]
Example #4
0
def test_docnetdb_load_vertices(tmp_path):
    """Test if the DocNetDB load restores all the vertices in the object."""
    path = tmp_path / "db.db"
    db1 = DocNetDB(path)
    music_names = ["Prologue", "First Steps", "Resurrections"]
    for name in music_names:
        db1.insert(Vertex({"name": name}))
    db1.save()

    db2 = DocNetDB(path)
    assert len(db1) == len(db2)
    for vertex, target_name in zip(db2.vertices(), music_names):
        assert vertex["name"] == target_name
Example #5
0
def test_intlistvertex_from_pack(tmp_path):
    """Test if the from_pack method raises a ValueError."""
    db = DocNetDB(tmp_path / "db.db")
    v = ListVertex()
    v.append("not OK")
    db.insert(v)
    db.save()

    with pytest.raises(ValueError):
        db2 = DocNetDB(
            tmp_path / "db.db",
            vertex_creation_callable=IntListVertex.from_pack,
        )
        del db2
Example #6
0
def test_docnetdb_load_edges(tmp_path):
    """Test if the DocNetDB load restores all the edges in the object."""
    path = tmp_path / "db.db"
    db1 = DocNetDB(path)
    v1, v2, v3 = Vertex(), Vertex(), Vertex()
    db1.insert(v1)
    db1.insert(v2)
    db1.insert(v3)
    db1.insert_edge(Edge(v1, v2, "edge1", False))
    db1.insert_edge(Edge(v3, v2, "edge2", True))
    db1.save()

    db2 = DocNetDB(path)
    assert list(db2.search_edge(db2[2])) == [
        Edge(db2[1], db2[2], "edge1", False),
        Edge(db2[3], db2[2], "edge2", True),
    ]
Example #7
0
def test_docnetdb_load_no_duplication(tmp_path):
    """Test if calling DocNetDB load two times doesn't duplicate anything.

    Like the vertices or the edges.
    """
    path = tmp_path / "db.db"
    db1 = DocNetDB(path)
    v1, v2 = Vertex(), Vertex()
    db1.insert(v1)
    db1.insert(v2)
    db1.insert_edge(Edge(v1, v2, "my_edge", True))
    db1.save()

    # The file is loaded into the same database.
    db1.load()

    assert len(db1) == 2
    assert len(list(db1.search_edge(db1[1]))) == 1
Example #8
0
def test_docnetdb_save_with_subfolder(tmp_path):
    """Test if the DocNetDB save creates non-existing subfolders."""
    path = tmp_path / "subfolder" / "db.db"
    db = DocNetDB(path)
    db.save()
    assert path.exists() is True
Example #9
0
def test_docnetdb_save_file_creation(tmp_path):
    """Test if the DocNetDB save creates a file."""
    path = tmp_path / "file.db"
    db = DocNetDB(path)
    db.save()
    assert path.exists() is True