Skip to content

[3.10] bpo-45496: Allow flexibility in winfo_rgb tests (GH-30185) #30266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions Lib/tkinter/test/test_tkinter/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,13 @@ def test_clipboard_astral(self):
root.clipboard_get()

def test_winfo_rgb(self):

def assertApprox(col1, col2):
# A small amount of flexibility is required (bpo-45496)
# 33 is ~0.05% of 65535, which is a reasonable margin
for col1_channel, col2_channel in zip(col1, col2):
self.assertAlmostEqual(col1_channel, col2_channel, delta=33)

root = self.root
rgb = root.winfo_rgb

Expand All @@ -209,9 +216,9 @@ def test_winfo_rgb(self):
# #RGB - extends each 4-bit hex value to be 16-bit.
self.assertEqual(rgb('#F0F'), (0xFFFF, 0x0000, 0xFFFF))
# #RRGGBB - extends each 8-bit hex value to be 16-bit.
self.assertEqual(rgb('#4a3c8c'), (0x4a4a, 0x3c3c, 0x8c8c))
assertApprox(rgb('#4a3c8c'), (0x4a4a, 0x3c3c, 0x8c8c))
# #RRRRGGGGBBBB
self.assertEqual(rgb('#dede14143939'), (0xdede, 0x1414, 0x3939))
assertApprox(rgb('#dede14143939'), (0xdede, 0x1414, 0x3939))
# Invalid string.
with self.assertRaises(tkinter.TclError):
rgb('#123456789a')
Expand Down