Bopytex/test/worker/test_join_pdf.py
Bertrand Benjamin cd2fdc162e
All checks were successful
continuous-integration/drone/push Build is passing
Fix: run pre-commit hooks
2022-07-28 09:39:51 +02:00

52 lines
1.1 KiB
Python

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()