Skip to content

Commit bb0b5c1

Browse files
bpo-45496: Allow flexibility in winfo_rgb tests (GH-30185)
(cherry picked from commit 2e3e0d2) Co-authored-by: E-Paine <[email protected]>
1 parent a550820 commit bb0b5c1

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

Lib/tkinter/test/test_tkinter/test_misc.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,13 @@ def test_clipboard_astral(self):
200200
root.clipboard_get()
201201

202202
def test_winfo_rgb(self):
203+
204+
def assertApprox(col1, col2):
205+
# A small amount of flexibility is required (bpo-45496)
206+
# 33 is ~0.05% of 65535, which is a reasonable margin
207+
for col1_channel, col2_channel in zip(col1, col2):
208+
self.assertAlmostEqual(col1_channel, col2_channel, delta=33)
209+
203210
root = self.root
204211
rgb = root.winfo_rgb
205212

@@ -209,9 +216,9 @@ def test_winfo_rgb(self):
209216
# #RGB - extends each 4-bit hex value to be 16-bit.
210217
self.assertEqual(rgb('#F0F'), (0xFFFF, 0x0000, 0xFFFF))
211218
# #RRGGBB - extends each 8-bit hex value to be 16-bit.
212-
self.assertEqual(rgb('#4a3c8c'), (0x4a4a, 0x3c3c, 0x8c8c))
219+
assertApprox(rgb('#4a3c8c'), (0x4a4a, 0x3c3c, 0x8c8c))
213220
# #RRRRGGGGBBBB
214-
self.assertEqual(rgb('#dede14143939'), (0xdede, 0x1414, 0x3939))
221+
assertApprox(rgb('#dede14143939'), (0xdede, 0x1414, 0x3939))
215222
# Invalid string.
216223
with self.assertRaises(tkinter.TclError):
217224
rgb('#123456789a')

0 commit comments

Comments
 (0)