diff options
author | James R. Barlow <jim@purplerock.ca> | 2017-02-20 14:54:50 -0800 |
---|---|---|
committer | James R. Barlow <jim@purplerock.ca> | 2017-02-20 14:54:50 -0800 |
commit | 0587f00fdbe6c1298063042c80c39968538ed735 (patch) | |
tree | e244022f63b08b69725b6a9e668710039c65cee9 /tests/test_pdfa.py | |
parent | 4c8441fb2dbda001d577086d2417213c67ba21c3 (diff) |
Formalize PDF/A testing
Diffstat (limited to 'tests/test_pdfa.py')
-rw-r--r-- | tests/test_pdfa.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/test_pdfa.py b/tests/test_pdfa.py new file mode 100644 index 0000000..b15b6fd --- /dev/null +++ b/tests/test_pdfa.py @@ -0,0 +1,45 @@ +import pytest +from pikepdf import qpdf + +import os +import platform +import shutil +from pathlib import Path +from contextlib import suppress +from subprocess import run, PIPE, STDOUT, DEVNULL +import xml.etree.ElementTree as ET + + +VERAPDF = Path(os.environ['HOME']) / 'verapdf' / 'verapdf' + + +NO_PDFA_VALIDATOR = not VERAPDF.is_file() + + +def verapdf_validate(filename): + with open(filename, 'rb') as f: + proc = run([VERAPDF], stdin=f, stdout=PIPE, stderr=STDOUT, check=True) + result = proc.stdout.decode('utf-8') + + xml_start = result.find('<?xml version') + xml = result[xml_start:] + + root = ET.fromstring(xml) + node = root.find(".//taskResult[@type='VALIDATE']") + return node.attrib['isExecuted'] == 'true' and \ + node.attrib['isSuccess'] == 'true' + + +@pytest.mark.skipif(NO_PDFA_VALIDATOR, reason="can't find verapdf") +def test_pdfa_sanity(resources, outdir): + filename = resources / 'veraPDF test suite 6-2-10-t02-pass-a.pdf' + + assert verapdf_validate(filename) + + pdf = qpdf.QPDF.open(filename) + pdf.save(outdir / 'pdfa.pdf') + + assert verapdf_validate(outdir / 'pdfa.pdf') + + + |