test(ffmpeg_handling): add test commands for ffmpeg_handler
This commit is contained in:
1 parent
74519f62d7
commit
7d5494243f
5 files changed
+520
No files matched your search
@@ -0,0 +1,60 @@
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
from ffmpeg_handling import build_parser, main
|
||||
|
||||
ASSET_DIR = Path(__file__).resolve().parents[1] / "testfiles"
|
||||
|
||||
|
||||
class CliTests(unittest.TestCase):
|
||||
def test_test_command_is_not_registered(self):
|
||||
with self.assertRaises(SystemExit) as error:
|
||||
build_parser().parse_args(["test"])
|
||||
self.assertEqual(error.exception.code, 2)
|
||||
|
||||
def test_short_command_alias_resolves_to_canonical_name(self):
|
||||
args = build_parser().parse_args(["i", str(ASSET_DIR / "test_auto.mp4")])
|
||||
self.assertEqual(args.command, "info")
|
||||
|
||||
def test_missing_ffmpeg_logs_error_and_returns_failure(self):
|
||||
with patch("ffmpeg_handling.cli.shutil.which", return_value=None), \
|
||||
patch("ffmpeg_handling.cli.setup_logging"), \
|
||||
self.assertLogs("ffmpeg_handling", level="ERROR") as captured:
|
||||
result = main(["info", str(ASSET_DIR / "test_auto_no_subs.mkv")])
|
||||
|
||||
self.assertEqual(result, 1)
|
||||
self.assertIn("FFmpeg is not installed", captured.output[0])
|
||||
|
||||
def test_non_output_command_returns_success(self):
|
||||
with patch("ffmpeg_handling.cli.setup_logging"), \
|
||||
self.assertLogs("ffmpeg_handling", level="INFO"):
|
||||
self.assertEqual(
|
||||
main(["info", str(ASSET_DIR / "test_auto_no_subs.mkv")]), 0
|
||||
)
|
||||
|
||||
def test_cli_dry_run_uses_requested_output_and_creates_nothing(self):
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
output = Path(temp_dir) / "dry_run.mkv"
|
||||
with patch("ffmpeg_handling.cli.setup_logging"), \
|
||||
self.assertLogs("ffmpeg_handling", level="INFO"):
|
||||
result = main([
|
||||
"downsize",
|
||||
str(ASSET_DIR / "test_auto_no_subs.mkv"),
|
||||
"-o",
|
||||
str(output),
|
||||
"--dry-run",
|
||||
"-w",
|
||||
"320",
|
||||
"-he",
|
||||
"180",
|
||||
"-c",
|
||||
"30",
|
||||
])
|
||||
self.assertEqual(result, 0)
|
||||
self.assertFalse(output.exists())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user