1# test subclassing framebuf.FrameBuffer 2 3try: 4 import framebuf 5except ImportError: 6 print("SKIP") 7 raise SystemExit 8 9 10class FB(framebuf.FrameBuffer): 11 def __init__(self, n): 12 self.n = n 13 super().__init__(bytearray(2 * n * n), n, n, framebuf.RGB565) 14 15 def foo(self): 16 self.hline(0, 2, self.n, 0x0304) 17 18 19fb = FB(n=3) 20fb.pixel(0, 0, 0x0102) 21fb.foo() 22print(bytes(fb)) 23 24# Test that blitting a subclass works. 25fb2 = framebuf.FrameBuffer(bytearray(2 * 3 * 3), 3, 3, framebuf.RGB565) 26fb.fill(0) 27fb.pixel(0, 0, 0x0506) 28fb.pixel(2, 2, 0x0708) 29fb2.blit(fb, 0, 0) 30print(bytes(fb2)) 31 32# Test that blitting something that isn't a subclass fails with TypeError. 33class NotAFrameBuf: 34 pass 35 36 37try: 38 fb.blit(NotAFrameBuf(), 0, 0) 39except TypeError: 40 print("TypeError") 41 42try: 43 fb.blit(None, 0, 0) 44except TypeError: 45 print("TypeError") 46