AL-2020/venv/Lib/site-packages/pygame/tests/key_test.py

69 lines
2.0 KiB
Python
Raw Normal View History

2020-05-15 17:25:01 +02:00
import unittest
import pygame
import pygame.key
class KeyModuleTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
pygame.init()
@classmethod
def tearDownClass(cls):
pygame.quit()
def setUp(cls):
# This makes sure pygame is always initialized before each test (in
# case a test calls pygame.quit()).
if not pygame.get_init():
pygame.init()
def test_import(self):
'does it import'
import pygame.key
def todo_test_get_focused(self):
# __doc__ (as of 2008-08-02) for pygame.key.get_focused:
# pygame.key.get_focused(): return bool
# true if the display is receiving keyboard input from the system
#
# This is true when the display window has keyboard focus from the
# system. If the display needs to ensure it does not lose keyboard
# focus, it can use pygame.event.set_grab() to grab all input.
#
self.fail()
def test_get_pressed(self):
states = pygame.key.get_pressed()
self.assertEqual(states[pygame.K_RIGHT], 0)
def test_name(self):
self.assertEqual(pygame.key.name(pygame.K_RETURN), "return")
self.assertEqual(pygame.key.name(pygame.K_0), "0")
self.assertEqual(pygame.key.name(pygame.K_SPACE), "space")
def test_set_and_get_mods(self):
pygame.key.set_mods(pygame.KMOD_CTRL)
self.assertEqual(pygame.key.get_mods(), pygame.KMOD_CTRL)
pygame.key.set_mods(pygame.KMOD_ALT)
self.assertEqual(pygame.key.get_mods(), pygame.KMOD_ALT)
pygame.key.set_mods(pygame.KMOD_CTRL | pygame.KMOD_ALT)
self.assertEqual(pygame.key.get_mods(), pygame.KMOD_CTRL | pygame.KMOD_ALT)
def test_set_and_get_repeat(self):
self.assertEqual(pygame.key.get_repeat(), (0, 0))
pygame.key.set_repeat(10, 15)
self.assertEqual(pygame.key.get_repeat(), (10, 15))
pygame.key.set_repeat()
self.assertEqual(pygame.key.get_repeat(), (0, 0))
if __name__ == '__main__':
unittest.main()