Skip to content

Commit 8d07d34

Browse files
committed
Simplify test code
1 parent 19cff53 commit 8d07d34

File tree

3 files changed

+22
-360
lines changed

3 files changed

+22
-360
lines changed

tests/ffwrapper.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ class FileInfo:
5050
path: Path
5151
bitrate: int
5252
duration: float
53-
timecode: str # in SMPTE
5453
videos: tuple[VideoStream, ...]
5554
audios: tuple[AudioStream, ...]
5655
subtitles: tuple[SubtitleStream, ...]
@@ -135,22 +134,12 @@ def init(self, path: str, log: Log) -> FileInfo:
135134
ext = sub_exts.get(codec, "vtt")
136135
subtitles += (SubtitleStream(codec, ext, s.language),)
137136

138-
def get_timecode() -> str:
139-
for d in cont.streams.data:
140-
if (result := d.metadata.get("timecode")) is not None:
141-
return result
142-
for v in cont.streams.video:
143-
if (result := v.metadata.get("timecode")) is not None:
144-
return result
145-
return "00:00:00:00"
146-
147-
timecode = get_timecode()
148137
bitrate = 0 if cont.bit_rate is None else cont.bit_rate
149138
dur = 0 if cont.duration is None else cont.duration / av.time_base
150139

151140
cont.close()
152141

153-
return FileInfo(Path(path), bitrate, dur, timecode, videos, audios, subtitles)
142+
return FileInfo(Path(path), bitrate, dur, videos, audios, subtitles)
154143

155144
def __repr__(self) -> str:
156145
return f"@{self.path.name}"

tests/test.py

Lines changed: 21 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import shutil
55
import subprocess
66
import sys
7+
import argparse
78
from collections.abc import Callable
8-
from dataclasses import dataclass, field
99
from fractions import Fraction
1010
from hashlib import sha256
1111
from tempfile import mkdtemp
@@ -16,26 +16,12 @@
1616

1717
from ffwrapper import FileInfo
1818
from log import Log
19-
from vanparse import ArgumentParser
2019

2120

22-
@dataclass(slots=True)
23-
class TestArgs:
24-
only: list[str] = field(default_factory=list)
25-
help: bool = False
26-
no_failfast: bool = False
27-
category: str = "cli"
28-
29-
30-
def test_options(parser: ArgumentParser) -> ArgumentParser:
31-
parser.add_argument("--only", "-n", nargs="*")
32-
parser.add_argument("--no-failfast", flag=True)
33-
parser.add_required(
34-
"category",
35-
nargs=1,
36-
choices=("cli", "sub", "all"),
37-
metavar="category [options]",
38-
)
21+
def test_options() -> argparse.ArgumentParser:
22+
parser = argparse.ArgumentParser(description="Test options")
23+
parser.add_argument("--only", "-n", nargs="*", default=[])
24+
parser.add_argument("--no-failfast", action="store_true", default=False)
3925
return parser
4026

4127

@@ -394,7 +380,9 @@ def test_premiere(self) -> None:
394380
continue
395381

396382
p_xml = self.main([f"resources/{test_name}"], ["-exp"], "out.xml")
397-
self.main([p_xml], [])
383+
384+
# TODO: Support premiere XML as input.
385+
# self.main([p_xml], [])
398386

399387
def test_export(self):
400388
for test_name in all_files:
@@ -547,7 +535,7 @@ def test_audio_norm_ebu(self) -> None:
547535
)
548536

549537

550-
def run_tests(tests: list[Callable], args: TestArgs) -> None:
538+
def run_tests(tests: list[Callable], args) -> None:
551539
if args.only != []:
552540
tests = list(filter(lambda t: t.__name__ in args.only, tests))
553541

@@ -613,33 +601,25 @@ def timed_test(test_func):
613601
)
614602

615603

616-
def main(sys_args: list[str] | None = None) -> None:
617-
if sys_args is None:
618-
sys_args = sys.argv[1:]
619-
620-
args = test_options(ArgumentParser("test")).parse_args(TestArgs, sys_args)
604+
def main():
605+
args = test_options().parse_args()
621606
run = Runner()
622607
tests = []
623-
624608
test_methods = {
625609
name: getattr(run, name)
626610
for name in dir(Runner)
627611
if callable(getattr(Runner, name)) and name not in ["main", "raw", "check"]
628612
}
629-
630-
if args.category in {"sub", "all"}:
631-
tests.extend(
632-
[test_methods[name] for name in ["info", "levels", "subdump", "desc"]]
633-
)
634-
635-
if args.category in {"cli", "all"}:
636-
tests.extend(
637-
[
638-
getattr(run, name)
639-
for name in dir(Runner)
640-
if callable(getattr(Runner, name)) and name.startswith("test_")
641-
]
642-
)
613+
tests.extend(
614+
[test_methods[name] for name in ["info", "levels", "subdump", "desc"]]
615+
)
616+
tests.extend(
617+
[
618+
getattr(run, name)
619+
for name in dir(Runner)
620+
if callable(getattr(Runner, name)) and name.startswith("test_")
621+
]
622+
)
643623
try:
644624
run_tests(tests, args)
645625
except KeyboardInterrupt:

0 commit comments

Comments
 (0)