Browse Source

python: test trade.AbstractImporter.image2d() by name.

And a failure of the by-name API.
next
Vladimír Vondruš 3 years ago
parent
commit
f59d8bb9b6
  1. 15
      src/python/magnum/test/image.gltf
  2. 22
      src/python/magnum/test/test_trade.py

15
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"
}
]
}

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

@ -785,8 +785,6 @@ class Importer(unittest.TestCase):
del importer del importer
self.assertEqual(sys.getrefcount(manager), manager_refcount) self.assertEqual(sys.getrefcount(manager), manager_refcount)
# TODO image by name (in some gltf?)
def test_image_level_oob(self): def test_image_level_oob(self):
# importer refcounting tested in image2d # importer refcounting tested in image2d
importer = trade.ImporterManager().load_and_instantiate('StbImageImporter') importer = trade.ImporterManager().load_and_instantiate('StbImageImporter')
@ -795,6 +793,20 @@ class Importer(unittest.TestCase):
with self.assertRaises(IndexError): with self.assertRaises(IndexError):
importer.image2d(0, 1) 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): def test_image2d_data(self):
importer = trade.ImporterManager().load_and_instantiate('StbImageImporter') importer = trade.ImporterManager().load_and_instantiate('StbImageImporter')
@ -805,11 +817,13 @@ class Importer(unittest.TestCase):
self.assertEqual(image.size, Vector2i(3, 2)) self.assertEqual(image.size, Vector2i(3, 2))
def test_image2d_failed(self): def test_image2d_failed(self):
importer = trade.ImporterManager().load_and_instantiate('StbImageImporter') importer = trade.ImporterManager().load_and_instantiate('GltfImporter')
importer.open_data(b'bla') importer.open_file(os.path.join(os.path.dirname(__file__), 'image.gltf'))
with self.assertRaisesRegex(RuntimeError, "import failed"): with self.assertRaisesRegex(RuntimeError, "import failed"):
importer.image2d(0) importer.image2d(0)
with self.assertRaisesRegex(RuntimeError, "import failed"):
importer.image2d('A broken image')
class ImageConverter(unittest.TestCase): class ImageConverter(unittest.TestCase):
def test_image2d(self): def test_image2d(self):

Loading…
Cancel
Save