]> granicus.if.org Git - python/commitdiff
Issue 20567: Revise idle_test/README.txt and some tests to match new advice.
authorTerry Jan Reedy <tjreedy@udel.edu>
Fri, 3 Jun 2016 17:33:09 +0000 (13:33 -0400)
committerTerry Jan Reedy <tjreedy@udel.edu>
Fri, 3 Jun 2016 17:33:09 +0000 (13:33 -0400)
Lib/idlelib/idle_test/README.txt
Lib/idlelib/idle_test/test_autocomplete.py
Lib/idlelib/idle_test/test_autoexpand.py
Lib/idlelib/idle_test/test_configdialog.py
Lib/idlelib/idle_test/test_formatparagraph.py
Lib/idlelib/idle_test/test_textview.py
Lib/idlelib/idle_test/test_widgetredir.py

index 621b3e3c457ecba34e4120f578606093dfa05bb3..53c37b89d966c3d412cf191318f1a0392ea0dee6 100644 (file)
@@ -51,17 +51,20 @@ tests must be 'guarded' by "requires('gui')" in a setUp function or method.
 This will typically be setUpClass.
 
 To avoid interfering with other gui tests, all gui objects must be destroyed and
-deleted by the end of the test.  Widgets, such as a Tk root, created in a setUpX
-function, should be destroyed in the corresponding tearDownX.  Module and class
-widget attributes should also be deleted..
+deleted by the end of the test.  The Tk root created in a setUpX function should
+be destroyed in the corresponding tearDownX and the module or class attribute
+deleted.  Others widgets should descend from the single root and the attributes
+deleted BEFORE root is destroyed.  See https://bugs.python.org/issue20567.
 
     @classmethod
     def setUpClass(cls):
         requires('gui')
         cls.root = tk.Tk()
+        cls.text = tk.Text(root)
 
     @classmethod
     def tearDownClass(cls):
+        del cls.text
         cls.root.destroy()
         del cls.root
 
@@ -69,13 +72,15 @@ WARNING: In 2.7, "requires('gui') MUST NOT be called at module scope.
 See https://bugs.python.org/issue18910
 
 Requires('gui') causes the test(s) it guards to be skipped if any of
-a few conditions are met:
+these conditions are met:
     
  - The tests are being run by regrtest.py, and it was started without enabling
    the "gui" resource with the "-u" command line option.
    
  - The tests are being run on Windows by a service that is not allowed to
    interact with the graphical environment.
+
+ - The tests are being run on Linux and X window is not available.
    
  - The tests are being run on Mac OSX in a process that cannot make a window
    manager connection.
index c2a72666be59f5c8a2aaa4fe32b7f6993f08c94a..1e98590b9e4dfd98b037d7a55d9d9963035610de 100644 (file)
@@ -33,9 +33,8 @@ class AutoCompleteTest(unittest.TestCase):
 
     @classmethod
     def tearDownClass(cls):
+        del cls.editor, cls.text
         cls.root.destroy()
-        del cls.text
-        del cls.editor
         del cls.root
 
     def setUp(self):
index bdb7e8bf4ca11d46185405658e840818440f00c0..6be4fbf861b3d1130e335adfb136e51f5c36248c 100644 (file)
@@ -25,10 +25,10 @@ class AutoExpandTest(unittest.TestCase):
 
     @classmethod
     def tearDownClass(cls):
+        del cls.text, cls.auto_expand
         if hasattr(cls, 'tk'):
             cls.tk.destroy()
             del cls.tk
-        del cls.text, cls.auto_expand
 
     def tearDown(self):
         self.text.delete('1.0', 'end')
index 6302164f59e7d1ab61cf27f6e2d4486ff1da4634..62727c0875a98dc5678404f993f621a443c9e597 100644 (file)
@@ -24,9 +24,8 @@ class ConfigDialogTest(unittest.TestCase):
         del cls.root
 
     def test_dialog(self):
-        d=ConfigDialog(self.root, 'Test', _utest=True)
+        d = ConfigDialog(self.root, 'Test', _utest=True)
         d.remove_var_callbacks()
-        d.destroy()
 
 
 if __name__ == '__main__':
index 9185a968a65c5f8769f4e4952bce80e38fb8ea1d..938110dc8ab614a874c062b6575fd8a23198eda4 100644 (file)
@@ -276,10 +276,9 @@ class FormatEventTest(unittest.TestCase):
 
     @classmethod
     def tearDownClass(cls):
+        del cls.text, cls.formatter
         cls.root.destroy()
         del cls.root
-        del cls.text
-        del cls.formatter
 
     def test_short_line(self):
         self.text.insert('1.0', "Short line\n")
index 0e81b63eeeb952d4875ed2bdcf1ec3759831b3c8..4af7b49a8056e10ce6538e32d81b8a1fa1c490d0 100644 (file)
@@ -23,10 +23,9 @@ class textviewClassTest(unittest.TestCase):
 
     @classmethod
     def tearDownClass(cls):
+        del cls.TV
         cls.root.destroy()
-        TV = cls.TV
-        del cls.root, cls.TV
-        del TV.transient, TV.grab_set, TV.wait_window
+        del cls.root
 
     def setUp(self):
         TV = self.TV
index 5a231fdbd984735ca815f723ae37931b9422b0bd..7129bb722f9a2976b3e5c5455dc27483c19cad30 100644 (file)
@@ -14,14 +14,14 @@ class InitCloseTest(unittest.TestCase):
     @classmethod
     def setUpClass(cls):
         requires('gui')
-        cls.tk = Tk()
-        cls.text = Text(cls.tk)
+        cls.root = Tk()
+        cls.text = Text(cls.root)
 
     @classmethod
     def tearDownClass(cls):
-        cls.text.destroy()
-        cls.tk.destroy()
-        del cls.text, cls.tk
+        del cls.text
+        cls.root.destroy()
+        del cls.root
 
     def test_init(self):
         redir = WidgetRedirector(self.text)
@@ -43,14 +43,14 @@ class WidgetRedirectorTest(unittest.TestCase):
     @classmethod
     def setUpClass(cls):
         requires('gui')
-        cls.tk = Tk()
-        cls.text = Text(cls.tk)
+        cls.root = Tk()
+        cls.text = Text(cls.root)
 
     @classmethod
     def tearDownClass(cls):
-        cls.text.destroy()
-        cls.tk.destroy()
-        del cls.text, cls.tk
+        del cls.text
+        cls.root.destroy()
+        del cls.root
 
     def setUp(self):
         self.redir = WidgetRedirector(self.text)
@@ -108,13 +108,13 @@ class WidgetRedirectorTest(unittest.TestCase):
     def test_command_dispatch(self):
         # Test that .__init__ causes redirection of tk calls
         # through redir.dispatch
-        self.tk.call(self.text._w, 'insert', 'hello')
+        self.root.call(self.text._w, 'insert', 'hello')
         self.assertEqual(self.func.args, ('hello',))
         self.assertEqual(self.text.get('1.0', 'end'), '\n')
         # Ensure that called through redir .dispatch and not through
         # self.text.insert by having mock raise TclError.
         self.func.__init__(TclError())
-        self.assertEqual(self.tk.call(self.text._w, 'insert', 'boo'), '')
+        self.assertEqual(self.root.call(self.text._w, 'insert', 'boo'), '')