Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switching to context managers in Tests #2818

Open
bjd2385 opened this issue Oct 30, 2017 · 4 comments

Comments

@bjd2385
Copy link

commented Oct 30, 2017

Looking through Tests, I see a lot of places where I would typically use a context manager. But is it worth a quick PR to change the styling?

For example, I see a lot of places that use im = Image.open(some_file); im.load() instead of

with Image.open(some_file) as im:
    im.load()
    ...

I know it's not a huge concern, but I also see that these are almost never followed by im.close(), which the CM would implicitly call.

By the way, I wrote a quick Bash script to output all of the instances in Tests that I'm talking about.

Tests/32bit_segfault_check.py
Tests/bench_cffi_access.py
Tests/bench_get.py
Tests/check_fli_overflow.py
        im = Image.open(TEST_FILE)
Tests/check_icns_dos.py
Tests/check_imaging_leaks.py
Tests/check_j2k_dos.py
Tests/check_j2k_leaks.py
Tests/check_j2k_overflow.py
Tests/check_jpeg_leaks.py
Tests/check_large_memory_numpy.py
Tests/check_large_memory.py
Tests/check_libtiff_segfault.py
            im = Image.open(TEST_FILE)
Tests/check_png_dos.py
            im = Image.open(TEST_FILE)
            im = Image.open(TEST_FILE)
            im2 = Image.open(b)
Tests/check_webp_leaks.py
Tests/createfontdatachunk.py
Tests/helper.py
Tests/import_all.py
Tests/make_hash.py
Tests/README.rst
Tests/test_000_sanity.py
Tests/test_binary.py
Tests/test_bmp_reference.py
                im = Image.open(f)
                im = Image.open(f)
                im = Image.open(f)
                compare = Image.open(get_compare(f))
Tests/test_box_blur.py
Tests/test_decompression_bomb.py
Tests/test_features.py
Tests/test_file_bmp.py
        reloaded = Image.open(outfile)
        reloaded = Image.open(output)
        reloaded = Image.open(output)
Tests/test_file_bufrstub.py
        im = Image.open(TEST_FILE)
        im = Image.open(TEST_FILE)
Tests/test_file_container.py
Tests/test_file_cur.py
        im = Image.open(TEST_FILE)
Tests/test_file_dcx.py
        im = Image.open(TEST_FILE)
        im = Image.open(TEST_FILE)
        im = Image.open(TEST_FILE)
        im = Image.open(TEST_FILE)
        im = Image.open(TEST_FILE)
Tests/test_file_dds.py
        target = Image.open(TEST_FILE_DXT1.replace('.dds', '.png'))
        im = Image.open(TEST_FILE_DXT1)
        target = Image.open(TEST_FILE_DXT5.replace('.dds', '.png'))
        im = Image.open(TEST_FILE_DXT5)
        target = Image.open(TEST_FILE_DXT3.replace('.dds', '.png'))
        im = Image.open(TEST_FILE_DXT3)
        target = Image.open(TEST_FILE_DX10_BC7.replace('.dds', '.png'))
        im = Image.open(TEST_FILE_DX10_BC7)
            im = Image.open(BytesIO(img_file[:-100]))
Tests/test_file_eps.py
        image1 = Image.open(file1)
        image2 = Image.open(file2)
        image1_scale2 = Image.open(file1)
        image2_scale2 = Image.open(file2)
        cmyk_image = Image.open("Tests/images/pil_sample_cmyk.eps")
            target = Image.open('Tests/images/pil_sample_rgb.jpg')
        image1 = Image.open(file1)
        image1 = Image.open(file1)
        img = Image.open(img_bytes)
        image1_scale1_compare = Image.open(file1_compare).convert("RGB")
        image1_scale1 = Image.open(file1)
        image1_scale1_compare = Image.open(file1_compare).convert("RGB")
        image2_scale1 = Image.open(file2)
        image2_scale1_compare = Image.open(file2_compare).convert("RGB")
        image1_scale2 = Image.open(file1)
        image1_scale2_compare = Image.open(file1_compare_scale2).convert("RGB")
        image2_scale2 = Image.open(file2)
        image2_scale2_compare = Image.open(file2_compare_scale2).convert("RGB")
        image1 = Image.open(file1)
        image2 = Image.open(file2)
        image3 = Image.open("Tests/images/illu10_preview.eps")
        image1 = Image.open(file1)
        image2 = Image.open(file2)
            img = Image.open(filename)
Tests/test_file_fitsstub.py
        im = Image.open(TEST_FILE)
        im = Image.open(TEST_FILE)
        im = Image.open(TEST_FILE)
Tests/test_file_fli.py
        im = Image.open(static_test_file)
        im = Image.open(animated_test_file)
        im = Image.open(static_test_file)
        im = Image.open(static_test_file)
        im = Image.open(animated_test_file)
        im = Image.open(animated_test_file)
        im = Image.open(static_test_file)
        im = Image.open(animated_test_file)
Tests/test_file_fpx.py
Tests/test_file_ftex.py
        im = Image.open('Tests/images/ftex_uncompressed.ftu')
        target = Image.open('Tests/images/ftex_uncompressed.png')
        im = Image.open('Tests/images/ftex_dxt1.ftc')
        target = Image.open('Tests/images/ftex_dxt1.png')
Tests/test_file_gbr.py
        im = Image.open('Tests/images/gbr.gbr')
        target = Image.open('Tests/images/gbr.png')
Tests/test_file_gif.py
        im = Image.open(TEST_GIF)
            reloaded = Image.open(outfile)
        reread = Image.open(out)
        im = Image.open(TEST_GIF)
        reread = Image.open(out)
        reread = Image.open(out)
        im = Image.open("Tests/images/dispose_bgnd.gif")
        reread = Image.open(out)
        im = Image.open("Tests/images/dispose_bgnd.gif")
        reread = Image.open(out)
        im = Image.open(TEST_GIF)
        reloaded = Image.open(f)
            reloaded = Image.open(out)
        im = Image.open(orig)
        img = Image.open(TEST_GIF).convert("RGB")
        img = Image.open(TEST_GIF).convert("L")
        img = Image.open("Tests/images/dispose_none.gif")
        im = Image.open(TEST_GIF)
        im = Image.open("Tests/images/iss634.gif")
        im = Image.open(TEST_GIF)
        img = Image.open("Tests/images/dispose_none.gif")
        img = Image.open("Tests/images/dispose_bgnd.gif")
        img = Image.open("Tests/images/dispose_prev.gif")
        img = Image.open("Tests/images/iss634.gif")
        reread = Image.open(out)
        reread = Image.open(out)
        reread = Image.open(out)
        reread = Image.open(out)
        reread = Image.open(out)
        reread = Image.open(out)
        im = Image.open(TEST_GIF)
        reread = Image.open(out)
        reread = Image.open(out)
        reread = Image.open(out)
        im = Image.open("Tests/images/test.colors.gif")
        reread = Image.open(out)
        reread = Image.open(out)
        reread = Image.open(out)
        im = Image.open("Tests/images/dispose_none.gif")
        reread = Image.open(out)
        reloaded = Image.open(out)
        reread = Image.open(out)
        reloaded = Image.open(out)
        reloaded = Image.open(out)
        reloaded = Image.open(out)
        reloaded = Image.open(out)
Tests/test_file_gimpgradient.py
Tests/test_file_gimppalette.py
Tests/test_file_gribstub.py
        im = Image.open(TEST_FILE)
        im = Image.open(TEST_FILE)
Tests/test_file_hdf5stub.py
        im = Image.open(TEST_FILE)
        im = Image.open(TEST_FILE)
        im = Image.open(TEST_FILE)
Tests/test_file_icns.py
        im = Image.open(TEST_FILE)
        im = Image.open(TEST_FILE)
        reread = Image.open(temp_file)
        im = Image.open(TEST_FILE)
            im2 = Image.open(TEST_FILE)
        im = Image.open('Tests/images/pillow2.icns')
            im2 = Image.open('Tests/images/pillow2.icns')
        im = Image.open('Tests/images/pillow3.icns')
            im2 = Image.open('Tests/images/pillow3.icns')
Tests/test_file_ico.py
        im = Image.open(TEST_ICO_FILE)
        reloaded = Image.open(output)
        reloaded = Image.open(output)
        im = Image.open("Tests/images/hopper_256x256.ico")
        im_saved = Image.open(outfile)
        im = Image.open("Tests/images/python.ico")  # 16x16, 32x32, 48x48
        im_saved = Image.open(outfile)
Tests/test_file_im.py
        im = Image.open(TEST_IM)
        im = Image.open(TEST_IM)
        im = Image.open(TEST_IM)
        im = Image.open(TEST_IM)
        reread = Image.open(out)
Tests/test_file_iptc.py
        im = Image.open(TEST_FILE)
        im = Image.open("Tests/images/hopper.tif")
Tests/test_file_jpeg2k.py
test_card = Image.open('Tests/images/test-card.png')
        im = Image.open(out)
        im = Image.open('Tests/images/test-card-lossless.jp2')
        im = Image.open(data)
        im = Image.open('Tests/images/test-card-lossless.jp2')
        im = Image.open('Tests/images/test-card-lossy-tiled.jp2')
        im = Image.open('Tests/images/test-card-lossless.jp2')
        im = Image.open(out)
        im = Image.open(out)
        j2k = Image.open('Tests/images/rgb_trns_ycbc.j2k')
        jp2 = Image.open('Tests/images/rgb_trns_ycbc.jp2')
        j2k = Image.open('Tests/images/16bit.cropped.j2k')
        jp2 = Image.open('Tests/images/16bit.cropped.jp2')
        tiff_16bit = Image.open('Tests/images/16bit.cropped.tif')
        jp2 = Image.open('Tests/images/16bit.cropped.jp2')
        tiff_16bit = Image.open('Tests/images/16bit.cropped.tif')
        j2k = Image.open('Tests/images/16bit.cropped.j2k')
        j2k = Image.open('Tests/images/16bit.cropped.j2k')
        jp2 = Image.open('Tests/images/16bit.cropped.jp2')
Tests/test_file_jpeg.py
        im = Image.open(out)
        im = Image.open(TEST_FILE)
        im = Image.open(TEST_FILE)
        im = Image.open(f)
            im = Image.open(TEST_FILE)
        im1 = Image.open("Tests/images/rgb.jpg")
        im2 = Image.open(f)
        im = Image.open('Tests/images/icc_profile_big.jpg')
        im = Image.open('Tests/images/exif_typeerror.jpg')
        im = Image.open('Tests/images/exif_gps.jpg')
        im = Image.open('Tests/images/exif_gps.jpg')
        im = Image.open('Tests/images/exif_gps_typeerror.jpg')
        im = Image.open("Tests/images/pil_sample_rgb.jpg")
        im = Image.open("Tests/images/pil_sample_rgb.jpg")
        im = Image.open("Tests/images/hopper.jpg")
        im = Image.open("Tests/images/hopper_gray.jpg")
        im = Image.open("Tests/images/pil_sample_cmyk.jpg")
        im = Image.open(test_file)
        im = Image.open(f)
        im = Image.open("Tests/images/hopper.jpg")
        img = Image.open(TEST_FILE)
        img = Image.open(TEST_FILE)
        reloaded = Image.open(f)
        im = Image.open("Tests/images/hopper.tif")
        reloaded = Image.open(outfile)
        im = Image.open("Tests/images/photoshop-200dpi.jpg")
        im = Image.open("Tests/images/exif-72dpi-int.jpg")
        im = Image.open("Tests/images/exif-200dpcm.jpg")
        im = Image.open("Tests/images/exif-dpi-zerodivision.jpg")
        im = Image.open("Tests/images/no-dpi-in-exif.jpg")
        im = Image.open("Tests/images/invalid-exif.jpg")
        im = Image.open(tmpfile)
Tests/test_file_libtiff.py
        im = Image.open(test_file)
        im = Image.open(test_file)
            im = Image.open(f)
        im = Image.open(s)
        png = Image.open('Tests/images/hopper_bw_500.png')
        g4 = Image.open('Tests/images/hopper_g4_500.tif')
        png = Image.open('Tests/images/g4-fillorder-test.png')
        g4 = Image.open('Tests/images/g4-fillorder-test.tif')
        orig = Image.open(test_file)
        reread = Image.open(out)
        im = Image.open(test_file)
            img = Image.open('Tests/images/hopper_g4.tif')
            loaded = Image.open(f)
        im = Image.open('Tests/images/hopper_g4.tif')
        i = Image.open('Tests/images/hopper_g4_500.tif')
        reread = Image.open(out)
        im = Image.open('Tests/images/16bit.deflate.tif')
        reread = Image.open(out)
        im = Image.open('Tests/images/16bit.MM.deflate.tif')
        reread = Image.open(out)
        orig = Image.open(test_file)
        reread = Image.open(out)
        im = Image.open('Tests/images/12bit.cropped.tif')
        im2 = Image.open('Tests/images/12in16bit.tif')
        im = Image.open('Tests/images/pport_g4.tif')
        im2 = Image.open(out)
            im2 = Image.open(out)
        im2 = Image.open(out)
        im2 = Image.open(out)
        im = Image.open("Tests/images/hopper_g4_500.tif")
        im = Image.open('Tests/images/multipage.tiff')
        im = Image.open('Tests/images/multipage.tiff')
        im = Image.open('Tests/images/hopper.tif')
        im = Image.open(test_file)
            im = Image.open(group[0])
                im2 = Image.open(file)
            pilim_load = Image.open(buffer_io)
        im = Image.open('Tests/images/rdf.tif')
        im = Image.open(infile)
        im = Image.open(tmpfile)
        im = Image.open('Tests/images/compression.tif')
        im = Image.open(infile)
Tests/test_file_libtiff_small.py
            im = Image.open(f)
        im = Image.open(s)
        im = Image.open(test_file)
Tests/test_file_mcidas.py
        im = Image.open(test_file)
        im2 = Image.open(saved_file)
Tests/test_file_mic.py
        im = Image.open(TEST_FILE)
        im = Image.open(TEST_FILE)
        im = Image.open(TEST_FILE)
        im = Image.open(TEST_FILE)
        im = Image.open(TEST_FILE)
Tests/test_file_mpo.py
        im = Image.open(out)
            im = Image.open(test_file)
            im = Image.open(test_file)
            im = Image.open(test_file)
            im = Image.open(test_file)
            im = Image.open(test_file)
            im = Image.open(test_file)
        im = Image.open("Tests/images/sugarshack.mpo")
        im = Image.open("Tests/images/sugarshack.mpo")
            im = Image.open(test_file)
            im = Image.open(test_file)
Tests/test_file_msp.py
        im = Image.open(file)
        im = Image.open(TEST_FILE)
            target = Image.open(target_path)
Tests/test_file_palm.py
Tests/test_file_pcd.py
        im = Image.open('Tests/images/hopper.pcd')
Tests/test_file_pcx.py
        im2 = Image.open(f)
        im = Image.open(test_file)
Tests/test_file_pdf.py
        im = Image.open("Tests/images/dispose_bgnd.gif")
Tests/test_file_pixar.py
        im = Image.open(TEST_FILE)
Tests/test_file_png.py
        im = Image.open(test_file)
        im = Image.open(test_file)
        im = Image.open(test_file)
        im = Image.open(test_file)
        im = Image.open(test_file)
        im = Image.open(test_file)
        im = Image.open(test_file)
        im = Image.open(test_file)
        im = Image.open(test_file)
        im = Image.open(test_file)
        im = Image.open(in_file)
        im = Image.open(test_file)
        im = Image.open(in_file)
        im = Image.open(test_file)
        im = Image.open(test_file)
        im = Image.open(in_file)
        im = Image.open(in_file)
        im = Image.open(TEST_PNG_FILE)
        im = Image.open(TEST_PNG_FILE)
            im = Image.open(BytesIO(test_file))
        im = Image.open(TEST_PNG_FILE)
        im = Image.open(TEST_PNG_FILE)
        im = Image.open(test_file)
        im2 = Image.open(f)
        im = Image.open(test_file)
        im = Image.open("Tests/images/icc_profile_none.png")
        with_icc = Image.open("Tests/images/icc_profile.png")
        im = Image.open('Tests/images/icc_profile.png')
        im = Image.open('Tests/images/icc_profile.png')
        im = Image.open("Tests/images/icc_profile_none.png")
        repr_png = Image.open(BytesIO(im._repr_png_()))
        im = Image.open("Tests/images/icc_profile.png")
Tests/test_file_ppm.py
        im = Image.open(test_file)
        im = Image.open('Tests/images/16_bit_binary.pgm')
        tgt = Image.open('Tests/images/16_bit_binary_pgm.png')
        im = Image.open('Tests/images/16_bit_binary.pgm')
        reloaded = Image.open(f)
Tests/test_file_psd.py
        im = Image.open(test_file)
        im = Image.open("Tests/images/hopper_merged.psd")
        im = Image.open(test_file)
        im = Image.open(test_file)
        im = Image.open(test_file)
        im = Image.open(test_file)
        im = Image.open(test_file)
        im = Image.open("Tests/images/hopper_merged.psd")
Tests/test_file_sgi.py
        im = Image.open(test_file)
        im = Image.open(test_file)
        im = Image.open(test_file)
        target = Image.open('Tests/images/transparent.png')
            reloaded = Image.open(out)
Tests/test_file_spider.py
        im = Image.open(TEST_FILE)
        im2 = Image.open(temp)
        im = Image.open(TEST_FILE)
        im = Image.open(TEST_FILE)
        im = Image.open(TEST_FILE)
        im = Image.open(TEST_FILE)
Tests/test_file_sun.py
        im = Image.open(test_file)
        im = Image.open('Tests/images/sunraster.im1')
        target = Image.open('Tests/images/sunraster.im1.png')
Tests/test_file_tar.py
            im = Image.open(tar)
            im = Image.open(tar)
Tests/test_file_tga.py
        im = Image.open(test_file)
        im = Image.open(test_file)
        im = Image.open(test_file)
        test_im = Image.open(test_file)
        test_im = Image.open(test_file)
        im = Image.open(test_file)
        test_im = Image.open(test_file)
        test_im = Image.open(test_file)
Tests/test_file_tiff_metadata.py
        loaded = Image.open(f)
        img = Image.open('Tests/images/hopper_g4.tif')
        img = Image.open('Tests/images/hopper.tif')
        loaded = Image.open(f)
        im = Image.open('Tests/images/hopper.iccprofile.tif')
        reloaded = Image.open(out)
        im = Image.open('Tests/images/hopper.iccprofile_binary.tif')
        im = Image.open('Tests/images/hopper.iccprofile.tif')
        im = Image.open('Tests/images/hopper.iccprofile_binary.tif')
        reloaded = Image.open(out)
Tests/test_file_tiff.py
        im = Image.open(filename)
        im = Image.open(filename)
        im = Image.open(filename)
        im = Image.open(filename)
        im = Image.open(filename)
        im = Image.open(filename)
        im = Image.open(filename)
        im = Image.open(filename)
        im = Image.open("Tests/images/copyleft.tiff")
        im = Image.open(filename)
        im = Image.open(filename)
        im = Image.open(filename)
        im = Image.open(b)
        i = Image.open('Tests/images/hopper_bad_exif.jpg')
        im = Image.open('Tests/images/16bit.cropped.tif')
        im = Image.open('Tests/images/16bit.MM.cropped.tif')
        im = Image.open('Tests/images/12bit.cropped.tif')
        im2 = Image.open('Tests/images/12in16bit.tif')
        im = Image.open(path)
        im = Image.open('Tests/images/multipage-lastframe.tif')
        im = Image.open('Tests/images/multipage.tiff')
        im = Image.open('Tests/images/multipage-lastframe.tif')
        im = Image.open('Tests/images/multipage.tiff')
        im = Image.open('Tests/images/multipage-lastframe.tif')
        im = Image.open(filename)
        im = Image.open(filename)
        im = Image.open(filename)
        im = Image.open(filename)
        im = Image.open(filename)
        im = Image.open(test_file)
            im = Image.open(group[0])
                im2 = Image.open(file)
        im = Image.open(filename)
        im = Image.open("Tests/images/hopper_lzw.tif")
        im = Image.open(infile)
        reloaded = Image.open(tmpfile)
        reread = Image.open(mp)
        reloaded = Image.open(tmpfile)
        im = Image.open(tmpfile)
        im = Image.open(f)
        im = Image.open(tmpfile)
Tests/test_file_webp_alpha.py
        image = Image.open(file_path)
        target = Image.open('Tests/images/transparent.png')
        image = Image.open(temp_file)
        image = Image.open(temp_file)
Tests/test_file_webp_lossless.py
        image = Image.open(temp_file)
Tests/test_file_webp_metadata.py
        image = Image.open(file_path)
        jpeg_image = Image.open('Tests/images/flower.jpg')
        image = Image.open(file_path)
        webp_image = Image.open(test_buffer)
        image = Image.open(file_path)
        jpeg_image = Image.open('Tests/images/flower2.jpg')
        image = Image.open(file_path)
        webp_image = Image.open(test_buffer)
        image = Image.open(file_path)
        webp_image = Image.open(test_buffer)
Tests/test_file_webp.py
        image = Image.open(file_path)
        target = Image.open('Tests/images/hopper_webp_bits.ppm')
        image = Image.open(temp_file)
        # target = Image.open('Tests/images/hopper_webp_write.ppm')
Tests/test_file_wmf.py
        im = Image.open('Tests/images/drawing.emf')
            imref = Image.open('Tests/images/drawing_emf_ref.png')
        im = Image.open('Tests/images/drawing.wmf')
            imref = Image.open('Tests/images/drawing_wmf_ref.png')
Tests/test_file_xbm.py
        im = Image.open(BytesIO(PIL151))
        im = Image.open(filename)
        im = Image.open(filename)
Tests/test_file_xpm.py
        im = Image.open(TEST_FILE)
        im = Image.open(TEST_FILE)
Tests/test_file_xvthumb.py
        im = Image.open(TEST_FILE)
Tests/test_font_bdf.py
Tests/test_font_pcf.py
        compare = Image.open('Tests/images/high_ascii_chars.png')
Tests/test_format_hsv.py
Tests/test_format_lab.py
        i = Image.open('Tests/images/lab.tif')
        i = Image.open('Tests/images/lab-green.tif')
        i = Image.open('Tests/images/lab-red.tif')
Tests/test_image_access.py
Tests/test_image_array.py
Tests/test_imagechops.py
Tests/test_imagecms.py
        i = Image.open("Tests/images/rgb.jpg")
        target = Image.open('Tests/images/hopper.Lab.tif')
        img = Image.open('Tests/images/hopper.Lab.tif')
        i = Image.open("Tests/images/rgb.jpg")
Tests/test_imagecolor.py
Tests/test_image_convert.py
        im = Image.open('Tests/images/hopper.jpg')
        im = Image.open('Tests/images/16bit.cropped.tif')
        im = Image.open('Tests/images/16bit.cropped.tif')
            target = Image.open('Tests/images/hopper-XYZ.png')
Tests/test_image_copy.py
Tests/test_image_crop.py
        img = Image.open(test_img)
        img = Image.open(test_img)
Tests/test_image_draft.py
Tests/test_imagedraw.py
        im = Image.open("Tests/images/chi.gif")
        small = Image.open("Tests/images/pil123rgba.png").resize((50, 50))
        im_floodfill = Image.open("Tests/images/imagedraw_floodfill.png")
        expected = Image.open(os.path.join(IMAGES_PATH, 'square.png'))
        expected = Image.open(os.path.join(IMAGES_PATH, 'triangle_right.png'))
        expected = Image.open(os.path.join(IMAGES_PATH,
        expected = Image.open(os.path.join(IMAGES_PATH,
        expected = Image.open(os.path.join(IMAGES_PATH,
        expected = Image.open(os.path.join(IMAGES_PATH,
        expected = Image.open(os.path.join(IMAGES_PATH,
        expected = Image.open(os.path.join(IMAGES_PATH,
        expected = Image.open(os.path.join(IMAGES_PATH,
        expected = Image.open(os.path.join(IMAGES_PATH,
        expected = Image.open(os.path.join(IMAGES_PATH,
        expected = Image.open(os.path.join(IMAGES_PATH,
        expected = Image.open(os.path.join(IMAGES_PATH,
        expected = Image.open(os.path.join(IMAGES_PATH,
Tests/test_imageenhance.py
Tests/test_imagefile.py
        im = Image.open("Tests/images/truncated_image.png")
        im = Image.open("Tests/images/truncated_image.png")
        im = Image.open("Tests/images/broken_data_stream.png")
        im = Image.open("Tests/images/broken_data_stream.png")
Tests/test_image_filter.py
        im = Image.open("Tests/images/hopper.bmp")
        im = Image.open("Tests/images/hopper.bmp")
Tests/test_imagefont_bitmap.py
Tests/test_imagefontctl.py
        target_img = Image.open(target)
        target_img = Image.open(target)
        target_img = Image.open(target)
        target_img = Image.open(target)
        target_img = Image.open(target)
        target_img = Image.open(target)
        target_img = Image.open(target)
        target_img = Image.open(target)
        target_img = Image.open(target)
Tests/test_imagefont.py
        target_img = Image.open(target)
        target_img = Image.open(target)
        target_img = Image.open(target)
            target_img = Image.open(target)
        target_img = Image.open(target)
        target_img = Image.open(target)
Tests/test_image_frombytes.py
Tests/test_image_fromqimage.py
Tests/test_image_fromqpixmap.py
Tests/test_image_getbands.py
Tests/test_image_getbbox.py
Tests/test_image_getcolors.py
Tests/test_image_getdata.py
Tests/test_image_getextrema.py
Tests/test_image_getim.py
Tests/test_image_getpalette.py
Tests/test_image_getprojection.py
Tests/test_imagegrab.py
Tests/test_image_histogram.py
Tests/test_image_load.py
        im = Image.open("Tests/images/hopper.gif")
Tests/test_imagemath.py
Tests/test_image_mode.py
Tests/test_imagemorph.py
        im = Image.open('Tests/images/morph_a.png')
Tests/test_imageops.py
Tests/test_imageops_usm.py
im = Image.open("Tests/images/hopper.ppm")
snakes = Image.open("Tests/images/color_snakes.png")
Tests/test_imagepalette.py
        reloaded = Image.open(outfile)
Tests/test_image_paste.py
Tests/test_imagepath.py
Tests/test_image_point.py
Tests/test_image_putalpha.py
Tests/test_image_putdata.py
Tests/test_image_putpalette.py
Tests/test_image.py
        im = Image.open(Path("Tests/images/hopper.jpg"))
            reloaded = Image.open(fp)
        im2 = Image.open('Tests/images/effect_mandelbrot.png')
        im3 = Image.open('Tests/images/effect_spread.png')
            target = Image.open(target_file).convert(mode)
            target = Image.open(target_file).convert(mode)
Tests/test_imageqt.py
Tests/test_image_quantize.py
        image = Image.open('Tests/images/caption_6_33_22.png').convert('RGB')
Tests/test_image_resample.py
Tests/test_image_resize.py
Tests/test_image_rotate.py
            im = Image.open('Tests/images/test-card.png')
        # >>> im = Image.open('Tests/images/hopper.ppm')
        target = Image.open('Tests/images/hopper_45.png')
        target = Image.open('Tests/images/hopper_45.png')
        target = Image.open('Tests/images/hopper_45.png')
        target = Image.open('Tests/images/hopper_45.png')
Tests/test_imagesequence.py
        im = Image.open('Tests/images/multipage.tiff')
        im = Image.open('Tests/images/multipage.tiff')
        im = Image.open('Tests/images/multipage.tiff')
        im = Image.open('Tests/images/multipage-mmap.tiff')
Tests/test_imageshow.py
Tests/test_image_split.py
            im = Image.open(test_file)
Tests/test_imagestat.py
Tests/test_image_thumbnail.py
Tests/test_imagetk.py
        im1 = Image.open(TEST_JPG)
        im2 = Image.open(TEST_PNG)
Tests/test_image_tobitmap.py
Tests/test_image_tobytes.py
Tests/test_image_toqimage.py
            reloaded = Image.open(tempfile)
Tests/test_image_toqpixmap.py
Tests/test_image_transform.py
Tests/test_image_transpose.py
Tests/test_imagewin_pointers.py
Tests/test_imagewin.py
Tests/test_lib_image.py
Tests/test_lib_pack.py
Tests/test_locale.py
Tests/test_map.py
        im = Image.open('Tests/images/l2rgb_read.bmp')
Tests/test_mode_i16.py
            imOut = Image.open(filename)
Tests/test_numpy.py
        img = Image.open('Tests/images/16bit.cropped.tif')
Tests/test_pickle.py
        im = Image.open('Tests/images/hopper.jpg')
        im = Image.open(test_file)
Tests/test_psdraw.py
        im = Image.open("Tests/images/hopper.ppm")
Tests/test_pyroma.py
Tests/test_scipy.py
Tests/test_shell_injection.py
            im = Image.open(src_file)
        im = Image.open(TEST_JPG)
        im = Image.open(TEST_GIF).convert("RGB")
        im = Image.open(TEST_GIF).convert("L")
Tests/test_tiff_ifdrational.py
            reloaded = Image.open(out)
Tests/test_util.py
Tests/threaded_save.py
im = Image.open("Tests/images/hopper.ppm")
            im = Image.open(io.BytesIO(data))
Tests/versions.py
@wiredfool

This comment has been minimized.

Copy link
Member

commented Nov 11, 2017

im.close is not a required step for most images, as the load stage should close the open file as appropriate. Generally, it's only required in the case of multiframe images, as there's no good way to determine when to close the image when you can always seek to another frame.

@aclark4life aclark4life added NumPy and removed NumPy labels Jun 30, 2018
@radarhere

This comment has been minimized.

Copy link
Member

commented Jul 4, 2018

Just to create a link between the two issues, #2786 is another issue about unclosed files in the test suite.

@bjd2385

This comment has been minimized.

Copy link
Author

commented Jul 5, 2018

Sorry, I forgot about this issue.

@wiredfool isn't it a better idea to just close them, instead of relying on load to close them?

@radarhere radarhere added File Closing and removed NumPy labels Nov 7, 2018
@radarhere

This comment has been minimized.

Copy link
Member

commented Jan 14, 2019

#3577 looks like an implementation of this

@aclark4life aclark4life added BMP Memory and removed BMP labels May 11, 2019
@aclark4life aclark4life added this to Backlog in Pillow May 11, 2019
@aclark4life aclark4life moved this from Backlog to In progress in Pillow May 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Pillow
  
In progress
4 participants
You can’t perform that action at this time.