test(ffmpeg_handling): test overwrite functionality
FFmpeg Handling CI / build (push) Successful in 27s
FFmpeg Handling CI / test (push) Successful in 49s
FFmpeg Handling CI / lint (push) Successful in 8s
FFmpeg Handling CI / install (quiethost) (push) Waiting to run
FFmpeg Handling CI / install (serverhost) (push) Successful in 3s
FFmpeg Handling CI / install (vivohost) (push) Successful in 3s
FFmpeg Handling CI / install (mediahost) (push) Successful in 2s

This commit is contained in:
Lucas Vivo committed 2026-11-26 14:32:01 +01:00
1 parent 8f0e9f0f85
commit 8bd7d6a1f0
1 file changed
+68
+68
View File
@@ -55,6 +55,74 @@ class CliTests(unittest.TestCase):
self.assertEqual(result, 0)
self.assertFalse(output.exists())
def test_cli_overwrite_replaces_input_and_creates_backup(self):
with tempfile.TemporaryDirectory() as temp_dir:
input_path = Path(temp_dir) / "media.mkv"
input_path.write_text("original", encoding="utf-8")
def create_ffmpeg_output(args, command):
Path(command[-1]).write_text("converted", encoding="utf-8")
return True, "success"
with patch("ffmpeg_handling.cli.shutil.which", return_value="/usr/bin/ffmpeg"), \
patch("ffmpeg_handling.cli.setup_logging"), \
patch(
"ffmpeg_handling.video_commands.run_ffmpeg_for_args",
side_effect=create_ffmpeg_output,
), \
self.assertLogs("ffmpeg_handling", level="INFO"):
result = main([
"downsize",
str(input_path),
"--overwrite",
"--backup",
"-w",
"320",
"-he",
"180",
"-c",
"30",
])
self.assertEqual(result, 0)
self.assertEqual(input_path.read_text(encoding="utf-8"), "converted")
backup = input_path.with_name("media_backup.mkv")
self.assertEqual(backup.read_text(encoding="utf-8"), "original")
self.assertFalse(input_path.with_name("media_overwrite.mkv").exists())
def test_cli_overwrite_replaces_input_after_successful_command(self):
with tempfile.TemporaryDirectory() as temp_dir:
input_path = Path(temp_dir) / "media.mkv"
input_path.write_text("original", encoding="utf-8")
def create_ffmpeg_output(args, command):
Path(command[-1]).write_text("converted", encoding="utf-8")
return True, "success"
with patch("ffmpeg_handling.cli.shutil.which", return_value="/usr/bin/ffmpeg"), \
patch("ffmpeg_handling.cli.setup_logging"), \
patch(
"ffmpeg_handling.video_commands.run_ffmpeg_for_args",
side_effect=create_ffmpeg_output,
), \
self.assertLogs("ffmpeg_handling", level="INFO"):
result = main([
"downsize",
str(input_path),
"--overwrite",
"-w",
"320",
"-he",
"180",
"-c",
"30",
])
self.assertEqual(result, 0)
self.assertEqual(input_path.read_text(encoding="utf-8"), "converted")
self.assertFalse(input_path.with_name("media_overwrite.mkv").exists())
self.assertFalse(input_path.with_name("media_backup.mkv").exists())
if __name__ == "__main__":
unittest.main()