import os import shutil from pathlib import Path import pytest from bopytex.worker.join_pdf import pdfjam @pytest.fixture def multiple_pdf(tmp_path, request): this_file = Path(request.module.__file__) source = this_file.parent / "source.pdf" assert source.exists() qty = 3 dests = [] for i in range(qty): dest = tmp_path / f"source_{i}.pdf" shutil.copyfile(source, dest) assert dest.exists() dests.append(dest) return dests def test_join_pdf(multiple_pdf): tmp_path = multiple_pdf[0].parent os.chdir(tmp_path) deps = [str(d.name) for d in multiple_pdf] output = "joined.pdf" message = pdfjam({"pwd": Path.cwd()}, deps, output) assert message.status == 0 assert Path(output).exists() def test_join_pdf_failed(multiple_pdf, tmp_path): os.chdir(tmp_path) deps = [str(d.name) for d in multiple_pdf] + ["doesnotexists.pdf"] output = "joined.pdf" message = pdfjam({"pwd": Path.cwd()}, deps, output) assert message.status == 66 assert not Path(output).exists()