Skip to content

Commit b9b6b08

Browse files
authored
Merge pull request #34 from jlaine/improve-test-coverage
Exercise both compressed and un-compressed `PDF.write`
2 parents 99582db + b8f239d commit b9b6b08

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

tests/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@
2727
)
2828

2929

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

3333
# Transform the PDF document into a list of RGB tuples
3434
pdf = io.BytesIO()
35-
document.write(pdf)
35+
document.write(pdf, compress=compress)
3636
command = [
3737
'gs', '-q', '-dNOPAUSE', '-dSAFER', '-sDEVICE=png16m',
3838
'-r576', '-dDownScaleFactor=8', '-sOutputFile=-', '-']

tests/test_pydyf.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import io
22
import re
33

4+
import pytest
5+
46
import pydyf
57

68
from . import assert_pixels
79

810

9-
def test_fill():
11+
@pytest.mark.parametrize("compress", [False, True])
12+
def test_fill(compress):
1013
document = pydyf.PDF()
1114

1215
draw = pydyf.Stream()
@@ -32,7 +35,7 @@ def test_fill():
3235
__KKKKK___
3336
__________
3437
__________
35-
''')
38+
''', compress)
3639

3740

3841
def test_stroke():
@@ -705,30 +708,33 @@ def test_text():
705708
''')
706709

707710

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

717721

718-
def test_default_identifier():
722+
@pytest.mark.parametrize("compress", [False, True])
723+
def test_default_identifier(compress):
719724
document = pydyf.PDF()
720725
pdf = io.BytesIO()
721-
document.write(pdf, identifier=True)
726+
document.write(pdf, compress=compress, identifier=True)
722727
assert re.search(
723728
b'/ID \\[\\((?P<hash>[0-9a-f]{32})\\) \\((?P=hash)\\)\\]',
724729
pdf.getvalue()
725730
) is not None
726731

727732

728-
def test_custom_identifier():
733+
@pytest.mark.parametrize("compress", [False, True])
734+
def test_custom_identifier(compress):
729735
document = pydyf.PDF()
730736
pdf = io.BytesIO()
731-
document.write(pdf, identifier=b'abc')
737+
document.write(pdf, compress=compress, identifier=b'abc')
732738
assert re.search(
733739
b'/ID \\[\\(abc\\) \\(([0-9a-f]{32})\\)\\]',
734740
pdf.getvalue()

0 commit comments

Comments
 (0)