diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2014-08-24 09:07:47 +0300 |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2014-08-24 09:07:47 +0300 |
commit | d00aff2f62481c3e8cf3b8e9cbbaf888361ffdd4 (patch) | |
tree | b76421157985cf86b00a39f3b652765667d96adb /Lib/tkinter/test/support.py | |
parent | ee558260727d160d43b14fc01851f73ef94ea587 (diff) | |
download | cpython-git-d00aff2f62481c3e8cf3b8e9cbbaf888361ffdd4.tar.gz |
Issue #22236: Tkinter tests now don't reuse default root window. New root
window is created for every test class.
Fixed Tkinter images copying operations in NoDefaultRoot mode.
Tcl command names generated for "after" callbacks now contains a name of
original function.
Diffstat (limited to 'Lib/tkinter/test/support.py')
-rw-r--r-- | Lib/tkinter/test/support.py | 51 |
1 files changed, 32 insertions, 19 deletions
diff --git a/Lib/tkinter/test/support.py b/Lib/tkinter/test/support.py index 7ae0cbb3da..017681f038 100644 --- a/Lib/tkinter/test/support.py +++ b/Lib/tkinter/test/support.py @@ -3,30 +3,43 @@ import tkinter import unittest from test.support import requires -def get_tk_root(): - requires('gui') # raise exception if tk unavailable - try: - root = tkinter._default_root - except AttributeError: - # it is possible to disable default root in Tkinter, although - # I haven't seen people doing it (but apparently someone did it - # here). - root = None +class AbstractTkTest: - if root is None: - # create a new master only if there isn't one already - root = tkinter.Tk() + @classmethod + def setUpClass(cls): + cls._old_support_default_root = tkinter._support_default_root + destroy_default_root() + tkinter.NoDefaultRoot() + cls.root = tkinter.Tk() + cls.wantobjects = cls.root.wantobjects() + # De-maximize main window. + # Some window managers can maximize new windows. + cls.root.wm_state('normal') + try: + cls.root.wm_attributes('-zoomed', False) + except tkinter.TclError: + pass - return root + @classmethod + def tearDownClass(cls): + cls.root.destroy() + cls.root = None + tkinter._default_root = None + tkinter._support_default_root = cls._old_support_default_root -def root_deiconify(): - root = get_tk_root() - root.deiconify() + def setUp(self): + self.root.deiconify() -def root_withdraw(): - root = get_tk_root() - root.withdraw() + def tearDown(self): + for w in self.root.winfo_children(): + w.destroy() + self.root.withdraw() +def destroy_default_root(): + if getattr(tkinter, '_default_root', None): + tkinter._default_root.update_idletasks() + tkinter._default_root.destroy() + tkinter._default_root = None def simulate_mouse_click(widget, x, y): """Generate proper events to click at the x, y position (tries to act |