diff options
author | James R. Barlow <jim@purplerock.ca> | 2019-04-13 22:04:57 -0700 |
---|---|---|
committer | James R. Barlow <jim@purplerock.ca> | 2019-04-13 22:04:57 -0700 |
commit | dd142beb8df1857ed032e1876d574a4ad6d80b64 (patch) | |
tree | d4484184bfd4455bbd421015fd6f5691e8b1923e /tests | |
parent | 6332913c5cf6da016f8bdee1c65e9b5d05816740 (diff) |
Fix test for DCTDecode images with unusual ColorTransform not actually working
The test passed unconditionally because it accidentally tested for
the existence of the function instead of being defined, and did
not correctly compare results to the exepcted value.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_image_access.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/test_image_access.py b/tests/test_image_access.py index 3543090..037c5fc 100644 --- a/tests/test_image_access.py +++ b/tests/test_image_access.py @@ -1,11 +1,14 @@ import zlib from io import BytesIO +from pathlib import Path import pytest from PIL import Image from PIL import features as PIL_features from pikepdf import ( + Array, + Dictionary, Name, Pdf, PdfError, @@ -16,6 +19,8 @@ from pikepdf import ( parse_content_stream, ) +from pikepdf.models.image import UnsupportedImageTypeError + # pylint: disable=redefined-outer-name @@ -271,3 +276,29 @@ def test_jp2(resources): pim = PdfImage(xobj) assert pim.colorspace == '/DeviceRGB' assert pim.bits_per_component == 8 + + +def test_extract_filepath(congress, outdir): + xobj, _pdf = congress + pim = PdfImage(xobj) + + result = pim.extract_to(fileprefix=(outdir / 'image')) + assert Path(result).exists() + + +def test_extract_direct_fails_nondefault_colortransform(congress): + xobj, _pdf = congress + + xobj.DecodeParms = Dictionary( + ColorTransform=42 # Non standard (or allowed in the spec) + ) + pim = PdfImage(xobj) + + bio = BytesIO() + with pytest.raises(UnsupportedImageTypeError): + pim._extract_direct(stream=bio) + + xobj.ColorSpace = Name.DeviceCMYK + pim = PdfImage(xobj) + with pytest.raises(UnsupportedImageTypeError): + pim._extract_direct(stream=bio) |