133 lines
5.7 KiB
Python
Executable File
133 lines
5.7 KiB
Python
Executable File
"""Single-file structure tests — verify open-transcode.py is the program.
|
|
|
|
The application ships as ONE self-contained module: ``open-transcode.py``
|
|
(everything inlined; runs with only Python + PySide6). These tests pin
|
|
that arrangement:
|
|
|
|
- the module loads cleanly via the conftest program loader,
|
|
- its metadata (version / author / contact / license) is intact,
|
|
- the expected public symbol surface is present (the tables, the
|
|
worker, the UI class, the probe helpers, the CLI parser),
|
|
- the file stays self-contained — a stray ``import opentranscode``
|
|
would reintroduce a second copy of the program and fails here.
|
|
|
|
Runs WITHOUT PySide6 installed (the conftest installs stubs first).
|
|
"""
|
|
import re
|
|
|
|
from conftest import OPENTRANSCODE_SCRIPT_PATH, load_program_module
|
|
|
|
# Every symbol the app's own tests and tooling reach for — one flat set
|
|
# now that the program is a single module.
|
|
EXPECTED_PROGRAM_SYMBOLS = {
|
|
# profile tables + helpers
|
|
"AUDIO_PROFILES", "CONTAINER_PROFILES", "DEFAULT_INPUT_EXTENSIONS",
|
|
"FFMPEG_LIB_KEY_MAP", "RESOLUTION_PRESETS", "SUBTITLE_OPTIONS",
|
|
"VIDEO_CODECS", "TITLE_ARTIFACT_TOKENS", "THEORA_Q_RANGE",
|
|
"AudioProfile", "ContainerProfile", "ResolutionProfile",
|
|
"VideoCodecProfile", "clean_title", "ffmpeg_lib_key_for",
|
|
"theora_quality_from_crf",
|
|
# encode pipeline
|
|
"EncoderWorker", "scan_input_files", "resolve_gpu_encoder",
|
|
"plan_hybrid", "HybridPlan", "KeepAwake",
|
|
# environment
|
|
"EnvProbe", "probe_environment", "detect_distro", "DistroProfile",
|
|
"DISTRO_REGISTRY", "CpuTopology", "GPU_PROFILES", "match_gpu_profile",
|
|
"_probe_vs_source_plugins", "_identify_file_type",
|
|
# UI + CLI
|
|
"OpenCodecMaster", "launch_gui", "SourceBuildWorker",
|
|
"RadioKnob", "build_parser", "main",
|
|
}
|
|
|
|
|
|
# ─────────────────────────────────────────────────────────────────────────────
|
|
# Tests
|
|
# ─────────────────────────────────────────────────────────────────────────────
|
|
|
|
|
|
class TestProgramMetadata:
|
|
def test_version_is_pep440_compliant(self):
|
|
v = load_program_module().__version__
|
|
assert isinstance(v, str)
|
|
parts = v.split(".")
|
|
assert len(parts) >= 3, f"Version '{v}' should have at least major.minor.patch"
|
|
assert parts[0].isdigit() and parts[1].isdigit(), \
|
|
f"Version '{v}' should be PEP 440 numeric"
|
|
|
|
def test_author_and_contact_are_set(self):
|
|
m = load_program_module()
|
|
assert m.__author__ == "Jeremy Anderson"
|
|
assert m.__email__ == "info@dcos.net"
|
|
assert "dcos.net" in m.__website__
|
|
|
|
def test_license_is_agpl(self):
|
|
assert "AGPL" in load_program_module().__license__
|
|
|
|
|
|
class TestSingleFileArrangement:
|
|
def test_program_file_exists_at_repo_root(self):
|
|
assert OPENTRANSCODE_SCRIPT_PATH.is_file()
|
|
|
|
def test_no_second_copy_of_the_program(self):
|
|
"""The opentranscode/ package directory must not exist — the
|
|
single file is the whole program. Two copies cannot drift if
|
|
there is only one."""
|
|
repo_root = OPENTRANSCODE_SCRIPT_PATH.parent
|
|
assert not (repo_root / "opentranscode").exists(), \
|
|
"opentranscode/ package directory exists alongside the " \
|
|
"single-file program — pick one copy"
|
|
|
|
def test_program_file_is_self_contained(self):
|
|
"""No import of a package copy from inside the program file."""
|
|
src = OPENTRANSCODE_SCRIPT_PATH.read_text()
|
|
stray = re.findall(r"^\s*(?:from|import)\s+opentranscode.*$", src, re.M)
|
|
assert stray == [], f"program imports its old package copy: {stray}"
|
|
|
|
|
|
class TestPublicSurface:
|
|
def test_expected_symbols_present(self):
|
|
m = load_program_module()
|
|
missing = sorted(n for n in EXPECTED_PROGRAM_SYMBOLS
|
|
if not hasattr(m, n))
|
|
assert missing == [], f"missing program symbols: {missing}"
|
|
|
|
def test_video_codecs_table_populated(self):
|
|
VIDEO_CODECS = load_program_module().VIDEO_CODECS
|
|
assert len(VIDEO_CODECS) >= 4, \
|
|
"Should have at least 4 video codecs (AV1, VP9, x265, Theora)"
|
|
labels = [c.label for c in VIDEO_CODECS]
|
|
assert any("AV1" in l for l in labels)
|
|
assert any("VP9" in l for l in labels)
|
|
assert any("x265" in l or "HEVC" in l for l in labels)
|
|
assert any("Theora" in l for l in labels)
|
|
|
|
def test_audio_profiles_have_ffmpeg_encoder_name(self):
|
|
AUDIO_PROFILES = load_program_module().AUDIO_PROFILES
|
|
for ap in AUDIO_PROFILES:
|
|
assert ap.ffmpeg_encoder_name, \
|
|
f"AudioProfile '{ap.label}' has empty ffmpeg_encoder_name"
|
|
|
|
def test_distro_registry_has_six_entries(self):
|
|
DISTRO_REGISTRY = load_program_module().DISTRO_REGISTRY
|
|
families = {e.family for e in DISTRO_REGISTRY}
|
|
assert {"arch", "debian", "redhat", "suse", "nixos"} <= families
|
|
assert len(DISTRO_REGISTRY) >= 6
|
|
|
|
|
|
class TestCLIParser:
|
|
def test_build_parser_parses_empty_argv(self):
|
|
args = load_program_module().build_parser().parse_args([])
|
|
assert args.engine == "auto"
|
|
assert args.verbose is False
|
|
|
|
def test_build_parser_accepts_all_flags(self):
|
|
args = load_program_module().build_parser().parse_args([
|
|
"--verbose", "--use-av1an", "--engine", "hybrid",
|
|
"--timeout", "3600", "--force-reencode",
|
|
])
|
|
assert args.verbose is True
|
|
assert args.use_av1an is True
|
|
assert args.engine == "hybrid"
|
|
assert args.timeout == 3600
|
|
assert args.skip_existing is False
|