Download tests/test_swa_speech_failures.py from Tinghong-Ye22/code-HFD: direct link, hf CLI and curl.
- Browser
- Download file 1.03 kB
-
https://huggingface.co/Tinghong-Ye22/code-HFD/resolve/main/tests/test_swa_speech_failures.py
- Command line
-
hf download hf://Tinghong-Ye22/code-HFD/tests/test_swa_speech_failures.py
-
curl -L -o test_swa_speech_failures.py https://huggingface.co/Tinghong-Ye22/code-HFD/resolve/main/tests/test_swa_speech_failures.py
1.03 kB
| from concurrent.futures import Future, ThreadPoolExecutor | |
| import pytest | |
| from psi.runtime.swa_speech import SwaSpeechWorker, IncompleteSpeechError | |
| def worker(error): | |
| result=SwaSpeechWorker.__new__(SwaSpeechWorker) | |
| result.pool=ThreadPoolExecutor(1) | |
| good,bad=Future(),Future() | |
| good.set_result({'text':'complete answer'}) | |
| bad.set_exception(error) | |
| result.jobs=[good,bad] | |
| return result | |
| def test_keep_completed_answers_but_explicitly_report_codec_limit(): | |
| speech=worker(IncompleteSpeechError('codec limit')) | |
| assert speech.finish(allow_incomplete=True)==[{'text':'complete answer'}] | |
| assert speech.failures==[{'ordinal':1,'error':'codec limit'}] | |
| def test_legacy_strict_behavior_remains(): | |
| speech=worker(IncompleteSpeechError('codec limit')) | |
| with pytest.raises(IncompleteSpeechError):speech.finish() | |
| def test_model_or_cache_failure_is_never_swallowed(): | |
| speech=worker(RuntimeError('bad KV')) | |
| with pytest.raises(RuntimeError,match='bad KV'):speech.finish(allow_incomplete=True) | |