mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-06-05 05:33:10 +03:00
imagetk testing draft
This commit is contained in:
parent
78f600acc3
commit
379b3922f1
|
@ -1,6 +1,5 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import gc
|
||||
import pytest
|
||||
import tkinter as tk
|
||||
from unittest import mock
|
||||
|
@ -101,26 +100,14 @@ def test_bitmapimage() -> None:
|
|||
# assert_image_equal(reloaded, im)
|
||||
|
||||
|
||||
def test_bitmapimage_del() -> None:
|
||||
# Set up an image
|
||||
im = Image.new("1", (10, 10))
|
||||
def test_photoimage_del() -> None:
|
||||
# Create a dummy PIL image
|
||||
im = Image.new("RGB", (100, 100))
|
||||
|
||||
# Mock the tkinter PhotoImage to track calls
|
||||
with mock.patch.object(tk, 'BitmapImage', wraps=tk.BitmapImage) as mock_bitmapimage:
|
||||
# Create an instance of BitmapImage
|
||||
bitmap_image = ImageTk.BitmapImage(im)
|
||||
|
||||
# Ensure the BitmapImage was created
|
||||
assert mock_bitmapimage.call_count == 1
|
||||
# Create a PhotoImage object
|
||||
photo = ImageTk.PhotoImage(im)
|
||||
|
||||
# Get the internal Tkinter image object
|
||||
tk_image = bitmap_image._BitmapImage__photo
|
||||
|
||||
# Mock the tk.call method to track the 'image delete' call
|
||||
with mock.patch.object(tk_image.tk, 'call', wraps=tk_image.tk.call) as mock_tk_call:
|
||||
# Delete the instance and force garbage collection
|
||||
del bitmap_image
|
||||
gc.collect()
|
||||
# Delete the PhotoImage object
|
||||
del photo
|
||||
|
||||
# Check that the 'image delete' command was called
|
||||
mock_tk_call.assert_any_call("image", "delete", tk_image.name)
|
||||
# No assertion needed, just ensuring that the __del__ method is executed
|
|
@ -235,7 +235,6 @@ class BitmapImage:
|
|||
self.__photo.tk.call("image", "delete", name)
|
||||
except Exception:
|
||||
BitmapImage.branches["2"] = True
|
||||
BitmapImage
|
||||
pass # ignore internal errors
|
||||
|
||||
def width(self) -> int:
|
||||
|
|
Loading…
Reference in New Issue
Block a user