From 8fdc939ae3244f65f4d776daf8732f1c44aeb97c Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Wed, 20 Jun 2018 16:16:45 -0400 Subject: [PATCH 1/5] Fix template. --- Lib/idlelib/idle_test/template.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/idlelib/idle_test/template.py b/Lib/idlelib/idle_test/template.py index 34ceac3f405e18..725a55b9c47230 100644 --- a/Lib/idlelib/idle_test/template.py +++ b/Lib/idlelib/idle_test/template.py @@ -1,6 +1,6 @@ "Test , coverage %." -from idlelib import +from idlelib import zzdummy import unittest from test.support import requires from tkinter import Tk @@ -23,7 +23,7 @@ def tearDownClass(cls): del cls.root def test_init(self): - self.assert + self.assertTrue(True) if __name__ == '__main__': From 5429b3a6a5a9e8611f0288ce65221d7c8f12191e Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Wed, 20 Jun 2018 16:19:10 -0400 Subject: [PATCH 2/5] Document template in README. --- Lib/idlelib/idle_test/README.txt | 60 +++++++++++++++++++------------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/Lib/idlelib/idle_test/README.txt b/Lib/idlelib/idle_test/README.txt index 5f3678fc7e1de3..6aa0b8bd8baa44 100644 --- a/Lib/idlelib/idle_test/README.txt +++ b/Lib/idlelib/idle_test/README.txt @@ -15,28 +15,27 @@ python -m idlelib.idle_test.htest 1. Test Files The idle directory, idlelib, has over 60 xyz.py files. The idle_test -subdirectory should contain a test_xyz.py for each, where 'xyz' is -lowercased even if xyz.py is not. Here is a possible template, with the -blanks after '.' and 'as', and before and after '_' to be filled in. +subdirectory contains a test_xyz.py for each implementation file. To +add a test for abc.py, open idle_test/template.py and immediately Save +As test_abc.py. Iinsert 'abc' on the first line, and replace 'zzdummy' +with 'abc. -import unittest -from test.support import requires -import idlelib. as - -class _Test(unittest.TestCase): +Remove the imports of requires and tkinter if not needed. Otherwise, +add to the tkinter imports as needed. - def test_(self): +Add a prefix to 'Test' for the initial test class. The template class +contains code needed or possibly needed for gui tests. See the next +section if doing gui tests. If not, and not needed for further classes, +this code can be removed. -if __name__ == '__main__': - unittest.main(verbosity=2) - -Add the following at the end of xyy.py, with the appropriate name added -after 'test_'. Some files already have something like this for htest. -If so, insert the import and unittest.main lines before the htest lines. +Add the following at the end of abc.py. If an htest was added first, +insert the import and main lines before the htest lines. if __name__ == "__main__": - import unittest - unittest.main('idlelib.idle_test.test_', verbosity=2, exit=False) + from unittest import main + main('idlelib.idle_test.test_abc', verbosity=2, exit=False) + +The ', exit=False' is only needed if an htest follows. @@ -55,12 +54,14 @@ from test.support import requires requires('gui') To guard a test class, put "requires('gui')" in its setUpClass function. +The template class does this. -To avoid interfering with other GUI tests, all GUI objects must be destroyed and -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. +To avoid interfering with other GUI tests, all GUI objects must be +destroyed and 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): @@ -75,12 +76,23 @@ deleted BEFORE root is destroyed. See https://bugs.python.org/issue20567. cls.root.destroy() del cls.root -The update_idletasks call is sometimes needed to prevent the following warning -either when running a test alone or as part of the test suite (#27196). +The update_idletasks call is sometimes needed to prevent the following +warning either when running a test alone or as part of the test suite +(#27196). It should not hurt if not needed. + can't invoke "event" command: application has been destroyed ... "ttk::ThemeChanged" +If a test creates instance 'e' of EditorWindow, call 'e._close()' before +or as the first part of teardown. The effect of omitting this depends +on the later shutdown. Then enable the after_cancel loop in the +template. This prevents messages like the following. + +bgerror failed to handle background error. + Original error: invalid command name "106096696timer_event" + Error in bgerror: can't invoke "tk" command: application has been destroyed + Requires('gui') causes the test(s) it guards to be skipped if any of these conditions are met: From 62f81745f4e68acc09a6cd7b7cfc7331454558cc Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Wed, 20 Jun 2018 16:28:37 -0400 Subject: [PATCH 3/5] add blurb --- Misc/NEWS.d/next/IDLE/2018-06-20-16-27-48.bpo-33917.ZXHs8x.rst | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 Misc/NEWS.d/next/IDLE/2018-06-20-16-27-48.bpo-33917.ZXHs8x.rst diff --git a/Misc/NEWS.d/next/IDLE/2018-06-20-16-27-48.bpo-33917.ZXHs8x.rst b/Misc/NEWS.d/next/IDLE/2018-06-20-16-27-48.bpo-33917.ZXHs8x.rst new file mode 100644 index 00000000000000..fe62d81461cb78 --- /dev/null +++ b/Misc/NEWS.d/next/IDLE/2018-06-20-16-27-48.bpo-33917.ZXHs8x.rst @@ -0,0 +1,3 @@ +Fix and document idlelib/idle_test/template.py. The revised file compiles, +runs, and tests OK. idle_test/README.txt explains how to use it to create +new IDLE test files. From 9d7ead32219c51817727fa8dd3b01c46d5e416bf Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Wed, 20 Jun 2018 16:44:58 -0400 Subject: [PATCH 4/5] Fix readme. --- Lib/idlelib/idle_test/README.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/idlelib/idle_test/README.txt b/Lib/idlelib/idle_test/README.txt index 6aa0b8bd8baa44..4390ea3f25a1da 100644 --- a/Lib/idlelib/idle_test/README.txt +++ b/Lib/idlelib/idle_test/README.txt @@ -15,9 +15,9 @@ python -m idlelib.idle_test.htest 1. Test Files The idle directory, idlelib, has over 60 xyz.py files. The idle_test -subdirectory contains a test_xyz.py for each implementation file. To +subdirectory contains test_xyz.py for each implementation file xyz. To add a test for abc.py, open idle_test/template.py and immediately Save -As test_abc.py. Iinsert 'abc' on the first line, and replace 'zzdummy' +As test_abc.py. Insert 'abc' on the first line, and replace 'zzdummy' with 'abc. Remove the imports of requires and tkinter if not needed. Otherwise, @@ -54,7 +54,7 @@ from test.support import requires requires('gui') To guard a test class, put "requires('gui')" in its setUpClass function. -The template class does this. +The template.py file does this. To avoid interfering with other GUI tests, all GUI objects must be destroyed and deleted by the end of the test. The Tk root created in a From 67cbdfcd66f3f0dcd04a33d26ee7aeefd8d3bf7a Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Wed, 20 Jun 2018 16:47:14 -0400 Subject: [PATCH 5/5] another readme fix. --- Lib/idlelib/idle_test/README.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Lib/idlelib/idle_test/README.txt b/Lib/idlelib/idle_test/README.txt index 4390ea3f25a1da..566bfd179fdf1b 100644 --- a/Lib/idlelib/idle_test/README.txt +++ b/Lib/idlelib/idle_test/README.txt @@ -15,10 +15,10 @@ python -m idlelib.idle_test.htest 1. Test Files The idle directory, idlelib, has over 60 xyz.py files. The idle_test -subdirectory contains test_xyz.py for each implementation file xyz. To -add a test for abc.py, open idle_test/template.py and immediately Save -As test_abc.py. Insert 'abc' on the first line, and replace 'zzdummy' -with 'abc. +subdirectory contains test_xyz.py for each implementation file xyz.py. +To add a test for abc.py, open idle_test/template.py and immediately +Save As test_abc.py. Insert 'abc' on the first line, and replace +'zzdummy' with 'abc. Remove the imports of requires and tkinter if not needed. Otherwise, add to the tkinter imports as needed.