workflows: close pdf file after reading (#51881)

This commit is contained in:
Frédéric Péters 2021-03-10 17:05:00 +01:00
parent 08780d7935
commit 74c9e66d6a
2 changed files with 7 additions and 5 deletions

View File

@ -3404,10 +3404,10 @@ def test_geolocate_overwrite(pub):
@pytest.mark.skipif(transform_to_pdf is None, reason='libreoffice not found')
def test_transform_to_pdf():
instream = open(os.path.join(os.path.dirname(__file__), 'template.odt'), 'rb')
outstream = transform_to_pdf(instream)
assert outstream is not False
assert outstream.read(10).startswith(b'%PDF-')
with open(os.path.join(os.path.dirname(__file__), 'template.odt'), 'rb') as instream:
outstream = transform_to_pdf(instream)
assert outstream is not False
assert outstream.read(10).startswith(b'%PDF-')
def test_export_to_model_image(pub):

View File

@ -119,7 +119,9 @@ try:
'libreoffice failed to produce pdf (stdout: %r, stderr: %r)'
% (lo_output.stdout, lo_output.stderr)
)
return open(infile.name + '.pdf', 'rb')
with open(infile.name + '.pdf', 'rb') as fd:
pdf_stream = io.BytesIO(fd.read())
return pdf_stream
except subprocess.CalledProcessError:
raise Exception('libreoffice is failing')
finally: