File size: 3,271 Bytes
f4931e8 | 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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | from __future__ import annotations
import csv
import tempfile
import unittest
from pathlib import Path
from buddi_asr.data.local import import_local_csv
from buddi_asr.data.manifest import read_manifest
from buddi_asr.errors import ManifestError
from tests.helpers import write_silent_wav
class LocalImportTests(unittest.TestCase):
def test_consent_and_identity_pseudonymization(self) -> None:
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
write_silent_wav(root / "private-name.wav")
csv_path = root / "input.csv"
with csv_path.open("w", encoding="utf-8", newline="") as handle:
writer = csv.DictWriter(
handle,
fieldnames=[
"audio",
"text",
"speaker_key",
"language",
"consent_basis",
"dialect",
"age_group",
],
)
writer.writeheader()
writer.writerow(
{
"audio": "private-name.wav",
"text": "بودي شنو يعني ديناصور",
"speaker_key": "private-child-key",
"language": "ar",
"consent_basis": "verified_parental_consent",
"dialect": "gulf_omani",
"age_group": "6-8",
}
)
output = root / "manifests/local.jsonl"
report = import_local_csv(
csv_path,
output,
processed_audio_dir=root / "processed",
salt="0123456789abcdef",
)
item = next(read_manifest(output))
self.assertEqual(report["direct_identity_exported"], False)
self.assertNotIn("private-name", item.audio)
self.assertNotIn("private-child-key", output.read_text(encoding="utf-8"))
def test_invalid_consent_is_rejected(self) -> None:
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
write_silent_wav(root / "a.wav")
csv_path = root / "input.csv"
with csv_path.open("w", encoding="utf-8", newline="") as handle:
writer = csv.DictWriter(handle, fieldnames=sorted({
"audio", "text", "speaker_key", "language", "consent_basis"
}))
writer.writeheader()
writer.writerow(
{
"audio": "a.wav",
"text": "hello",
"speaker_key": "child-1",
"language": "en",
"consent_basis": "unknown",
}
)
with self.assertRaises(ManifestError):
import_local_csv(
csv_path,
root / "out.jsonl",
processed_audio_dir=root / "processed",
salt="0123456789abcdef",
)
if __name__ == "__main__":
unittest.main()
|