mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-05-02 23:13:40 +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):
|
||||
im = hopper("RGB")
|
||||
temp_dir = tempfile.mkdtemp()
|
||||
try:
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
self.assertRaises(
|
||||
IOError, im.save, os.path.join(temp_dir, "nonexistent.pdf"), append=True
|
||||
)
|
||||
finally:
|
||||
os.rmdir(temp_dir)
|
||||
|
||||
def check_pdf_pages_consistency(self, pdf):
|
||||
pages_info = pdf.read_indirect(pdf.pages_ref)
|
||||
|
|
|
@ -314,8 +314,10 @@ def _save(im, fp, filename):
|
|||
fp.flush()
|
||||
|
||||
# create the temporary set of pngs
|
||||
iconset = tempfile.mkdtemp(".iconset")
|
||||
provided_images = {im.width: im for im in im.encoderinfo.get("append_images", [])}
|
||||
with tempfile.TemporaryDirectory(".iconset") as iconset:
|
||||
provided_images = {
|
||||
im.width: im for im in im.encoderinfo.get("append_images", [])
|
||||
}
|
||||
last_w = None
|
||||
second_path = None
|
||||
for w in [16, 32, 128, 256, 512]:
|
||||
|
@ -344,9 +346,6 @@ def _save(im, fp, filename):
|
|||
|
||||
retcode = convert_proc.wait()
|
||||
|
||||
# remove the temporary files
|
||||
shutil.rmtree(iconset)
|
||||
|
||||
if retcode:
|
||||
raise subprocess.CalledProcessError(retcode, convert_cmd)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user