Datasets:
Download src/test_common_voice_pl_contract.py from SlayerLab/polish-dynaword: direct link, hf CLI and curl.
- Browser
- Download file 3.01 kB
-
https://huggingface.co/datasets/SlayerLab/polish-dynaword/resolve/f15edbb30e543ec414549121849ca063522a862d/src/test_common_voice_pl_contract.py
- Command line
-
hf download hf://datasets/SlayerLab/polish-dynaword@f15edbb30e543ec414549121849ca063522a862d/src/test_common_voice_pl_contract.py
-
curl -L -o test_common_voice_pl_contract.py https://huggingface.co/datasets/SlayerLab/polish-dynaword/resolve/f15edbb30e543ec414549121849ca063522a862d/src/test_common_voice_pl_contract.py
3.01 kB
| """Contract checks for the common_voice_pl contribution.""" | |
| import hashlib | |
| import json | |
| from pathlib import Path | |
| import pyarrow.parquet as pq | |
| ROOT = Path(__file__).resolve().parents[1] | |
| DATA = ROOT / "data" / "common_voice_pl" | |
| MANIFEST = ROOT / "artifacts" / "common_voice_pl_ontology_manifest.json" | |
| def sha256_file(path): | |
| digest = hashlib.sha256() | |
| with path.open("rb") as stream: | |
| for chunk in iter(lambda: stream.read(1024 * 1024), b""): | |
| digest.update(chunk) | |
| return digest.hexdigest() | |
| def test_schema_and_counts(): | |
| parquet = DATA / "common_voice_pl.parquet" | |
| stats = json.loads((DATA / "common_voice_pl.stats.json").read_text(encoding="utf-8")) | |
| table = pq.read_table(parquet) | |
| assert table.column_names == ['id', 'text', 'source', 'added', 'created', 'token_count', 'license', 'author'] | |
| assert table.num_rows == stats["kept"] | |
| assert len(set(table.column("id").to_pylist())) == table.num_rows | |
| assert len(set(table.column("text").to_pylist())) == table.num_rows | |
| assert set(table.column("source").to_pylist()) == {"common_voice_pl"} | |
| assert set(table.column("license").to_pylist()) == {"CC0-1.0"} | |
| def test_privacy_and_sidecars(): | |
| stats = json.loads((DATA / "common_voice_pl.stats.json").read_text(encoding="utf-8")) | |
| sidecar = DATA / "common_voice_pl.attribution.jsonl" | |
| sample = DATA / "common_voice_pl.sample.jsonl" | |
| lines = [json.loads(line) for line in sidecar.read_text(encoding="utf-8").splitlines()] | |
| assert len(lines) == stats["kept"] | |
| assert len(sample.read_text(encoding="utf-8").splitlines()) == min(20, stats["kept"]) | |
| forbidden = {"client_id", "age", "gender", "accents", "path", "audio"} | |
| assert all(not (forbidden & set(item)) for item in lines) | |
| def test_manifest_and_checksums(): | |
| manifest = json.loads(MANIFEST.read_text(encoding="utf-8")) | |
| required = {"object", "version", "protocol", "run", "relations", "evidence", "claims", "claim_evidence", "actors", "attestations"} | |
| assert required <= set(manifest) | |
| assert manifest["ontology_version"] == "slayer.ai/research-ontology/v0.1" | |
| assert manifest["version"]["payload_uri"].startswith("hf://datasets/PiotrSty/common-voice-pl-text@") | |
| evidence = {item["observation_type"]: item["payload"] for item in manifest["evidence"]} | |
| checksums = evidence["artifact_checksums"] | |
| expected = { | |
| "parquet_sha256": DATA / "common_voice_pl.parquet", | |
| "attribution_sha256": DATA / "common_voice_pl.attribution.jsonl", | |
| "stats_sha256": DATA / "common_voice_pl.stats.json", | |
| "license_evidence_sha256": DATA / "common_voice_pl.license-evidence.json", | |
| "sample_sha256": DATA / "common_voice_pl.sample.jsonl", | |
| } | |
| if "language_audit_sha256" in checksums: | |
| expected["language_audit_sha256"] = ROOT / "artifacts" / "common_voice_pl_language_audit.json" | |
| assert {key: sha256_file(path) for key, path in expected.items()} == checksums | |