Browse Source

python: properly test text.AbstractFont.fill_glyph_cache().

It *is* possible to test this, so why it is not?
next
Vladimír Vondruš 1 year ago
parent
commit
4ae645c54b
  1. 4
      src/python/magnum/test/test_text.py
  2. 20
      src/python/magnum/test/test_text_gl.py

4
src/python/magnum/test/test_text.py

@ -66,8 +66,8 @@ class Font(unittest.TestCase):
font.glyph_size(0) font.glyph_size(0)
with self.assertRaisesRegex(AssertionError, "no file opened"): with self.assertRaisesRegex(AssertionError, "no file opened"):
font.glyph_advance(0) font.glyph_advance(0)
# fill_glyph_cache() not tested as it needs a GL context; assuming it's # fill_glyph_cache() not tested as it needs a GL context; verified in
# correct # test_text_gl instead
def test_open_failed(self): def test_open_failed(self):
font = text.FontManager().load_and_instantiate('StbTrueTypeFont') font = text.FontManager().load_and_instantiate('StbTrueTypeFont')

20
src/python/magnum/test/test_text_gl.py

@ -63,6 +63,26 @@ class GlyphCacheGL(GLTestCase):
cache = text.GlyphCacheGL(PixelFormat.R8_UNORM, (128, 128)) cache = text.GlyphCacheGL(PixelFormat.R8_UNORM, (128, 128))
self.assertEqual(cache.padding, (1, 1)) 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): class DistanceFieldGlyphCacheGL(GLTestCase):
def test(self): def test(self):
cache = text.DistanceFieldGlyphCacheGL((1024, 1024), (128, 128), 2) cache = text.DistanceFieldGlyphCacheGL((1024, 1024), (128, 128), 2)

Loading…
Cancel
Save