From f59d8bb9b642ccc68cb8d242a8147ebd49e71e13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 9 Feb 2023 00:17:58 +0100 Subject: [PATCH] python: test trade.AbstractImporter.image2d() by name. And a failure of the by-name API. --- src/python/magnum/test/image.gltf | 15 +++++++++++++++ src/python/magnum/test/test_trade.py | 22 ++++++++++++++++++---- 2 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 src/python/magnum/test/image.gltf diff --git a/src/python/magnum/test/image.gltf b/src/python/magnum/test/image.gltf new file mode 100644 index 0000000..4190e09 --- /dev/null +++ b/src/python/magnum/test/image.gltf @@ -0,0 +1,15 @@ +{ + "asset": { + "version": "2.0" + }, + "images": [ + { + "uri": "nonexistent.foo", + "name": "A broken image" + }, + { + "uri": "rgb.png", + "name": "A named image" + } + ] +} diff --git a/src/python/magnum/test/test_trade.py b/src/python/magnum/test/test_trade.py index 9ad9a45..42173a9 100644 --- a/src/python/magnum/test/test_trade.py +++ b/src/python/magnum/test/test_trade.py @@ -785,8 +785,6 @@ class Importer(unittest.TestCase): del importer self.assertEqual(sys.getrefcount(manager), manager_refcount) - # TODO image by name (in some gltf?) - def test_image_level_oob(self): # importer refcounting tested in image2d importer = trade.ImporterManager().load_and_instantiate('StbImageImporter') @@ -795,6 +793,20 @@ class Importer(unittest.TestCase): with self.assertRaises(IndexError): importer.image2d(0, 1) + def test_image2d_by_name(self): + importer = trade.ImporterManager().load_and_instantiate('GltfImporter') + importer.open_file(os.path.join(os.path.dirname(__file__), 'image.gltf')) + + image = importer.image2d('A named image') + self.assertEqual(image.size, Vector2i(3, 2)) + + def test_image2d_by_name_not_found(self): + importer = trade.ImporterManager().load_and_instantiate('GltfImporter') + importer.open_file(os.path.join(os.path.dirname(__file__), 'image.gltf')) + + with self.assertRaises(KeyError): + importer.image2d('Nonexistent') + def test_image2d_data(self): importer = trade.ImporterManager().load_and_instantiate('StbImageImporter') @@ -805,11 +817,13 @@ class Importer(unittest.TestCase): self.assertEqual(image.size, Vector2i(3, 2)) def test_image2d_failed(self): - importer = trade.ImporterManager().load_and_instantiate('StbImageImporter') - importer.open_data(b'bla') + importer = trade.ImporterManager().load_and_instantiate('GltfImporter') + importer.open_file(os.path.join(os.path.dirname(__file__), 'image.gltf')) with self.assertRaisesRegex(RuntimeError, "import failed"): importer.image2d(0) + with self.assertRaisesRegex(RuntimeError, "import failed"): + importer.image2d('A broken image') class ImageConverter(unittest.TestCase): def test_image2d(self):