bro
This commit is contained in:
1 parent
de41a02749
commit
9af09cebd3
764 files changed
+54218
-78859
No files matched your search
@@ -1,38 +1,36 @@
|
||||
import os
|
||||
import unittest
|
||||
|
||||
import os
|
||||
import pygame
|
||||
from pygame._sdl2 import touch
|
||||
from pygame.tests.test_utils import question
|
||||
|
||||
|
||||
has_touchdevice = touch.get_num_devices() > 0
|
||||
|
||||
|
||||
class TouchTest(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
os.environ["SDL_MOUSE_TOUCH_EVENTS"] = "0"
|
||||
pygame.init()
|
||||
pygame.display.init()
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
pygame.quit()
|
||||
pygame.display.quit()
|
||||
|
||||
def test_num_devices(self):
|
||||
touch.get_num_devices()
|
||||
|
||||
@unittest.skipIf(not has_touchdevice, "no touch devices found")
|
||||
def test_get_device(self):
|
||||
if touch.get_num_devices() > 0:
|
||||
touch.get_device(0)
|
||||
touch.get_device(0)
|
||||
|
||||
def test_get_device__invalid(self):
|
||||
self.assertRaises(pygame.error, touch.get_device, -1234)
|
||||
self.assertRaises(TypeError, touch.get_device, "test")
|
||||
|
||||
@unittest.skipIf(not has_touchdevice, "no touch devices found")
|
||||
def test_num_fingers(self):
|
||||
if touch.get_num_devices() > 0:
|
||||
if touch.get_device(0) >= 0:
|
||||
# mice acting as touch devices have negative device IDs
|
||||
# they also do not work with get_num_fingers()
|
||||
touch.get_num_fingers(touch.get_device(0))
|
||||
touch.get_num_fingers(touch.get_device(0))
|
||||
|
||||
def test_num_fingers__invalid(self):
|
||||
self.assertRaises(TypeError, touch.get_num_fingers, "test")
|
||||
@@ -42,31 +40,22 @@ class TouchTest(unittest.TestCase):
|
||||
class TouchInteractiveTest(unittest.TestCase):
|
||||
__tags__ = ["interactive"]
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
# if we don't have a touch device, enable the mouse to act as a
|
||||
# touch device for the interactive tests.
|
||||
os.environ["SDL_MOUSE_TOUCH_EVENTS"] = "0"
|
||||
pygame.init()
|
||||
if touch.get_num_devices() == 0:
|
||||
pygame.quit()
|
||||
os.environ["SDL_MOUSE_TOUCH_EVENTS"] = "1"
|
||||
pygame.init()
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
pygame.quit()
|
||||
|
||||
@unittest.skipIf(not has_touchdevice, "no touch devices found")
|
||||
def test_get_finger(self):
|
||||
"""ask for touch input and check the dict"""
|
||||
|
||||
pygame.display.init()
|
||||
pygame.font.init()
|
||||
|
||||
os.environ["SDL_VIDEO_WINDOW_POS"] = "50,50"
|
||||
screen = pygame.display.set_mode((1000, 600))
|
||||
screen = pygame.display.set_mode((800, 600))
|
||||
screen.fill((255, 255, 255))
|
||||
|
||||
font = pygame.font.Font(None, 32)
|
||||
instructions_str_1 = "Please place some fingers on your touch device"
|
||||
instructions_str_2 = "Close the window when finished, and answer the question"
|
||||
instructions_str_2 = (
|
||||
"Close the window when finished, " "and answer the question"
|
||||
)
|
||||
inst_1_render = font.render(instructions_str_1, True, pygame.Color("#000000"))
|
||||
inst_2_render = font.render(instructions_str_2, True, pygame.Color("#000000"))
|
||||
|
||||
@@ -80,10 +69,7 @@ class TouchInteractiveTest(unittest.TestCase):
|
||||
num_devices = pygame._sdl2.touch.get_num_devices()
|
||||
if num_devices > 0:
|
||||
first_device = pygame._sdl2.touch.get_device(0)
|
||||
if first_device >= 0:
|
||||
num_fingers = pygame._sdl2.touch.get_num_fingers(first_device)
|
||||
else:
|
||||
num_fingers = 1
|
||||
num_fingers = pygame._sdl2.touch.get_num_fingers(first_device)
|
||||
if num_fingers > 0:
|
||||
for finger_index in range(0, num_fingers):
|
||||
data = pygame._sdl2.touch.get_finger(first_device, finger_index)
|
||||
@@ -104,6 +90,8 @@ class TouchInteractiveTest(unittest.TestCase):
|
||||
response = question("Does the finger data seem correct?")
|
||||
self.assertTrue(response)
|
||||
|
||||
pygame.display.quit()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user