Add cleanup and artifact test coverage
This commit is contained in:
@@ -2,6 +2,7 @@ import os
|
||||
from argparse import Namespace
|
||||
from pathlib import Path
|
||||
import sys
|
||||
from dataclasses import dataclass
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -29,3 +30,42 @@ def test_infer_output_path_for_directory(tmp_path: Path) -> None:
|
||||
def test_infer_output_path_for_explicit_file(tmp_path: Path) -> None:
|
||||
destination = main.infer_output_path(tmp_path / "custom-name.txt", Path("clip.wav"), "txt")
|
||||
assert destination == tmp_path / "custom-name.txt"
|
||||
|
||||
|
||||
@dataclass
|
||||
class FakeResponse:
|
||||
content: bytes
|
||||
text: str
|
||||
|
||||
def raise_for_status(self) -> None:
|
||||
return None
|
||||
|
||||
|
||||
class FakeClient:
|
||||
def __init__(self, response: FakeResponse) -> None:
|
||||
self.response = response
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc, tb) -> None:
|
||||
return None
|
||||
|
||||
def post(self, endpoint: str, data: dict[str, str], files: dict[str, tuple[str, object, str]]):
|
||||
return self.response
|
||||
|
||||
|
||||
def test_main_writes_transcript_to_file(monkeypatch, tmp_path: Path, capsys) -> None:
|
||||
input_file = tmp_path / "clip.wav"
|
||||
input_file.write_bytes(b"audio")
|
||||
destination = tmp_path / "saved" / "clip.txt"
|
||||
|
||||
monkeypatch.setenv("WHISPER_REMOTE", "http://localhost:8000")
|
||||
monkeypatch.setattr(main.httpx, "Client", lambda timeout: FakeClient(FakeResponse(b"hello world", "hello world")))
|
||||
monkeypatch.setattr(sys, "argv", ["whisper-remote", str(input_file), "--model", "base", "--to-file", str(destination)])
|
||||
|
||||
exit_code = main.main()
|
||||
|
||||
assert exit_code == 0
|
||||
assert destination.read_bytes() == b"hello world"
|
||||
assert capsys.readouterr().out == f"{destination}\n"
|
||||
|
||||
Reference in New Issue
Block a user