From 12950365e34cddfe2fd5fcbfc3cc2d3ed2ba974b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 29 Sep 2022 19:53:11 +0200 Subject: [PATCH] python: properly test trade.ImageData.data refcounting. Was tested for the Image/ImageView classes but not here. --- src/python/magnum/test/test_trade.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/python/magnum/test/test_trade.py b/src/python/magnum/test/test_trade.py index 61f0889..aaee76a 100644 --- a/src/python/magnum/test/test_trade.py +++ b/src/python/magnum/test/test_trade.py @@ -37,7 +37,9 @@ class ImageData(unittest.TestCase): # The only way to get an image instance is through a manager importer = trade.ImporterManager().load_and_instantiate('StbImageImporter') importer.open_file(os.path.join(os.path.dirname(__file__), "rgb.png")) + image = importer.image2d(0) + image_refcount = sys.getrefcount(image) self.assertFalse(image.is_compressed) self.assertEqual(image.storage.alignment, 1) # libPNG has 4 tho self.assertEqual(image.format, PixelFormat.RGB8_UNORM) @@ -47,6 +49,14 @@ class ImageData(unittest.TestCase): self.assertEqual(ord(image.pixels[1, 2, 2]), 181) self.assertEqual(ord(image.data[9 + 6 + 2]), 181) # libPNG has 12 + + data = image.data + self.assertEqual(len(data), 3*3*2) + self.assertIs(data.owner, image) + self.assertEqual(sys.getrefcount(image), image_refcount + 1) + + del data + self.assertEqual(sys.getrefcount(image), image_refcount) + def test_compressed(self): # The only way to get an image instance is through a manager importer = trade.ImporterManager().load_and_instantiate('DdsImporter')