gh-100814: Fix exception for invalid callable value of Tkinter image option (GH-107692)

Passing a callable object as an option value to a Tkinter image now raises
the expected TclError instead of an AttributeError.
This commit is contained in:
Serhiy Storchaka 2023-08-07 17:38:55 +03:00 committed by GitHub
parent 835e388915
commit 50e3cc9748
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 4 deletions

View file

@ -144,6 +144,14 @@ class BitmapImageTest(AbstractTkTest, unittest.TestCase):
self.assertEqual(image['foreground'],
'-foreground {} {} #000000 yellow')
def test_bug_100814(self):
# gh-100814: Passing a callable option value causes AttributeError.
with self.assertRaises(tkinter.TclError):
tkinter.BitmapImage('::img::test', master=self.root, spam=print)
image = tkinter.BitmapImage('::img::test', master=self.root)
with self.assertRaises(tkinter.TclError):
image.configure(spam=print)
class PhotoImageTest(AbstractTkTest, unittest.TestCase):
@ -274,6 +282,14 @@ class PhotoImageTest(AbstractTkTest, unittest.TestCase):
image.configure(palette='3/4/2')
self.assertEqual(image['palette'], '3/4/2')
def test_bug_100814(self):
# gh-100814: Passing a callable option value causes AttributeError.
with self.assertRaises(tkinter.TclError):
tkinter.PhotoImage('::img::test', master=self.root, spam=print)
image = tkinter.PhotoImage('::img::test', master=self.root)
with self.assertRaises(tkinter.TclError):
image.configure(spam=print)
def test_blank(self):
image = self.create()
image.blank()