0.2.2 #25
29
.gitea/workflows/test.yml
Normal file
29
.gitea/workflows/test.yml
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
name: Run Controller Tests
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches-ignore: [ main ]
|
||||||
|
pull-request:
|
||||||
|
branches: [ main ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout Code
|
||||||
|
uses: actions/setup-python@v3
|
||||||
|
|
||||||
|
- name: Set up Python
|
||||||
|
uses: actions/setup-python@v4
|
||||||
|
with:
|
||||||
|
python-version: '3.10'
|
||||||
|
|
||||||
|
- name: Install Dependencies
|
||||||
|
run:
|
||||||
|
python -m pip install --upgrade pip
|
||||||
|
pip install pygame
|
||||||
|
|
||||||
|
- name: Run Unit Tests
|
||||||
|
run:
|
||||||
|
python -m unittest discover tests
|
@@ -1,3 +1,6 @@
|
|||||||
# PyGame-Controller
|
# PyGame-Controller
|
||||||
|
|
||||||
Small module to make it easy to add controller support.
|
Small module to make it easy to add controller support.
|
||||||
|
|
||||||
|

|
||||||
|

|
@@ -1,7 +1,7 @@
|
|||||||
import pygame
|
import pygame
|
||||||
from . import globals
|
from . import globals
|
||||||
|
|
||||||
__version__ = "0.2.1"
|
__version__ = "0.2.2"
|
||||||
|
|
||||||
class Controllers:
|
class Controllers:
|
||||||
def __init__(self, joy):
|
def __init__(self, joy):
|
||||||
|
31
pygameControls/tests/test_controller.py
Normal file
31
pygameControls/tests/test_controller.py
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import unittest
|
||||||
|
from unittest.mock import MagicMock
|
||||||
|
from pygameControls import Controller
|
||||||
|
|
||||||
|
class TestController(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.mock_js = MagicMock()
|
||||||
|
self.mock_js.get_button.side_effect = lambda i: 1 if i == 0 else 0
|
||||||
|
self.mock_js.get_axis.side_effect = lambda i: 0.5 if i == 1 else 0.0
|
||||||
|
self.mock_js.get_name.return_value = "DualSense Wireless Controller"
|
||||||
|
self.mock_js.get_guid.return_value = "030000004c0500000c0e000011010000"
|
||||||
|
|
||||||
|
self.controller = Controller(self.mock_js)
|
||||||
|
|
||||||
|
def test_button_press(self):
|
||||||
|
self.assertEqual(self.controller.get_button(0), 1)
|
||||||
|
self.assertEqual(self.controller.get_button(1), 0)
|
||||||
|
|
||||||
|
def test_axis_reading(self):
|
||||||
|
self.assertAlmostEqual(self.controller.get_axis(1), 0.5)
|
||||||
|
|
||||||
|
def test_profile_mapping(self):
|
||||||
|
self.assertEqual(self.controller.get_mapping(), "Sony DualSense")
|
||||||
|
|
||||||
|
def test_custom_config(self):
|
||||||
|
cfg = self.controller.get_custom_config()
|
||||||
|
self.assertIn("cross", cfg)
|
||||||
|
self.assertEqual(cfg["cross"], 0)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
Reference in New Issue
Block a user