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