fix: Lint fixes of last tests

This commit is contained in:
JSC
2025-08-01 09:30:15 +02:00
parent dc29915fbc
commit fceff92ca1
20 changed files with 326 additions and 313 deletions

View File

@@ -1,4 +1,5 @@
"""Tests for extraction service."""
# ruff: noqa: ANN001, ANN201, PLR2004, SLF001, E501
import tempfile
from pathlib import Path
@@ -26,13 +27,13 @@ class TestExtractionService:
with patch("app.services.extraction.Path.mkdir"):
return ExtractionService(mock_session)
def test_init(self, extraction_service):
def test_init(self, extraction_service) -> None:
"""Test service initialization."""
assert extraction_service.session is not None
assert extraction_service.extraction_repo is not None
assert extraction_service.sound_repo is not None
def test_sanitize_filename(self, extraction_service):
def test_sanitize_filename(self, extraction_service) -> None:
"""Test filename sanitization."""
test_cases = [
("Hello World", "Hello World"),
@@ -54,7 +55,7 @@ class TestExtractionService:
@pytest.mark.asyncio
async def test_detect_service_info_youtube(
self, mock_ydl_class, extraction_service,
):
) -> None:
"""Test service detection for YouTube."""
mock_ydl = Mock()
mock_ydl_class.return_value.__enter__.return_value = mock_ydl
@@ -79,7 +80,7 @@ class TestExtractionService:
@pytest.mark.asyncio
async def test_detect_service_info_failure(
self, mock_ydl_class, extraction_service,
):
) -> None:
"""Test service detection failure."""
mock_ydl = Mock()
mock_ydl_class.return_value.__enter__.return_value = mock_ydl
@@ -90,7 +91,7 @@ class TestExtractionService:
assert result is None
@pytest.mark.asyncio
async def test_create_extraction_success(self, extraction_service):
async def test_create_extraction_success(self, extraction_service) -> None:
"""Test successful extraction creation."""
url = "https://www.youtube.com/watch?v=test123"
user_id = 1
@@ -118,7 +119,7 @@ class TestExtractionService:
assert result["status"] == "pending"
@pytest.mark.asyncio
async def test_create_extraction_basic(self, extraction_service):
async def test_create_extraction_basic(self, extraction_service) -> None:
"""Test basic extraction creation without validation."""
url = "https://www.youtube.com/watch?v=test123"
user_id = 1
@@ -144,7 +145,7 @@ class TestExtractionService:
assert result["status"] == "pending"
@pytest.mark.asyncio
async def test_create_extraction_any_url(self, extraction_service):
async def test_create_extraction_any_url(self, extraction_service) -> None:
"""Test extraction creation accepts any URL."""
url = "https://invalid.url"
user_id = 1
@@ -170,7 +171,7 @@ class TestExtractionService:
assert result["status"] == "pending"
@pytest.mark.asyncio
async def test_process_extraction_with_service_detection(self, extraction_service):
async def test_process_extraction_with_service_detection(self, extraction_service) -> None:
"""Test extraction processing with service detection."""
extraction_id = 1
@@ -211,8 +212,8 @@ class TestExtractionService:
patch.object(
extraction_service, "_create_sound_record",
) as mock_create_sound,
patch.object(extraction_service, "_normalize_sound") as mock_normalize,
patch.object(extraction_service, "_add_to_main_playlist") as mock_playlist,
patch.object(extraction_service, "_normalize_sound"),
patch.object(extraction_service, "_add_to_main_playlist"),
):
mock_sound = Sound(id=42, type="EXT", name="Test", filename="test.mp3")
mock_extract.return_value = (Path("/fake/audio.mp3"), None)
@@ -234,7 +235,7 @@ class TestExtractionService:
assert result["service_id"] == "test123"
assert result["title"] == "Test Video"
def test_ensure_unique_filename(self, extraction_service):
def test_ensure_unique_filename(self, extraction_service) -> None:
"""Test unique filename generation."""
with tempfile.TemporaryDirectory() as temp_dir:
temp_path = Path(temp_dir)
@@ -255,7 +256,7 @@ class TestExtractionService:
assert result == expected_2
@pytest.mark.asyncio
async def test_create_sound_record(self, extraction_service):
async def test_create_sound_record(self, extraction_service) -> None:
"""Test sound record creation."""
# Create temporary audio file
with tempfile.NamedTemporaryFile(suffix=".mp3", delete=False) as f:
@@ -317,7 +318,7 @@ class TestExtractionService:
audio_path.unlink()
@pytest.mark.asyncio
async def test_normalize_sound_success(self, extraction_service):
async def test_normalize_sound_success(self, extraction_service) -> None:
"""Test sound normalization."""
sound = Sound(
id=1,
@@ -349,7 +350,7 @@ class TestExtractionService:
mock_normalizer.normalize_sound.assert_called_once_with(sound)
@pytest.mark.asyncio
async def test_normalize_sound_failure(self, extraction_service):
async def test_normalize_sound_failure(self, extraction_service) -> None:
"""Test sound normalization failure."""
sound = Sound(
id=1,
@@ -381,7 +382,7 @@ class TestExtractionService:
mock_normalizer.normalize_sound.assert_called_once_with(sound)
@pytest.mark.asyncio
async def test_get_extraction_by_id(self, extraction_service):
async def test_get_extraction_by_id(self, extraction_service) -> None:
"""Test getting extraction by ID."""
extraction = Extraction(
id=1,
@@ -409,7 +410,7 @@ class TestExtractionService:
assert result["sound_id"] == 42
@pytest.mark.asyncio
async def test_get_extraction_by_id_not_found(self, extraction_service):
async def test_get_extraction_by_id_not_found(self, extraction_service) -> None:
"""Test getting extraction by ID when not found."""
extraction_service.extraction_repo.get_by_id = AsyncMock(return_value=None)
@@ -418,7 +419,7 @@ class TestExtractionService:
assert result is None
@pytest.mark.asyncio
async def test_get_user_extractions(self, extraction_service):
async def test_get_user_extractions(self, extraction_service) -> None:
"""Test getting user extractions."""
extractions = [
Extraction(
@@ -455,7 +456,7 @@ class TestExtractionService:
assert result[1]["title"] == "Test Video 2"
@pytest.mark.asyncio
async def test_get_pending_extractions(self, extraction_service):
async def test_get_pending_extractions(self, extraction_service) -> None:
"""Test getting pending extractions."""
pending_extractions = [
Extraction(