Skip to main content

tests/python/test_cli.py

1"""
2Tests for the CLI scripts.
3"""
5from pathlib import Path
6import subprocess
7from subprocess import PIPE
9from chives import cli # noqa: F401
12class TestConvertSrtToVtt:
13 """
14 Tests for the `srt-to-vtt` command.
15 """
17 def test_no_args(self) -> None:
18 """
19 If you don't supply any arguments, you get an error.
20 """
21 proc = subprocess.Popen(["srt-to-vtt"], stdout=PIPE, stderr=PIPE, text=True)
22 stdout, stderr = proc.communicate(timeout=1)
24 assert proc.returncode == 1
25 assert stdout == ""
26 assert stderr == "Usage: srt-to-vtt <SRT_PATH>...\n"
28 def test_multiple_args(self, tmp_path: Path) -> None:
29 """
30 If you supply multiple SRT paths, they all get converted to VTT.
31 """
32 srt_path1 = tmp_path / "example1.en.srt"
33 srt_path1.write_text(
34 "1\n00:00:01,001 --> 00:00:10,010\nSomebody said the first thing\n"
35 )
37 srt_path2 = tmp_path / "example2.en.srt"
38 srt_path2.write_text(
39 "1\n00:02:00,002 --> 00:20:00,020\nSomebody else said the second thing\n"
40 )
42 proc = subprocess.Popen(
43 ["srt-to-vtt", str(srt_path1), str(srt_path2)],
44 stdout=PIPE,
45 stderr=PIPE,
46 text=True,
47 )
48 stdout, stderr = proc.communicate(timeout=1)
50 assert proc.returncode == 0
51 assert stdout == (f"{tmp_path}/example1.en.vtt\n{tmp_path}/example2.en.vtt\n")
52 assert stderr == ""