def test_docnetdb_remove_place_affectation(tmp_path): """Test if the DocNetDB remove resets the place of a Vertex.""" db = DocNetDB(tmp_path / "db.db") vertex = Vertex() db.insert(vertex) db.remove(vertex) assert vertex.is_inserted is False
def test_docnetdb_remove_with_edges(tmp_path): """Test if the DocNetDB remove fails with vertices connected to edges.""" db = DocNetDB(tmp_path / "db.db") v1, v2 = Vertex(), Vertex() db.insert(v1) db.insert(v2) db.insert_edge(Edge(v1, v2)) with pytest.raises(ValueError): db.remove(v1)
def test_docnetdb_insert_always_increments(tmp_path): """Test if the DocNetDB insert always uses a new place. Even if vertices have been removed, a new place should always be used. """ db = DocNetDB(tmp_path / "db.db") vertices = [Vertex() for __ in range(5)] for vertex in vertices: db.insert(vertex) db.remove(vertices[4]) assert db.insert(vertices[4]) == 6
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
def test_docnetdb_remove(tmp_path): """Test if the DocNetD remove works properly. It should remove the vertex from the DocNetDB and return the correct place. """ db = DocNetDB(tmp_path / "db.db") vertex = Vertex() old_place = db.insert(vertex) assert db.remove(vertex) == old_place assert vertex not in db
def test_docnetdb_insert_edge_exception(tmp_path): """Test if the DocNetDB insert_edge raises exceptions. When vertices are not inserted in the database. """ db = DocNetDB(tmp_path / "db.db") wrong_db = DocNetDB(tmp_path / "Wrong.db") v1, v2 = Vertex(), Vertex() wrong_db.insert(v1) wrong_db.insert(v2) new_edge = Edge(v1, v2, label="", has_direction=False) with pytest.raises(VertexInsertionException): db.insert_edge(new_edge) wrong_db.remove(v1) wrong_db.remove(v2) db.insert(v1) db.insert(v2) db.insert_edge(new_edge)
def test_docnetdb_remove_parameter(tmp_path): """Test if the DocNetDB remove fails if the parameter is not a Vertex.""" db = DocNetDB(tmp_path / "db.db") with pytest.raises(TypeError): db.remove("this is not valid")
def test_docnetdb_remove_not_inserted_vertex(tmp_path): """Test if the DocNetDB remove refuses not inserted vertices.""" db = DocNetDB(tmp_path / "db.db") vertex = Vertex() with pytest.raises(VertexInsertionException): db.remove(vertex)