Skip to content

Commit

Permalink
throw exception if read_mesh() fails
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Dielen committed Mar 26, 2018
1 parent 9b40bdd commit 033e7b5
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/InputOutput.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,13 @@ void def_read_mesh(py::module& m, const char *_name) {
if (_color_alpha) options += OM::IO::Options::ColorAlpha;
if (_color_float) options += OM::IO::Options::ColorFloat;

OM::IO::read_mesh(mesh,_filename, options);
const bool ok = OM::IO::read_mesh(mesh,_filename, options);

if (!ok) {
const std::string msg = "File could not be read: " + _filename;
PyErr_SetString(PyExc_RuntimeError, msg.c_str());
throw py::error_already_set();
}
if (_vertex_normal && !options.vertex_has_normal()) {
PyErr_SetString(PyExc_RuntimeError, "Vertex normals could not be read.");
throw py::error_already_set();
Expand Down
6 changes: 6 additions & 0 deletions tests/test_read_write_obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ def test_load_simple_obj_with_vertex_colors_as_vc_lines(self):

self.mesh.release_vertex_colors()

def test_read_nonexistent_obj(self):
with self.assertRaises(RuntimeError):
self.mesh = openmesh.read_trimesh("TestFiles/nonexistent.obj")
with self.assertRaises(RuntimeError):
self.mesh = openmesh.read_polymesh("TestFiles/nonexistent.obj")


if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(ReadWriteOBJ)
Expand Down
6 changes: 6 additions & 0 deletions tests/test_read_write_off.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ def test_write_and_read_binary_float_vertex_colors_to_and_from_off_file(self):

self.mesh.release_vertex_colors()

def test_read_nonexistent_off(self):
with self.assertRaises(RuntimeError):
self.mesh = openmesh.read_trimesh("TestFiles/nonexistent.off")
with self.assertRaises(RuntimeError):
self.mesh = openmesh.read_polymesh("TestFiles/nonexistent.off")


if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(ReadWriteOFF)
Expand Down
6 changes: 6 additions & 0 deletions tests/test_read_write_om.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ def test_write_triangle_vertex_integer_color(self):

# TODO property tests

def test_read_nonexistent_om(self):
with self.assertRaises(RuntimeError):
self.mesh = openmesh.read_trimesh("TestFiles/nonexistent.om")
with self.assertRaises(RuntimeError):
self.mesh = openmesh.read_polymesh("TestFiles/nonexistent.om")


if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(ReadWriteOM)
Expand Down
6 changes: 6 additions & 0 deletions tests/test_read_write_ply.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,12 @@ def test_load_simple_ply_with_normals(self):

self.mesh.release_vertex_normals()

def test_read_nonexistent_ply(self):
with self.assertRaises(RuntimeError):
self.mesh = openmesh.read_trimesh("TestFiles/nonexistent.ply")
with self.assertRaises(RuntimeError):
self.mesh = openmesh.read_polymesh("TestFiles/nonexistent.ply")


if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(ReadWritePLY)
Expand Down
6 changes: 6 additions & 0 deletions tests/test_read_write_stl.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ def test_load_simple_stl_binary_file_with_normals(self):

self.mesh.release_face_normals()

def test_read_nonexistent_stl(self):
with self.assertRaises(RuntimeError):
self.mesh = openmesh.read_trimesh("TestFiles/nonexistent.stl")
with self.assertRaises(RuntimeError):
self.mesh = openmesh.read_polymesh("TestFiles/nonexistent.stl")


if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(ReadWriteSTL)
Expand Down

0 comments on commit 033e7b5

Please sign in to comment.