fix: Lint fixes of last tests
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
"""Tests for player service."""
|
||||
# ruff: noqa: ANN001, ANN201, ARG002, PLR2004, SLF001, E501, SIM117, ARG005
|
||||
|
||||
import asyncio
|
||||
import threading
|
||||
@@ -24,7 +25,7 @@ from app.services.player import (
|
||||
class TestPlayerState:
|
||||
"""Test player state data structure."""
|
||||
|
||||
def test_init_creates_default_state(self):
|
||||
def test_init_creates_default_state(self) -> None:
|
||||
"""Test that player state initializes with default values."""
|
||||
state = PlayerState()
|
||||
|
||||
@@ -42,7 +43,7 @@ class TestPlayerState:
|
||||
assert state.playlist_duration == 0
|
||||
assert state.playlist_sounds == []
|
||||
|
||||
def test_to_dict_serializes_correctly(self):
|
||||
def test_to_dict_serializes_correctly(self) -> None:
|
||||
"""Test that player state serializes to dict correctly."""
|
||||
state = PlayerState()
|
||||
state.status = PlayerStatus.PLAYING
|
||||
@@ -70,7 +71,7 @@ class TestPlayerState:
|
||||
assert result["playlist"]["length"] == 5
|
||||
assert result["playlist"]["duration"] == 150000
|
||||
|
||||
def test_serialize_sound_with_sound_object(self):
|
||||
def test_serialize_sound_with_sound_object(self) -> None:
|
||||
"""Test serializing a sound object."""
|
||||
state = PlayerState()
|
||||
sound = Sound(
|
||||
@@ -95,7 +96,7 @@ class TestPlayerState:
|
||||
assert result["thumbnail"] == "test.jpg"
|
||||
assert result["play_count"] == 5
|
||||
|
||||
def test_serialize_sound_with_none(self):
|
||||
def test_serialize_sound_with_none(self) -> None:
|
||||
"""Test serializing None sound."""
|
||||
state = PlayerState()
|
||||
result = state._serialize_sound(None)
|
||||
@@ -133,10 +134,9 @@ class TestPlayerService:
|
||||
@pytest.fixture
|
||||
def player_service(self, mock_db_session_factory, mock_vlc_instance, mock_socket_manager):
|
||||
"""Create a player service instance for testing."""
|
||||
service = PlayerService(mock_db_session_factory)
|
||||
return service
|
||||
return PlayerService(mock_db_session_factory)
|
||||
|
||||
def test_init_creates_player_service(self, mock_db_session_factory, mock_vlc_instance):
|
||||
def test_init_creates_player_service(self, mock_db_session_factory, mock_vlc_instance) -> None:
|
||||
"""Test that player service initializes correctly."""
|
||||
with patch("app.services.player.socket_manager"):
|
||||
service = PlayerService(mock_db_session_factory)
|
||||
@@ -153,7 +153,7 @@ class TestPlayerService:
|
||||
assert service._loop is None
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_start_initializes_service(self, player_service, mock_vlc_instance):
|
||||
async def test_start_initializes_service(self, player_service, mock_vlc_instance) -> None:
|
||||
"""Test that start method initializes the service."""
|
||||
with patch.object(player_service, "reload_playlist", new_callable=AsyncMock):
|
||||
await player_service.start()
|
||||
@@ -165,7 +165,7 @@ class TestPlayerService:
|
||||
player_service._player.audio_set_volume.assert_called_once_with(50)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_stop_cleans_up_service(self, player_service):
|
||||
async def test_stop_cleans_up_service(self, player_service) -> None:
|
||||
"""Test that stop method cleans up the service."""
|
||||
# Setup initial state
|
||||
player_service._is_running = True
|
||||
@@ -180,7 +180,7 @@ class TestPlayerService:
|
||||
player_service._player.release.assert_called_once()
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_play_new_track(self, player_service, mock_vlc_instance):
|
||||
async def test_play_new_track(self, player_service, mock_vlc_instance) -> None:
|
||||
"""Test playing a new track."""
|
||||
# Setup test sound
|
||||
sound = Sound(
|
||||
@@ -212,7 +212,7 @@ class TestPlayerService:
|
||||
assert 1 in player_service._play_time_tracking
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_play_resume_from_pause(self, player_service):
|
||||
async def test_play_resume_from_pause(self, player_service) -> None:
|
||||
"""Test resuming playback from pause."""
|
||||
# Setup paused state
|
||||
sound = Sound(id=1, name="Test Song", filename="test.mp3", duration=30000)
|
||||
@@ -230,7 +230,7 @@ class TestPlayerService:
|
||||
player_service._player.play.assert_called_once()
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_play_invalid_index(self, player_service):
|
||||
async def test_play_invalid_index(self, player_service) -> None:
|
||||
"""Test playing with invalid index raises ValueError."""
|
||||
player_service.state.playlist_sounds = []
|
||||
|
||||
@@ -238,7 +238,7 @@ class TestPlayerService:
|
||||
await player_service.play(0)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_pause_when_playing(self, player_service):
|
||||
async def test_pause_when_playing(self, player_service) -> None:
|
||||
"""Test pausing when currently playing."""
|
||||
player_service.state.status = PlayerStatus.PLAYING
|
||||
|
||||
@@ -249,7 +249,7 @@ class TestPlayerService:
|
||||
player_service._player.pause.assert_called_once()
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_pause_when_not_playing(self, player_service):
|
||||
async def test_pause_when_not_playing(self, player_service) -> None:
|
||||
"""Test pausing when not playing does nothing."""
|
||||
player_service.state.status = PlayerStatus.STOPPED
|
||||
|
||||
@@ -260,7 +260,7 @@ class TestPlayerService:
|
||||
mock_broadcast.assert_not_called()
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_stop_playback(self, player_service):
|
||||
async def test_stop_playback(self, player_service) -> None:
|
||||
"""Test stopping playback."""
|
||||
player_service.state.status = PlayerStatus.PLAYING
|
||||
player_service.state.current_sound_position = 5000
|
||||
@@ -274,7 +274,7 @@ class TestPlayerService:
|
||||
player_service._player.stop.assert_called_once()
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_next_track(self, player_service):
|
||||
async def test_next_track(self, player_service) -> None:
|
||||
"""Test skipping to next track."""
|
||||
sound1 = Sound(id=1, name="Song 1", filename="song1.mp3")
|
||||
sound2 = Sound(id=2, name="Song 2", filename="song2.mp3")
|
||||
@@ -286,7 +286,7 @@ class TestPlayerService:
|
||||
mock_play.assert_called_once_with(1)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_previous_track(self, player_service):
|
||||
async def test_previous_track(self, player_service) -> None:
|
||||
"""Test going to previous track."""
|
||||
sound1 = Sound(id=1, name="Song 1", filename="song1.mp3")
|
||||
sound2 = Sound(id=2, name="Song 2", filename="song2.mp3")
|
||||
@@ -298,7 +298,7 @@ class TestPlayerService:
|
||||
mock_play.assert_called_once_with(0)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_seek_position(self, player_service):
|
||||
async def test_seek_position(self, player_service) -> None:
|
||||
"""Test seeking to specific position."""
|
||||
player_service.state.status = PlayerStatus.PLAYING
|
||||
player_service.state.current_sound_duration = 30000
|
||||
@@ -311,7 +311,7 @@ class TestPlayerService:
|
||||
assert player_service.state.current_sound_position == 15000
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_seek_when_stopped(self, player_service):
|
||||
async def test_seek_when_stopped(self, player_service) -> None:
|
||||
"""Test seeking when stopped does nothing."""
|
||||
player_service.state.status = PlayerStatus.STOPPED
|
||||
|
||||
@@ -322,7 +322,7 @@ class TestPlayerService:
|
||||
mock_broadcast.assert_not_called()
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_set_volume(self, player_service):
|
||||
async def test_set_volume(self, player_service) -> None:
|
||||
"""Test setting volume."""
|
||||
with patch.object(player_service, "_broadcast_state", new_callable=AsyncMock):
|
||||
await player_service.set_volume(75)
|
||||
@@ -331,7 +331,7 @@ class TestPlayerService:
|
||||
player_service._player.audio_set_volume.assert_called_once_with(75)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_set_volume_clamping(self, player_service):
|
||||
async def test_set_volume_clamping(self, player_service) -> None:
|
||||
"""Test volume clamping to valid range."""
|
||||
with patch.object(player_service, "_broadcast_state", new_callable=AsyncMock):
|
||||
# Test upper bound
|
||||
@@ -343,7 +343,7 @@ class TestPlayerService:
|
||||
assert player_service.state.volume == 0
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_set_mode(self, player_service):
|
||||
async def test_set_mode(self, player_service) -> None:
|
||||
"""Test setting playback mode."""
|
||||
with patch.object(player_service, "_broadcast_state", new_callable=AsyncMock):
|
||||
await player_service.set_mode(PlayerMode.LOOP)
|
||||
@@ -351,7 +351,7 @@ class TestPlayerService:
|
||||
assert player_service.state.mode == PlayerMode.LOOP
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_reload_playlist(self, player_service):
|
||||
async def test_reload_playlist(self, player_service) -> None:
|
||||
"""Test reloading playlist from database."""
|
||||
mock_session = AsyncMock()
|
||||
player_service.db_session_factory = lambda: mock_session
|
||||
@@ -383,7 +383,7 @@ class TestPlayerService:
|
||||
assert player_service.state.playlist_duration == 75000
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_handle_playlist_id_changed(self, player_service):
|
||||
async def test_handle_playlist_id_changed(self, player_service) -> None:
|
||||
"""Test handling when playlist ID changes."""
|
||||
# Setup initial state
|
||||
player_service.state.status = PlayerStatus.PLAYING
|
||||
@@ -405,7 +405,7 @@ class TestPlayerService:
|
||||
assert player_service.state.current_sound_id == 1
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_handle_playlist_id_changed_empty_playlist(self, player_service):
|
||||
async def test_handle_playlist_id_changed_empty_playlist(self, player_service) -> None:
|
||||
"""Test handling playlist ID change with empty playlist."""
|
||||
player_service.state.status = PlayerStatus.PLAYING
|
||||
|
||||
@@ -418,7 +418,7 @@ class TestPlayerService:
|
||||
assert player_service.state.current_sound_id is None
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_handle_same_playlist_track_exists_same_index(self, player_service):
|
||||
async def test_handle_same_playlist_track_exists_same_index(self, player_service) -> None:
|
||||
"""Test handling same playlist when track exists at same index."""
|
||||
sound1 = Sound(id=1, name="Song 1", filename="song1.mp3", duration=30000)
|
||||
sound2 = Sound(id=2, name="Song 2", filename="song2.mp3", duration=45000)
|
||||
@@ -431,7 +431,7 @@ class TestPlayerService:
|
||||
assert player_service.state.current_sound == sound1
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_handle_same_playlist_track_exists_different_index(self, player_service):
|
||||
async def test_handle_same_playlist_track_exists_different_index(self, player_service) -> None:
|
||||
"""Test handling same playlist when track exists at different index."""
|
||||
sound1 = Sound(id=2, name="Song 2", filename="song2.mp3", duration=45000)
|
||||
sound2 = Sound(id=1, name="Song 1", filename="song1.mp3", duration=30000)
|
||||
@@ -444,7 +444,7 @@ class TestPlayerService:
|
||||
assert player_service.state.current_sound == sound2
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_handle_same_playlist_track_not_found(self, player_service):
|
||||
async def test_handle_same_playlist_track_not_found(self, player_service) -> None:
|
||||
"""Test handling same playlist when current track no longer exists."""
|
||||
player_service.state.status = PlayerStatus.PLAYING
|
||||
sound1 = Sound(id=2, name="Song 2", filename="song2.mp3", duration=45000)
|
||||
@@ -456,7 +456,7 @@ class TestPlayerService:
|
||||
mock_removed.assert_called_once_with(1, sounds)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_handle_track_removed_with_sounds(self, player_service):
|
||||
async def test_handle_track_removed_with_sounds(self, player_service) -> None:
|
||||
"""Test handling when current track is removed with sounds available."""
|
||||
player_service.state.status = PlayerStatus.PLAYING
|
||||
sound1 = Sound(id=2, name="Song 2", filename="song2.mp3", duration=45000)
|
||||
@@ -471,7 +471,7 @@ class TestPlayerService:
|
||||
assert player_service.state.current_sound_id == 2
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_handle_track_removed_empty_playlist(self, player_service):
|
||||
async def test_handle_track_removed_empty_playlist(self, player_service) -> None:
|
||||
"""Test handling when current track is removed with empty playlist."""
|
||||
player_service.state.status = PlayerStatus.PLAYING
|
||||
|
||||
@@ -483,7 +483,7 @@ class TestPlayerService:
|
||||
assert player_service.state.current_sound is None
|
||||
assert player_service.state.current_sound_id is None
|
||||
|
||||
def test_update_playlist_state(self, player_service):
|
||||
def test_update_playlist_state(self, player_service) -> None:
|
||||
"""Test updating playlist state information."""
|
||||
mock_playlist = Mock()
|
||||
mock_playlist.id = 5
|
||||
@@ -501,7 +501,7 @@ class TestPlayerService:
|
||||
assert player_service.state.playlist_length == 2
|
||||
assert player_service.state.playlist_duration == 75000
|
||||
|
||||
def test_find_sound_index_found(self, player_service):
|
||||
def test_find_sound_index_found(self, player_service) -> None:
|
||||
"""Test finding sound index when sound exists."""
|
||||
sound1 = Sound(id=1, name="Song 1", filename="song1.mp3", duration=30000)
|
||||
sound2 = Sound(id=2, name="Song 2", filename="song2.mp3", duration=45000)
|
||||
@@ -510,7 +510,7 @@ class TestPlayerService:
|
||||
index = player_service._find_sound_index(2, sounds)
|
||||
assert index == 1
|
||||
|
||||
def test_find_sound_index_not_found(self, player_service):
|
||||
def test_find_sound_index_not_found(self, player_service) -> None:
|
||||
"""Test finding sound index when sound doesn't exist."""
|
||||
sound1 = Sound(id=1, name="Song 1", filename="song1.mp3", duration=30000)
|
||||
sounds = [sound1]
|
||||
@@ -518,7 +518,7 @@ class TestPlayerService:
|
||||
index = player_service._find_sound_index(999, sounds)
|
||||
assert index is None
|
||||
|
||||
def test_set_first_track_as_current(self, player_service):
|
||||
def test_set_first_track_as_current(self, player_service) -> None:
|
||||
"""Test setting first track as current."""
|
||||
sound1 = Sound(id=1, name="Song 1", filename="song1.mp3", duration=30000)
|
||||
sound2 = Sound(id=2, name="Song 2", filename="song2.mp3", duration=45000)
|
||||
@@ -530,7 +530,7 @@ class TestPlayerService:
|
||||
assert player_service.state.current_sound == sound1
|
||||
assert player_service.state.current_sound_id == 1
|
||||
|
||||
def test_clear_current_track(self, player_service):
|
||||
def test_clear_current_track(self, player_service) -> None:
|
||||
"""Test clearing current track state."""
|
||||
# Set some initial state
|
||||
player_service.state.current_sound_index = 2
|
||||
@@ -544,7 +544,7 @@ class TestPlayerService:
|
||||
assert player_service.state.current_sound_id is None
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_reload_playlist_different_id_scenario(self, player_service):
|
||||
async def test_reload_playlist_different_id_scenario(self, player_service) -> None:
|
||||
"""Test complete reload scenario when playlist ID changes."""
|
||||
# Setup current state
|
||||
player_service.state.playlist_id = 1
|
||||
@@ -580,7 +580,7 @@ class TestPlayerService:
|
||||
assert player_service.state.current_sound_id == 1
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_reload_playlist_same_id_track_moved(self, player_service):
|
||||
async def test_reload_playlist_same_id_track_moved(self, player_service) -> None:
|
||||
"""Test reload when playlist ID same but track moved to different index."""
|
||||
# Setup current state
|
||||
player_service.state.playlist_id = 1
|
||||
@@ -616,7 +616,7 @@ class TestPlayerService:
|
||||
assert player_service.state.current_sound == sound1
|
||||
|
||||
|
||||
def test_get_next_index_continuous_mode(self, player_service):
|
||||
def test_get_next_index_continuous_mode(self, player_service) -> None:
|
||||
"""Test getting next index in continuous mode."""
|
||||
player_service.state.mode = PlayerMode.CONTINUOUS
|
||||
player_service.state.playlist_sounds = [Mock(), Mock(), Mock()]
|
||||
@@ -628,7 +628,7 @@ class TestPlayerService:
|
||||
# Test end of playlist
|
||||
assert player_service._get_next_index(2) is None
|
||||
|
||||
def test_get_next_index_loop_mode(self, player_service):
|
||||
def test_get_next_index_loop_mode(self, player_service) -> None:
|
||||
"""Test getting next index in loop mode."""
|
||||
player_service.state.mode = PlayerMode.LOOP
|
||||
player_service.state.playlist_sounds = [Mock(), Mock(), Mock()]
|
||||
@@ -640,7 +640,7 @@ class TestPlayerService:
|
||||
# Test wrapping to beginning
|
||||
assert player_service._get_next_index(2) == 0
|
||||
|
||||
def test_get_next_index_loop_one_mode(self, player_service):
|
||||
def test_get_next_index_loop_one_mode(self, player_service) -> None:
|
||||
"""Test getting next index in loop one mode."""
|
||||
player_service.state.mode = PlayerMode.LOOP_ONE
|
||||
player_service.state.playlist_sounds = [Mock(), Mock(), Mock()]
|
||||
@@ -650,7 +650,7 @@ class TestPlayerService:
|
||||
assert player_service._get_next_index(1) == 1
|
||||
assert player_service._get_next_index(2) == 2
|
||||
|
||||
def test_get_next_index_single_mode(self, player_service):
|
||||
def test_get_next_index_single_mode(self, player_service) -> None:
|
||||
"""Test getting next index in single mode."""
|
||||
player_service.state.mode = PlayerMode.SINGLE
|
||||
player_service.state.playlist_sounds = [Mock(), Mock(), Mock()]
|
||||
@@ -660,7 +660,7 @@ class TestPlayerService:
|
||||
assert player_service._get_next_index(1) is None
|
||||
assert player_service._get_next_index(2) is None
|
||||
|
||||
def test_get_next_index_random_mode(self, player_service):
|
||||
def test_get_next_index_random_mode(self, player_service) -> None:
|
||||
"""Test getting next index in random mode."""
|
||||
player_service.state.mode = PlayerMode.RANDOM
|
||||
player_service.state.playlist_sounds = [Mock(), Mock(), Mock()]
|
||||
@@ -674,7 +674,7 @@ class TestPlayerService:
|
||||
# Should exclude current index
|
||||
mock_choice.assert_called_once_with([1, 2])
|
||||
|
||||
def test_get_previous_index(self, player_service):
|
||||
def test_get_previous_index(self, player_service) -> None:
|
||||
"""Test getting previous index."""
|
||||
player_service.state.playlist_sounds = [Mock(), Mock(), Mock()]
|
||||
|
||||
@@ -690,7 +690,7 @@ class TestPlayerService:
|
||||
player_service.state.mode = PlayerMode.LOOP
|
||||
assert player_service._get_previous_index(0) == 2
|
||||
|
||||
def test_update_play_time(self, player_service):
|
||||
def test_update_play_time(self, player_service) -> None:
|
||||
"""Test updating play time tracking."""
|
||||
# Setup state
|
||||
player_service.state.status = PlayerStatus.PLAYING
|
||||
@@ -716,7 +716,7 @@ class TestPlayerService:
|
||||
assert tracking["last_update"] == current_time
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_record_play_count(self, player_service):
|
||||
async def test_record_play_count(self, player_service) -> None:
|
||||
"""Test recording play count for a sound."""
|
||||
mock_session = AsyncMock()
|
||||
player_service.db_session_factory = lambda: mock_session
|
||||
@@ -742,7 +742,7 @@ class TestPlayerService:
|
||||
mock_session.add.assert_called_once()
|
||||
mock_session.commit.assert_called_once()
|
||||
|
||||
def test_get_state(self, player_service):
|
||||
def test_get_state(self, player_service) -> None:
|
||||
"""Test getting current player state."""
|
||||
result = player_service.get_state()
|
||||
assert isinstance(result, dict)
|
||||
@@ -750,7 +750,7 @@ class TestPlayerService:
|
||||
assert "mode" in result
|
||||
assert "volume" in result
|
||||
|
||||
def test_uses_shared_sound_path_utility(self, player_service):
|
||||
def test_uses_shared_sound_path_utility(self, player_service) -> None:
|
||||
"""Test that player service uses the shared sound path utility."""
|
||||
sound = Sound(
|
||||
id=1,
|
||||
@@ -767,7 +767,7 @@ class TestPlayerService:
|
||||
mock_path.return_value = mock_file_path
|
||||
|
||||
# This should fail because file doesn't exist
|
||||
result = asyncio.run(player_service.play(0))
|
||||
asyncio.run(player_service.play(0))
|
||||
# Verify the utility was called
|
||||
mock_path.assert_called_once_with(sound)
|
||||
|
||||
@@ -776,7 +776,7 @@ class TestPlayerServiceGlobalFunctions:
|
||||
"""Test global player service functions."""
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_initialize_player_service(self):
|
||||
async def test_initialize_player_service(self) -> None:
|
||||
"""Test initializing global player service."""
|
||||
mock_factory = Mock()
|
||||
|
||||
@@ -790,7 +790,7 @@ class TestPlayerServiceGlobalFunctions:
|
||||
mock_service.start.assert_called_once()
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_shutdown_player_service(self):
|
||||
async def test_shutdown_player_service(self) -> None:
|
||||
"""Test shutting down global player service."""
|
||||
# Mock global player service exists
|
||||
with patch("app.services.player.player_service") as mock_global:
|
||||
@@ -802,7 +802,7 @@ class TestPlayerServiceGlobalFunctions:
|
||||
await shutdown_player_service()
|
||||
mock_service.stop.assert_called_once()
|
||||
|
||||
def test_get_player_service_success(self):
|
||||
def test_get_player_service_success(self) -> None:
|
||||
"""Test getting player service when initialized."""
|
||||
mock_service = Mock()
|
||||
|
||||
@@ -810,7 +810,7 @@ class TestPlayerServiceGlobalFunctions:
|
||||
result = get_player_service()
|
||||
assert result is mock_service
|
||||
|
||||
def test_get_player_service_not_initialized(self):
|
||||
def test_get_player_service_not_initialized(self) -> None:
|
||||
"""Test getting player service when not initialized."""
|
||||
with patch("app.services.player.player_service", None):
|
||||
with pytest.raises(RuntimeError, match="Player service not initialized"):
|
||||
|
||||
Reference in New Issue
Block a user