bpo-33917: Fix and document idlelib/idle_test/template.py (GH-7830) · python/cpython@a717c56

@@ -15,28 +15,27 @@ python -m idlelib.idle_test.htest

1515

1. Test Files

16161717

The idle directory, idlelib, has over 60 xyz.py files. The idle_test

18-

subdirectory should contain a test_xyz.py for each, where 'xyz' is

19-

lowercased even if xyz.py is not. Here is a possible template, with the

20-

blanks after '.' and 'as', and before and after '_' to be filled in.

18+

subdirectory contains test_xyz.py for each implementation file xyz.py.

19+

To add a test for abc.py, open idle_test/template.py and immediately

20+

Save As test_abc.py. Insert 'abc' on the first line, and replace

21+

'zzdummy' with 'abc.

212222-

import unittest

23-

from test.support import requires

24-

import idlelib. as

25-26-

class _Test(unittest.TestCase):

23+

Remove the imports of requires and tkinter if not needed. Otherwise,

24+

add to the tkinter imports as needed.

272528-

def test_(self):

26+

Add a prefix to 'Test' for the initial test class. The template class

27+

contains code needed or possibly needed for gui tests. See the next

28+

section if doing gui tests. If not, and not needed for further classes,

29+

this code can be removed.

293030-

if __name__ == '__main__':

31-

unittest.main(verbosity=2)

32-33-

Add the following at the end of xyy.py, with the appropriate name added

34-

after 'test_'. Some files already have something like this for htest.

35-

If so, insert the import and unittest.main lines before the htest lines.

31+

Add the following at the end of abc.py. If an htest was added first,

32+

insert the import and main lines before the htest lines.

36333734

if __name__ == "__main__":

38-

import unittest

39-

unittest.main('idlelib.idle_test.test_', verbosity=2, exit=False)

35+

from unittest import main

36+

main('idlelib.idle_test.test_abc', verbosity=2, exit=False)

37+38+

The ', exit=False' is only needed if an htest follows.

403941404241

@@ -55,12 +54,14 @@ from test.support import requires

5554

requires('gui')

56555756

To guard a test class, put "requires('gui')" in its setUpClass function.

57+

The template.py file does this.

585859-

To avoid interfering with other GUI tests, all GUI objects must be destroyed and

60-

deleted by the end of the test. The Tk root created in a setUpX function should

61-

be destroyed in the corresponding tearDownX and the module or class attribute

62-

deleted. Others widgets should descend from the single root and the attributes

63-

deleted BEFORE root is destroyed. See https://bugs.python.org/issue20567.

59+

To avoid interfering with other GUI tests, all GUI objects must be

60+

destroyed and deleted by the end of the test. The Tk root created in a

61+

setUpX function should be destroyed in the corresponding tearDownX and

62+

the module or class attribute deleted. Others widgets should descend

63+

from the single root and the attributes deleted BEFORE root is

64+

destroyed. See https://bugs.python.org/issue20567.

64656566

@classmethod

6667

def setUpClass(cls):

@@ -75,12 +76,23 @@ deleted BEFORE root is destroyed. See https://bugs.python.org/issue20567.

7576

cls.root.destroy()

7677

del cls.root

777878-

The update_idletasks call is sometimes needed to prevent the following warning

79-

either when running a test alone or as part of the test suite (#27196).

79+

The update_idletasks call is sometimes needed to prevent the following

80+

warning either when running a test alone or as part of the test suite

81+

(#27196). It should not hurt if not needed.

82+8083

can't invoke "event" command: application has been destroyed

8184

...

8285

"ttk::ThemeChanged"

838687+

If a test creates instance 'e' of EditorWindow, call 'e._close()' before

88+

or as the first part of teardown. The effect of omitting this depends

89+

on the later shutdown. Then enable the after_cancel loop in the

90+

template. This prevents messages like the following.

91+92+

bgerror failed to handle background error.

93+

Original error: invalid command name "106096696timer_event"

94+

Error in bgerror: can't invoke "tk" command: application has been destroyed

95+8496

Requires('gui') causes the test(s) it guards to be skipped if any of

8597

these conditions are met:

8698