Skip to content

Commit

Permalink
Fix test broken in commit 85d6fb8
Browse files Browse the repository at this point in the history
  • Loading branch information
jbarlow83 committed Nov 27, 2024
1 parent d70296b commit fe89be5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 12 additions & 5 deletions src/ocrmypdf/_exec/ghostscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,12 @@ def rasterize_pdf(
p = run(args_gs, stdout=PIPE, stderr=PIPE, check=True)
except CalledProcessError as e:
log.error(e.stderr.decode(errors='replace'))
raise SubprocessOutputError('Ghostscript rasterizing failed') from e
else:
stderr = p.stderr.decode(errors='replace')
if _gs_error_reported(stderr):
log.error(stderr)
Path(output_file).unlink(missing_ok=True)
raise SubprocessOutputError("Ghostscript rasterizing failed") from e

stderr = p.stderr.decode(errors='replace')
if _gs_error_reported(stderr):
log.error(stderr)

try:
with Image.open(output_file) as im:
Expand All @@ -164,6 +165,12 @@ def rasterize_pdf(
"an invalid page image file."
)
raise
except OSError as e:
log.error(
f"Ghostscript (using {raster_device} at {raster_dpi} dpi) produced "
"an invalid page image file."
)
raise UnidentifiedImageError() from e


class GhostscriptFollower:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ghostscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def test_ghostscript_mandatory_color_conversion(resources, outpdf):

def test_rasterize_pdf_errors(resources, no_outpdf, caplog):
with patch('ocrmypdf._exec.ghostscript.run') as mock:
# ghostscript can produce
# ghostscript can produce empty files with return code 0
mock.return_value = subprocess.CompletedProcess(
['fakegs'], returncode=0, stdout=b'', stderr=b'error this is an error'
)
Expand Down

0 comments on commit fe89be5

Please sign in to comment.