Merge pull request '0.2.2' (#25) from 0.2.2 into main

Reviewed-on: #25
This commit is contained in:
2025-05-07 16:49:36 +02:00
5 changed files with 66 additions and 3 deletions

29
.gitea/workflows/test.yml Normal file
View 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

View File

@@ -1,3 +1,6 @@
# PyGame-Controller
Small module to make it easy to add controller support.
Small module to make it easy to add controller support.
![Tests](https://gitpot-lerking.servehttp.com/api/v1/badges/CodingPirates/PyGame-Controller/workflows/test.yml)
![Version](https://img.shields.io/badge/version-0.2.2-blue)

View File

@@ -1,7 +1,7 @@
import pygame
from . import globals
__version__ = "0.2.1"
__version__ = "0.2.2"
class Controllers:
def __init__(self, joy):

View 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()

View File

@@ -3,7 +3,7 @@ if __name__ == "__main__":
setup(
name='pygameControls',
version='0.2.1',
version='0.2.2',
packages=find_packages(),
install_requires=[],
author='Jan Lerking',