trackembeddingapi / tests /test_benchmark.py
kxmWebwe's picture
update
330f477
Raw
History Blame Contribute Delete
1.49 kB
from pathlib import Path
from tools.nearest_neighbors import _cache_key, _neighbor_report
def test_benchmark_cache_key_covers_content_model_and_configuration(tmp_path: Path):
audio = tmp_path / "track.wav"
audio.write_bytes(b"first content")
model = {
"model_id": "model",
"model_version": "revision",
"preprocessing_version": "prep",
"representation": "audio.global",
"configuration": {"windows": 4},
}
first = _cache_key(audio, None, model)
changed_model = {**model, "configuration": {"windows": 5}}
assert _cache_key(audio, None, changed_model) != first
audio.write_bytes(b"different content")
assert _cache_key(audio, None, model) != first
def test_temporal_neighbor_report_contains_both_experimental_metrics():
records = [
{
"path": "a.wav",
"representation": {
"segments": [{"embedding": [1.0, 0.0]}, {"embedding": [0.0, 1.0]}]
},
},
{
"path": "b.wav",
"representation": {
"segments": [
{"embedding": [1.0, 0.0]},
{"embedding": [0.7, 0.7]},
{"embedding": [0.0, 1.0]},
]
},
},
]
report = _neighbor_report(records, "audio.temporal", 1)
assert set(report["tracks"][0]["neighbors"]) == {"aligned", "dtw"}
assert report["tracks"][0]["neighbors"]["aligned"][0]["track"] == "b.wav"