File size: 1,494 Bytes
330f477
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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"