Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Lib/idlelib/idle_test/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ insert the import and main lines before the htest lines.

if __name__ == "__main__":
from unittest import main
main('idlelib.idle_test.test_abc', verbosity=2, exit=False)
main('idlelib.idle_test.test_abc', verbosity=2)

The ', exit=False' is only needed if an htest follows.
Add ', exit=False' to the main call if and only if an htest follows.



Expand Down
66 changes: 34 additions & 32 deletions Lib/idlelib/idle_test/htest.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,51 @@
"""Run human tests of Idle's window, dialog, and popup widgets.

run(*tests) Create a master Tk() htest window. Within that, run each
callable in tests after finding the matching test spec in this file. If
tests is empty, run an htest for each spec dict in this file after
finding the matching callable in the module named in the spec. Close
the master window to end testing.

In a tested module, let X be a global name bound to a callable (class or
function) whose .__name__ attribute is also X (the usual situation). The
first parameter of X must be 'parent' or 'master'. When called, the
first argument will be the root window. X must create a child
Toplevel(parent/master) (or subclass thereof). The Toplevel may be a
test widget or dialog, in which case the callable is the corresponding
class. Or the Toplevel may contain the widget to be tested or set up a
context in which a test widget is invoked. In this latter case, the
callable is a wrapper function that sets up the Toplevel and other
objects. Wrapper function names, such as _editor_window', should start
with '_' and be lowercase.

The main function, `run(*tests)`, is defined at the end of this file.
Argument `tests` is a possibly empty tuple of callables defined in some
idlelib.abc module (or possibly modules). Its steps:
1. Create a master Tk() htest window. Within that window ...
2a. If tuple `tests` is not empty, run was likely called from one
module. Run each callable in `tests` after finding the matching
callable_spec test spec in this file.
2b. If tests is empty, run was likely called from this file.
Run an htest for each spec dict in this file after finding the
matching callable in the module named in the spec.
3. Close the master window to end testing.

In a tested module, let X be a global name bound to a callable (class
or function) whose .__name__ attribute (its `class` or `def` definition
name) is also X. X must expect exactly 1 positional argument, a
parent toplevel window. Run passes the htest window. X must create a
child Toplevel(parent/master). The callable may be either a runtime
object or a wrapper function written just for the test. In the latter
case, its name should start with '_' and be lowercase (such as '_ttt').

End the module with

```
if __name__ == '__main__':
<run unittest.main with 'exit=False'>
from unittest import main
main("idlelib.idle_test.test_xyz", verbosity=2, exit=False)

from idlelib.idle_test.htest import run
run(callable) # There could be multiple comma-separated callables.
run(callable)
```
Replace 'xyz' as appropriate and 'callable' with the callable name or
comma-separated names (multiple names is rare). 'exit=False' is needed
for the htest to run.

To have wrapper functions ignored by coverage reports, tag the def
header like so: "def _wrapper(parent): # htest #". Use the same tag
for htest lines in widget code. Make sure that the 'if __name__' line
matches the above. Then have make sure that .coveragerc includes the
following:

header like so: "def _wrapper(root): # htest #". Use the same tag
for htest-only lines in the main code. To ignore the 'if __name__'
statement, match the example above. Add the below to coveragerc.
```
[report]
exclude_lines =
.*# htest #
if __name__ == .__main__.:

(The "." instead of "'" is intentional and necessary.)

```

To run any X, this file must contain a matching instance of the
following template, with X.__name__ prepended to '_spec'.
When all tests are run, the prefix is use to get X.

callable_spec = {
'file': '',
Expand All @@ -51,11 +54,10 @@
}

file (no .py): run() imports file.py.
kwds: augmented with {'parent':root} and passed to X as **kwds.
kwds: run() augments with {'parent':root} and passes to X as **kwds.
title: an example kwd; some widgets need this, delete line if not.
msg: master window hints about testing the widget.


TODO test these modules and classes:
autocomplete_w.AutoCompleteWindow
debugger.Debugger
Expand Down
2 changes: 1 addition & 1 deletion Lib/idlelib/idle_test/test_delegator.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ def test_mydel(self):


if __name__ == '__main__':
unittest.main(verbosity=2, exit=2)
unittest.main(verbosity=2)
2 changes: 1 addition & 1 deletion Lib/idlelib/idle_test/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,4 +665,4 @@ def test_rstrip_end(self):


if __name__ == '__main__':
unittest.main(verbosity=2, exit=2)
unittest.main(verbosity=2)
2 changes: 1 addition & 1 deletion Lib/idlelib/idle_test/test_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,4 @@ def test_history_prev_next(self):


if __name__ == '__main__':
unittest.main(verbosity=2, exit=2)
unittest.main(verbosity=2)
2 changes: 1 addition & 1 deletion Lib/idlelib/idle_test/test_pathbrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,4 @@ def test_PathBrowserTreeItem(self):


if __name__ == '__main__':
unittest.main(verbosity=2, exit=False)
unittest.main(verbosity=2)
2 changes: 1 addition & 1 deletion Lib/idlelib/idle_test/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,4 +448,4 @@ def test_click_args(self):


if __name__ == '__main__':
unittest.main(verbosity=2, exit=False)
unittest.main(verbosity=2)
2 changes: 1 addition & 1 deletion Lib/idlelib/idle_test/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ def test_find_selection(self):
text.delete('2.0', 'end')

if __name__ == '__main__':
unittest.main(verbosity=2, exit=2)
unittest.main(verbosity=2)
2 changes: 1 addition & 1 deletion Lib/idlelib/idle_test/test_searchbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,4 @@ def test_create_command_buttons(self):


if __name__ == '__main__':
unittest.main(verbosity=2, exit=2)
unittest.main(verbosity=2)
2 changes: 1 addition & 1 deletion Lib/idlelib/idle_test/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,4 @@ def setUp(self):


if __name__ == '__main__':
unittest.main(verbosity=2, exit=False)
unittest.main(verbosity=2)
2 changes: 1 addition & 1 deletion Lib/idlelib/idle_test/test_undo.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,4 @@ def test_addcmd(self):


if __name__ == '__main__':
unittest.main(verbosity=2, exit=False)
unittest.main(verbosity=2)
Loading