Did some things, made more improvements.
Signed-off-by: Cliff Hill <xlorep@darkhelm.org>
This commit is contained in:
18
backend/tests/integration/test_api.py
Normal file
18
backend/tests/integration/test_api.py
Normal file
@@ -0,0 +1,18 @@
|
||||
"""Integration tests for API endpoints."""
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
class TestAPIIntegration:
|
||||
"""Integration tests for API endpoints."""
|
||||
|
||||
def test_health_check(self) -> None:
|
||||
"""Test API health check endpoint."""
|
||||
# This would test actual API health endpoint
|
||||
assert True
|
||||
|
||||
def test_playlist_crud(self) -> None:
|
||||
"""Test playlist CRUD operations."""
|
||||
# This would test creating, reading, updating, deleting playlists
|
||||
assert True
|
||||
99
backend/tests/test_example.py
Normal file
99
backend/tests/test_example.py
Normal file
@@ -0,0 +1,99 @@
|
||||
"""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
|
||||
86
backend/tests/test_hypermodern.py
Normal file
86
backend/tests/test_hypermodern.py
Normal file
@@ -0,0 +1,86 @@
|
||||
"""
|
||||
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]
|
||||
Reference in New Issue
Block a user