Skip to content

Commit d936fe5

Browse files
committed
Add missing test_colorchooser source
1 parent 179d3a2 commit d936fe5

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
@@ -49,10 +49,10 @@ def _fixresult(self, widget, result):
4949
"""Adjust result returned from call to tk_chooseColor.
5050
5151
Return both an RGB tuple of ints in the range (0, 255) and the
52-
tk color string in the form #xxxxxx.
52+
tk color string in the form #rrggbb.
5353
"""
5454
# Result can be many things: an empty tuple, an empty string, or
55-
# a Tcl_Obj, so this somewhat weird check handles that.
55+
# a _tkinter.Tcl_Obj, so this somewhat weird check handles that.
5656
if not result or not str(result):
5757
return None, None # canceled
5858

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)