Download tests/test_export_hfd_overlay_assets.py from Tinghong-Ye22/code-HFD: direct link, hf CLI and curl.
- Browser
- Download file 1.84 kB
-
https://huggingface.co/Tinghong-Ye22/code-HFD/resolve/main/tests/test_export_hfd_overlay_assets.py
- Command line
-
hf download hf://Tinghong-Ye22/code-HFD/tests/test_export_hfd_overlay_assets.py
-
curl -L -o test_export_hfd_overlay_assets.py https://huggingface.co/Tinghong-Ye22/code-HFD/resolve/main/tests/test_export_hfd_overlay_assets.py
1.84 kB
| import json | |
| from pathlib import Path | |
| import pytest | |
| from scripts.data.export_hfd_overlay_assets import export, sha | |
| def approved(tmp_path): | |
| image, audio = tmp_path/'image.jpg', tmp_path/'question.wav' | |
| image.write_bytes(b'reviewed-image');audio.write_bytes(b'reviewed-wave') | |
| feature=tmp_path/'components_r0/visual'/f'{sha(str(image))}.pt' | |
| feature.parent.mkdir(parents=True);feature.write_bytes(b'existing-feature') | |
| row=dict(cohort='vqav2_static',id='vqav2_one',split='train',voice='female_01_en', | |
| question=dict(question='What color?',answer='red',image_path=str(image),image_sha256=sha(str(image))), | |
| visual_review=dict(accepted=True,blind_to_reference=True,image_sha256=sha(str(image))), | |
| asr_review=dict(accepted=True,wave_sha256=sha(str(audio))),timeline=dict(question_voice=str(audio))) | |
| plan=tmp_path/'source_plan.json';plan.write_text(json.dumps([row])) | |
| return plan,row | |
| def test_reuses_only_independent_question_and_visual_assets(tmp_path): | |
| plan,row=approved(tmp_path) | |
| result=export(plan,tmp_path) | |
| asset=result['assets'][0] | |
| assert result['format']=='hfd_overlay_assets_v1' | |
| assert asset['question_audio_path']==row['timeline']['question_voice'] | |
| assert 'path' not in asset and 'frontend_root' not in asset | |
| assert result['provenance']['motion_pairing_discarded'] is True | |
| def test_rejects_unapproved_visual_and_cross_split_image(tmp_path): | |
| plan,row=approved(tmp_path) | |
| row['visual_review']['blind_to_reference']=False | |
| plan.write_text(json.dumps([row])) | |
| with pytest.raises(ValueError,match='Unapproved'):export(plan,tmp_path) | |
| row['visual_review']['blind_to_reference']=True | |
| other={**row,'id':'vqav2_two','split':'val'} | |
| plan.write_text(json.dumps([row,other])) | |
| with pytest.raises(ValueError,match='overlaps'):export(plan,tmp_path) | |