def test_convert_alpha(self):
"""Ensure method convert_alpha() preserves the surface's class
When Surface is subclassed, the inherited convert_alpha() method will
return instances of the subclass. Non Surface fields are omitted,
however. This includes instance attributes.
"""
pygame.display.init()
try:
pygame.display.set_mode((40, 40))
s = pygame.Surface((32, 32), pygame.SRCALPHA, 16)
ms1 = self.MySurface((32, 32), pygame.SRCALPHA, 32)
ms2 = ms1.convert_alpha(s)
self.assertTrue(ms2 is not ms1)
self.assertTrue(isinstance(ms2, self.MySurface))
self.assertTrue(ms1.an_attribute)
self.assertRaises(AttributeError, getattr, ms2, "an_attribute")
finally:
pygame.display.quit()
评论列表
文章目录