Spaces:
Running on Zero
Running on Zero
Download tests/conftest.py from WolfDavid/japanese-learning-avatar: direct link, hf CLI and curl.
- Browser
- Download file 2.29 kB
-
https://huggingface.co/spaces/WolfDavid/japanese-learning-avatar/resolve/f13c9e2db20eb1318242fc3e3dcebe3a465e367d/tests/conftest.py
- Command line
-
hf download hf://spaces/WolfDavid/japanese-learning-avatar@f13c9e2db20eb1318242fc3e3dcebe3a465e367d/tests/conftest.py
-
curl -L -o conftest.py https://huggingface.co/spaces/WolfDavid/japanese-learning-avatar/resolve/f13c9e2db20eb1318242fc3e3dcebe3a465e367d/tests/conftest.py
2.29 kB
| """Shared fixtures and the deployed-Space plumbing for the whole Phase 1 suite.""" | |
| from __future__ import annotations | |
| import json | |
| import wave | |
| from pathlib import Path | |
| import pytest | |
| FIXTURES = Path(__file__).parent / "fixtures" | |
| def pytest_addoption(parser): | |
| parser.addoption( | |
| "--space-url", | |
| action="store", | |
| default=None, | |
| help="Base URL of the deployed Space, e.g. https://wolfdavid-japanese-learning-avatar.hf.space", | |
| ) | |
| def pytest_collection_modifyitems(config, items): | |
| if config.getoption("--space-url"): | |
| return | |
| skip = pytest.mark.skip(reason="needs --space-url (deployed Space)") | |
| for item in items: | |
| if "deployed" in item.keywords: | |
| item.add_marker(skip) | |
| def space_url(request) -> str: | |
| url = request.config.getoption("--space-url") | |
| if not url: | |
| pytest.skip("needs --space-url") | |
| return url.rstrip("/") | |
| def fixtures_dir() -> Path: | |
| return FIXTURES | |
| def silence_wav() -> Path: | |
| return FIXTURES / "silence_30s.wav" | |
| def cafe_noise_wav() -> Path: | |
| return FIXTURES / "cafe_noise_30s.wav" | |
| def speech_wav() -> Path: | |
| """Japanese speech fixture. Produced by plan 01-04 from real VOICEVOX synthesis.""" | |
| p = FIXTURES / "speech_ja.wav" | |
| if not p.exists(): | |
| pytest.skip("speech_ja.wav not generated yet (plan 01-04)") | |
| return p | |
| def synth_meta() -> dict: | |
| """Recorded synthesis metadata written by plan 01-04. | |
| Shape: {"cases": {"<case>": {"query": "<file>.json", "wav": "<file>.wav", | |
| "text": "...", "speed_scale": 1.0, | |
| "duration_seconds": <float from the WAV header>, | |
| "mora_count": <int>, "vowel_symbols": [...]}}} | |
| """ | |
| p = FIXTURES / "synth_meta.json" | |
| if not p.exists(): | |
| pytest.skip("synth_meta.json not generated yet (plan 01-04)") | |
| return json.loads(p.read_text(encoding="utf-8")) | |
| def wav_duration_seconds(path: Path) -> float: | |
| with wave.open(str(path), "rb") as w: | |
| return w.getnframes() / float(w.getframerate()) | |