1 | n/a | import unittest |
---|
2 | n/a | import tkinter |
---|
3 | n/a | from test import support |
---|
4 | n/a | from tkinter.test.support import AbstractTkTest |
---|
5 | n/a | |
---|
6 | n/a | support.requires('gui') |
---|
7 | n/a | |
---|
8 | n/a | class MiscTest(AbstractTkTest, unittest.TestCase): |
---|
9 | n/a | |
---|
10 | n/a | def test_repr(self): |
---|
11 | n/a | t = tkinter.Toplevel(self.root, name='top') |
---|
12 | n/a | f = tkinter.Frame(t, name='child') |
---|
13 | n/a | self.assertEqual(repr(f), '<tkinter.Frame object .top.child>') |
---|
14 | n/a | |
---|
15 | n/a | def test_generated_names(self): |
---|
16 | n/a | t = tkinter.Toplevel(self.root) |
---|
17 | n/a | f = tkinter.Frame(t) |
---|
18 | n/a | f2 = tkinter.Frame(t) |
---|
19 | n/a | b = tkinter.Button(f2) |
---|
20 | n/a | for name in str(b).split('.'): |
---|
21 | n/a | self.assertFalse(name.isidentifier(), msg=repr(name)) |
---|
22 | n/a | |
---|
23 | n/a | def test_tk_setPalette(self): |
---|
24 | n/a | root = self.root |
---|
25 | n/a | root.tk_setPalette('black') |
---|
26 | n/a | self.assertEqual(root['background'], 'black') |
---|
27 | n/a | root.tk_setPalette('white') |
---|
28 | n/a | self.assertEqual(root['background'], 'white') |
---|
29 | n/a | self.assertRaisesRegex(tkinter.TclError, |
---|
30 | n/a | '^unknown color name "spam"$', |
---|
31 | n/a | root.tk_setPalette, 'spam') |
---|
32 | n/a | |
---|
33 | n/a | root.tk_setPalette(background='black') |
---|
34 | n/a | self.assertEqual(root['background'], 'black') |
---|
35 | n/a | root.tk_setPalette(background='blue', highlightColor='yellow') |
---|
36 | n/a | self.assertEqual(root['background'], 'blue') |
---|
37 | n/a | self.assertEqual(root['highlightcolor'], 'yellow') |
---|
38 | n/a | root.tk_setPalette(background='yellow', highlightColor='blue') |
---|
39 | n/a | self.assertEqual(root['background'], 'yellow') |
---|
40 | n/a | self.assertEqual(root['highlightcolor'], 'blue') |
---|
41 | n/a | self.assertRaisesRegex(tkinter.TclError, |
---|
42 | n/a | '^unknown color name "spam"$', |
---|
43 | n/a | root.tk_setPalette, background='spam') |
---|
44 | n/a | self.assertRaisesRegex(tkinter.TclError, |
---|
45 | n/a | '^must specify a background color$', |
---|
46 | n/a | root.tk_setPalette, spam='white') |
---|
47 | n/a | self.assertRaisesRegex(tkinter.TclError, |
---|
48 | n/a | '^must specify a background color$', |
---|
49 | n/a | root.tk_setPalette, highlightColor='blue') |
---|
50 | n/a | |
---|
51 | n/a | |
---|
52 | n/a | tests_gui = (MiscTest, ) |
---|
53 | n/a | |
---|
54 | n/a | if __name__ == "__main__": |
---|
55 | n/a | support.run_unittest(*tests_gui) |
---|