from __future__ import annotations import subprocess import unittest from pathlib import Path from unittest.mock import patch from tools.exiftool import run_exiftool_command class ExiftoolInvocationTests(unittest.TestCase): def test_windows_uses_utf8_argument_file_for_unicode_paths(self) -> None: captured: dict[str, object] = {} def fake_run(command, **kwargs): captured["command"] = command argument_file = Path(kwargs["cwd"]) / command[-1] captured["contents"] = argument_file.read_text(encoding="utf-8") return subprocess.CompletedProcess(command, 0) with ( patch("tools.exiftool._use_windows_argument_file", return_value=True), patch("tools.exiftool.subprocess.run", side_effect=fake_run), ): run_exiftool_command( "exiftool.exe", ["-j", "C:\\Photos\\M\u00e4rchen.jpg"], check=True, ) self.assertEqual( captured["command"], ["exiftool.exe", "-charset", "filename=UTF8", "-@", "arguments.txt"], ) self.assertEqual(captured["contents"], "-j\nC:\\Photos\\M\u00e4rchen.jpg\n") if __name__ == "__main__": unittest.main()