summaryrefslogtreecommitdiffstats
path: root/Lib/tkinter/test
diff options
context:
space:
mode:
authorCheryl Sabella <cheryl.sabella@gmail.com>2021-01-21 19:14:04 (GMT)
committerGitHub <noreply@github.com>2021-01-21 19:14:04 (GMT)
commit6713e869c4989c04318158b406c30a147ea52904 (patch)
tree766a06687de09455c661cbfa2dc4cd0f05ed37f4 /Lib/tkinter/test
parent805ede8ae88fb517dea0df6de71cf88159b07e62 (diff)
downloadcpython-6713e869c4989c04318158b406c30a147ea52904.zip
cpython-6713e869c4989c04318158b406c30a147ea52904.tar.gz
cpython-6713e869c4989c04318158b406c30a147ea52904.tar.bz2
bpo-33289: Return RGB triplet of ints instead of floats from tkinter.colorchooser (GH-6578)
Diffstat (limited to 'Lib/tkinter/test')
-rw-r--r--Lib/tkinter/test/test_tkinter/test_colorchooser.py37
-rw-r--r--Lib/tkinter/test/test_tkinter/test_misc.py20
2 files changed, 54 insertions, 3 deletions
diff --git a/Lib/tkinter/test/test_tkinter/test_colorchooser.py b/Lib/tkinter/test/test_tkinter/test_colorchooser.py
index 600c8cd..41da86c 100644
--- a/Lib/tkinter/test/test_tkinter/test_colorchooser.py
+++ b/Lib/tkinter/test/test_tkinter/test_colorchooser.py
@@ -1,13 +1,44 @@
import unittest
import tkinter
from test.support import requires, run_unittest, swap_attr
-from tkinter.test.support import AbstractDefaultRootTest
-from tkinter.commondialog import Dialog
+from tkinter.test.support import AbstractDefaultRootTest, AbstractTkTest
+from tkinter import colorchooser
from tkinter.colorchooser import askcolor
+from tkinter.commondialog import Dialog
requires('gui')
+class ChooserTest(AbstractTkTest, unittest.TestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ AbstractTkTest.setUpClass.__func__(cls)
+ cls.cc = colorchooser.Chooser(initialcolor='dark blue slate')
+
+ def test_fixoptions(self):
+ cc = self.cc
+ cc._fixoptions()
+ self.assertEqual(cc.options['initialcolor'], 'dark blue slate')
+
+ cc.options['initialcolor'] = '#D2D269691E1E'
+ cc._fixoptions()
+ self.assertEqual(cc.options['initialcolor'], '#D2D269691E1E')
+
+ cc.options['initialcolor'] = (210, 105, 30)
+ cc._fixoptions()
+ self.assertEqual(cc.options['initialcolor'], '#d2691e')
+
+ def test_fixresult(self):
+ cc = self.cc
+ self.assertEqual(cc._fixresult(self.root, ()), (None, None))
+ self.assertEqual(cc._fixresult(self.root, ''), (None, None))
+ self.assertEqual(cc._fixresult(self.root, 'chocolate'),
+ ((210, 105, 30), 'chocolate'))
+ self.assertEqual(cc._fixresult(self.root, '#4a3c8c'),
+ ((74, 60, 140), '#4a3c8c'))
+
+
class DefaultRootTest(AbstractDefaultRootTest, unittest.TestCase):
def test_askcolor(self):
@@ -33,7 +64,7 @@ class DefaultRootTest(AbstractDefaultRootTest, unittest.TestCase):
self.assertRaises(RuntimeError, askcolor)
-tests_gui = (DefaultRootTest,)
+tests_gui = (ChooserTest, DefaultRootTest,)
if __name__ == "__main__":
run_unittest(*tests_gui)
diff --git a/Lib/tkinter/test/test_tkinter/test_misc.py b/Lib/tkinter/test/test_tkinter/test_misc.py
index 585d81d..f6e5b4d 100644
--- a/Lib/tkinter/test/test_tkinter/test_misc.py
+++ b/Lib/tkinter/test/test_tkinter/test_misc.py
@@ -192,6 +192,26 @@ class MiscTest(AbstractTkTest, unittest.TestCase):
with self.assertRaises(tkinter.TclError):
root.clipboard_get()
+ def test_winfo_rgb(self):
+ root = self.root
+ rgb = root.winfo_rgb
+
+ # Color name.
+ self.assertEqual(rgb('red'), (65535, 0, 0))
+ self.assertEqual(rgb('dark slate blue'), (18504, 15677, 35723))
+ # #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))
+ # #RRRRGGGGBBBB
+ self.assertEqual(rgb('#dede14143939'), (0xdede, 0x1414, 0x3939))
+ # Invalid string.
+ with self.assertRaises(tkinter.TclError):
+ rgb('#123456789a')
+ # RGB triplet is invalid input.
+ with self.assertRaises(tkinter.TclError):
+ rgb((111, 78, 55))
+
def test_event_repr_defaults(self):
e = tkinter.Event()
e.serial = 12345