Refactor test files for improved readability and consistency
- Removed unnecessary blank lines and adjusted formatting in test files. - Ensured consistent use of commas in function calls and assertions across various test cases. - Updated import statements for better organization and clarity. - Enhanced mock setups in tests for better isolation and reliability. - Improved assertions to follow a consistent style for better readability.
This commit is contained in:
@@ -55,7 +55,7 @@ class TestSoundNormalizerService:
|
||||
normalized_path = normalizer_service._get_normalized_path(sound)
|
||||
|
||||
assert "sounds/normalized/soundboard" in str(normalized_path)
|
||||
assert "test_audio.mp3" == normalized_path.name
|
||||
assert normalized_path.name == "test_audio.mp3"
|
||||
|
||||
def test_get_original_path(self, normalizer_service):
|
||||
"""Test original path generation."""
|
||||
@@ -72,7 +72,7 @@ class TestSoundNormalizerService:
|
||||
original_path = normalizer_service._get_original_path(sound)
|
||||
|
||||
assert "sounds/originals/soundboard" in str(original_path)
|
||||
assert "test_audio.wav" == original_path.name
|
||||
assert original_path.name == "test_audio.wav"
|
||||
|
||||
def test_get_file_hash(self, normalizer_service):
|
||||
"""Test file hash calculation."""
|
||||
@@ -172,14 +172,14 @@ class TestSoundNormalizerService:
|
||||
patch.object(normalizer_service, "_get_original_path") as mock_orig_path,
|
||||
patch.object(normalizer_service, "_get_normalized_path") as mock_norm_path,
|
||||
patch.object(
|
||||
normalizer_service, "_normalize_audio_two_pass"
|
||||
normalizer_service, "_normalize_audio_two_pass",
|
||||
) as mock_normalize,
|
||||
patch(
|
||||
"app.services.sound_normalizer.get_audio_duration", return_value=6000
|
||||
"app.services.sound_normalizer.get_audio_duration", return_value=6000,
|
||||
),
|
||||
patch("app.services.sound_normalizer.get_file_size", return_value=2048),
|
||||
patch(
|
||||
"app.services.sound_normalizer.get_file_hash", return_value="new_hash"
|
||||
"app.services.sound_normalizer.get_file_hash", return_value="new_hash",
|
||||
),
|
||||
):
|
||||
# Setup path mocks
|
||||
@@ -245,14 +245,14 @@ class TestSoundNormalizerService:
|
||||
patch.object(normalizer_service, "_get_original_path") as mock_orig_path,
|
||||
patch.object(normalizer_service, "_get_normalized_path") as mock_norm_path,
|
||||
patch.object(
|
||||
normalizer_service, "_normalize_audio_one_pass"
|
||||
normalizer_service, "_normalize_audio_one_pass",
|
||||
) as mock_normalize,
|
||||
patch(
|
||||
"app.services.sound_normalizer.get_audio_duration", return_value=5500
|
||||
"app.services.sound_normalizer.get_audio_duration", return_value=5500,
|
||||
),
|
||||
patch("app.services.sound_normalizer.get_file_size", return_value=1500),
|
||||
patch(
|
||||
"app.services.sound_normalizer.get_file_hash", return_value="norm_hash"
|
||||
"app.services.sound_normalizer.get_file_hash", return_value="norm_hash",
|
||||
),
|
||||
):
|
||||
# Setup path mocks
|
||||
@@ -300,7 +300,7 @@ class TestSoundNormalizerService:
|
||||
with (
|
||||
patch("pathlib.Path.exists", return_value=True),
|
||||
patch.object(
|
||||
normalizer_service, "_normalize_audio_two_pass"
|
||||
normalizer_service, "_normalize_audio_two_pass",
|
||||
) as mock_normalize,
|
||||
):
|
||||
mock_normalize.side_effect = Exception("Normalization failed")
|
||||
@@ -339,7 +339,7 @@ class TestSoundNormalizerService:
|
||||
|
||||
# Mock repository calls
|
||||
normalizer_service.sound_repo.get_unnormalized_sounds = AsyncMock(
|
||||
return_value=sounds
|
||||
return_value=sounds,
|
||||
)
|
||||
|
||||
# Mock individual normalization
|
||||
@@ -399,7 +399,7 @@ class TestSoundNormalizerService:
|
||||
|
||||
# Mock repository calls
|
||||
normalizer_service.sound_repo.get_unnormalized_sounds_by_type = AsyncMock(
|
||||
return_value=sdb_sounds
|
||||
return_value=sdb_sounds,
|
||||
)
|
||||
|
||||
# Mock individual normalization
|
||||
@@ -428,7 +428,7 @@ class TestSoundNormalizerService:
|
||||
|
||||
# Verify correct repository method was called
|
||||
normalizer_service.sound_repo.get_unnormalized_sounds_by_type.assert_called_once_with(
|
||||
"SDB"
|
||||
"SDB",
|
||||
)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -459,7 +459,7 @@ class TestSoundNormalizerService:
|
||||
|
||||
# Mock repository calls
|
||||
normalizer_service.sound_repo.get_unnormalized_sounds = AsyncMock(
|
||||
return_value=sounds
|
||||
return_value=sounds,
|
||||
)
|
||||
|
||||
# Mock individual normalization with one success and one error
|
||||
@@ -529,7 +529,7 @@ class TestSoundNormalizerService:
|
||||
# Verify ffmpeg chain was called correctly
|
||||
mock_ffmpeg.input.assert_called_once_with(str(input_path))
|
||||
mock_ffmpeg.filter.assert_called_once_with(
|
||||
mock_stream, "loudnorm", I=-23, TP=-2, LRA=7
|
||||
mock_stream, "loudnorm", I=-23, TP=-2, LRA=7,
|
||||
)
|
||||
mock_ffmpeg.output.assert_called_once()
|
||||
mock_ffmpeg.run.assert_called_once()
|
||||
|
||||
Reference in New Issue
Block a user