From 4ae645c54b020fd4e7d6c23dd260cc534c34e336 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 3 May 2025 21:42:34 +0200 Subject: [PATCH] python: properly test text.AbstractFont.fill_glyph_cache(). It *is* possible to test this, so why it is not? --- src/python/magnum/test/test_text.py | 4 ++-- src/python/magnum/test/test_text_gl.py | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/python/magnum/test/test_text.py b/src/python/magnum/test/test_text.py index f441eca..9c19962 100644 --- a/src/python/magnum/test/test_text.py +++ b/src/python/magnum/test/test_text.py @@ -66,8 +66,8 @@ class Font(unittest.TestCase): font.glyph_size(0) with self.assertRaisesRegex(AssertionError, "no file opened"): font.glyph_advance(0) - # fill_glyph_cache() not tested as it needs a GL context; assuming it's - # correct + # fill_glyph_cache() not tested as it needs a GL context; verified in + # test_text_gl instead def test_open_failed(self): font = text.FontManager().load_and_instantiate('StbTrueTypeFont') diff --git a/src/python/magnum/test/test_text_gl.py b/src/python/magnum/test/test_text_gl.py index 09e205b..b6e6d7e 100644 --- a/src/python/magnum/test/test_text_gl.py +++ b/src/python/magnum/test/test_text_gl.py @@ -63,6 +63,26 @@ class GlyphCacheGL(GLTestCase): cache = text.GlyphCacheGL(PixelFormat.R8_UNORM, (128, 128)) self.assertEqual(cache.padding, (1, 1)) + def test_fill(self): + # Tested here and not in test_text.Font as the AbstractGlyphCache base + # isn't instantiable + cache = text.GlyphCacheGL(PixelFormat.R8_UNORM, (128, 128)) + font = text.FontManager().load_and_instantiate('StbTrueTypeFont') + + font.open_file(os.path.join(os.path.dirname(__file__), 'Oxygen.ttf'), 16.0) + self.assertTrue(font.is_opened) + self.assertTrue(font.fill_glyph_cache(cache, "abcd")) + + def test_fill_no_file_opened(self): + # Tested here and not in test_text.Font as the AbstractGlyphCache base + # isn't instantiable + cache = text.GlyphCacheGL(PixelFormat.R8_UNORM, (128, 128)) + font = text.FontManager().load_and_instantiate('StbTrueTypeFont') + self.assertFalse(font.is_opened) + + with self.assertRaisesRegex(AssertionError, "no file opened"): + font.fill_glyph_cache(cache, "abcd") + class DistanceFieldGlyphCacheGL(GLTestCase): def test(self): cache = text.DistanceFieldGlyphCacheGL((1024, 1024), (128, 128), 2)