mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-05-03 07:23:41 +03:00
Simplify temporary directory cleanup
Co-Authored-By: Jon Dufresne <jon.dufresne@gmail.com>
This commit is contained in:
parent
84e53e3757
commit
3a34081db5
|
@ -162,13 +162,10 @@ class TestFilePdf(PillowTestCase):
|
||||||
|
|
||||||
def test_pdf_append_fails_on_nonexistent_file(self):
|
def test_pdf_append_fails_on_nonexistent_file(self):
|
||||||
im = hopper("RGB")
|
im = hopper("RGB")
|
||||||
temp_dir = tempfile.mkdtemp()
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
try:
|
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
IOError, im.save, os.path.join(temp_dir, "nonexistent.pdf"), append=True
|
IOError, im.save, os.path.join(temp_dir, "nonexistent.pdf"), append=True
|
||||||
)
|
)
|
||||||
finally:
|
|
||||||
os.rmdir(temp_dir)
|
|
||||||
|
|
||||||
def check_pdf_pages_consistency(self, pdf):
|
def check_pdf_pages_consistency(self, pdf):
|
||||||
pages_info = pdf.read_indirect(pdf.pages_ref)
|
pages_info = pdf.read_indirect(pdf.pages_ref)
|
||||||
|
|
|
@ -314,8 +314,10 @@ def _save(im, fp, filename):
|
||||||
fp.flush()
|
fp.flush()
|
||||||
|
|
||||||
# create the temporary set of pngs
|
# create the temporary set of pngs
|
||||||
iconset = tempfile.mkdtemp(".iconset")
|
with tempfile.TemporaryDirectory(".iconset") as iconset:
|
||||||
provided_images = {im.width: im for im in im.encoderinfo.get("append_images", [])}
|
provided_images = {
|
||||||
|
im.width: im for im in im.encoderinfo.get("append_images", [])
|
||||||
|
}
|
||||||
last_w = None
|
last_w = None
|
||||||
second_path = None
|
second_path = None
|
||||||
for w in [16, 32, 128, 256, 512]:
|
for w in [16, 32, 128, 256, 512]:
|
||||||
|
@ -344,9 +346,6 @@ def _save(im, fp, filename):
|
||||||
|
|
||||||
retcode = convert_proc.wait()
|
retcode = convert_proc.wait()
|
||||||
|
|
||||||
# remove the temporary files
|
|
||||||
shutil.rmtree(iconset)
|
|
||||||
|
|
||||||
if retcode:
|
if retcode:
|
||||||
raise subprocess.CalledProcessError(retcode, convert_cmd)
|
raise subprocess.CalledProcessError(retcode, convert_cmd)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user