@@ -2,22 +2,23 @@ README FOR IDLE TESTS IN IDLELIB.IDLE_TEST
22
330. Quick Start
44
5- Automated unit tests were added in 2.7 for Python 2.x and 3.3 for Python 3.x.
5+ Automated unit tests were added in 3.3 for Python 3.x.
66To run the tests from a command line:
77
88python -m test.test_idle
99
10- Human-mediated tests were added later in 2.7 and in 3.4.
10+ Human-mediated tests were added later in 3.4.
1111
1212python -m idlelib.idle_test.htest
1313
1414
15151. Test Files
1616
1717The 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 lowercased
19- even if xyz.py is not. Here is a possible template, with the blanks after after
20- '.' and 'as', and before and after '_' to be filled in.
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 after '.' and 'as', and before and after '_' to be filled
21+ in.
2122
2223import unittest
2324from test.support import requires
@@ -30,9 +31,9 @@ class _Test(unittest.TestCase):
3031if __name__ == '__main__':
3132 unittest.main(verbosity=2)
3233
33- Add the following at the end of xyy.py, with the appropriate name added after
34- 'test_'. Some files already have something like this for htest. If so, insert
35- the import and unittest.main lines before the htest lines.
34+ Add the following at the end of xyy.py, with the appropriate name added
35+ after 'test_'. Some files already have something like this for htest.
36+ If so, insert the import and unittest.main lines before the htest lines.
3637
3738if __name__ == "__main__":
3839 import unittest
@@ -42,18 +43,25 @@ if __name__ == "__main__":
4243
43442. GUI Tests
4445
45- When run as part of the Python test suite, Idle gui tests need to run
46- test.support.requires('gui') (test.test_support in 2.7). A test is a gui test
47- if it creates a Tk root or master object either directly or indirectly by
48- instantiating a tkinter or idle class. For the benefit of test processes that
49- either have no graphical environment available or are not allowed to use it, gui
50- tests must be 'guarded' by "requires('gui')" in a setUp function or method.
51- This will typically be setUpClass.
46+ When run as part of the Python test suite, Idle GUI tests need to run
47+ test.support.requires('gui'). A test is a GUI test if it creates a
48+ tkinter.Tk root or master object either directly or indirectly by
49+ instantiating a tkinter or idle class. GUI tests cannot run in test
50+ processes that either have no graphical environment available or are not
51+ allowed to use it.
5252
53- To avoid interfering with other gui tests, all gui objects must be destroyed and
54- deleted by the end of the test. Widgets, such as a Tk root, created in a setUpX
55- function, should be destroyed in the corresponding tearDownX. Module and class
56- widget attributes should also be deleted..
53+ To guard a module consisting entirely of GUI tests, start with
54+
55+ from test.support import requires
56+ requires('gui')
57+
58+ To guard a test class, put "requires('gui')" in its setUpClass function.
59+
60+ To avoid interfering with other GUI tests, all GUI objects must be
61+ destroyed and deleted by the end of the test. Widgets, such as a Tk
62+ root, created in a setUpX function, should be destroyed in the
63+ corresponding tearDownX. Module and class widget attributes should also
64+ be deleted.
5765
5866 @classmethod
5967 def setUpClass(cls):
@@ -69,37 +77,38 @@ widget attributes should also be deleted..
6977Requires('gui') causes the test(s) it guards to be skipped if any of
7078a few conditions are met:
7179
72- - The tests are being run by regrtest.py, and it was started without enabling
73- the "gui" resource with the "-u" command line option.
80+ - The tests are being run by regrtest.py, and it was started without
81+ enabling the "gui" resource with the "-u" command line option.
7482
75- - The tests are being run on Windows by a service that is not allowed to
76- interact with the graphical environment.
83+ - The tests are being run on Windows by a service that is not allowed
84+ to interact with the graphical environment.
7785
78- - The tests are being run on Mac OSX in a process that cannot make a window
79- manager connection.
86+ - The tests are being run on Mac OSX in a process that cannot make a
87+ window manager connection.
8088
8189 - tkinter.Tk cannot be successfully instantiated for some reason.
8290
8391 - test.support.use_resources has been set by something other than
8492 regrtest.py and does not contain "gui".
8593
86- Tests of non-gui operations should avoid creating tk widgets. Incidental uses of
87- tk variables and messageboxes can be replaced by the mock classes in
88- idle_test/mock_tk.py. The mock text handles some uses of the tk Text widget.
94+ Tests of non-GUI operations should avoid creating tk widgets. Incidental
95+ uses of tk variables and messageboxes can be replaced by the mock
96+ classes in idle_test/mock_tk.py. The mock text handles some uses of the
97+ tk Text widget.
8998
9099
911003. Running Unit Tests
92101
93102Assume that xyz.py and test_xyz.py both end with a unittest.main() call.
94- Running either from an Idle editor runs all tests in the test_xyz file with the
95- version of Python running Idle. Test output appears in the Shell window. The
96- 'verbosity=2' option lists all test methods in the file, which is appropriate
97- when developing tests. The 'exit=False' option is needed in xyx.py files when an
98- htest follows.
103+ Running either from an Idle editor runs all tests in the test_xyz file
104+ with the version of Python running Idle. Test output appears in the
105+ Shell window. The 'verbosity=2' option lists all test methods in the
106+ file, which is appropriate when developing tests. The 'exit=False'
107+ option is needed in xyx.py files when an htest follows.
99108
100109The following command lines also run all test methods, including
101- gui tests, in test_xyz.py. (Both '-m idlelib' and '-m idlelib.idle' start
102- Idle and so cannot run tests.)
110+ gui tests, in test_xyz.py. (Both '-m idlelib' and '-m idlelib.idle'
111+ start Idle and so cannot run tests.)
103112
104113python -m idlelib.xyz
105114python -m idlelib.idle_test.test_xyz
@@ -109,35 +118,35 @@ The following runs all idle_test/test_*.py tests interactively.
109118>>> import unittest
110119>>> unittest.main('idlelib.idle_test', verbosity=2)
111120
112- The following run all Idle tests at a command line. Option '-v' is the same as
113- 'verbosity=2'. (For 2.7, replace 'test' in the second line with
114- 'test.regrtest'.)
121+ The following run all Idle tests at a command line. Option '-v' is the
122+ same as 'verbosity=2'.
115123
116124python -m unittest -v idlelib.idle_test
117125python -m test -v -ugui test_idle
118126python -m test.test_idle
119127
120- The idle tests are 'discovered' by idlelib.idle_test.__init__.load_tests,
121- which is also imported into test.test_idle. Normally, neither file should be
122- changed when working on individual test modules. The third command runs
123- unittest indirectly through regrtest. The same happens when the entire test
124- suite is run with 'python -m test'. So that command must work for buildbots
125- to stay green. Idle tests must not disturb the environment in a way that
126- makes other tests fail (issue 18081).
128+ The idle tests are 'discovered' by
129+ idlelib.idle_test.__init__.load_tests, which is also imported into
130+ test.test_idle. Normally, neither file should be changed when working on
131+ individual test modules. The third command runs unittest indirectly
132+ through regrtest. The same happens when the entire test suite is run
133+ with 'python -m test'. So that command must work for buildbots to stay
134+ green. Idle tests must not disturb the environment in a way that makes
135+ other tests fail (issue 18081).
127136
128- To run an individual Testcase or test method, extend the dotted name given to
129- unittest on the command line.
137+ To run an individual Testcase or test method, extend the dotted name
138+ given to unittest on the command line.
130139
131140python -m unittest -v idlelib.idle_test.test_xyz.Test_case.test_meth
132141
133142
1341434. Human-mediated Tests
135144
136- Human-mediated tests are widget tests that cannot be automated but need human
137- verification. They are contained in idlelib/idle_test/htest.py, which has
138- instructions. (Some modules need an auxiliary function, identified with # htest
139- # on the header line.) The set is about complete, though some tests need
140- improvement. To run all htests, run the htest file from an editor or from the
141- command line with:
145+ Human-mediated tests are widget tests that cannot be automated but need
146+ human verification. They are contained in idlelib/idle_test/htest.py,
147+ which has instructions. (Some modules need an auxiliary function,
148+ identified with "# htest # on the header line.) The set is about
149+ complete, though some tests need improvement. To run all htests, run the
150+ htest file from an editor or from the command line with:
142151
143152python -m idlelib.idle_test.htest
0 commit comments