| from __future__ import annotations |
|
|
| import tempfile |
| import unittest |
| from pathlib import Path |
| from types import SimpleNamespace |
| from unittest.mock import patch |
|
|
| import numpy as np |
|
|
| import app |
| from turn_detection.runtime import Prediction |
|
|
|
|
| class _DevelopmentPredictor: |
| metadata = SimpleNamespace( |
| development_only=True, |
| training_status="preview-only", |
| data_scope="one audited shard", |
| threshold=0.73, |
| ) |
|
|
| def predict(self, audio: object, sample_rate: int) -> Prediction: |
| del audio, sample_rate |
| return Prediction( |
| endpoint_probability=0.8, |
| inference_ms=1.25, |
| model_name="partial-preview", |
| ) |
|
|
|
|
| class DemoEvidenceStatusTest(unittest.TestCase): |
| def test_default_model_supports_space_and_model_repository_layouts(self) -> None: |
| with tempfile.TemporaryDirectory() as directory: |
| root = Path(directory) |
| space_model = root / "artifacts" / "model.onnx" |
| repository_model = root / "model.onnx" |
| repository_model.write_bytes(b"onnx") |
| with patch.object( |
| app, |
| "DEFAULT_MODEL_CANDIDATES", |
| (space_model, repository_model), |
| ): |
| self.assertEqual(app._default_model_path(), repository_model) |
|
|
| space_model.parent.mkdir(parents=True) |
| space_model.write_bytes(b"onnx") |
| with patch.object( |
| app, |
| "DEFAULT_MODEL_CANDIDATES", |
| (space_model, repository_model), |
| ): |
| self.assertEqual(app._default_model_path(), space_model) |
|
|
| space_model.unlink() |
| repository_model.unlink() |
| with patch.object( |
| app, |
| "DEFAULT_MODEL_CANDIDATES", |
| (space_model, repository_model), |
| ): |
| self.assertEqual(app._default_model_path(), space_model) |
|
|
| def test_development_model_is_conspicuously_labelled(self) -> None: |
| with patch.object(app, "get_predictor", return_value=_DevelopmentPredictor()): |
| status, labels, diagnostics, timeline = app.analyze_turn( |
| (16_000, np.zeros(1_600, dtype=np.float32)), |
| threshold=0.73, |
| silence_ms=300, |
| max_silence_ms=1_800, |
| ) |
|
|
| self.assertIn("Development model", status) |
| self.assertIn("one audited shard", status) |
| self.assertTrue(diagnostics["development_only"]) |
| self.assertTrue(diagnostics["emit_response"]) |
| self.assertEqual(diagnostics["training_status"], "preview-only") |
| self.assertEqual(labels["END"], 0.8) |
| self.assertIn("threshold 0.73", timeline) |
|
|
|
|
| if __name__ == "__main__": |
| unittest.main() |
|
|