bro
This commit is contained in:
1 parent
de41a02749
commit
9af09cebd3
764 files changed
+54218
-78859
No files matched your search
@@ -1,5 +1,4 @@
|
||||
import unittest
|
||||
|
||||
import pygame
|
||||
import pygame._sdl2.controller as controller
|
||||
from pygame.tests.test_utils import prompt, question
|
||||
@@ -34,6 +33,15 @@ class ControllerModuleTest(unittest.TestCase):
|
||||
def test_get_init(self):
|
||||
self.assertTrue(controller.get_init())
|
||||
|
||||
def test_get_eventstate(self):
|
||||
controller.set_eventstate(True)
|
||||
self.assertTrue(controller.get_eventstate())
|
||||
|
||||
controller.set_eventstate(False)
|
||||
self.assertFalse(controller.get_eventstate())
|
||||
|
||||
controller.set_eventstate(True)
|
||||
|
||||
def test_get_count(self):
|
||||
self.assertGreaterEqual(controller.get_count(), 0)
|
||||
|
||||
@@ -44,12 +52,15 @@ class ControllerModuleTest(unittest.TestCase):
|
||||
self.assertIsInstance(c, controller.Controller)
|
||||
c.quit()
|
||||
else:
|
||||
with self.assertRaises(pygame.error):
|
||||
with self.assertRaises(pygame._sdl2.sdl2.error):
|
||||
c = controller.Controller(i)
|
||||
|
||||
with self.assertRaises(TypeError):
|
||||
controller.is_controller("Test")
|
||||
|
||||
def test_name_forindex(self):
|
||||
self.assertIsNone(controller.name_forindex(-1))
|
||||
|
||||
|
||||
class ControllerTypeTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
@@ -64,19 +75,22 @@ class ControllerTypeTest(unittest.TestCase):
|
||||
return controller.Controller(i)
|
||||
|
||||
def test_construction(self):
|
||||
if c := self._get_first_controller():
|
||||
c = self._get_first_controller()
|
||||
if c:
|
||||
self.assertIsInstance(c, controller.Controller)
|
||||
else:
|
||||
self.skipTest("No controller connected")
|
||||
|
||||
def test__auto_init(self):
|
||||
if c := self._get_first_controller():
|
||||
c = self._get_first_controller()
|
||||
if c:
|
||||
self.assertTrue(c.get_init())
|
||||
else:
|
||||
self.skipTest("No controller connected")
|
||||
|
||||
def test_get_init(self):
|
||||
if c := self._get_first_controller():
|
||||
c = self._get_first_controller()
|
||||
if c:
|
||||
self.assertTrue(c.get_init())
|
||||
c.quit()
|
||||
self.assertFalse(c.get_init())
|
||||
@@ -95,14 +109,16 @@ class ControllerTypeTest(unittest.TestCase):
|
||||
self.assertIsInstance(c, controller.Controller)
|
||||
|
||||
def test_as_joystick(self):
|
||||
if c := self._get_first_controller():
|
||||
c = self._get_first_controller()
|
||||
if c:
|
||||
joy = c.as_joystick()
|
||||
self.assertIsInstance(joy, type(pygame.joystick.Joystick(0)))
|
||||
else:
|
||||
self.skipTest("No controller connected")
|
||||
|
||||
def test_get_mapping(self):
|
||||
if c := self._get_first_controller():
|
||||
c = self._get_first_controller()
|
||||
if c:
|
||||
mapping = c.get_mapping()
|
||||
self.assertIsInstance(mapping, dict)
|
||||
self.assertIsNotNone(mapping["a"])
|
||||
@@ -110,7 +126,8 @@ class ControllerTypeTest(unittest.TestCase):
|
||||
self.skipTest("No controller connected")
|
||||
|
||||
def test_set_mapping(self):
|
||||
if c := self._get_first_controller():
|
||||
c = self._get_first_controller()
|
||||
if c:
|
||||
mapping = c.get_mapping()
|
||||
mapping["a"] = "b3"
|
||||
mapping["y"] = "b0"
|
||||
@@ -162,6 +179,75 @@ class ControllerInteractiveTest(unittest.TestCase):
|
||||
|
||||
self.assertTrue(ans)
|
||||
|
||||
def test_set_eventstate_on_interactive(self):
|
||||
c = self._get_first_controller()
|
||||
if not c:
|
||||
self.skipTest("No controller connected")
|
||||
|
||||
pygame.display.init()
|
||||
pygame.font.init()
|
||||
|
||||
screen = pygame.display.set_mode((400, 400))
|
||||
font = pygame.font.Font(None, 20)
|
||||
running = True
|
||||
|
||||
screen.fill((255, 255, 255))
|
||||
screen.blit(
|
||||
font.render("Press button 'x' (on ps4) or 'a' (on xbox).", True, (0, 0, 0)),
|
||||
(0, 0),
|
||||
)
|
||||
pygame.display.update()
|
||||
|
||||
controller.set_eventstate(True)
|
||||
|
||||
while running:
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
running = False
|
||||
|
||||
if event.type == pygame.CONTROLLERBUTTONDOWN:
|
||||
running = False
|
||||
|
||||
pygame.display.quit()
|
||||
pygame.font.quit()
|
||||
|
||||
def test_set_eventstate_off_interactive(self):
|
||||
c = self._get_first_controller()
|
||||
if not c:
|
||||
self.skipTest("No controller connected")
|
||||
|
||||
pygame.display.init()
|
||||
pygame.font.init()
|
||||
|
||||
screen = pygame.display.set_mode((400, 400))
|
||||
font = pygame.font.Font(None, 20)
|
||||
running = True
|
||||
|
||||
screen.fill((255, 255, 255))
|
||||
screen.blit(
|
||||
font.render("Press button 'x' (on ps4) or 'a' (on xbox).", True, (0, 0, 0)),
|
||||
(0, 0),
|
||||
)
|
||||
pygame.display.update()
|
||||
|
||||
controller.set_eventstate(False)
|
||||
|
||||
while running:
|
||||
for event in pygame.event.get(pygame.QUIT):
|
||||
if event:
|
||||
running = False
|
||||
|
||||
if c.get_button(pygame.CONTROLLER_BUTTON_A):
|
||||
if pygame.event.peek(pygame.CONTROLLERBUTTONDOWN):
|
||||
pygame.display.quit()
|
||||
pygame.font.quit()
|
||||
self.fail()
|
||||
else:
|
||||
running = False
|
||||
|
||||
pygame.display.quit()
|
||||
pygame.font.quit()
|
||||
|
||||
def test_get_button_interactive(self):
|
||||
c = self._get_first_controller()
|
||||
if not c:
|
||||
|
||||
Reference in new issue
Block a user