Feat: join_pdf work

This commit is contained in:
Bertrand Benjamin 2022-04-13 10:46:53 +02:00
parent ac8fe3dfdd
commit 527ad160cf
3 changed files with 68 additions and 0 deletions

View File

@ -0,0 +1,17 @@
import subprocess
def pdfjam(args: dict, deps, output):
joining_process = subprocess.Popen(
["pdfjam"] + deps + ["-o", output],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True,
)
# exit_code is always 66...
exit_code = joining_process.wait()
if exit_code == 0:
yield "pdfjam success"
else:
yield "pdfjam failed"

BIN
test/worker/source.pdf Normal file

Binary file not shown.

View File

@ -0,0 +1,51 @@
import os
import shutil
from pathlib import Path
from bopytex.worker.join_pdf import pdfjam
import pytest
@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"
for msg in pdfjam({"pwd": Path.cwd()}, deps, output):
assert msg == "pdfjam success"
assert Path(output).exists()
def test_join_pdf_failed(multiple_pdf):
tmp_path = multiple_pdf[0].parent
os.chdir(tmp_path)
deps = [str(d.name) for d in multiple_pdf] + ["doesnotexists.pdf"]
output = "joined.pdf"
for msg in pdfjam({"pwd": Path.cwd()}, deps, output):
assert msg == "pdfjam failed"
assert not Path(output).exists()