diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml new file mode 100644 index 0000000..051435c --- /dev/null +++ b/.gitea/workflows/test.yml @@ -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 \ No newline at end of file diff --git a/README.md b/README.md index 1bdb451..ca0caa4 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ # PyGame-Controller -Small module to make it easy to add controller support. \ No newline at end of file +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) \ No newline at end of file diff --git a/pygameControls/controller.py b/pygameControls/controller.py index 69a6655..057b31f 100644 --- a/pygameControls/controller.py +++ b/pygameControls/controller.py @@ -1,7 +1,7 @@ import pygame from . import globals -__version__ = "0.2.1" +__version__ = "0.2.2" class Controllers: def __init__(self, joy): diff --git a/pygameControls/tests/test_controller.py b/pygameControls/tests/test_controller.py new file mode 100644 index 0000000..f667793 --- /dev/null +++ b/pygameControls/tests/test_controller.py @@ -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() \ No newline at end of file diff --git a/setup.py b/setup.py index 2a834e7..2174b0e 100644 --- a/setup.py +++ b/setup.py @@ -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',