Skip to content

Commit 597495e

Browse files
committed
Add missing test_colorchooser source
1 parent 471f093 commit 597495e

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

Lib/tkinter/colorchooser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ def _fixresult(self, widget, result):
4747
"""Adjust result returned from call to tk_chooseColor.
4848
4949
Return both an RGB tuple of ints in the range (0, 255) and the
50-
tk color string in the form #xxxxxx.
50+
tk color string in the form #rrggbb.
5151
"""
5252
# Result can be many things: an empty tuple, an empty string, or
53-
# a Tcl_Obj, so this somewhat weird check handles that.
53+
# a _tkinter.Tcl_Obj, so this somewhat weird check handles that.
5454
if not result or not str(result):
5555
return None, None # canceled
5656

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import unittest
2+
import tkinter
3+
from tkinter import colorchooser
4+
from test.support import requires, run_unittest, gc_collect
5+
from tkinter.test.support import AbstractTkTest
6+
7+
requires('gui')
8+
9+
class ChooserTest(AbstractTkTest, unittest.TestCase):
10+
11+
@classmethod
12+
def setUpClass(cls):
13+
AbstractTkTest.setUpClass.__func__(cls)
14+
cls.cc = colorchooser.Chooser(initialcolor='red')
15+
16+
def test_fixoptions(self):
17+
cc = self.cc
18+
cc._fixoptions()
19+
self.assertEqual(cc.options['initialcolor'], 'red')
20+
21+
cc.options['initialcolor'] = '#ffff00000000'
22+
cc._fixoptions()
23+
self.assertEqual(cc.options['initialcolor'], '#ffff00000000')
24+
25+
cc.options['initialcolor'] = (255, 0, 0)
26+
cc._fixoptions()
27+
self.assertEqual(cc.options['initialcolor'], '#ff0000')
28+
29+
def test_fixresult(self):
30+
cc = self.cc
31+
self.assertEqual(cc._fixresult(self.root, ()), (None, None))
32+
self.assertEqual(cc._fixresult(self.root, ''), (None, None))
33+
self.assertEqual(cc._fixresult(self.root, 'red'),
34+
((255, 0, 0), 'red'))
35+
self.assertEqual(cc._fixresult(self.root, '#ff0000'),
36+
((255, 0, 0), '#ff0000'))
37+
38+
39+
tests_gui = (ChooserTest, )
40+
41+
if __name__ == "__main__":
42+
run_unittest(*tests_gui)

0 commit comments

Comments
 (0)