Files
PaperPod/tests/test_pdf_build.py
T
ilia 17be9cef33 Add homelab CI with hard ruff/pytest gates
Adds .gitea/workflows/ci.yml (python-ci with tesseract + libgl for the OCR/opencv tests, plus gitleaks secret-scan) and ruff.toml (E4/E7/E9/F/I, line-length 120). Cleans up the remaining unused-variable findings so the lint gate is green.
2026-07-26 15:37:45 -04:00

54 lines
1.4 KiB
Python

import pytest
from PIL import Image
from paperpod.pdf.build import images_to_pdf
def _write_png(path, color):
Image.new("RGB", (200, 300), color).save(path)
def test_images_to_pdf_single_page(tmp_path):
img_path = tmp_path / "page.png"
_write_png(img_path, (255, 255, 255))
out = tmp_path / "out.pdf"
result = images_to_pdf([img_path], out, title="Test Doc")
assert result == out
assert out.exists()
data = out.read_bytes()
assert data.startswith(b"%PDF")
def test_images_to_pdf_multi_page(tmp_path):
paths = []
for i, color in enumerate([(255, 0, 0), (0, 255, 0), (0, 0, 255)]):
p = tmp_path / f"page_{i}.png"
_write_png(p, color)
paths.append(p)
out = tmp_path / "multi.pdf"
images_to_pdf(paths, out)
# img2pdf writes one xobject image per page; a 3-page PDF should be
# meaningfully larger than a 1-page PDF of the same-size images.
single = tmp_path / "single.pdf"
images_to_pdf([paths[0]], single)
assert out.stat().st_size > single.stat().st_size
def test_images_to_pdf_requires_at_least_one_image(tmp_path):
with pytest.raises(ValueError):
images_to_pdf([], tmp_path / "empty.pdf")
def test_images_to_pdf_creates_parent_dirs(tmp_path):
img_path = tmp_path / "page.png"
_write_png(img_path, (10, 20, 30))
out = tmp_path / "nested" / "dir" / "out.pdf"
images_to_pdf([img_path], out)
assert out.exists()