Use local svgo.cmd wrapper binary

Switch SVG optimizer resolution from bin/svgo-cli.exe to bin/svgo.cmd.

Update unit tests to validate the new local binary path behavior.

Co-Authored-By: Abacus.AI CLI <agent@abacus.ai>
This commit is contained in:
2026-06-08 14:50:19 +02:00
parent 75059f829a
commit 6c5a5256c7
1054 changed files with 152359 additions and 7 deletions
+27 -2
View File
@@ -273,18 +273,43 @@ class TestPptxImageCompress(unittest.TestCase):
self.fail("Output should not be None")
self.assertEqual(out.name, "image1.png")
self.assertEqual(out.stat().st_size, 80)
def test_compress_svg_with_svgo_returns_none_when_npx_missing(self):
def test_compress_svg_with_svgo_returns_none_when_binary_missing(self):
with tempfile.TemporaryDirectory() as td:
root = Path(td)
svg = root / "vector.svg"
svg.write_text("<svg></svg>", encoding="utf-8")
out_dir = root / "out"
with mock.patch("pptx_image_compress.which", return_value=None):
with mock.patch("pptx_image_compress.get_svgo_executable_path", return_value=root / "bin" / "svgo.cmd"):
out = pic.compress_svg_with_svgo(svg, out_dir)
self.assertEqual(out, None)
def test_compress_svg_with_svgo_uses_local_binary(self):
with tempfile.TemporaryDirectory() as td:
root = Path(td)
svg = root / "vector.svg"
svg.write_text("<svg></svg>", encoding="utf-8")
out_dir = root / "out"
fake_exe = root / "bin" / "svgo.cmd"
fake_exe.parent.mkdir(parents=True, exist_ok=True)
fake_exe.write_bytes(b"exe")
def fake_run(cmd, capture_output, text):
self.assertEqual(cmd[0], str(fake_exe))
self.assertEqual(cmd[1], str(svg))
self.assertEqual(cmd[2], "-o")
self.assertEqual(cmd[3], str(out_dir / "vector.svg"))
out_dir.mkdir(parents=True, exist_ok=True)
(out_dir / "vector.svg").write_text("<svg/>", encoding="utf-8")
return mock.Mock(returncode=0, stderr="")
with mock.patch("pptx_image_compress.get_svgo_executable_path", return_value=fake_exe):
with mock.patch("pptx_image_compress.subprocess.run", side_effect=fake_run):
out = pic.compress_svg_with_svgo(svg, out_dir)
self.assertEqual(out, out_dir / "vector.svg")
def test_compress_image_with_routing_uses_svg_backend(self):
with tempfile.TemporaryDirectory() as td:
root = Path(td)