File size: 2,090 Bytes
5cda731 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
"""
ビルド結果をテストする
"""
import argparse
import json
import time
from io import BytesIO
from pathlib import Path
from subprocess import Popen
from urllib.parse import urlencode
from urllib.request import Request, urlopen
import soundfile
base_url = "http://127.0.0.1:50021/"
def test_release_build(dist_dir: Path, skip_run_process: bool) -> None:
run_file = dist_dir / "run"
if not run_file.exists():
run_file = dist_dir / "run.exe"
# 起動
process = None
if not skip_run_process:
process = Popen([run_file.absolute()], cwd=dist_dir)
time.sleep(60) # 待機
# バージョン取得テスト
req = Request(base_url + "version")
with urlopen(req) as res:
assert len(res.read()) > 0
# テキスト -> クエリ
text = "こんにちは、音声合成の世界へようこそ"
req = Request(
base_url + "audio_query?" + urlencode({"speaker": "1", "text": text}),
method="POST",
)
with urlopen(req) as res:
query = json.loads(res.read().decode("utf-8"))
# クエリ -> 音声
req = Request(base_url + "synthesis?speaker=1", method="POST")
req.add_header("Content-Type", "application/json")
req.data = json.dumps(query).encode("utf-8")
with urlopen(req) as res:
wave = res.read()
soundfile.read(BytesIO(wave))
# エンジンマニフェスト
req = Request(base_url + "engine_manifest", method="GET")
with urlopen(req) as res:
manifest = json.loads(res.read().decode("utf-8"))
assert "uuid" in manifest
if not skip_run_process:
# プロセスが稼働中であることを確認
assert process.poll() is None
# 停止
process.terminate()
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--dist_dir", type=Path, default=Path("dist/"))
parser.add_argument("--skip_run_process", action="store_true")
args = parser.parse_args()
test_release_build(dist_dir=args.dist_dir, skip_run_process=args.skip_run_process)
|