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 sound normalizer service."""
# ruff: noqa: ANN001, ANN201, ARG002, PLR2004, SLF001, E501, PLC0415
import tempfile
from pathlib import Path
@@ -28,7 +29,7 @@ class TestSoundNormalizerService:
mock_settings.NORMALIZED_AUDIO_PASSES = 2
return SoundNormalizerService(mock_session)
def test_init(self, normalizer_service):
def test_init(self, normalizer_service) -> None:
"""Test normalizer service initialization."""
assert normalizer_service.session is not None
assert normalizer_service.sound_repo is not None
@@ -40,7 +41,7 @@ class TestSoundNormalizerService:
assert "TTS" in normalizer_service.type_directories
assert "EXT" in normalizer_service.type_directories
def test_get_normalized_path(self, normalizer_service):
def test_get_normalized_path(self, normalizer_service) -> None:
"""Test normalized path generation."""
sound = Sound(
id=1,
@@ -57,7 +58,7 @@ class TestSoundNormalizerService:
assert "sounds/normalized/soundboard" in str(normalized_path)
assert normalized_path.name == "test_audio.mp3"
def test_get_original_path(self, normalizer_service):
def test_get_original_path(self, normalizer_service) -> None:
"""Test original path generation."""
sound = Sound(
id=1,
@@ -74,7 +75,7 @@ class TestSoundNormalizerService:
assert "sounds/originals/soundboard" in str(original_path)
assert original_path.name == "test_audio.wav"
def test_get_file_hash(self, normalizer_service):
def test_get_file_hash(self, normalizer_service) -> None:
"""Test file hash calculation."""
# Create a temporary file
with tempfile.NamedTemporaryFile(mode="w", delete=False) as f:
@@ -90,7 +91,7 @@ class TestSoundNormalizerService:
finally:
temp_path.unlink()
def test_get_file_size(self, normalizer_service):
def test_get_file_size(self, normalizer_service) -> None:
"""Test file size calculation."""
# Create a temporary file
with tempfile.NamedTemporaryFile(mode="w", delete=False) as f:
@@ -107,7 +108,7 @@ class TestSoundNormalizerService:
temp_path.unlink()
@patch("app.utils.audio.ffmpeg.probe")
def test_get_audio_duration_success(self, mock_probe, normalizer_service):
def test_get_audio_duration_success(self, mock_probe, normalizer_service) -> None:
"""Test successful audio duration extraction."""
mock_probe.return_value = {"format": {"duration": "123.456"}}
@@ -120,7 +121,7 @@ class TestSoundNormalizerService:
mock_probe.assert_called_once_with(str(temp_path))
@patch("app.utils.audio.ffmpeg.probe")
def test_get_audio_duration_failure(self, mock_probe, normalizer_service):
def test_get_audio_duration_failure(self, mock_probe, normalizer_service) -> None:
"""Test audio duration extraction failure."""
mock_probe.side_effect = Exception("FFmpeg error")
@@ -133,7 +134,7 @@ class TestSoundNormalizerService:
mock_probe.assert_called_once_with(str(temp_path))
@pytest.mark.asyncio
async def test_normalize_sound_already_normalized(self, normalizer_service):
async def test_normalize_sound_already_normalized(self, normalizer_service) -> None:
"""Test normalizing a sound that's already normalized."""
sound = Sound(
id=1,
@@ -154,7 +155,7 @@ class TestSoundNormalizerService:
assert result["id"] == 1
@pytest.mark.asyncio
async def test_normalize_sound_force_already_normalized(self, normalizer_service):
async def test_normalize_sound_force_already_normalized(self, normalizer_service) -> None:
"""Test force normalizing a sound that's already normalized."""
sound = Sound(
id=1,
@@ -173,7 +174,7 @@ class TestSoundNormalizerService:
patch.object(normalizer_service, "_get_normalized_path") as mock_norm_path,
patch.object(
normalizer_service, "_normalize_audio_two_pass",
) as mock_normalize,
),
patch(
"app.services.sound_normalizer.get_audio_duration", return_value=6000,
),
@@ -203,7 +204,7 @@ class TestSoundNormalizerService:
normalizer_service.sound_repo.update.assert_called_once()
@pytest.mark.asyncio
async def test_normalize_sound_file_not_found(self, normalizer_service):
async def test_normalize_sound_file_not_found(self, normalizer_service) -> None:
"""Test normalizing a sound where original file doesn't exist."""
sound = Sound(
id=1,
@@ -228,7 +229,7 @@ class TestSoundNormalizerService:
assert result["filename"] == "missing.mp3"
@pytest.mark.asyncio
async def test_normalize_sound_one_pass(self, normalizer_service):
async def test_normalize_sound_one_pass(self, normalizer_service) -> None:
"""Test normalizing a sound using one-pass method."""
sound = Sound(
id=1,
@@ -275,7 +276,7 @@ class TestSoundNormalizerService:
mock_normalize.assert_called_once()
@pytest.mark.asyncio
async def test_normalize_sound_normalization_error(self, normalizer_service):
async def test_normalize_sound_normalization_error(self, normalizer_service) -> None:
"""Test handling normalization errors."""
sound = Sound(
id=1,
@@ -312,7 +313,7 @@ class TestSoundNormalizerService:
assert result["filename"] == "test.mp3"
@pytest.mark.asyncio
async def test_normalize_all_sounds(self, normalizer_service):
async def test_normalize_all_sounds(self, normalizer_service) -> None:
"""Test normalizing all unnormalized sounds."""
sounds = [
Sound(
@@ -382,7 +383,7 @@ class TestSoundNormalizerService:
assert len(results["files"]) == 2
@pytest.mark.asyncio
async def test_normalize_sounds_by_type(self, normalizer_service):
async def test_normalize_sounds_by_type(self, normalizer_service) -> None:
"""Test normalizing sounds by type."""
sdb_sounds = [
Sound(
@@ -432,7 +433,7 @@ class TestSoundNormalizerService:
)
@pytest.mark.asyncio
async def test_normalize_sounds_with_errors(self, normalizer_service):
async def test_normalize_sounds_with_errors(self, normalizer_service) -> None:
"""Test normalizing sounds with some errors."""
sounds = [
Sound(
@@ -512,7 +513,7 @@ class TestSoundNormalizerService:
self,
mock_ffmpeg,
normalizer_service,
):
) -> None:
"""Test one-pass audio normalization for MP3."""
input_path = Path("/fake/input.wav")
output_path = Path("/fake/output.mp3")
@@ -547,7 +548,7 @@ class TestSoundNormalizerService:
self,
mock_ffmpeg,
normalizer_service,
):
) -> None:
"""Test two-pass audio normalization analysis phase."""
input_path = Path("/fake/input.wav")
output_path = Path("/fake/output.mp3")
@@ -562,7 +563,7 @@ class TestSoundNormalizerService:
# Mock analysis output with valid JSON
analysis_json = """{
"input_i": "-23.0",
"input_lra": "11.0",
"input_lra": "11.0",
"input_tp": "-2.0",
"input_thresh": "-33.0",
"target_offset": "0.0"