This repository has been archived by the owner on May 1, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
58 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,42 @@ | ||
#!/usr/bin/env python3 | ||
|
||
|
||
import sys | ||
from unittest.mock import patch | ||
|
||
from pydantic import BaseModel | ||
|
||
from whispering.cli import get_opts, is_valid_arg | ||
from whispering.cli import Mode, is_valid_arg | ||
|
||
|
||
class ArgExample(BaseModel): | ||
mode: Mode | ||
cmd: str | ||
ok: bool | ||
|
||
|
||
def test_options(): | ||
|
||
exs = [ | ||
ArgExample(cmd="--mode server --mic 0", ok=False), | ||
ArgExample(cmd="--mode server --mic 1", ok=False), | ||
ArgExample(cmd="--mode server --beam_size 3", ok=False), | ||
ArgExample(cmd="--mode server --temperature 0", ok=False), | ||
ArgExample(cmd="--mode server --num_block 3", ok=False), | ||
ArgExample(cmd="--mode mic --host 0.0.0.0", ok=False), | ||
ArgExample(cmd="--mode mic --port 8000", ok=False), | ||
ArgExample(mode=Mode.server, cmd="--mic 0", ok=False), | ||
ArgExample(mode=Mode.server, cmd="--mic 1", ok=False), | ||
ArgExample( | ||
mode=Mode.server, | ||
cmd="--host 0.0.0.0 --port 8000", | ||
ok=True, | ||
), | ||
ArgExample( | ||
mode=Mode.server, | ||
cmd="--language en --model tiny --host 0.0.0.0 --port 8000", | ||
ok=True, | ||
), | ||
ArgExample(mode=Mode.server, cmd="--beam_size 3", ok=False), | ||
ArgExample(mode=Mode.server, cmd="--temperature 0", ok=False), | ||
ArgExample(mode=Mode.server, cmd="--num_block 3", ok=False), | ||
ArgExample(mode=Mode.mic, cmd="--host 0.0.0.0", ok=False), | ||
ArgExample(mode=Mode.mic, cmd="--port 8000", ok=False), | ||
] | ||
|
||
for ex in exs: | ||
with patch.object(sys, "argv", [""] + ex.cmd.split()): | ||
opts = get_opts() | ||
ok = is_valid_arg(opts) | ||
assert ok is ex.ok, f"{ex.cmd} should be invalid" | ||
ok = is_valid_arg( | ||
mode=ex.mode.value, | ||
args=ex.cmd.split(), | ||
) | ||
assert ok is ex.ok, f"{ex.cmd} should be {ex.ok}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters