Commit 033e7b5e authored by Alexander Dielen's avatar Alexander Dielen

throw exception if read_mesh() fails

parent 9b40bddc
......@@ -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();
......
......@@ -135,6 +135,12 @@ class ReadWriteOBJ(unittest.TestCase):
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)
......
......@@ -133,6 +133,12 @@ class ReadWriteOFF(unittest.TestCase):
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)
......
......@@ -158,6 +158,12 @@ class ReadWriteOM(unittest.TestCase):
# 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)
......
......@@ -249,6 +249,12 @@ class ReadWritePLY(unittest.TestCase):
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)
......
......@@ -44,6 +44,12 @@ class ReadWriteSTL(unittest.TestCase):
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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment