From 219fa06601218afc2063b2209ad0588fd322bd18 Mon Sep 17 00:00:00 2001 From: E-Paine <63801254+E-Paine@users.noreply.github.com> Date: Sat, 18 Dec 2021 13:28:23 +0000 Subject: [PATCH 1/4] Allow flexibility in winfo_rgb tests --- Lib/tkinter/test/test_tkinter/test_misc.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Lib/tkinter/test/test_tkinter/test_misc.py b/Lib/tkinter/test/test_tkinter/test_misc.py index 2c78eaca2c85b4..a8ff18c9318fae 100644 --- a/Lib/tkinter/test/test_tkinter/test_misc.py +++ b/Lib/tkinter/test/test_tkinter/test_misc.py @@ -201,6 +201,14 @@ 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 + self.assertTrue(all( + abs(i - j) < 33 for i, j in zip(col1, col2) + )) + root = self.root rgb = root.winfo_rgb @@ -210,9 +218,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') From 0e4d888ce5167ca0e7a4c77836f9dd85f8cc1490 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Sat, 18 Dec 2021 13:31:30 +0000 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Misc/NEWS.d/next/Tests/2021-12-18-13-31-29.bpo-45496.lQsPOW.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Tests/2021-12-18-13-31-29.bpo-45496.lQsPOW.rst diff --git a/Misc/NEWS.d/next/Tests/2021-12-18-13-31-29.bpo-45496.lQsPOW.rst b/Misc/NEWS.d/next/Tests/2021-12-18-13-31-29.bpo-45496.lQsPOW.rst new file mode 100644 index 00000000000000..2d558857f5db4d --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2021-12-18-13-31-29.bpo-45496.lQsPOW.rst @@ -0,0 +1 @@ +Allow a small margin to avoid failing the tkinter `winfo_rgb` test when on different hardware. \ No newline at end of file From 59401369ab38a61cbb0a593bad40401f7f18403a Mon Sep 17 00:00:00 2001 From: E-Paine <63801254+E-Paine@users.noreply.github.com> Date: Sat, 18 Dec 2021 13:32:45 +0000 Subject: [PATCH 3/4] Fix ReST backticks --- Misc/NEWS.d/next/Tests/2021-12-18-13-31-29.bpo-45496.lQsPOW.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Tests/2021-12-18-13-31-29.bpo-45496.lQsPOW.rst b/Misc/NEWS.d/next/Tests/2021-12-18-13-31-29.bpo-45496.lQsPOW.rst index 2d558857f5db4d..45df6c3ac1e442 100644 --- a/Misc/NEWS.d/next/Tests/2021-12-18-13-31-29.bpo-45496.lQsPOW.rst +++ b/Misc/NEWS.d/next/Tests/2021-12-18-13-31-29.bpo-45496.lQsPOW.rst @@ -1 +1 @@ -Allow a small margin to avoid failing the tkinter `winfo_rgb` test when on different hardware. \ No newline at end of file +Allow a small margin to avoid failing the tkinter ``winfo_rgb`` test when on different hardware. From 0ce316b3b591c57a71fc39ebd7ad418d8e618c1e Mon Sep 17 00:00:00 2001 From: E-Paine <63801254+E-Paine@users.noreply.github.com> Date: Sun, 19 Dec 2021 12:44:38 +0000 Subject: [PATCH 4/4] Use assertAlmostEqual and remove news entry --- Lib/tkinter/test/test_tkinter/test_misc.py | 5 ++--- .../next/Tests/2021-12-18-13-31-29.bpo-45496.lQsPOW.rst | 1 - 2 files changed, 2 insertions(+), 4 deletions(-) delete mode 100644 Misc/NEWS.d/next/Tests/2021-12-18-13-31-29.bpo-45496.lQsPOW.rst diff --git a/Lib/tkinter/test/test_tkinter/test_misc.py b/Lib/tkinter/test/test_tkinter/test_misc.py index a8ff18c9318fae..044eb10d688356 100644 --- a/Lib/tkinter/test/test_tkinter/test_misc.py +++ b/Lib/tkinter/test/test_tkinter/test_misc.py @@ -205,9 +205,8 @@ 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 - self.assertTrue(all( - abs(i - j) < 33 for i, j in zip(col1, col2) - )) + for col1_channel, col2_channel in zip(col1, col2): + self.assertAlmostEqual(col1_channel, col2_channel, delta=33) root = self.root rgb = root.winfo_rgb diff --git a/Misc/NEWS.d/next/Tests/2021-12-18-13-31-29.bpo-45496.lQsPOW.rst b/Misc/NEWS.d/next/Tests/2021-12-18-13-31-29.bpo-45496.lQsPOW.rst deleted file mode 100644 index 45df6c3ac1e442..00000000000000 --- a/Misc/NEWS.d/next/Tests/2021-12-18-13-31-29.bpo-45496.lQsPOW.rst +++ /dev/null @@ -1 +0,0 @@ -Allow a small margin to avoid failing the tkinter ``winfo_rgb`` test when on different hardware.