ASVspoof2019_LA / tests /test_schema.py
korallll's picture
test: add schema validation smoke tests
d929ead
Raw
History Blame Contribute Delete
1.32 kB
import json
from pathlib import Path
import pyarrow.parquet as pq
DATA_DIR = Path(__file__).resolve().parent.parent / "data"
def test_schema_columns():
shard = sorted(DATA_DIR.glob("test-*.parquet"))[0]
table = pq.read_table(str(shard))
assert set(table.column_names) == {"path", "audio", "label", "notes"}
def test_label_classes():
shard = sorted(DATA_DIR.glob("test-*.parquet"))[0]
table = pq.read_table(str(shard))
label_col = table.column("label")
unique_labels = set(label_col.to_pylist())
assert unique_labels == {0, 1}
def test_notes_parse_as_json():
shard = sorted(DATA_DIR.glob("test-*.parquet"))[0]
table = pq.read_table(str(shard))
notes_col = table.column("notes")
for i in range(min(10, table.num_rows)):
parsed = json.loads(notes_col[i].as_py())
assert "utterance_id" in parsed
assert parsed["utterance_id"].startswith("LA_E_")
assert "speaker_id" in parsed
assert parsed["speaker_id"].startswith("LA_")
def test_path_format():
shard = sorted(DATA_DIR.glob("test-*.parquet"))[0]
table = pq.read_table(str(shard))
path_col = table.column("path")
for i in range(min(10, table.num_rows)):
p = path_col[i].as_py()
assert p.endswith(".flac")
assert p.startswith("LA_E_")