update pre-commit config

This commit is contained in:
barry 2025-01-11 01:22:16 +01:00
parent cb78206c2d
commit 0f9e295ba3
3 changed files with 64 additions and 0 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
spotiplayer_pi/__pycache__
tests/__pycache__

View File

@ -6,3 +6,12 @@ repos:
args: ["--ignore=E711,E721"]
# args: ["--fix"] # Automatically apply fixes where possible
- id: ruff-format
repos:
- repo: local
hooks:
- id: run-unittest
name: Run Unit Tests
entry: bash -c "python -m unittest discover -s tests -p '*_test.py'"
language: system
always_run: true

54
tests/test_app.py Normal file
View File

@ -0,0 +1,54 @@
import unittest
from spotiplayer_pi.main import parse_config
from spotiplayer_pi.api import Api
class TestApp(unittest.TestCase):
def test_config(self):
self.cfg = parse_config()
# Assertions for config structure and values
self.assertIsNotNone(self.cfg["refresh_token"])
self.assertIsNotNone(self.cfg["base_64"])
self.assertIsInstance(self.cfg["api_interval"], (int, float))
self.assertGreater(self.cfg["api_interval"], 0)
self.assertIsInstance(self.cfg["refresh_interval"], (int, float))
self.assertGreater(self.cfg["refresh_interval"], 0)
self.assertIn("color_theme", self.cfg)
# Check color_theme structure
color_theme = self.cfg["color_theme"]
self.assertIsInstance(color_theme, dict)
for key in ["text", "bar_outline", "bar_inside", "background"]:
self.assertIn(key, color_theme)
self.assertIsInstance(color_theme[key], tuple)
self.assertEqual(len(color_theme[key]), 3)
self.assertTrue(
all(isinstance(c, int) and 0 <= c <= 255 for c in color_theme[key])
)
def test_refreshAuth(self):
self.cfg = parse_config()
self.api = Api(self.cfg["refresh_token"], self.cfg["base_64"])
expires_in = self.api.refreshAuth()
self.assertIsNotNone(self.api.access_token)
self.assertIsNotNone(expires_in)
self.assertGreater(expires_in, 0)
self.assertIn("Authorization", self.api.header)
def test_getPlaying(self):
self.cfg = parse_config()
self.api = Api(self.cfg["refresh_token"], self.cfg["base_64"])
self.api.refreshAuth()
result = self.api.getPlaying()
if result != "not-playing":
self.assertIsNotNone(result)
self.assertIn("track", result)
self.assertIn("album", result)
self.assertIn("artists", result)
if __name__ == "__main__":
unittest.main()