-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_tooltips.py
More file actions
50 lines (42 loc) · 1.93 KB
/
test_tooltips.py
File metadata and controls
50 lines (42 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""
Author: RedFantom
License: GNU GPLv3
Source: The ttkwidgets repository
"""
from unittest import TestCase
import tkinter as tk
from tkinter import ttk
from ttkstyles.hooks import is_hooked
# TODO: Adjust tests for different module
from ttkstyles import tooltips
class TestTooltipsModule(TestCase):
def test_hook_exists(self):
self.assertTrue(is_hooked(tooltips.OPTIONS))
def test_hook_works(self):
tooltip = "This is a great tooltip."
widget = ttk.Button(text="Hello World", tooltip=tooltip)
# Check the holder existence
holder = getattr(widget, tooltips.NAME.lower(), None)
self.assertIsNotNone(holder)
self.assertTrue(hasattr(holder, "tooltip_widget"))
# Check that the tooltip widget exists and is created with the given value
tooltip_widget = getattr(holder, "tooltip_widget", None)
self.assertIsNotNone(tooltip_widget)
self.assertEqual(tooltip_widget["text"], tooltip)
# Check that the text is updated when configuring the widget only
tooltip = "This is another great tooltip."
widget["tooltip"] = tooltip
self.assertEqual(tooltip_widget["text"], tooltip)
self.assertEqual(widget["tooltip"], tooltip)
# Check that the tooltip is destroyed when configured with None
widget["tooltip"] = None
tooltip_widget = getattr(holder, "tooltip_widget")
self.assertIsNone(tooltip_widget)
# Check that the tooltip is updated when its options are changed
widget.configure(tooltip_options={"headertext": "header"}, tooltip=tooltip)
tooltip_widget = getattr(holder, "tooltip_widget", None)
self.assertIsNotNone(tooltip_widget)
self.assertEqual(tooltip_widget["headertext"], "header")
self.assertEqual(tooltip_widget["text"], tooltip)
self.assertEqual(widget["tooltip"], tooltip)
self.assertEqual(widget["tooltip_options"], {"headertext": "header"})