Skip to content

Commit

Permalink
Add tests for window surface
Browse files Browse the repository at this point in the history
  • Loading branch information
yunline committed Oct 16, 2023
1 parent 23aa287 commit 025aaec
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test/window_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,47 @@ def test_from_display_module(self):
pygame.display.quit()
pygame.init()

def test_window_surface(self):
win = Window(size=(640, 480))
surf = win.get_surface()

self.assertIsInstance(surf, pygame.Surface)

# test auto resize
self.assertTupleEqual(win.size, surf.get_size())
win.size = (100, 100)
self.assertTupleEqual(win.size, surf.get_size())
win.size = (1280, 720)
self.assertTupleEqual(win.size, surf.get_size())

# window surface should be invalid after the window is destroyed
win.destroy()
self.assertRaises(pygame.error, lambda: surf.fill((0, 0, 0)))

def test_window_surface_with_display_module(self):
# get_surface() should raise an error if the set_mode() is not called.
pygame.display.set_mode((640, 480))
win1 = Window.from_display_module()
pygame.display.quit()
pygame.init()
self.assertRaises(pygame.error, lambda: win1.get_surface())

# the surface returned by get_surface() should be
# the surface returned by set_mode()
surf1 = pygame.display.set_mode((640, 480))
win2 = Window.from_display_module()
surf2 = win2.get_surface()
self.assertIs(surf1, surf2)

def test_window_update_from_surface(self):
win = Window(size=(640, 480))
surf = win.get_surface()
surf.fill((255, 0, 0))

self.assertRaises(TypeError, lambda: win.update_from_surface("an argument"))
self.assertIs(win.update_from_surface(), None)
win.destroy()

def tearDown(self):
self.win.destroy()

Expand Down

0 comments on commit 025aaec

Please sign in to comment.