Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
)


def assert_pixels(document, reference_pixels):
def assert_pixels(document, reference_pixels, compress=False):
"""Test that the rendered document matches the reference pixels."""

# Transform the PDF document into a list of RGB tuples
pdf = io.BytesIO()
document.write(pdf)
document.write(pdf, compress=compress)
command = [
'gs', '-q', '-dNOPAUSE', '-dSAFER', '-sDEVICE=png16m',
'-r576', '-dDownScaleFactor=8', '-sOutputFile=-', '-']
Expand Down
22 changes: 14 additions & 8 deletions tests/test_pydyf.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import io
import re

import pytest

import pydyf

from . import assert_pixels


def test_fill():
@pytest.mark.parametrize("compress", [False, True])
def test_fill(compress):
document = pydyf.PDF()

draw = pydyf.Stream()
Expand All @@ -32,7 +35,7 @@ def test_fill():
__KKKKK___
__________
__________
''')
''', compress)


def test_stroke():
Expand Down Expand Up @@ -705,30 +708,33 @@ def test_text():
''')


def test_no_identifier():
@pytest.mark.parametrize("compress", [False, True])
def test_no_identifier(compress):
document = pydyf.PDF()
pdf = io.BytesIO()
document.write(pdf, identifier=False)
document.write(pdf, compress=compress, identifier=False)
assert re.search(
b'/ID \\[\\((?P<hash>[0-9a-f]{32})\\) \\((?P=hash)\\)\\]',
pdf.getvalue()
) is None


def test_default_identifier():
@pytest.mark.parametrize("compress", [False, True])
def test_default_identifier(compress):
document = pydyf.PDF()
pdf = io.BytesIO()
document.write(pdf, identifier=True)
document.write(pdf, compress=compress, identifier=True)
assert re.search(
b'/ID \\[\\((?P<hash>[0-9a-f]{32})\\) \\((?P=hash)\\)\\]',
pdf.getvalue()
) is not None


def test_custom_identifier():
@pytest.mark.parametrize("compress", [False, True])
def test_custom_identifier(compress):
document = pydyf.PDF()
pdf = io.BytesIO()
document.write(pdf, identifier=b'abc')
document.write(pdf, compress=compress, identifier=b'abc')
assert re.search(
b'/ID \\[\\(abc\\) \\(([0-9a-f]{32})\\)\\]',
pdf.getvalue()
Expand Down