Bopytex/test/worker/test_join_pdf.py

52 lines
1.1 KiB
Python
Raw Normal View History

2022-04-13 08:46:53 +00:00
import os
import shutil
from pathlib import Path
2022-07-28 07:39:51 +00:00
2022-04-13 08:46:53 +00:00
import pytest
2022-07-28 07:39:51 +00:00
from bopytex.worker.join_pdf import pdfjam
2022-04-13 08:46:53 +00:00
@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"
2022-04-13 10:26:04 +00:00
message = pdfjam({"pwd": Path.cwd()}, deps, output)
2022-04-13 08:46:53 +00:00
2022-04-13 10:26:04 +00:00
assert message.status == 0
2022-04-13 08:46:53 +00:00
assert Path(output).exists()
2022-04-13 18:41:34 +00:00
def test_join_pdf_failed(multiple_pdf, tmp_path):
2022-04-13 08:46:53 +00:00
os.chdir(tmp_path)
deps = [str(d.name) for d in multiple_pdf] + ["doesnotexists.pdf"]
output = "joined.pdf"
2022-04-13 10:26:04 +00:00
message = pdfjam({"pwd": Path.cwd()}, deps, output)
2022-04-13 08:46:53 +00:00
2022-04-13 10:26:04 +00:00
assert message.status == 66
2022-04-13 08:46:53 +00:00
assert not Path(output).exists()