Improved test

This commit is contained in:
Yuta Hayashibe 2022-10-17 21:18:13 +09:00
parent 256bf38b4d
commit 62b6d9a3b0

View file

@ -4,23 +4,30 @@
import sys import sys
from unittest.mock import patch from unittest.mock import patch
from pydantic import BaseModel
from whispering.cli import get_opts, is_valid_arg from whispering.cli import get_opts, is_valid_arg
class ArgExample(BaseModel):
cmd: str
ok: bool
def test_options(): def test_options():
invalid_args = [ exs = [
"--mode server --mic 0", ArgExample(cmd="--mode server --mic 0", ok=False),
"--mode server --mic 1", ArgExample(cmd="--mode server --mic 1", ok=False),
"--mode server --beam_size 3", ArgExample(cmd="--mode server --beam_size 3", ok=False),
"--mode server --temperature 0", ArgExample(cmd="--mode server --temperature 0", ok=False),
"--mode server --num_block 3", ArgExample(cmd="--mode server --num_block 3", ok=False),
"--mode mic --host 0.0.0.0", ArgExample(cmd="--mode mic --host 0.0.0.0", ok=False),
"--mode mic --port 8000", ArgExample(cmd="--mode mic --port 8000", ok=False),
] ]
for invalid_arg in invalid_args: for ex in exs:
with patch.object(sys, "argv", [""] + invalid_arg.split()): with patch.object(sys, "argv", [""] + ex.cmd.split()):
opts = get_opts() opts = get_opts()
ok = is_valid_arg(opts) ok = is_valid_arg(opts)
assert ok is False, f"{invalid_arg} should be invalid" assert ok is ex.ok, f"{ex.cmd} should be invalid"