Added exception handling/capture for convert-to-jpeg, issue #322

This commit is contained in:
Rhet Turnbull
2021-01-03 09:36:26 -08:00
parent 83915c65ab
commit 05f111a287
4 changed files with 13 additions and 9 deletions

View File

@@ -89,14 +89,15 @@ def test_image_converter_bad_file():
""" Try to convert a file that's not an image """
import pathlib
import tempfile
from osxphotos.imageconverter import ImageConverter
from osxphotos.imageconverter import ImageConverter, ImageConversionError
converter = ImageConverter()
tempdir = tempfile.TemporaryDirectory(prefix="osxphotos_")
with tempdir:
imgfile = pathlib.Path(TEST_NOT_AN_IMAGE)
outfile = pathlib.Path(tempdir.name) / f"{imgfile.stem}.jpeg"
assert not converter.write_jpeg(imgfile, outfile)
with pytest.raises(ImageConversionError):
converter.write_jpeg(imgfile, outfile)
def test_image_converter_missing_file():