Refactor compression flow with routing seam
Introduce compress_image_with_routing and compress_raster_image to prepare extensible backend routing while keeping existing behavior unchanged. Add unit test that verifies routing currently delegates to raster compressor. Co-Authored-By: Abacus.AI CLI <agent@abacus.ai>
This commit is contained in:
@@ -244,5 +244,34 @@ class TestPptxImageCompress(unittest.TestCase):
|
||||
self.assertIn("png_jpg", log_text)
|
||||
|
||||
|
||||
def test_compress_image_with_routing_delegates_to_raster(self):
|
||||
with tempfile.TemporaryDirectory() as td:
|
||||
root = Path(td)
|
||||
original = root / "image1.png"
|
||||
original.write_bytes(b"A" * 100)
|
||||
out_dir = root / "out"
|
||||
|
||||
def fake_compressor(original_path: Path, out_subdir: Path, caesium_threads: int | None, quality: int, min_savings: str):
|
||||
out_subdir.mkdir(parents=True, exist_ok=True)
|
||||
out = out_subdir / original_path.name
|
||||
out.write_bytes(b"B" * 80)
|
||||
return out
|
||||
|
||||
out = pic.compress_image_with_routing(
|
||||
compressor=fake_compressor,
|
||||
original=original,
|
||||
out_dir=out_dir,
|
||||
caesium_threads=1,
|
||||
quality=90,
|
||||
min_savings="2%",
|
||||
)
|
||||
|
||||
self.assertIsNotNone(out)
|
||||
if out is None:
|
||||
self.fail("Output should not be None")
|
||||
self.assertEqual(out.name, "image1.png")
|
||||
self.assertEqual(out.stat().st_size, 80)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user