Refactor test cases for improved readability and consistency
- Adjusted function signatures in various test files to enhance clarity by aligning parameters. - Updated patching syntax for better readability across test cases. - Improved formatting and spacing in test assertions and mock setups. - Ensured consistent use of async/await patterns in async test functions. - Enhanced comments for better understanding of test intentions.
This commit is contained in:
@@ -156,7 +156,8 @@ class ExtractionService:
|
||||
|
||||
# Check if extraction already exists for this service
|
||||
existing = await self.extraction_repo.get_by_service_and_id(
|
||||
service_info["service"], service_info["service_id"],
|
||||
service_info["service"],
|
||||
service_info["service_id"],
|
||||
)
|
||||
if existing and existing.id != extraction_id:
|
||||
error_msg = (
|
||||
@@ -181,7 +182,8 @@ class ExtractionService:
|
||||
|
||||
# Extract audio and thumbnail
|
||||
audio_file, thumbnail_file = await self._extract_media(
|
||||
extraction_id, extraction_url,
|
||||
extraction_id,
|
||||
extraction_url,
|
||||
)
|
||||
|
||||
# Move files to final locations
|
||||
@@ -227,7 +229,9 @@ class ExtractionService:
|
||||
except Exception as e:
|
||||
error_msg = str(e)
|
||||
logger.exception(
|
||||
"Failed to process extraction %d: %s", extraction_id, error_msg,
|
||||
"Failed to process extraction %d: %s",
|
||||
extraction_id,
|
||||
error_msg,
|
||||
)
|
||||
else:
|
||||
return {
|
||||
@@ -262,7 +266,9 @@ class ExtractionService:
|
||||
}
|
||||
|
||||
async def _extract_media(
|
||||
self, extraction_id: int, extraction_url: str,
|
||||
self,
|
||||
extraction_id: int,
|
||||
extraction_url: str,
|
||||
) -> tuple[Path, Path | None]:
|
||||
"""Extract audio and thumbnail using yt-dlp."""
|
||||
temp_dir = Path(settings.EXTRACTION_TEMP_DIR)
|
||||
|
||||
@@ -65,7 +65,8 @@ class ExtractionProcessor:
|
||||
# The processor will pick it up on the next cycle
|
||||
else:
|
||||
logger.warning(
|
||||
"Extraction %d is already being processed", extraction_id,
|
||||
"Extraction %d is already being processed",
|
||||
extraction_id,
|
||||
)
|
||||
|
||||
async def _process_queue(self) -> None:
|
||||
|
||||
@@ -35,10 +35,11 @@ async def _is_current_playlist(session: AsyncSession, playlist_id: int) -> bool:
|
||||
|
||||
playlist_repo = PlaylistRepository(session)
|
||||
current_playlist = await playlist_repo.get_current_playlist()
|
||||
return current_playlist is not None and current_playlist.id == playlist_id
|
||||
except Exception: # noqa: BLE001
|
||||
logger.warning("Failed to check if playlist is current", exc_info=True)
|
||||
return False
|
||||
else:
|
||||
return current_playlist is not None and current_playlist.id == playlist_id
|
||||
|
||||
|
||||
class PlaylistService:
|
||||
@@ -199,7 +200,7 @@ class PlaylistService:
|
||||
await self.playlist_repo.delete(playlist)
|
||||
logger.info("Deleted playlist %s for user %s", playlist_id, user_id)
|
||||
|
||||
# If the deleted playlist was current, reload player to use main playlist fallback
|
||||
# If the deleted playlist was current, reload player to use main fallback
|
||||
if was_current:
|
||||
await _reload_player_playlist()
|
||||
|
||||
|
||||
@@ -140,7 +140,10 @@ class SoundNormalizerService:
|
||||
stream = ffmpeg.overwrite_output(stream)
|
||||
|
||||
await asyncio.to_thread(
|
||||
ffmpeg.run, stream, quiet=True, overwrite_output=True,
|
||||
ffmpeg.run,
|
||||
stream,
|
||||
quiet=True,
|
||||
overwrite_output=True,
|
||||
)
|
||||
logger.info("One-pass normalization completed: %s", output_path)
|
||||
|
||||
@@ -180,7 +183,10 @@ class SoundNormalizerService:
|
||||
# Run first pass and capture output
|
||||
try:
|
||||
result = await asyncio.to_thread(
|
||||
ffmpeg.run, stream, capture_stderr=True, quiet=True,
|
||||
ffmpeg.run,
|
||||
stream,
|
||||
capture_stderr=True,
|
||||
quiet=True,
|
||||
)
|
||||
analysis_output = result[1].decode("utf-8")
|
||||
except ffmpeg.Error as e:
|
||||
@@ -262,7 +268,10 @@ class SoundNormalizerService:
|
||||
|
||||
try:
|
||||
await asyncio.to_thread(
|
||||
ffmpeg.run, stream, quiet=True, overwrite_output=True,
|
||||
ffmpeg.run,
|
||||
stream,
|
||||
quiet=True,
|
||||
overwrite_output=True,
|
||||
)
|
||||
logger.info("Two-pass normalization completed: %s", output_path)
|
||||
except ffmpeg.Error as e:
|
||||
|
||||
Reference in New Issue
Block a user