From 527ad160cfd2bfecbf2c6e8d5df31db279763540 Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Wed, 13 Apr 2022 10:46:53 +0200 Subject: [PATCH] Feat: join_pdf work --- bopytex/worker/join_pdf.py | 17 ++++++++++++ test/worker/source.pdf | Bin 0 -> 5193 bytes test/worker/test_join_pdf.py | 51 +++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 bopytex/worker/join_pdf.py create mode 100644 test/worker/source.pdf create mode 100644 test/worker/test_join_pdf.py diff --git a/bopytex/worker/join_pdf.py b/bopytex/worker/join_pdf.py new file mode 100644 index 0000000..45927f1 --- /dev/null +++ b/bopytex/worker/join_pdf.py @@ -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" + diff --git a/test/worker/source.pdf b/test/worker/source.pdf new file mode 100644 index 0000000000000000000000000000000000000000..e74542756c47b43f658665a8ea19c93c7605ead2 GIT binary patch literal 5193 zcma)A2UJtdwpOXq2^|3g1nDNBh6vJ2fC$n8(jh^5P3WQ&=}7O00{YX7g3^0v7CK08 zf`D`osltoz-M6l9-GANt&N^qE*)#jB{mq`e=j?CzbXC+up|>R|_&$xbk9JKA;=3ut zfe@gZjU$DuED)^b;Ect165h_%Sd0qB)(wpTg0(TO53%+@F$o#q-MhelTohhdPmHw- zh3}MkqKqpZLZuq;LW!lSLv{2Ts}M(gbnzI8!^p~oi^k+W)ioC4zDo7|fSr%(${tX$^n2CaMVa@Q00@kVX5ZaWbzkkgSX5UIqxuHa_g(j}rR6UJzHyKoAP^$Jm{ zzplwNQ?0Ks>3v%^>wOiWc>R5?v(=v0xJ%Aqte|2+a|=$2k7VQ$wI-!*P7+cw+*Ku4 z_qlcv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 100644 index 0000000..5edd7a4 --- /dev/null +++ b/test/worker/test_join_pdf.py @@ -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()