Browse Source

python: distinguish OOB ID and OOB level in trade.AbstractImporter.

So when it fails, it's possible to know on which.
next
Vladimír Vondruš 3 years ago
parent
commit
551fd567f9
  1. 14
      src/python/magnum/test/test_trade.py
  2. 6
      src/python/magnum/trade.cpp

14
src/python/magnum/test/test_trade.py

@ -657,7 +657,7 @@ class Importer(unittest.TestCase):
importer.mesh_level_count(0)
with self.assertRaises(IndexError):
importer.mesh_name(0)
with self.assertRaises(IndexError):
with self.assertRaisesRegex(IndexError, "ID out of bounds"):
importer.mesh(0)
with self.assertRaises(IndexError):
@ -674,13 +674,13 @@ class Importer(unittest.TestCase):
with self.assertRaises(IndexError):
importer.image3d_name(0)
with self.assertRaises(IndexError):
with self.assertRaisesRegex(IndexError, "ID out of bounds"):
importer.image1d(0)
with self.assertRaises(IndexError):
with self.assertRaisesRegex(IndexError, "level out of bounds"):
importer.image2d(0, 1)
with self.assertRaises(IndexError):
with self.assertRaisesRegex(IndexError, "ID out of bounds"):
importer.image2d(1)
with self.assertRaises(IndexError):
with self.assertRaisesRegex(IndexError, "ID out of bounds"):
importer.image3d(0)
def test_open_failed(self):
@ -750,7 +750,7 @@ class Importer(unittest.TestCase):
importer = trade.ImporterManager().load_and_instantiate('GltfImporter')
importer.open_file(os.path.join(os.path.dirname(__file__), 'mesh.gltf'))
with self.assertRaises(IndexError):
with self.assertRaisesRegex(IndexError, "level out of bounds"):
importer.mesh('Non-indexed mesh', 1)
def test_mesh_failed(self):
@ -790,7 +790,7 @@ class Importer(unittest.TestCase):
importer = trade.ImporterManager().load_and_instantiate('StbImageImporter')
importer.open_file(os.path.join(os.path.dirname(__file__), 'rgb.png'))
with self.assertRaises(IndexError):
with self.assertRaisesRegex(IndexError, "level out of bounds"):
importer.image2d(0, 1)
def test_image2d_by_name(self):

6
src/python/magnum/trade.cpp

@ -329,12 +329,12 @@ template<class R, Containers::Optional<R>(Trade::AbstractImporter::*f)(UnsignedI
}
if(id >= (self.*bounds)()) {
PyErr_SetNone(PyExc_IndexError);
PyErr_SetString(PyExc_IndexError, "ID out of bounds");
throw py::error_already_set{};
}
if(level >= (self.*levelBounds)(id)) {
PyErr_SetNone(PyExc_IndexError);
PyErr_SetString(PyExc_IndexError, "level out of bounds");
throw py::error_already_set{};
}
@ -362,7 +362,7 @@ template<class R, Containers::Optional<R>(Trade::AbstractImporter::*f)(UnsignedI
}
if(level >= (self.*levelBounds)(id)) {
PyErr_SetNone(PyExc_IndexError);
PyErr_SetString(PyExc_IndexError, "level out of bounds");
throw py::error_already_set{};
}

Loading…
Cancel
Save