Add comprehensive tests for playlist service and refactor socket service tests

- Introduced a new test suite for the PlaylistService covering various functionalities including creation, retrieval, updating, and deletion of playlists.
- Added tests for handling sounds within playlists, ensuring correct behavior when adding/removing sounds and managing current playlists.
- Refactored socket service tests for improved readability by adjusting function signatures.
- Cleaned up unnecessary whitespace in sound normalizer and sound scanner tests for consistency.
- Enhanced audio utility tests to ensure accurate hash and size calculations, including edge cases for nonexistent files.
- Removed redundant blank lines in cookie utility tests for cleaner code.
This commit is contained in:
JSC
2025-07-29 19:25:46 +02:00
parent 301b5dd794
commit 5ed19c8f0f
31 changed files with 4248 additions and 194 deletions

View File

@@ -107,7 +107,6 @@ class SoundNormalizerService:
original_dir = type_to_original_dir.get(sound_type, "sounds/originals/other")
return Path(original_dir) / filename
async def _normalize_audio_one_pass(
self,
input_path: Path,
@@ -178,9 +177,12 @@ class SoundNormalizerService:
result = ffmpeg.run(stream, capture_stderr=True, quiet=True)
analysis_output = result[1].decode("utf-8")
except ffmpeg.Error as e:
logger.error("FFmpeg first pass failed for %s. Stdout: %s, Stderr: %s",
input_path, e.stdout.decode() if e.stdout else "None",
e.stderr.decode() if e.stderr else "None")
logger.error(
"FFmpeg first pass failed for %s. Stdout: %s, Stderr: %s",
input_path,
e.stdout.decode() if e.stdout else "None",
e.stderr.decode() if e.stderr else "None",
)
raise
# Extract loudnorm measurements from the output
@@ -190,19 +192,28 @@ class SoundNormalizerService:
# Find JSON in the output
json_match = re.search(r'\{[^{}]*"input_i"[^{}]*\}', analysis_output)
if not json_match:
logger.error("Could not find JSON in loudnorm output: %s", analysis_output)
logger.error(
"Could not find JSON in loudnorm output: %s", analysis_output
)
raise ValueError("Could not extract loudnorm analysis data")
logger.debug("Found JSON match: %s", json_match.group())
analysis_data = json.loads(json_match.group())
# Check for invalid values that would cause second pass to fail
invalid_values = ["-inf", "inf", "nan"]
for key in ["input_i", "input_lra", "input_tp", "input_thresh", "target_offset"]:
for key in [
"input_i",
"input_lra",
"input_tp",
"input_thresh",
"target_offset",
]:
if str(analysis_data.get(key, "")).lower() in invalid_values:
logger.warning(
"Invalid analysis value for %s: %s. Falling back to one-pass normalization.",
key, analysis_data.get(key)
"Invalid analysis value for %s: %s. Falling back to one-pass normalization.",
key,
analysis_data.get(key),
)
# Fall back to one-pass normalization
await self._normalize_audio_one_pass(input_path, output_path)
@@ -241,9 +252,12 @@ class SoundNormalizerService:
ffmpeg.run(stream, quiet=True, overwrite_output=True)
logger.info("Two-pass normalization completed: %s", output_path)
except ffmpeg.Error as e:
logger.error("FFmpeg second pass failed for %s. Stdout: %s, Stderr: %s",
input_path, e.stdout.decode() if e.stdout else "None",
e.stderr.decode() if e.stderr else "None")
logger.error(
"FFmpeg second pass failed for %s. Stdout: %s, Stderr: %s",
input_path,
e.stdout.decode() if e.stdout else "None",
e.stderr.decode() if e.stderr else "None",
)
raise
except Exception as e: