Spaces:
Running on Zero
Running on Zero
Download tests/test_audio.py from fffiloni/ZONOS3-Mini: direct link, hf CLI and curl.
- Browser
- Download file 1.51 kB
-
https://huggingface.co/spaces/fffiloni/ZONOS3-Mini/resolve/main/tests/test_audio.py
- Command line
-
hf download hf://spaces/fffiloni/ZONOS3-Mini/tests/test_audio.py
-
curl -L -o test_audio.py https://huggingface.co/spaces/fffiloni/ZONOS3-Mini/resolve/main/tests/test_audio.py
1.51 kB
| import numpy as np | |
| import pytest | |
| import soundfile as sf | |
| from audio_files import export_take, prune_outputs, read_reference | |
| from requests_schema import InputError | |
| def test_silent_reference_rejected(tmp_path): | |
| p=tmp_path/'silent.wav';sf.write(p,np.zeros(16000),16000) | |
| with pytest.raises(InputError):read_reference(p) | |
| def test_reference_duration_and_original_bytes(tmp_path): | |
| p=tmp_path/'voice.wav';sf.write(p,.1*np.sin(np.arange(16000)*.05),16000) | |
| assert read_reference(p)==p.read_bytes() | |
| short=tmp_path/'short.wav';sf.write(short,np.ones(20)*.1,16000) | |
| with pytest.raises(InputError):read_reference(short) | |
| def test_invalid_output_is_not_saved(tmp_path,pcm): | |
| with pytest.raises(ValueError):export_take(pcm,tmp_path,seed=1,request_seconds=1,inference_seconds=.5) | |
| assert not list(tmp_path.iterdir()) | |
| def test_pruning_tolerates_another_session_removing_old_output(tmp_path, monkeypatch): | |
| from pathlib import Path | |
| old=tmp_path/'zonos-old.wav';old.write_bytes(b'old') | |
| fresh=tmp_path/'zonos-fresh.wav';fresh.write_bytes(b'fresh') | |
| original_stat=Path.stat | |
| def raced_stat(path, *args, **kwargs): | |
| if path == old: | |
| old.unlink(missing_ok=True) | |
| raise FileNotFoundError() | |
| return original_stat(path, *args, **kwargs) | |
| monkeypatch.setattr(Path,'stat',raced_stat) | |
| prune_outputs(tmp_path) | |
| assert fresh.read_bytes()==b'fresh' | |