fix: Lint fixes of last tests
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
"""Tests for sound scanner service."""
|
||||
# ruff: noqa: ANN001, ANN201, ARG002, PLR2004, SLF001, PLC0415, SIM117
|
||||
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
@@ -24,7 +25,7 @@ class TestSoundScannerService:
|
||||
"""Create a scanner service with mock session."""
|
||||
return SoundScannerService(mock_session)
|
||||
|
||||
def test_init(self, scanner_service):
|
||||
def test_init(self, scanner_service) -> None:
|
||||
"""Test scanner service initialization."""
|
||||
assert scanner_service.session is not None
|
||||
assert scanner_service.sound_repo is not None
|
||||
@@ -32,7 +33,7 @@ class TestSoundScannerService:
|
||||
assert ".mp3" in scanner_service.supported_extensions
|
||||
assert ".wav" in scanner_service.supported_extensions
|
||||
|
||||
def test_get_file_hash(self, scanner_service):
|
||||
def test_get_file_hash(self, scanner_service) -> None:
|
||||
"""Test file hash calculation."""
|
||||
# Create a temporary file
|
||||
with tempfile.NamedTemporaryFile(mode="w", delete=False) as f:
|
||||
@@ -48,7 +49,7 @@ class TestSoundScannerService:
|
||||
finally:
|
||||
temp_path.unlink()
|
||||
|
||||
def test_get_file_size(self, scanner_service):
|
||||
def test_get_file_size(self, scanner_service) -> None:
|
||||
"""Test file size calculation."""
|
||||
# Create a temporary file
|
||||
with tempfile.NamedTemporaryFile(mode="w", delete=False) as f:
|
||||
@@ -64,7 +65,7 @@ class TestSoundScannerService:
|
||||
finally:
|
||||
temp_path.unlink()
|
||||
|
||||
def test_extract_name_from_filename(self, scanner_service):
|
||||
def test_extract_name_from_filename(self, scanner_service) -> None:
|
||||
"""Test name extraction from filename."""
|
||||
test_cases = [
|
||||
("hello_world.mp3", "Hello World"),
|
||||
@@ -79,7 +80,7 @@ class TestSoundScannerService:
|
||||
assert result == expected_name
|
||||
|
||||
@patch("app.utils.audio.ffmpeg.probe")
|
||||
def test_get_audio_duration_success(self, mock_probe, scanner_service):
|
||||
def test_get_audio_duration_success(self, mock_probe, scanner_service) -> None:
|
||||
"""Test successful audio duration extraction."""
|
||||
mock_probe.return_value = {"format": {"duration": "123.456"}}
|
||||
|
||||
@@ -92,7 +93,7 @@ class TestSoundScannerService:
|
||||
mock_probe.assert_called_once_with(str(temp_path))
|
||||
|
||||
@patch("app.utils.audio.ffmpeg.probe")
|
||||
def test_get_audio_duration_failure(self, mock_probe, scanner_service):
|
||||
def test_get_audio_duration_failure(self, mock_probe, scanner_service) -> None:
|
||||
"""Test audio duration extraction failure."""
|
||||
mock_probe.side_effect = Exception("FFmpeg error")
|
||||
|
||||
@@ -105,13 +106,13 @@ class TestSoundScannerService:
|
||||
mock_probe.assert_called_once_with(str(temp_path))
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_scan_directory_nonexistent(self, scanner_service):
|
||||
async def test_scan_directory_nonexistent(self, scanner_service) -> None:
|
||||
"""Test scanning a non-existent directory."""
|
||||
with pytest.raises(ValueError, match="Directory does not exist"):
|
||||
await scanner_service.scan_directory("/non/existent/path")
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_scan_directory_not_directory(self, scanner_service):
|
||||
async def test_scan_directory_not_directory(self, scanner_service) -> None:
|
||||
"""Test scanning a path that is not a directory."""
|
||||
# Create a temporary file
|
||||
with tempfile.NamedTemporaryFile() as f:
|
||||
@@ -119,7 +120,7 @@ class TestSoundScannerService:
|
||||
await scanner_service.scan_directory(f.name)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sync_audio_file_unchanged(self, scanner_service):
|
||||
async def test_sync_audio_file_unchanged(self, scanner_service) -> None:
|
||||
"""Test syncing file that is unchanged."""
|
||||
# Existing sound with same hash as file
|
||||
existing_sound = Sound(
|
||||
@@ -166,7 +167,7 @@ class TestSoundScannerService:
|
||||
temp_path.unlink()
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sync_audio_file_new(self, scanner_service):
|
||||
async def test_sync_audio_file_new(self, scanner_service) -> None:
|
||||
"""Test syncing a new audio file."""
|
||||
created_sound = Sound(
|
||||
id=1,
|
||||
@@ -221,7 +222,7 @@ class TestSoundScannerService:
|
||||
temp_path.unlink()
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sync_audio_file_updated(self, scanner_service):
|
||||
async def test_sync_audio_file_updated(self, scanner_service) -> None:
|
||||
"""Test syncing a file that was modified (different hash)."""
|
||||
# Existing sound with different hash than file
|
||||
existing_sound = Sound(
|
||||
@@ -280,7 +281,7 @@ class TestSoundScannerService:
|
||||
temp_path.unlink()
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sync_audio_file_custom_type(self, scanner_service):
|
||||
async def test_sync_audio_file_custom_type(self, scanner_service) -> None:
|
||||
"""Test syncing file with custom type."""
|
||||
created_sound = Sound(
|
||||
id=1,
|
||||
|
||||
Reference in New Issue
Block a user