fix: Lint fixes of last tests
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
"""Tests for VLC player service."""
|
||||
# ruff: noqa: ANN001, ANN201, PLR2004, SLF001, SIM117, E501, ANN202, PLC0415
|
||||
|
||||
import asyncio
|
||||
from pathlib import Path
|
||||
@@ -6,7 +7,6 @@ from unittest.mock import AsyncMock, Mock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from app.models.credit_transaction import CreditTransaction
|
||||
from app.models.sound import Sound
|
||||
from app.models.user import User
|
||||
from app.services.vlc_player import VLCPlayerService, get_vlc_player_service
|
||||
@@ -62,20 +62,20 @@ class TestVLCPlayerService:
|
||||
normalized_filename="normalized.mp3",
|
||||
)
|
||||
|
||||
def test_init(self, vlc_service):
|
||||
def test_init(self, vlc_service) -> None:
|
||||
"""Test VLC service initialization."""
|
||||
assert vlc_service.vlc_executable is not None
|
||||
assert isinstance(vlc_service.vlc_executable, str)
|
||||
|
||||
@patch("app.services.vlc_player.subprocess.run")
|
||||
def test_find_vlc_executable_found_in_path(self, mock_run):
|
||||
def test_find_vlc_executable_found_in_path(self, mock_run) -> None:
|
||||
"""Test VLC executable detection when found in PATH."""
|
||||
mock_run.return_value.returncode = 0
|
||||
service = VLCPlayerService()
|
||||
assert service.vlc_executable == "vlc"
|
||||
|
||||
@patch("app.services.vlc_player.subprocess.run")
|
||||
def test_find_vlc_executable_found_by_path(self, mock_run):
|
||||
def test_find_vlc_executable_found_by_path(self, mock_run) -> None:
|
||||
"""Test VLC executable detection when found by absolute path."""
|
||||
mock_run.return_value.returncode = 1 # which command fails
|
||||
|
||||
@@ -93,7 +93,7 @@ class TestVLCPlayerService:
|
||||
|
||||
@patch("app.services.vlc_player.subprocess.run")
|
||||
@patch("app.services.vlc_player.Path")
|
||||
def test_find_vlc_executable_fallback(self, mock_path, mock_run):
|
||||
def test_find_vlc_executable_fallback(self, mock_path, mock_run) -> None:
|
||||
"""Test VLC executable detection fallback to default."""
|
||||
# Mock all paths as non-existent
|
||||
mock_path_instance = Mock()
|
||||
@@ -111,7 +111,7 @@ class TestVLCPlayerService:
|
||||
@patch("app.services.vlc_player.asyncio.create_subprocess_exec")
|
||||
async def test_play_sound_success(
|
||||
self, mock_subprocess, vlc_service, sample_sound,
|
||||
):
|
||||
) -> None:
|
||||
"""Test successful sound playback."""
|
||||
# Mock subprocess
|
||||
mock_process = Mock()
|
||||
@@ -144,7 +144,7 @@ class TestVLCPlayerService:
|
||||
@pytest.mark.asyncio
|
||||
async def test_play_sound_file_not_found(
|
||||
self, vlc_service, sample_sound,
|
||||
):
|
||||
) -> None:
|
||||
"""Test sound playback when file doesn't exist."""
|
||||
# Mock the file path utility to return a non-existent path
|
||||
with patch("app.services.vlc_player.get_sound_file_path") as mock_get_path:
|
||||
@@ -160,7 +160,7 @@ class TestVLCPlayerService:
|
||||
@patch("app.services.vlc_player.asyncio.create_subprocess_exec")
|
||||
async def test_play_sound_subprocess_error(
|
||||
self, mock_subprocess, vlc_service, sample_sound,
|
||||
):
|
||||
) -> None:
|
||||
"""Test sound playback when subprocess fails."""
|
||||
# Mock the file path utility to return an existing path
|
||||
with patch("app.services.vlc_player.get_sound_file_path") as mock_get_path:
|
||||
@@ -177,7 +177,7 @@ class TestVLCPlayerService:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@patch("app.services.vlc_player.asyncio.create_subprocess_exec")
|
||||
async def test_stop_all_vlc_instances_success(self, mock_subprocess, vlc_service):
|
||||
async def test_stop_all_vlc_instances_success(self, mock_subprocess, vlc_service) -> None:
|
||||
"""Test successful stopping of all VLC instances."""
|
||||
# Mock pgrep process (find VLC processes)
|
||||
mock_find_process = Mock()
|
||||
@@ -214,7 +214,7 @@ class TestVLCPlayerService:
|
||||
@patch("app.services.vlc_player.asyncio.create_subprocess_exec")
|
||||
async def test_stop_all_vlc_instances_no_processes(
|
||||
self, mock_subprocess, vlc_service,
|
||||
):
|
||||
) -> None:
|
||||
"""Test stopping VLC instances when none are running."""
|
||||
# Mock pgrep process (no VLC processes found)
|
||||
mock_find_process = Mock()
|
||||
@@ -234,7 +234,7 @@ class TestVLCPlayerService:
|
||||
@patch("app.services.vlc_player.asyncio.create_subprocess_exec")
|
||||
async def test_stop_all_vlc_instances_partial_kill(
|
||||
self, mock_subprocess, vlc_service,
|
||||
):
|
||||
) -> None:
|
||||
"""Test stopping VLC instances when some processes remain."""
|
||||
# Mock pgrep process (find VLC processes)
|
||||
mock_find_process = Mock()
|
||||
@@ -267,7 +267,7 @@ class TestVLCPlayerService:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@patch("app.services.vlc_player.asyncio.create_subprocess_exec")
|
||||
async def test_stop_all_vlc_instances_error(self, mock_subprocess, vlc_service):
|
||||
async def test_stop_all_vlc_instances_error(self, mock_subprocess, vlc_service) -> None:
|
||||
"""Test stopping VLC instances when an error occurs."""
|
||||
# Mock subprocess exception
|
||||
mock_subprocess.side_effect = Exception("Command failed")
|
||||
@@ -280,7 +280,7 @@ class TestVLCPlayerService:
|
||||
assert "error" in result
|
||||
assert result["message"] == "Failed to stop VLC processes"
|
||||
|
||||
def test_get_vlc_player_service_singleton(self):
|
||||
def test_get_vlc_player_service_singleton(self) -> None:
|
||||
"""Test that get_vlc_player_service returns the same instance."""
|
||||
with patch("app.services.vlc_player.VLCPlayerService") as mock_service_class:
|
||||
mock_instance = Mock()
|
||||
@@ -306,7 +306,7 @@ class TestVLCPlayerService:
|
||||
@patch("app.services.vlc_player.asyncio.create_subprocess_exec")
|
||||
async def test_play_sound_with_play_count_tracking(
|
||||
self, mock_subprocess, vlc_service_with_db, sample_sound,
|
||||
):
|
||||
) -> None:
|
||||
"""Test sound playback with play count tracking."""
|
||||
# Mock subprocess
|
||||
mock_process = Mock()
|
||||
@@ -371,7 +371,7 @@ class TestVLCPlayerService:
|
||||
# mocking or using a real async test framework setup
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_record_play_count_success(self, vlc_service_with_db):
|
||||
async def test_record_play_count_success(self, vlc_service_with_db) -> None:
|
||||
"""Test successful play count recording."""
|
||||
# Mock session and repositories
|
||||
mock_session = AsyncMock()
|
||||
@@ -436,14 +436,14 @@ class TestVLCPlayerService:
|
||||
)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_record_play_count_no_session_factory(self, vlc_service):
|
||||
async def test_record_play_count_no_session_factory(self, vlc_service) -> None:
|
||||
"""Test play count recording when no session factory is available."""
|
||||
# This should not raise an error and should log a warning
|
||||
await vlc_service._record_play_count(1, "Test Sound")
|
||||
# The method should return early without doing anything
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_record_play_count_always_creates_record(self, vlc_service_with_db):
|
||||
async def test_record_play_count_always_creates_record(self, vlc_service_with_db) -> None:
|
||||
"""Test play count recording always creates a new SoundPlayed record."""
|
||||
# Mock session and repositories
|
||||
mock_session = AsyncMock()
|
||||
@@ -493,7 +493,7 @@ class TestVLCPlayerService:
|
||||
# Verify commit happened
|
||||
mock_session.commit.assert_called_once()
|
||||
|
||||
def test_uses_shared_sound_path_utility(self, vlc_service, sample_sound):
|
||||
def test_uses_shared_sound_path_utility(self, vlc_service, sample_sound) -> None:
|
||||
"""Test that VLC service uses the shared sound path utility."""
|
||||
with patch("app.services.vlc_player.get_sound_file_path") as mock_path:
|
||||
mock_file_path = Mock(spec=Path)
|
||||
|
||||
Reference in New Issue
Block a user