From d00aff2f62481c3e8cf3b8e9cbbaf888361ffdd4 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sun, 24 Aug 2014 09:07:47 +0300 Subject: 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. --- Lib/tkinter/test/support.py | 51 ++++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 19 deletions(-) (limited to 'Lib/tkinter/test/support.py') 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 -- cgit v1.2.1