|
| 1 | +import collections.abc |
1 | 2 | import unittest |
2 | 3 | import tkinter |
3 | 4 | from test import support |
@@ -61,7 +62,33 @@ def test_image_create_photo(self): |
61 | 62 | self.assertRaises(RuntimeError, tkinter.PhotoImage) |
62 | 63 |
|
63 | 64 |
|
64 | | -class BitmapImageTest(AbstractTkTest, unittest.TestCase): |
| 65 | +class BaseImageTest: |
| 66 | + def create(self): |
| 67 | + return self.image_class('::img::test', master=self.root, |
| 68 | + file=self.testfile) |
| 69 | + |
| 70 | + def test_bug_100814(self): |
| 71 | + # gh-100814: Passing a callable option value causes AttributeError. |
| 72 | + with self.assertRaises(tkinter.TclError): |
| 73 | + self.image_class('::img::test', master=self.root, spam=print) |
| 74 | + image = self.image_class('::img::test', master=self.root) |
| 75 | + with self.assertRaises(tkinter.TclError): |
| 76 | + image.configure(spam=print) |
| 77 | + |
| 78 | + def test_iterable_protocol(self): |
| 79 | + image = self.create() |
| 80 | + self.assertNotIsSubclass(self.image_class, collections.abc.Iterable) |
| 81 | + self.assertNotIsSubclass(self.image_class, collections.abc.Container) |
| 82 | + self.assertNotIsInstance(image, collections.abc.Iterable) |
| 83 | + self.assertNotIsInstance(image, collections.abc.Container) |
| 84 | + with self.assertRaisesRegex(TypeError, 'is not iterable'): |
| 85 | + iter(image) |
| 86 | + with self.assertRaisesRegex(TypeError, 'is not a container or iterable'): |
| 87 | + image in image |
| 88 | + |
| 89 | + |
| 90 | +class BitmapImageTest(BaseImageTest, AbstractTkTest, unittest.TestCase): |
| 91 | + image_class = tkinter.BitmapImage |
65 | 92 |
|
66 | 93 | @classmethod |
67 | 94 | def setUpClass(cls): |
@@ -144,26 +171,15 @@ def test_configure_foreground(self): |
144 | 171 | self.assertEqual(image['foreground'], |
145 | 172 | '-foreground {} {} #000000 yellow') |
146 | 173 |
|
147 | | - def test_bug_100814(self): |
148 | | - # gh-100814: Passing a callable option value causes AttributeError. |
149 | | - with self.assertRaises(tkinter.TclError): |
150 | | - tkinter.BitmapImage('::img::test', master=self.root, spam=print) |
151 | | - image = tkinter.BitmapImage('::img::test', master=self.root) |
152 | | - with self.assertRaises(tkinter.TclError): |
153 | | - image.configure(spam=print) |
154 | | - |
155 | 174 |
|
156 | | -class PhotoImageTest(AbstractTkTest, unittest.TestCase): |
| 175 | +class PhotoImageTest(BaseImageTest, AbstractTkTest, unittest.TestCase): |
| 176 | + image_class = tkinter.PhotoImage |
157 | 177 |
|
158 | 178 | @classmethod |
159 | 179 | def setUpClass(cls): |
160 | 180 | AbstractTkTest.setUpClass.__func__(cls) |
161 | 181 | cls.testfile = support.findfile('python.gif', subdir='tkinterdata') |
162 | 182 |
|
163 | | - def create(self): |
164 | | - return tkinter.PhotoImage('::img::test', master=self.root, |
165 | | - file=self.testfile) |
166 | | - |
167 | 183 | def colorlist(self, *args): |
168 | 184 | if tkinter.TkVersion >= 8.6 and self.wantobjects: |
169 | 185 | return args |
@@ -282,14 +298,6 @@ def test_configure_palette(self): |
282 | 298 | image.configure(palette='3/4/2') |
283 | 299 | self.assertEqual(image['palette'], '3/4/2') |
284 | 300 |
|
285 | | - def test_bug_100814(self): |
286 | | - # gh-100814: Passing a callable option value causes AttributeError. |
287 | | - with self.assertRaises(tkinter.TclError): |
288 | | - tkinter.PhotoImage('::img::test', master=self.root, spam=print) |
289 | | - image = tkinter.PhotoImage('::img::test', master=self.root) |
290 | | - with self.assertRaises(tkinter.TclError): |
291 | | - image.configure(spam=print) |
292 | | - |
293 | 301 | def test_blank(self): |
294 | 302 | image = self.create() |
295 | 303 | image.blank() |
|
0 commit comments