|
| 1 | +import unittest |
| 2 | +import tkinter |
| 3 | +from tkinter import ttk |
| 4 | +from test import support |
| 5 | + |
| 6 | +support.requires('gui') |
| 7 | + |
| 8 | +class MiscTest(unittest.TestCase): |
| 9 | + |
| 10 | + def setUp(self): |
| 11 | + self.root = ttk.setup_master() |
| 12 | + |
| 13 | + def test_tk_setPalette(self): |
| 14 | + root = self.root |
| 15 | + root.tk_setPalette('black') |
| 16 | + self.assertEqual(root['background'], 'black') |
| 17 | + root.tk_setPalette('white') |
| 18 | + self.assertEqual(root['background'], 'white') |
| 19 | + self.assertRaisesRegex(tkinter.TclError, |
| 20 | + '^unknown color name "spam"$', |
| 21 | + root.tk_setPalette, 'spam') |
| 22 | + |
| 23 | + root.tk_setPalette(background='black') |
| 24 | + self.assertEqual(root['background'], 'black') |
| 25 | + root.tk_setPalette(background='blue', highlightColor='yellow') |
| 26 | + self.assertEqual(root['background'], 'blue') |
| 27 | + self.assertEqual(root['highlightcolor'], 'yellow') |
| 28 | + root.tk_setPalette(background='yellow', highlightColor='blue') |
| 29 | + self.assertEqual(root['background'], 'yellow') |
| 30 | + self.assertEqual(root['highlightcolor'], 'blue') |
| 31 | + self.assertRaisesRegex(tkinter.TclError, |
| 32 | + '^unknown color name "spam"$', |
| 33 | + root.tk_setPalette, background='spam') |
| 34 | + self.assertRaisesRegex(tkinter.TclError, |
| 35 | + '^must specify a background color$', |
| 36 | + root.tk_setPalette, spam='white') |
| 37 | + self.assertRaisesRegex(tkinter.TclError, |
| 38 | + '^must specify a background color$', |
| 39 | + root.tk_setPalette, highlightColor='blue') |
| 40 | + |
| 41 | + |
| 42 | +tests_gui = (MiscTest, ) |
| 43 | + |
| 44 | +if __name__ == "__main__": |
| 45 | + support.run_unittest(*tests_gui) |
0 commit comments