check_flac_bit_depth now delegates to check_quality_target, which probes the real file and treats bit depth as a MINIMUM (24-bit satisfies a 16-bit target) — the old context-string parsing, per-quality bit_depth_fallback, and 'reject higher bit depth' semantics are gone. Rewrite the wrapper tests to the probe-based model and update the rejection-reason assertion to the unified 'quality filter' wording. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
55 lines
2 KiB
Python
55 lines
2 KiB
Python
"""``check_flac_bit_depth`` is a thin legacy wrapper that delegates to the
|
|
unified ``check_quality_target`` guard, which probes the REAL file (mutagen)
|
|
and ranks it against the v3 ranked-targets list.
|
|
|
|
The old per-quality ``bit_depth_fallback`` config and the "reject a higher bit
|
|
depth" semantics are gone by design: bit depth is now a MINIMUM, so a 24-bit
|
|
file satisfies a 16-bit target. These tests pin the wrapper's current
|
|
behaviour (deeper coverage of ``check_quality_target`` lives in
|
|
``tests/imports/test_quality_guard.py``).
|
|
"""
|
|
|
|
from types import SimpleNamespace
|
|
|
|
import core.imports.guards as guards
|
|
import core.imports.file_ops as file_ops
|
|
from core.quality.model import AudioQuality
|
|
|
|
|
|
class _FakeDB:
|
|
def __init__(self, profile):
|
|
self._profile = profile
|
|
|
|
def get_quality_profile(self):
|
|
return self._profile
|
|
|
|
|
|
_WANT_FLAC24 = {
|
|
"fallback_enabled": False,
|
|
"ranked_targets": [
|
|
{"label": "FLAC 24-bit/96kHz", "format": "flac", "bit_depth": 24, "min_sample_rate": 96000},
|
|
],
|
|
}
|
|
|
|
|
|
def _patch(monkeypatch, aq, profile):
|
|
monkeypatch.setattr(file_ops, "probe_audio_quality", lambda fp: aq)
|
|
monkeypatch.setattr(guards, "MusicDatabase", lambda: _FakeDB(profile))
|
|
monkeypatch.setattr(
|
|
guards, "_get_config_manager",
|
|
lambda: SimpleNamespace(get=lambda _key, default=None: False),
|
|
)
|
|
|
|
|
|
def test_check_flac_bit_depth_rejects_below_target(monkeypatch):
|
|
# 16-bit file, target wants 24-bit, fallback off → rejected.
|
|
_patch(monkeypatch, AudioQuality("flac", sample_rate=44100, bit_depth=16), _WANT_FLAC24)
|
|
reason = guards.check_flac_bit_depth("/tmp/Song One.flac", {})
|
|
assert reason is not None
|
|
assert "FLAC 24-bit/96kHz" in reason
|
|
|
|
|
|
def test_check_flac_bit_depth_accepts_when_meeting_target(monkeypatch):
|
|
# 24-bit/96k file meets the 24-bit target → accepted.
|
|
_patch(monkeypatch, AudioQuality("flac", sample_rate=96000, bit_depth=24), _WANT_FLAC24)
|
|
assert guards.check_flac_bit_depth("/tmp/Song One.flac", {}) is None
|