vidfix 0.4.0__tar.gz → 0.4.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {vidfix-0.4.0 → vidfix-0.4.2}/CHANGELOG.md +32 -0
- {vidfix-0.4.0 → vidfix-0.4.2}/PKG-INFO +1 -1
- {vidfix-0.4.0 → vidfix-0.4.2}/pyproject.toml +3 -1
- {vidfix-0.4.0 → vidfix-0.4.2}/src/vidfix/__init__.py +1 -1
- {vidfix-0.4.0 → vidfix-0.4.2}/src/vidfix/cli.py +9 -0
- {vidfix-0.4.0 → vidfix-0.4.2}/src/vidfix/core/convert.py +2 -0
- vidfix-0.4.2/tests/e2e/test_cli_journey.py +213 -0
- vidfix-0.4.2/tests/smoke/test_cli_boots.py +164 -0
- {vidfix-0.4.0 → vidfix-0.4.2}/tests/test_convert.py +22 -0
- {vidfix-0.4.0 → vidfix-0.4.2}/tests/test_integration.py +11 -0
- {vidfix-0.4.0 → vidfix-0.4.2}/uv.lock +2 -2
- {vidfix-0.4.0 → vidfix-0.4.2}/.github/dependabot.yml +0 -0
- {vidfix-0.4.0 → vidfix-0.4.2}/.github/workflows/ci.yml +0 -0
- {vidfix-0.4.0 → vidfix-0.4.2}/.github/workflows/publish.yml +0 -0
- {vidfix-0.4.0 → vidfix-0.4.2}/.gitignore +0 -0
- {vidfix-0.4.0 → vidfix-0.4.2}/.python-version +0 -0
- {vidfix-0.4.0 → vidfix-0.4.2}/LICENSE +0 -0
- {vidfix-0.4.0 → vidfix-0.4.2}/README.md +0 -0
- {vidfix-0.4.0 → vidfix-0.4.2}/src/vidfix/__main__.py +0 -0
- {vidfix-0.4.0 → vidfix-0.4.2}/src/vidfix/core/__init__.py +0 -0
- {vidfix-0.4.0 → vidfix-0.4.2}/src/vidfix/core/attach.py +0 -0
- {vidfix-0.4.0 → vidfix-0.4.2}/src/vidfix/core/capabilities.py +0 -0
- {vidfix-0.4.0 → vidfix-0.4.2}/src/vidfix/core/caption.py +0 -0
- {vidfix-0.4.0 → vidfix-0.4.2}/src/vidfix/core/duration.py +0 -0
- {vidfix-0.4.0 → vidfix-0.4.2}/src/vidfix/core/ffmpeg.py +0 -0
- {vidfix-0.4.0 → vidfix-0.4.2}/src/vidfix/core/formats.py +0 -0
- {vidfix-0.4.0 → vidfix-0.4.2}/src/vidfix/core/generate.py +0 -0
- {vidfix-0.4.0 → vidfix-0.4.2}/src/vidfix/core/matrix.py +0 -0
- {vidfix-0.4.0 → vidfix-0.4.2}/src/vidfix/core/presets.py +0 -0
- {vidfix-0.4.0 → vidfix-0.4.2}/src/vidfix/core/probe.py +0 -0
- {vidfix-0.4.0 → vidfix-0.4.2}/src/vidfix/core/verify.py +0 -0
- {vidfix-0.4.0 → vidfix-0.4.2}/src/vidfix/data/presets.yaml +0 -0
- {vidfix-0.4.0 → vidfix-0.4.2}/src/vidfix/exceptions.py +0 -0
- {vidfix-0.4.0 → vidfix-0.4.2}/src/vidfix/interactive.py +0 -0
- {vidfix-0.4.0 → vidfix-0.4.2}/src/vidfix/py.typed +0 -0
- {vidfix-0.4.0 → vidfix-0.4.2}/tests/test_attach.py +0 -0
- {vidfix-0.4.0 → vidfix-0.4.2}/tests/test_capabilities.py +0 -0
- {vidfix-0.4.0 → vidfix-0.4.2}/tests/test_caption.py +0 -0
- {vidfix-0.4.0 → vidfix-0.4.2}/tests/test_cli.py +0 -0
- {vidfix-0.4.0 → vidfix-0.4.2}/tests/test_duration.py +0 -0
- {vidfix-0.4.0 → vidfix-0.4.2}/tests/test_ffmpeg.py +0 -0
- {vidfix-0.4.0 → vidfix-0.4.2}/tests/test_formats.py +0 -0
- {vidfix-0.4.0 → vidfix-0.4.2}/tests/test_generate.py +0 -0
- {vidfix-0.4.0 → vidfix-0.4.2}/tests/test_guards.py +0 -0
- {vidfix-0.4.0 → vidfix-0.4.2}/tests/test_interactive.py +0 -0
- {vidfix-0.4.0 → vidfix-0.4.2}/tests/test_matrix.py +0 -0
- {vidfix-0.4.0 → vidfix-0.4.2}/tests/test_presets.py +0 -0
- {vidfix-0.4.0 → vidfix-0.4.2}/tests/test_probe.py +0 -0
- {vidfix-0.4.0 → vidfix-0.4.2}/tests/test_public_api.py +0 -0
- {vidfix-0.4.0 → vidfix-0.4.2}/tests/test_verify.py +0 -0
|
@@ -5,6 +5,38 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.4.2] - 2026-10-31
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- **Windows: every command that wrote a file crashed.** `vidfix generate`,
|
|
13
|
+
`convert`, `caption` and the rest printed a green tick on success, which a
|
|
14
|
+
console on a legacy code page cannot encode, so the command died with
|
|
15
|
+
`UnicodeEncodeError: 'charmap' codec can't encode character '\u2713'`
|
|
16
|
+
instead of reporting the file it had just written. The CLI now sets its own
|
|
17
|
+
output streams to UTF-8.
|
|
18
|
+
|
|
19
|
+
### Internal
|
|
20
|
+
|
|
21
|
+
- New `tests/smoke/` and `tests/e2e/` layers run the real CLI against real
|
|
22
|
+
files on every platform in CI. The existing tests drive the commands with
|
|
23
|
+
the FFmpeg layer mocked, or call the Python functions directly; neither runs
|
|
24
|
+
what a user runs, which is why the Windows crash above went unnoticed.
|
|
25
|
+
|
|
26
|
+
## [0.4.1] - 2026-10-19
|
|
27
|
+
|
|
28
|
+
### What's new
|
|
29
|
+
|
|
30
|
+
- **More exact: looping a clip to make it longer keeps its frame rate.**
|
|
31
|
+
Stretching a 1-minute 29.97 fps clip to 5 minutes with loop now gives
|
|
32
|
+
exactly 29.97 fps and 5:00, so `verify` passes.
|
|
33
|
+
|
|
34
|
+
### Fixed
|
|
35
|
+
|
|
36
|
+
- `convert --extend-mode loop` (and "loop" in the wizard) drifted the frame
|
|
37
|
+
rate at every loop point (29.97 came out as 29.957). The output now keeps the
|
|
38
|
+
source frame rate exactly.
|
|
39
|
+
|
|
8
40
|
## [0.4.0] - 2026-09-27
|
|
9
41
|
|
|
10
42
|
### What's new
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: vidfix
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.2
|
|
4
4
|
Summary: CLI toolkit to convert, generate, and verify videos and images to exact specs (fps, duration, resolution, format) — test fixtures, CI checks, and everyday conversions.
|
|
5
5
|
Project-URL: Homepage, https://github.com/gouravrana7/vidfix
|
|
6
6
|
Project-URL: Issues, https://github.com/gouravrana7/vidfix/issues
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "vidfix"
|
|
3
|
-
version = "0.4.
|
|
3
|
+
version = "0.4.2"
|
|
4
4
|
description = "CLI toolkit to convert, generate, and verify videos and images to exact specs (fps, duration, resolution, format) — test fixtures, CI checks, and everyday conversions."
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = { text = "MIT" }
|
|
@@ -90,6 +90,8 @@ testpaths = ["tests"]
|
|
|
90
90
|
addopts = "-q"
|
|
91
91
|
markers = [
|
|
92
92
|
"integration: tests that invoke the real FFmpeg binary (slower)",
|
|
93
|
+
"smoke: does it start at all -- no encoding, under a second",
|
|
94
|
+
"e2e: the real CLI binary on real files, start to finish (slowest)",
|
|
93
95
|
]
|
|
94
96
|
|
|
95
97
|
[tool.coverage.run]
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
+
import contextlib
|
|
6
|
+
import sys
|
|
5
7
|
from pathlib import Path
|
|
6
8
|
from typing import Annotated, NoReturn
|
|
7
9
|
|
|
@@ -30,6 +32,13 @@ app = typer.Typer(
|
|
|
30
32
|
),
|
|
31
33
|
rich_markup_mode="rich",
|
|
32
34
|
)
|
|
35
|
+
# A Windows console still defaults to a legacy code page, where printing
|
|
36
|
+
# "✓" raises UnicodeEncodeError and takes the whole command down with it.
|
|
37
|
+
# This module is the CLI entry point, so it owns its own streams.
|
|
38
|
+
for _stream in (sys.stdout, sys.stderr):
|
|
39
|
+
with contextlib.suppress(AttributeError, ValueError, OSError):
|
|
40
|
+
_stream.reconfigure(encoding="utf-8", errors="replace") # type: ignore[union-attr]
|
|
41
|
+
|
|
33
42
|
console = Console()
|
|
34
43
|
err_console = Console(stderr=True)
|
|
35
44
|
|
|
@@ -146,6 +146,8 @@ def build_convert_plan(
|
|
|
146
146
|
vf.append(f"minterpolate=fps={rate}:mi_mode=mci")
|
|
147
147
|
else:
|
|
148
148
|
vf.append(f"fps=fps={rate}")
|
|
149
|
+
elif extending and extend_mode == "loop" and source.fps_fraction > 0:
|
|
150
|
+
vf.append(f"fps=fps={fps_to_ffmpeg(source.fps_fraction)}")
|
|
149
151
|
if duration is not None and duration > source.duration and extend_mode == "freeze":
|
|
150
152
|
vf.append(f"tpad=stop_mode=clone:stop_duration={duration - source.duration}")
|
|
151
153
|
vf += overlay_vf
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
"""End to end: the real CLI binary, real files, no mocks.
|
|
2
|
+
|
|
3
|
+
The rest of the suite covers this code two other ways -- `test_cli.py` drives
|
|
4
|
+
the commands with the FFmpeg layer mocked, and `test_integration.py` calls the
|
|
5
|
+
Python functions against real FFmpeg. Neither runs the thing a user runs. If
|
|
6
|
+
argument wiring, exit codes or file output broke, both would still pass.
|
|
7
|
+
|
|
8
|
+
These are the slowest tests in the repo on purpose. Every clip is one second
|
|
9
|
+
at 160x120.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import json
|
|
15
|
+
import re
|
|
16
|
+
import subprocess
|
|
17
|
+
import sys
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
|
|
20
|
+
import pytest
|
|
21
|
+
|
|
22
|
+
from vidfix import probe
|
|
23
|
+
|
|
24
|
+
pytestmark = pytest.mark.e2e
|
|
25
|
+
|
|
26
|
+
TIMEOUT = 300
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def cli(*args: str) -> subprocess.CompletedProcess[str]:
|
|
30
|
+
"""Run the CLI the way a user does, through the module entry point.
|
|
31
|
+
|
|
32
|
+
stdin is DEVNULL because with no arguments the CLI opens an interactive
|
|
33
|
+
wizard and a test must never wait on a prompt. It is DEVNULL rather than
|
|
34
|
+
`input=""`, which on Windows returned a CompletedProcess whose stdout was
|
|
35
|
+
None. The encoding is explicit so a Windows runner does not decode the
|
|
36
|
+
output with its local code page.
|
|
37
|
+
"""
|
|
38
|
+
return subprocess.run(
|
|
39
|
+
[sys.executable, "-m", "vidfix", *args],
|
|
40
|
+
capture_output=True,
|
|
41
|
+
stdin=subprocess.DEVNULL,
|
|
42
|
+
text=True,
|
|
43
|
+
encoding="utf-8",
|
|
44
|
+
errors="replace",
|
|
45
|
+
timeout=TIMEOUT,
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def said(done: subprocess.CompletedProcess[str]) -> str:
|
|
50
|
+
"""Both streams as one string. Rich sends errors to either one."""
|
|
51
|
+
return (done.stdout or "") + (done.stderr or "")
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
ANSI = re.compile(r"\x1b\[[0-9;]*m")
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def plain(text: str) -> str:
|
|
58
|
+
"""Rich wraps and colours its errors, so match on the text, not the bytes."""
|
|
59
|
+
return ANSI.sub("", text).replace("\n", " ")
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def spoke(done: subprocess.CompletedProcess[str]) -> str:
|
|
63
|
+
"""Both streams, de-coloured and unwrapped."""
|
|
64
|
+
return plain(said(done))
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def ok(*args: str) -> subprocess.CompletedProcess[str]:
|
|
68
|
+
done = cli(*args)
|
|
69
|
+
assert done.returncode == 0, f"vidfix {' '.join(args)} failed:\n{said(done)}"
|
|
70
|
+
return done
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
@pytest.fixture(scope="module")
|
|
74
|
+
def clip(tmp_path_factory: pytest.TempPathFactory) -> Path:
|
|
75
|
+
"""One generated clip, made through the CLI, reused by the read-only tests."""
|
|
76
|
+
out = tmp_path_factory.mktemp("e2e") / "base.mp4"
|
|
77
|
+
ok("generate", "-o", str(out), "--fps", "30", "--duration", "1", "--res", "160x120")
|
|
78
|
+
return out
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class TestGenerate:
|
|
82
|
+
def test_it_writes_a_file_that_matches_the_spec(self, clip: Path) -> None:
|
|
83
|
+
assert clip.exists() and clip.stat().st_size > 0
|
|
84
|
+
info = probe(clip)
|
|
85
|
+
assert (info.width, info.height) == (160, 120)
|
|
86
|
+
assert info.fps_float == pytest.approx(30, abs=0.01)
|
|
87
|
+
assert info.duration == pytest.approx(1.0, abs=0.15)
|
|
88
|
+
|
|
89
|
+
def test_a_missing_output_flag_is_a_clean_error(self, tmp_path: Path) -> None:
|
|
90
|
+
done = cli("generate", "--fps", "30")
|
|
91
|
+
assert done.returncode != 0
|
|
92
|
+
assert "Traceback" not in said(done)
|
|
93
|
+
assert "Usage" in spoke(done)
|
|
94
|
+
|
|
95
|
+
def test_an_impossible_spec_is_refused_without_writing_a_file(self, tmp_path: Path) -> None:
|
|
96
|
+
out = tmp_path / "bad.mp4"
|
|
97
|
+
done = cli("generate", "-o", str(out), "--fps", "0", "--duration", "1")
|
|
98
|
+
assert done.returncode != 0
|
|
99
|
+
assert "Traceback" not in said(done)
|
|
100
|
+
assert not out.exists(), "a refused spec must not leave a partial file behind"
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
class TestVerifyExitCode:
|
|
104
|
+
"""Verify is documented as a CI gate: exit 0 on pass, 1 on fail.
|
|
105
|
+
|
|
106
|
+
Nothing else in the suite runs that contract against a real file, and a
|
|
107
|
+
gate with the wrong exit code fails silently in every pipeline using it.
|
|
108
|
+
"""
|
|
109
|
+
|
|
110
|
+
def test_it_exits_zero_when_the_file_matches(self, clip: Path) -> None:
|
|
111
|
+
done = cli("verify", str(clip), "--fps", "30", "--res", "160x120")
|
|
112
|
+
assert done.returncode == 0, said(done)
|
|
113
|
+
|
|
114
|
+
def test_it_exits_one_when_the_file_does_not_match(self, clip: Path) -> None:
|
|
115
|
+
done = cli("verify", str(clip), "--fps", "60")
|
|
116
|
+
assert done.returncode == 1, f"expected a failed gate, got {done.returncode}"
|
|
117
|
+
|
|
118
|
+
def test_a_wrong_resolution_fails_the_gate(self, clip: Path) -> None:
|
|
119
|
+
assert cli("verify", str(clip), "--res", "1920x1080").returncode == 1
|
|
120
|
+
|
|
121
|
+
def test_a_wrong_codec_fails_the_gate(self, clip: Path) -> None:
|
|
122
|
+
assert cli("verify", str(clip), "--codec", "vp9").returncode == 1
|
|
123
|
+
|
|
124
|
+
def test_the_json_output_is_machine_readable(self, clip: Path) -> None:
|
|
125
|
+
done = cli("verify", str(clip), "--fps", "30", "--json")
|
|
126
|
+
assert done.returncode == 0, said(done)
|
|
127
|
+
payload = json.loads(done.stdout or "")
|
|
128
|
+
assert payload["passed"] is True
|
|
129
|
+
|
|
130
|
+
def test_the_json_output_still_parses_when_the_gate_fails(self, clip: Path) -> None:
|
|
131
|
+
done = cli("verify", str(clip), "--fps", "60", "--json")
|
|
132
|
+
assert done.returncode == 1
|
|
133
|
+
assert json.loads(done.stdout or "")["passed"] is False
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
class TestConvert:
|
|
137
|
+
def test_it_changes_fps_and_resolution_on_disk(self, clip: Path, tmp_path: Path) -> None:
|
|
138
|
+
out = tmp_path / "converted.mp4"
|
|
139
|
+
ok("convert", str(clip), "-o", str(out), "--fps", "15", "--res", "120x120")
|
|
140
|
+
info = probe(out)
|
|
141
|
+
assert (info.width, info.height) == (120, 120)
|
|
142
|
+
assert info.fps_float == pytest.approx(15, abs=0.01)
|
|
143
|
+
|
|
144
|
+
def test_the_result_passes_its_own_verify(self, clip: Path, tmp_path: Path) -> None:
|
|
145
|
+
"""The two commands have to agree about the same file."""
|
|
146
|
+
out = tmp_path / "chained.mp4"
|
|
147
|
+
ok("convert", str(clip), "-o", str(out), "--fps", "15", "--res", "120x120")
|
|
148
|
+
done = cli("verify", str(out), "--fps", "15", "--res", "120x120")
|
|
149
|
+
assert done.returncode == 0, said(done)
|
|
150
|
+
|
|
151
|
+
def test_a_missing_input_fails_before_touching_the_output(self, tmp_path: Path) -> None:
|
|
152
|
+
out = tmp_path / "never.mp4"
|
|
153
|
+
done = cli("convert", str(tmp_path / "ghost.mp4"), "-o", str(out), "--fps", "15")
|
|
154
|
+
assert done.returncode != 0
|
|
155
|
+
assert "Traceback" not in said(done)
|
|
156
|
+
assert not out.exists()
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
class TestFormat:
|
|
160
|
+
def test_the_extension_picks_the_container(self, clip: Path, tmp_path: Path) -> None:
|
|
161
|
+
out = tmp_path / "repacked.mkv"
|
|
162
|
+
ok("format", str(clip), "-o", str(out))
|
|
163
|
+
assert out.exists()
|
|
164
|
+
assert "matroska" in probe(out).container or probe(out).container == "mkv"
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
class TestCaption:
|
|
168
|
+
def test_it_burns_text_and_keeps_the_timing(self, clip: Path, tmp_path: Path) -> None:
|
|
169
|
+
out = tmp_path / "captioned.mp4"
|
|
170
|
+
done = cli("caption", str(clip), "-o", str(out), "--text", "hello")
|
|
171
|
+
if done.returncode != 0 and "drawtext" in plain(done.stdout + done.stderr):
|
|
172
|
+
pytest.skip("the bundled FFmpeg on this platform has no drawtext filter")
|
|
173
|
+
assert done.returncode == 0, said(done) + done.stderr
|
|
174
|
+
before, after = probe(clip), probe(out)
|
|
175
|
+
assert after.duration == pytest.approx(before.duration, abs=0.2)
|
|
176
|
+
assert (after.width, after.height) == (before.width, before.height)
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
class TestVariants:
|
|
180
|
+
def test_it_writes_one_file_per_combination(self, clip: Path, tmp_path: Path) -> None:
|
|
181
|
+
outdir = tmp_path / "variants"
|
|
182
|
+
ok("variants", str(clip), "-o", str(outdir), "--fps", "15,30", "--res", "120x120")
|
|
183
|
+
written = sorted(outdir.glob("*.mp4"))
|
|
184
|
+
assert len(written) == 2, [p.name for p in written]
|
|
185
|
+
for path in written:
|
|
186
|
+
assert probe(path).width == 120
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
class TestInfo:
|
|
190
|
+
def test_the_json_output_round_trips(self, clip: Path) -> None:
|
|
191
|
+
done = ok("info", str(clip), "--json")
|
|
192
|
+
payload = json.loads(done.stdout or "")
|
|
193
|
+
assert payload["width"] == 160
|
|
194
|
+
assert payload["container"]
|
|
195
|
+
|
|
196
|
+
def test_the_table_output_names_the_file(self, clip: Path) -> None:
|
|
197
|
+
assert clip.name in spoke(ok("info", str(clip)))
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
class TestTheWholeJourney:
|
|
201
|
+
def test_generate_convert_verify_through_the_cli_only(self, tmp_path: Path) -> None:
|
|
202
|
+
"""What a user actually does, with nothing imported but the probe."""
|
|
203
|
+
source = tmp_path / "source.mp4"
|
|
204
|
+
final = tmp_path / "final.mkv"
|
|
205
|
+
|
|
206
|
+
ok("generate", "-o", str(source), "--fps", "30", "--duration", "1", "--res", "160x120")
|
|
207
|
+
ok("convert", str(source), "-o", str(final), "--fps", "15", "--res", "80x80")
|
|
208
|
+
gate = cli("verify", str(final), "--fps", "15", "--res", "80x80", "--duration", "1")
|
|
209
|
+
assert gate.returncode == 0, gate.stdout
|
|
210
|
+
|
|
211
|
+
info = probe(final)
|
|
212
|
+
assert (info.width, info.height) == (80, 80)
|
|
213
|
+
assert info.fps_float == pytest.approx(15, abs=0.01)
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"""Smoke: does the thing start at all.
|
|
2
|
+
|
|
3
|
+
No encoding, no fixtures, no mocks. These answer one question -- is the CLI
|
|
4
|
+
and the public API intact -- and they answer it in under a second. The rest of
|
|
5
|
+
the suite mocks the FFmpeg layer; nothing else checks that the entry point
|
|
6
|
+
itself still runs.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import json
|
|
12
|
+
import subprocess
|
|
13
|
+
import sys
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
|
|
16
|
+
import pytest
|
|
17
|
+
|
|
18
|
+
import vidfix
|
|
19
|
+
|
|
20
|
+
pytestmark = pytest.mark.smoke
|
|
21
|
+
|
|
22
|
+
# Every command the README and --help promise. A command disappearing from the
|
|
23
|
+
# CLI is a breaking change, and this is the only test that would notice.
|
|
24
|
+
COMMANDS = (
|
|
25
|
+
"generate",
|
|
26
|
+
"caption",
|
|
27
|
+
"attach",
|
|
28
|
+
"convert",
|
|
29
|
+
"format",
|
|
30
|
+
"verify",
|
|
31
|
+
"info",
|
|
32
|
+
"variants",
|
|
33
|
+
"preset",
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
TIMEOUT = 60
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def cli(*args: str) -> subprocess.CompletedProcess[str]:
|
|
40
|
+
"""Run the CLI the way a user does, through the module entry point.
|
|
41
|
+
|
|
42
|
+
stdin is DEVNULL because with no arguments the CLI opens an interactive
|
|
43
|
+
wizard and a test must never wait on a prompt. It is DEVNULL rather than
|
|
44
|
+
`input=""`, which on Windows returned a CompletedProcess whose stdout was
|
|
45
|
+
None. The encoding is explicit so a Windows runner does not decode the
|
|
46
|
+
output with its local code page.
|
|
47
|
+
"""
|
|
48
|
+
return subprocess.run(
|
|
49
|
+
[sys.executable, "-m", "vidfix", *args],
|
|
50
|
+
capture_output=True,
|
|
51
|
+
stdin=subprocess.DEVNULL,
|
|
52
|
+
text=True,
|
|
53
|
+
encoding="utf-8",
|
|
54
|
+
errors="replace",
|
|
55
|
+
timeout=TIMEOUT,
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def said(done: subprocess.CompletedProcess[str]) -> str:
|
|
60
|
+
"""Both streams as one string. Rich sends errors to either one."""
|
|
61
|
+
return (done.stdout or "") + (done.stderr or "")
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def test_the_cli_starts_and_prints_help():
|
|
65
|
+
done = cli("--help")
|
|
66
|
+
assert done.returncode == 0, said(done)
|
|
67
|
+
assert "Usage" in said(done)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
@pytest.mark.parametrize("command", COMMANDS)
|
|
71
|
+
def test_every_command_is_still_registered(command: str):
|
|
72
|
+
assert command in said(cli("--help"))
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
@pytest.mark.parametrize("command", COMMANDS)
|
|
76
|
+
def test_every_command_explains_itself(command: str):
|
|
77
|
+
done = cli(command, "--help")
|
|
78
|
+
assert done.returncode == 0, f"{command} --help failed: {said(done)}"
|
|
79
|
+
assert said(done).strip(), f"{command} --help printed nothing"
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def test_the_version_flag_matches_the_package():
|
|
83
|
+
done = cli("--version")
|
|
84
|
+
assert done.returncode == 0, said(done)
|
|
85
|
+
assert vidfix.__version__ in said(done)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def test_the_version_matches_the_project_metadata():
|
|
89
|
+
pyproject = (Path(__file__).resolve().parents[2] / "pyproject.toml").read_text()
|
|
90
|
+
assert f'version = "{vidfix.__version__}"' in pyproject, (
|
|
91
|
+
"pyproject and vidfix.__version__ disagree"
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def test_no_arguments_opens_the_wizard_without_crashing():
|
|
96
|
+
"""With no arguments the CLI is documented to start an interactive wizard.
|
|
97
|
+
With stdin closed it must bow out cleanly, not traceback."""
|
|
98
|
+
done = cli()
|
|
99
|
+
assert "Traceback" not in said(done), said(done)
|
|
100
|
+
assert said(done).strip(), "the wizard printed nothing at all"
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def test_an_unknown_command_fails_cleanly():
|
|
104
|
+
done = cli("definitely-not-a-command")
|
|
105
|
+
assert done.returncode != 0
|
|
106
|
+
assert "Traceback" not in said(done)
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def test_the_public_api_is_importable():
|
|
110
|
+
missing = [name for name in vidfix.__all__ if not hasattr(vidfix, name)]
|
|
111
|
+
assert missing == [], f"__all__ promises what the package does not export: {missing}"
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def test_the_console_script_is_installed():
|
|
115
|
+
script = Path(sys.executable).parent / "vidfix"
|
|
116
|
+
if not script.exists():
|
|
117
|
+
pytest.skip("console script not installed in this environment")
|
|
118
|
+
done = subprocess.run(
|
|
119
|
+
[str(script), "--version"], capture_output=True, text=True, timeout=TIMEOUT
|
|
120
|
+
)
|
|
121
|
+
assert done.returncode == 0, done.stderr
|
|
122
|
+
assert vidfix.__version__ in done.stdout
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def test_the_ffmpeg_binary_can_be_found():
|
|
126
|
+
"""Every real command needs this. Without it the CLI is decoration.
|
|
127
|
+
|
|
128
|
+
ffprobe is deliberately optional: imageio-ffmpeg does not bundle it and
|
|
129
|
+
vidfix probes through ffmpeg instead, so only ffmpeg is required here.
|
|
130
|
+
"""
|
|
131
|
+
from vidfix.core.ffmpeg import find_ffmpeg
|
|
132
|
+
|
|
133
|
+
found = find_ffmpeg()
|
|
134
|
+
assert found, "ffmpeg could not be resolved"
|
|
135
|
+
assert Path(found).exists(), f"ffmpeg resolved to a missing path: {found}"
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def test_presets_can_be_listed_without_touching_a_file():
|
|
139
|
+
done = cli("preset", "list")
|
|
140
|
+
assert done.returncode == 0, said(done)
|
|
141
|
+
assert said(done).strip()
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def test_probing_a_missing_file_is_a_clean_error_not_a_crash(tmp_path: Path):
|
|
145
|
+
done = cli("info", str(tmp_path / "nope.mp4"))
|
|
146
|
+
assert done.returncode != 0
|
|
147
|
+
assert "Traceback" not in said(done)
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def test_verify_with_no_expectations_refuses_instead_of_passing(tmp_path: Path):
|
|
151
|
+
"""Verify is a CI gate. A gate that passes when asked nothing is a hazard."""
|
|
152
|
+
target = tmp_path / "nope.mp4"
|
|
153
|
+
target.write_bytes(b"not a video")
|
|
154
|
+
done = cli("verify", str(target))
|
|
155
|
+
assert done.returncode != 0
|
|
156
|
+
assert "Traceback" not in said(done)
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def test_json_output_is_valid_json_when_the_input_is_bad(tmp_path: Path):
|
|
160
|
+
"""A --json flag that emits a half-written table on error is unusable in CI."""
|
|
161
|
+
done = cli("info", str(tmp_path / "nope.mp4"), "--json")
|
|
162
|
+
assert done.returncode != 0
|
|
163
|
+
if (done.stdout or "").strip():
|
|
164
|
+
json.loads(done.stdout)
|
|
@@ -91,6 +91,28 @@ class TestExtend:
|
|
|
91
91
|
assert p.args[p.args.index("-stream_loop") + 1] == "-1"
|
|
92
92
|
assert p.args[p.args.index("-t") + 1] == "25.0"
|
|
93
93
|
|
|
94
|
+
def test_loop_keeps_source_frame_rate(self) -> None:
|
|
95
|
+
p = build_convert_plan(
|
|
96
|
+
"in.mp4", "out.mp4", source(duration=10.0), duration=25.0, extend_mode="loop"
|
|
97
|
+
)
|
|
98
|
+
assert p.args[p.args.index("-vf") + 1] == "fps=fps=30"
|
|
99
|
+
|
|
100
|
+
def test_loop_unknown_source_rate_adds_no_filter(self) -> None:
|
|
101
|
+
src = source(duration=10.0).model_copy(update={"fps": "0"})
|
|
102
|
+
p = build_convert_plan("in.mp4", "out.mp4", src, duration=25.0, extend_mode="loop")
|
|
103
|
+
assert "-vf" not in p.args
|
|
104
|
+
|
|
105
|
+
def test_loop_with_fps_sets_rate_once(self) -> None:
|
|
106
|
+
p = build_convert_plan(
|
|
107
|
+
"in.mp4",
|
|
108
|
+
"out.mp4",
|
|
109
|
+
source(duration=10.0),
|
|
110
|
+
fps=Fraction(60),
|
|
111
|
+
duration=25.0,
|
|
112
|
+
extend_mode="loop",
|
|
113
|
+
)
|
|
114
|
+
assert p.args[p.args.index("-vf") + 1] == "fps=fps=60"
|
|
115
|
+
|
|
94
116
|
def test_bad_extend_mode(self) -> None:
|
|
95
117
|
with pytest.raises(InvalidSpecError):
|
|
96
118
|
build_convert_plan("in.mp4", "out.mp4", source(), extend_mode="stretch")
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
import tempfile
|
|
6
|
+
from fractions import Fraction
|
|
6
7
|
from functools import lru_cache
|
|
7
8
|
from pathlib import Path
|
|
8
9
|
|
|
@@ -66,6 +67,16 @@ class TestGenerateProbe:
|
|
|
66
67
|
convert(tiny_clip, out, duration="2")
|
|
67
68
|
assert probe(out).duration == pytest.approx(2.0, abs=0.15)
|
|
68
69
|
|
|
70
|
+
def test_convert_extend_loop_keeps_drop_frame_rate(self, tmp_path: Path) -> None:
|
|
71
|
+
from vidfix import convert, verify
|
|
72
|
+
|
|
73
|
+
src = tmp_path / "df.mov"
|
|
74
|
+
generate(src, fps="29.97", duration="2", res="160x120", pattern="testsrc")
|
|
75
|
+
out = tmp_path / "looped.mov"
|
|
76
|
+
convert(src, out, duration="7", extend_mode="loop")
|
|
77
|
+
assert verify(out, fps="29.97", duration="7").passed
|
|
78
|
+
assert probe(out).fps_fraction == Fraction(30000, 1001)
|
|
79
|
+
|
|
69
80
|
def test_generate_timecode(self, tmp_path: Path) -> None:
|
|
70
81
|
from vidfix.core.generate import drawtext_available
|
|
71
82
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
version = 1
|
|
2
|
-
revision =
|
|
2
|
+
revision = 5
|
|
3
3
|
requires-python = ">=3.10"
|
|
4
4
|
resolution-markers = [
|
|
5
5
|
"python_full_version >= '3.15'",
|
|
@@ -824,7 +824,7 @@ wheels = [
|
|
|
824
824
|
|
|
825
825
|
[[package]]
|
|
826
826
|
name = "vidfix"
|
|
827
|
-
version = "0.4.
|
|
827
|
+
version = "0.4.2"
|
|
828
828
|
source = { editable = "." }
|
|
829
829
|
dependencies = [
|
|
830
830
|
{ name = "imageio-ffmpeg" },
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|