100 lines
3.0 KiB
Python
100 lines
3.0 KiB
Python
"""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
|