Fixing everything, making the project structure ready for real code.
Some checks failed
Tests / Frontend Tests (TypeScript + Vue + Yarn Berry) (push) Failing after 7m49s
Tests / Backend Tests (Python 3.13 + uv) (push) Failing after 14m36s

Signed-off-by: Cliff Hill <xlorep@darkhelm.org>
This commit is contained in:
2025-10-23 12:58:32 -04:00
parent 17a8ab1a06
commit 2c8f424a81
13 changed files with 173 additions and 562 deletions

View File

@@ -1,99 +0,0 @@
"""Example tests for the Plex Playlist backend with automatic typeguard."""
import pytest
def add_numbers(a: int, b: int) -> int:
"""Add two numbers together.
Args:
a: First number to add
b: Second number to add
Returns:
The sum of a and b
"""
return a + b
def create_playlist_data(
name: str, description: str | None = None
) -> dict[str, str | None]:
"""Create playlist data structure.
Args:
name: Name of the playlist
description: Optional description
Returns:
Dictionary containing playlist data
"""
return {
"name": name,
"description": description,
"id": f"playlist_{name.lower().replace(' ', '_')}",
}
class TestMathFunctions:
"""Test mathematical functions with automatic type checking."""
def test_add_numbers_valid_types(self) -> None:
"""Test adding numbers with correct types."""
result = add_numbers(5, 3)
assert result == 8
assert isinstance(result, int)
def test_add_numbers_invalid_types(self) -> None:
"""Test that typeguard catches invalid types automatically."""
with pytest.raises(TypeError):
# Typeguard will automatically catch this type violation
add_numbers("5", 3) # type: ignore[arg-type]
def test_add_numbers_coverage_example(self) -> None:
"""Test different number combinations for coverage."""
assert add_numbers(0, 0) == 0
assert add_numbers(-1, 1) == 0
assert add_numbers(100, 200) == 300
class TestPlaylistFunctions:
"""Test playlist-related functions with automatic type checking."""
def test_create_playlist_data_with_description(self) -> None:
"""Test creating playlist data with description."""
result = create_playlist_data("My Playlist", "A great playlist")
expected = {
"name": "My Playlist",
"description": "A great playlist",
"id": "playlist_my_playlist",
}
assert result == expected
def test_create_playlist_data_without_description(self) -> None:
"""Test creating playlist data without description."""
result = create_playlist_data("Simple Playlist")
expected = {
"name": "Simple Playlist",
"description": None,
"id": "playlist_simple_playlist",
}
assert result == expected
def test_create_playlist_invalid_name_type(self) -> None:
"""Test that typeguard automatically catches invalid name type."""
with pytest.raises(TypeError):
# No decorator needed - typeguard import hook handles this
create_playlist_data(123, "description") # type: ignore[arg-type]
@pytest.mark.integration
class TestIntegrationExample:
"""Example integration tests with automatic type validation."""
def test_integration_placeholder(self) -> None:
"""Placeholder for real integration tests."""
# All functions called here will have automatic type checking
assert True

View File

@@ -1,86 +0,0 @@
"""
Tests demonstrating hypermodern typeguard usage.
No decorators needed - validation happens automatically.
"""
import pytest
from backend import PlaylistManager, calculate_playlist_duration, process_user_data
class TestHypermodernTypeguard:
"""Tests showing automatic type validation without decorators."""
def test_process_user_data_valid_types(self) -> None:
"""Test with correct types - should work normally."""
result = process_user_data(123, "John Doe", "JOHN@EXAMPLE.COM")
expected = {
"id": 123,
"name": "John Doe",
"email": "john@example.com",
"display_name": "John Doe (john@example.com)",
}
assert result == expected
def test_process_user_data_invalid_user_id(self) -> None:
"""Test with wrong user_id type - typeguard catches automatically."""
with pytest.raises(TypeError):
# This will fail because "123" is str, not int
process_user_data("123", "John", "john@example.com") # type: ignore[arg-type]
def test_process_user_data_invalid_name(self) -> None:
"""Test with wrong name type - typeguard catches automatically."""
with pytest.raises(TypeError):
# This will fail because 123 is int, not str
process_user_data(123, 123, "john@example.com") # type: ignore[arg-type]
def test_calculate_duration_valid(self) -> None:
"""Test duration calculation with valid types."""
durations = [3.5, 4.2, 2.8, 5.1]
total = calculate_playlist_duration(durations)
assert abs(total - 15.6) < 0.001 # Float comparison
def test_calculate_duration_invalid_list_type(self) -> None:
"""Test with wrong parameter type - not a list."""
with pytest.raises(TypeError):
# This will fail because "not a list" is str, not list[float]
calculate_playlist_duration("not a list") # type: ignore[arg-type]
def test_calculate_duration_invalid_element_types(self) -> None:
"""Test with wrong element types in list."""
with pytest.raises(TypeError):
# This will fail because list contains strings, not floats
calculate_playlist_duration(["3.5", "4.2"]) # type: ignore[list-item]
def test_playlist_manager_creation(self) -> None:
"""Test playlist manager creation with valid types."""
manager = PlaylistManager("My Playlist", 500)
assert manager.name == "My Playlist"
assert manager.max_size == 500
assert manager.get_track_count() == 0
def test_playlist_manager_invalid_name_type(self) -> None:
"""Test playlist manager creation with invalid name type."""
with pytest.raises(TypeError):
# This will fail because 123 is int, not str
PlaylistManager(123) # type: ignore[arg-type]
def test_playlist_manager_add_track_valid(self) -> None:
"""Test adding tracks with valid types."""
manager = PlaylistManager("Test Playlist", 2)
assert manager.add_track("track_1") is True
assert manager.add_track("track_2") is True
assert manager.add_track("track_3") is False # Exceeds max_size
assert manager.get_track_count() == 2
def test_playlist_manager_add_track_invalid_type(self) -> None:
"""Test adding track with invalid type."""
manager = PlaylistManager("Test Playlist")
with pytest.raises(TypeError):
# This will fail because 123 is int, not str
manager.add_track(123) # type: ignore[arg-type]