Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added unit tests for display.toggle_fullscreen and display.get_active #1927

Merged
merged 17 commits into from Jul 4, 2020
Merged
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
96 changes: 74 additions & 22 deletions test/display_test.py
Expand Up @@ -65,20 +65,50 @@ def todo_test_flip(self):

self.fail()

def todo_test_get_active(self):
def test_get_active(self):
"""Test the get_active function"""

# __doc__ (as of 2008-08-02) for pygame.display.get_active:
#Initially, the display is not active
pygame.quit()
MyreMylar marked this conversation as resolved.
Show resolved Hide resolved
pygame.display.quit()
self.assertEqual(pygame.display.get_active(), False)

# pygame.display.get_active(): return bool
# true when the display is active on the display
#
# After pygame.display.set_mode() is called the display Surface will
# be visible on the screen. Most windowed displays can be hidden by
# the user. If the display Surface is hidden or iconified this will
# return False.
#
#get_active defaults to true after a set_mode
pygame.init()
MyreMylar marked this conversation as resolved.
Show resolved Hide resolved
pygame.display.set_mode((640, 480))
self.assertEqual(pygame.display.get_active(), True)

self.fail()
#get_active after init/quit should be False
#since no display is visible
pygame.display.quit()
pygame.display.init()
self.assertEqual(pygame.display.get_active(), False)

"""
#Clear events so iconify/get_active can be tested
#in isolation
pygame.event.clear()

#According to the docs, get_active should return
#false if the display is iconified
pygame.display.set_mode((640, 480))

#Simulate a keydown causing iconify!
pygame.event.post(pygame.event.Event(pygame.KEYDOWN))

is_running = True
while is_running:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
pygame.display.iconify()

if not pygame.display.get_active():
self.assertEqual(pygame.display.get_active(), False)
is_running = False

pygame.display.update()

"""

def test_get_caption(self):
screen = display.set_mode((100, 100))
Expand Down Expand Up @@ -398,20 +428,42 @@ def todo_test_set_palette(self):

self.fail()

def todo_test_toggle_fullscreen(self):
def test_toggle_fullscreen(self):
MyreMylar marked this conversation as resolved.
Show resolved Hide resolved
"""Test for toggle fullscreen"""

# __doc__ (as of 2008-08-02) for pygame.display.toggle_fullscreen:
#try to toggle fullscreen with no active display
#this should result in an error
pygame.display.quit()
with self.assertRaises(pygame.error):
pygame.display.toggle_fullscreen()

pygame.display.init()
width_height = (640,480)
test_surf = pygame.display.set_mode(width_height)

#try to toggle fullscreen
try:
pygame.display.toggle_fullscreen()

except pygame.error:
with self.assertRaises(pygame.error):
pygame.display.toggle_fullscreen()
MyreMylar marked this conversation as resolved.
Show resolved Hide resolved

else:
#if toggle success, the width/height should be a
#value found in list_modes
if pygame.display.toggle_fullscreen() == 1:
boolean = (test_surf.get_width(), test_surf.get_height()) \
in pygame.display.list_modes(depth=0, flags=pygame.FULLSCREEN, display=0)

self.assertEqual(boolean, True)

#if not original width/height should be preserved
else:
self.assertEqual((test_surf.get_width(), test_surf.get_height()), \
width_height)

# pygame.display.toggle_fullscreen(): return bool
# switch between fullscreen and windowed displays
#
# Switches the display window between windowed and fullscreen modes.
# This function only works under the unix x11 video driver. For most
# situations it is better to call pygame.display.set_mode() with new
# display flags.
#

self.fail()


@unittest.skipIf(
Expand Down