Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
kj-9 committed Feb 12, 2024
1 parent 6feafda commit e9f8d9d
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import json
from pathlib import Path

import pytest
from click.testing import CliRunner

from ocrvid.cli import cli
Expand All @@ -14,10 +16,23 @@ def test_lang_command():
assert result.output != ""


def test_run_command_with_frames_dir():
@pytest.fixture
def input_file():
return str(Path(__file__).parent / "video/pexels-eva-elijas.mp4")


def test_props_command(input_file):
runner = CliRunner()
with runner.isolated_filesystem():
result = runner.invoke(cli, ["props", input_file])

assert result.exit_code == 0
assert result.output != ""


def test_run_command_with_frames_dir(input_file):
runner = CliRunner()
with runner.isolated_filesystem():
input_file = str(Path(__file__).parent / "video/pexels-eva-elijas.mp4")
frames_dir_str = ".ocrvid/frames/pexels-eva-elijas"
result = runner.invoke(cli, ["run", input_file, "-fd", frames_dir_str])

Expand All @@ -30,10 +45,9 @@ def test_run_command_with_frames_dir():
assert result.output != ""


def test_run_command_with_custom_path():
def test_run_command_with_custom_path(input_file):
runner = CliRunner()
with runner.isolated_filesystem():
input_file = str(Path(__file__).parent / "video/pexels-eva-elijas.mp4")
result = runner.invoke(
cli,
["run", input_file, "-o", "some/custom.json", "-fd", "custom-frame-dir"],
Expand All @@ -42,3 +56,16 @@ def test_run_command_with_custom_path():
assert result.exit_code == 0
assert (Path.cwd() / "some/custom.json").exists()
assert (Path.cwd() / "custom-frame-dir").is_dir()


def test_run_command_with_by_second(input_file):
runner = CliRunner()
with runner.isolated_filesystem():
result = runner.invoke(cli, ["run", input_file, "-bs", "1"])

assert result.exit_code == 0
assert (Path.cwd() / "pexels-eva-elijas.json").exists()

with open(Path.cwd() / "pexels-eva-elijas.json") as f:
data = json.load(f)
assert len(data["frames"]) == 24 # 24 seconds in the video

0 comments on commit e9f8d9d

Please sign in to comment.