This commit is contained in:
ton
2024-10-07 10:13:40 +07:00
parent aa1631742f
commit 3a7d696db6
9729 changed files with 1832837 additions and 161742 deletions

View File

@@ -1,2 +1,4 @@
# An example file to test recognition of a .pyi file as Python source code.
class Example:
def method(self, argument1: str, argument2: list[int]) -> None: ...

View File

@@ -1,38 +1,36 @@
'''Run human tests of Idle's window, dialog, and popup widgets.
"""Run human tests of Idle's window, dialog, and popup widgets.
run(*tests)
Create a master Tk 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 window to skip or
end the test.
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'. When called, the parent
argument will be the root window. X must create a child Toplevel
window (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 '_'.
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.
End the module with
if __name__ == '__main__':
<unittest, if there is one>
<run unittest.main with 'exit=False'>
from idlelib.idle_test.htest import run
run(X)
run(callable) # There could be multiple comma-separated callables.
To have wrapper functions and test invocation code ignored by coveragepy
reports, put '# htest #' on the def statement header line.
def _wrapper(parent): # htest #
Also make sure that the 'if __name__' line matches the above. Then have
make sure that .coveragerc includes the following.
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:
[report]
exclude_lines =
@@ -46,7 +44,7 @@ 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.
_spec = {
callable_spec = {
'file': '',
'kwds': {'title': ''},
'msg': ""
@@ -54,16 +52,16 @@ _spec = {
file (no .py): run() imports file.py.
kwds: augmented with {'parent':root} and passed to X as **kwds.
title: an example kwd; some widgets need this, delete if not.
title: an example kwd; some widgets need this, delete line if not.
msg: master window hints about testing the widget.
Modules and classes not being tested at the moment:
pyshell.PyShellEditorWindow
debugger.Debugger
autocomplete_w.AutoCompleteWindow
outwin.OutputWindow (indirectly being tested with grep test)
'''
TODO test these modules and classes:
autocomplete_w.AutoCompleteWindow
debugger.Debugger
outwin.OutputWindow (indirectly being tested with grep test)
pyshell.PyShellEditorWindow
"""
import idlelib.pyshell # Set Windows DPI awareness before Tk().
from importlib import import_module
@@ -91,15 +89,6 @@ _calltip_window_spec = {
"Force-open-calltip does not work here.\n"
}
_module_browser_spec = {
'file': 'browser',
'kwds': {},
'msg': "Inspect names of module, class(with superclass if "
"applicable), methods and functions.\nToggle nested items.\n"
"Double clicking on items prints a traceback for an exception "
"that is ignored."
}
_color_delegator_spec = {
'file': 'colorizer',
'kwds': {},
@@ -109,16 +98,6 @@ _color_delegator_spec = {
"The default color scheme is in idlelib/config-highlight.def"
}
CustomRun_spec = {
'file': 'query',
'kwds': {'title': 'Customize query.py Run',
'_htest': True},
'msg': "Enter with <Return> or [Run]. Print valid entry to Shell\n"
"Arguments are parsed into a list\n"
"Mode is currently restart True or False\n"
"Close dialog with valid entry, <Escape>, [Cancel], [X]"
}
ConfigDialog_spec = {
'file': 'configdialog',
'kwds': {'title': 'ConfigDialogTest',
@@ -135,6 +114,24 @@ ConfigDialog_spec = {
"changes made have persisted."
}
CustomRun_spec = {
'file': 'query',
'kwds': {'title': 'Customize query.py Run',
'_htest': True},
'msg': "Enter with <Return> or [OK]. Print valid entry to Shell\n"
"Arguments are parsed into a list\n"
"Mode is currently restart True or False\n"
"Close dialog with valid entry, <Escape>, [Cancel], [X]"
}
_debug_object_browser_spec = {
'file': 'debugobj',
'kwds': {},
'msg': "Double click on items up to the lowest level.\n"
"Attributes of the objects and related information "
"will be displayed side-by-side at each level."
}
# TODO Improve message
_dyn_option_menu_spec = {
'file': 'dynoption',
@@ -152,7 +149,7 @@ _editor_window_spec = {
"Best to close editor first."
}
GetKeysDialog_spec = {
GetKeysWindow_spec = {
'file': 'config_key',
'kwds': {'title': 'Test keybindings',
'action': 'find-again',
@@ -173,8 +170,8 @@ _grep_dialog_spec = {
'msg': "Click the 'Show GrepDialog' button.\n"
"Test the various 'Find-in-files' functions.\n"
"The results should be displayed in a new '*Output*' window.\n"
"'Right-click'->'Go to file/line' anywhere in the search results "
"should open that file \nin a new EditorWindow."
"'Right-click'->'Go to file/line' in the search results\n "
"should open that file in a new EditorWindow."
}
HelpSource_spec = {
@@ -190,7 +187,7 @@ HelpSource_spec = {
"Any url ('www...', 'http...') is accepted.\n"
"Test Browse with and without path, as cannot unittest.\n"
"[Ok] or <Return> prints valid entry to shell\n"
"[Cancel] or <Escape> prints None to shell"
"<Escape>, [Cancel], or [X] prints None to shell"
}
_io_binding_spec = {
@@ -206,56 +203,36 @@ _io_binding_spec = {
"Check that changes were saved by opening the file elsewhere."
}
_linenumbers_drag_scrolling_spec = {
'file': 'sidebar',
'kwds': {},
'msg': textwrap.dedent("""\
1. Click on the line numbers and drag down below the edge of the
window, moving the mouse a bit and then leaving it there for a while.
The text and line numbers should gradually scroll down, with the
selection updated continuously.
2. With the lines still selected, click on a line number above the
selected lines. Only the line whose number was clicked should be
selected.
3. Repeat step #1, dragging to above the window. The text and line
numbers should gradually scroll up, with the selection updated
continuously.
4. Repeat step #2, clicking a line number below the selection."""),
}
_multi_call_spec = {
'file': 'multicall',
'kwds': {},
'msg': "The following actions should trigger a print to console or IDLE"
" Shell.\nEntering and leaving the text area, key entry, "
"<Control-Key>,\n<Alt-Key-a>, <Control-Key-a>, "
"<Alt-Control-Key-a>, \n<Control-Button-1>, <Alt-Button-1> and "
"focusing out of the window\nare sequences to be tested."
'msg': "The following should trigger a print to console or IDLE Shell.\n"
"Entering and leaving the text area, key entry, <Control-Key>,\n"
"<Alt-Key-a>, <Control-Key-a>, <Alt-Control-Key-a>, \n"
"<Control-Button-1>, <Alt-Button-1> and focusing elsewhere."
}
_module_browser_spec = {
'file': 'browser',
'kwds': {},
'msg': textwrap.dedent("""
"Inspect names of module, class(with superclass if applicable),
"methods and functions. Toggle nested items. Double clicking
"on items prints a traceback for an exception that is ignored.""")
}
_multistatus_bar_spec = {
'file': 'statusbar',
'kwds': {},
'msg': "Ensure presence of multi-status bar below text area.\n"
"Click 'Update Status' to change the multi-status text"
"Click 'Update Status' to change the status text"
}
_object_browser_spec = {
'file': 'debugobj',
'kwds': {},
'msg': "Double click on items up to the lowest level.\n"
"Attributes of the objects and related information "
"will be displayed side-by-side at each level."
}
_path_browser_spec = {
PathBrowser_spec = {
'file': 'pathbrowser',
'kwds': {},
'kwds': {'_htest': True},
'msg': "Test for correct display of all paths in sys.path.\n"
"Toggle nested items up to the lowest level.\n"
"Toggle nested items out to the lowest level.\n"
"Double clicking on an item prints a traceback\n"
"for an exception that is ignored."
}
@@ -291,6 +268,15 @@ _replace_dialog_spec = {
"Click [Close] or [X] to close the 'Replace Dialog'."
}
_scrolled_list_spec = {
'file': 'scrolledlist',
'kwds': {},
'msg': "You should see a scrollable list of items\n"
"Selecting (clicking) or double clicking an item "
"prints the name to the console or Idle shell.\n"
"Right clicking an item will display a popup."
}
_search_dialog_spec = {
'file': 'search',
'kwds': {},
@@ -306,15 +292,6 @@ _searchbase_spec = {
"Its only action is to close."
}
_scrolled_list_spec = {
'file': 'scrolledlist',
'kwds': {},
'msg': "You should see a scrollable list of items\n"
"Selecting (clicking) or double clicking an item "
"prints the name to the console or Idle shell.\n"
"Right clicking an item will display a popup."
}
show_idlehelp_spec = {
'file': 'help',
'kwds': {},
@@ -322,12 +299,31 @@ show_idlehelp_spec = {
"Text is selectable. Window is scrollable."
}
_stack_viewer_spec = {
_sidebar_number_scrolling_spec = {
'file': 'sidebar',
'kwds': {},
'msg': textwrap.dedent("""\
1. Click on the line numbers and drag down below the edge of the
window, moving the mouse a bit and then leaving it there for a
while. The text and line numbers should gradually scroll down,
with the selection updated continuously.
2. With the lines still selected, click on a line number above
or below the selected lines. Only the line whose number was
clicked should be selected.
3. Repeat step #1, dragging to above the window. The text and
line numbers should gradually scroll up, with the selection
updated continuously.
4. Repeat step #2, clicking a line number below the selection."""),
}
_stackbrowser_spec = {
'file': 'stackviewer',
'kwds': {},
'msg': "A stacktrace for a NameError exception.\n"
"Expand 'idlelib ...' and '<locals>'.\n"
"Check that exc_value, exc_tb, and exc_type are correct.\n"
"Should have NameError and 1 traceback line."
}
_tooltip_spec = {
@@ -370,11 +366,12 @@ _widget_redirector_spec = {
}
def run(*tests):
"Run callables in tests."
root = tk.Tk()
root.title('IDLE htest')
root.resizable(0, 0)
# a scrollable Label like constant width text widget.
# A scrollable Label-like constant width text widget.
frameLabel = tk.Frame(root, padx=10)
frameLabel.pack()
text = tk.Text(frameLabel, wrap='word')
@@ -384,45 +381,44 @@ def run(*tests):
scrollbar.pack(side='right', fill='y', expand=False)
text.pack(side='left', fill='both', expand=True)
test_list = [] # List of tuples of the form (spec, callable widget)
test_list = [] # Make list of (spec, callable) tuples.
if tests:
for test in tests:
test_spec = globals()[test.__name__ + '_spec']
test_spec['name'] = test.__name__
test_list.append((test_spec, test))
else:
for k, d in globals().items():
if k.endswith('_spec'):
test_name = k[:-5]
test_spec = d
for key, dic in globals().items():
if key.endswith('_spec'):
test_name = key[:-5]
test_spec = dic
test_spec['name'] = test_name
mod = import_module('idlelib.' + test_spec['file'])
test = getattr(mod, test_name)
test_list.append((test_spec, test))
test_list.reverse() # So can pop in proper order in next_test.
test_name = tk.StringVar(root)
callable_object = None
test_kwds = None
def next_test():
nonlocal test_name, callable_object, test_kwds
if len(test_list) == 1:
next_button.pack_forget()
test_spec, callable_object = test_list.pop()
test_kwds = test_spec['kwds']
test_kwds['parent'] = root
test_name.set('Test ' + test_spec['name'])
text.configure(state='normal') # enable text editing
text.delete('1.0','end')
text.insert("1.0",test_spec['msg'])
text.configure(state='disabled') # preserve read-only property
text['state'] = 'normal' # Enable text replacement.
text.delete('1.0', 'end')
text.insert("1.0", test_spec['msg'])
text['state'] = 'disabled' # Restore read-only property.
def run_test(_=None):
widget = callable_object(**test_kwds)
widget = callable_object(root, **test_kwds)
try:
print(widget.result)
print(widget.result) # Only true for query classes(?).
except AttributeError:
pass
@@ -441,5 +437,6 @@ def run(*tests):
next_test()
root.mainloop()
if __name__ == '__main__':
run()

View File

@@ -7,6 +7,7 @@ import textwrap
import types
import re
from idlelib.idle_test.mock_tk import Text
from test.support import MISSING_C_DOCSTRINGS
# Test Class TC is used in multiple get_argspec test methods
@@ -50,6 +51,8 @@ class Get_argspecTest(unittest.TestCase):
# but a red buildbot is better than a user crash (as has happened).
# For a simple mismatch, change the expected output to the actual.
@unittest.skipIf(MISSING_C_DOCSTRINGS,
"Signature information for builtins requires docstrings")
def test_builtins(self):
def tiptest(obj, out):
@@ -76,6 +79,7 @@ class Get_argspecTest(unittest.TestCase):
tiptest(list.append, '(self, object, /)' + append_doc)
tiptest(List.append, '(self, object, /)' + append_doc)
tiptest([].append, '(object, /)' + append_doc)
# The use of 'object' above matches the signature text.
tiptest(types.MethodType,
'(function, instance, /)\n'
@@ -143,6 +147,8 @@ you\'ll probably have to override _wrap_chunks().''')
f.__doc__ = 'a'*300
self.assertEqual(get_spec(f), f"()\n{'a'*(calltip._MAX_COLS-3) + '...'}")
@unittest.skipIf(MISSING_C_DOCSTRINGS,
"Signature information for builtins requires docstrings")
def test_multiline_docstring(self):
# Test fewer lines than max.
self.assertEqual(get_spec(range),
@@ -157,6 +163,7 @@ bytes(bytes_or_buffer) -> immutable copy of bytes_or_buffer
bytes(int) -> bytes object of size given by the parameter initialized with null bytes
bytes() -> empty bytes object''')
def test_multiline_docstring_2(self):
# Test more than max lines
def f(): pass
f.__doc__ = 'a\n' * 15

View File

@@ -85,8 +85,8 @@ class IdleConfParserTest(unittest.TestCase):
self.assertEqual(parser.sections(), [])
def test_load_file(self):
# Borrow test/cfgparser.1 from test_configparser.
config_path = findfile('cfgparser.1')
# Borrow test/configdata/cfgparser.1 from test_configparser.
config_path = findfile('cfgparser.1', subdir='configdata')
parser = config.IdleConfParser(config_path)
parser.Load()
@@ -274,8 +274,8 @@ class IdleConfTest(unittest.TestCase):
conf.CreateConfigHandlers()
# Check keys are equal
self.assertCountEqual(conf.defaultCfg.keys(), conf.config_types)
self.assertCountEqual(conf.userCfg.keys(), conf.config_types)
self.assertCountEqual(conf.defaultCfg, conf.config_types)
self.assertCountEqual(conf.userCfg, conf.config_types)
# Check conf parser are correct type
for default_parser in conf.defaultCfg.values():
@@ -294,8 +294,8 @@ class IdleConfTest(unittest.TestCase):
def test_load_cfg_files(self):
conf = self.new_config(_utest=True)
# Borrow test/cfgparser.1 from test_configparser.
config_path = findfile('cfgparser.1')
# Borrow test/configdata/cfgparser.1 from test_configparser.
config_path = findfile('cfgparser.1', subdir='configdata')
conf.defaultCfg['foo'] = config.IdleConfParser(config_path)
conf.userCfg['foo'] = config.IdleUserConfParser(config_path)

View File

@@ -420,20 +420,14 @@ class HighPageTest(unittest.TestCase):
# Set highlight_target through clicking highlight_sample.
eq = self.assertEqual
d = self.page
elem = {}
count = 0
hs = d.highlight_sample
hs.focus_force()
hs.see(1.0)
hs.update_idletasks()
def tag_to_element(elem):
for element, tag in d.theme_elements.items():
elem[tag[0]] = element
def click_it(start):
x, y, dx, dy = hs.bbox(start)
def click_char(index):
"Simulate click on character at *index*."
hs.see(index)
hs.update_idletasks()
x, y, dx, dy = hs.bbox(index)
x += dx // 2
y += dy // 2
hs.event_generate('<Enter>', x=0, y=0)
@@ -441,17 +435,20 @@ class HighPageTest(unittest.TestCase):
hs.event_generate('<ButtonPress-1>', x=x, y=y)
hs.event_generate('<ButtonRelease-1>', x=x, y=y)
# Flip theme_elements to make the tag the key.
tag_to_element(elem)
# Reverse theme_elements to make the tag the key.
elem = {tag: element for element, tag in d.theme_elements.items()}
# If highlight_sample has a tag that isn't in theme_elements, there
# will be a KeyError in the test run.
count = 0
for tag in hs.tag_names():
for start_index in hs.tag_ranges(tag)[0::2]:
count += 1
click_it(start_index)
try:
click_char(hs.tag_nextrange(tag, "1.0")[0])
eq(d.highlight_target.get(), elem[tag])
count += 1
eq(d.set_highlight_target.called, count)
except IndexError:
pass # Skip unused theme_elements tag, like 'sel'.
def test_highlight_sample_double_click(self):
# Test double click on highlight_sample.

View File

@@ -1,16 +1,286 @@
"Test debugger, coverage 19%"
"""Test debugger, coverage 66%
Try to make tests pass with draft bdbx, which may replace bdb in 3.13+.
"""
from idlelib import debugger
import unittest
from test.support import requires
requires('gui')
from collections import namedtuple
from textwrap import dedent
from tkinter import Tk
from test.support import requires
import unittest
from unittest import mock
from unittest.mock import Mock, patch
"""A test python script for the debug tests."""
TEST_CODE = dedent("""
i = 1
i += 2
if i == 3:
print(i)
""")
class MockFrame:
"Minimal mock frame."
def __init__(self, code, lineno):
self.f_code = code
self.f_lineno = lineno
class IdbTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.gui = Mock()
cls.idb = debugger.Idb(cls.gui)
# Create test and code objects to simulate a debug session.
code_obj = compile(TEST_CODE, 'idlelib/file.py', mode='exec')
frame1 = MockFrame(code_obj, 1)
frame1.f_back = None
frame2 = MockFrame(code_obj, 2)
frame2.f_back = frame1
cls.frame = frame2
cls.msg = 'file.py:2: <module>()'
def test_init(self):
self.assertIs(self.idb.gui, self.gui)
# Won't test super call since two Bdbs are very different.
def test_user_line(self):
# Test that .user_line() creates a string message for a frame.
self.gui.interaction = Mock()
self.idb.user_line(self.frame)
self.gui.interaction.assert_called_once_with(self.msg, self.frame)
def test_user_exception(self):
# Test that .user_exception() creates a string message for a frame.
exc_info = (type(ValueError), ValueError(), None)
self.gui.interaction = Mock()
self.idb.user_exception(self.frame, exc_info)
self.gui.interaction.assert_called_once_with(
self.msg, self.frame, exc_info)
class FunctionTest(unittest.TestCase):
# Test module functions together.
def test_functions(self):
rpc_obj = compile(TEST_CODE,'rpc.py', mode='exec')
rpc_frame = MockFrame(rpc_obj, 2)
rpc_frame.f_back = rpc_frame
self.assertTrue(debugger._in_rpc_code(rpc_frame))
self.assertEqual(debugger._frame2message(rpc_frame),
'rpc.py:2: <module>()')
code_obj = compile(TEST_CODE, 'idlelib/debugger.py', mode='exec')
code_frame = MockFrame(code_obj, 1)
code_frame.f_back = None
self.assertFalse(debugger._in_rpc_code(code_frame))
self.assertEqual(debugger._frame2message(code_frame),
'debugger.py:1: <module>()')
code_frame.f_back = code_frame
self.assertFalse(debugger._in_rpc_code(code_frame))
code_frame.f_back = rpc_frame
self.assertTrue(debugger._in_rpc_code(code_frame))
class DebuggerTest(unittest.TestCase):
"Tests for Debugger that do not need a real root."
@classmethod
def setUpClass(cls):
cls.pyshell = Mock()
cls.pyshell.root = Mock()
cls.idb = Mock()
with patch.object(debugger.Debugger, 'make_gui'):
cls.debugger = debugger.Debugger(cls.pyshell, cls.idb)
cls.debugger.root = Mock()
def test_cont(self):
self.debugger.cont()
self.idb.set_continue.assert_called_once()
def test_step(self):
self.debugger.step()
self.idb.set_step.assert_called_once()
def test_quit(self):
self.debugger.quit()
self.idb.set_quit.assert_called_once()
def test_next(self):
with patch.object(self.debugger, 'frame') as frame:
self.debugger.next()
self.idb.set_next.assert_called_once_with(frame)
def test_ret(self):
with patch.object(self.debugger, 'frame') as frame:
self.debugger.ret()
self.idb.set_return.assert_called_once_with(frame)
def test_clear_breakpoint(self):
self.debugger.clear_breakpoint('test.py', 4)
self.idb.clear_break.assert_called_once_with('test.py', 4)
def test_clear_file_breaks(self):
self.debugger.clear_file_breaks('test.py')
self.idb.clear_all_file_breaks.assert_called_once_with('test.py')
def test_set_load_breakpoints(self):
# Test the .load_breakpoints() method calls idb.
FileIO = namedtuple('FileIO', 'filename')
class MockEditWindow(object):
def __init__(self, fn, breakpoints):
self.io = FileIO(fn)
self.breakpoints = breakpoints
self.pyshell.flist = Mock()
self.pyshell.flist.inversedict = (
MockEditWindow('test1.py', [4, 4]),
MockEditWindow('test2.py', [13, 44, 45]),
)
self.debugger.set_breakpoint('test0.py', 1)
self.idb.set_break.assert_called_once_with('test0.py', 1)
self.debugger.load_breakpoints() # Call set_breakpoint 5 times.
self.idb.set_break.assert_has_calls(
[mock.call('test0.py', 1),
mock.call('test1.py', 4),
mock.call('test1.py', 4),
mock.call('test2.py', 13),
mock.call('test2.py', 44),
mock.call('test2.py', 45)])
def test_sync_source_line(self):
# Test that .sync_source_line() will set the flist.gotofileline with fixed frame.
test_code = compile(TEST_CODE, 'test_sync.py', 'exec')
test_frame = MockFrame(test_code, 1)
self.debugger.frame = test_frame
self.debugger.flist = Mock()
with patch('idlelib.debugger.os.path.exists', return_value=True):
self.debugger.sync_source_line()
self.debugger.flist.gotofileline.assert_called_once_with('test_sync.py', 1)
class DebuggerGuiTest(unittest.TestCase):
"""Tests for debugger.Debugger that need tk root.
close needs debugger.top set in make_gui.
"""
@classmethod
def setUpClass(cls):
requires('gui')
cls.root = root = Tk()
root.withdraw()
cls.pyshell = Mock()
cls.pyshell.root = root
cls.idb = Mock()
# stack tests fail with debugger here.
## cls.debugger = debugger.Debugger(cls.pyshell, cls.idb)
## cls.debugger.root = root
## # real root needed for real make_gui
## # run, interacting, abort_loop
@classmethod
def tearDownClass(cls):
cls.root.destroy()
del cls.root
def setUp(self):
self.debugger = debugger.Debugger(self.pyshell, self.idb)
self.debugger.root = self.root
# real root needed for real make_gui
# run, interacting, abort_loop
def test_run_debugger(self):
self.debugger.run(1, 'two')
self.idb.run.assert_called_once_with(1, 'two')
self.assertEqual(self.debugger.interacting, 0)
def test_close(self):
# Test closing the window in an idle state.
self.debugger.close()
self.pyshell.close_debugger.assert_called_once()
def test_show_stack(self):
self.debugger.show_stack()
self.assertEqual(self.debugger.stackviewer.gui, self.debugger)
def test_show_stack_with_frame(self):
test_frame = MockFrame(None, None)
self.debugger.frame = test_frame
# Reset the stackviewer to force it to be recreated.
self.debugger.stackviewer = None
self.idb.get_stack.return_value = ([], 0)
self.debugger.show_stack()
# Check that the newly created stackviewer has the test gui as a field.
self.assertEqual(self.debugger.stackviewer.gui, self.debugger)
self.idb.get_stack.assert_called_once_with(test_frame, None)
class StackViewerTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
requires('gui')
cls.root = Tk()
cls.root.withdraw()
@classmethod
def tearDownClass(cls):
cls.root.destroy()
del cls.root
def setUp(self):
self.code = compile(TEST_CODE, 'test_stackviewer.py', 'exec')
self.stack = [
(MockFrame(self.code, 1), 1),
(MockFrame(self.code, 2), 2)
]
# Create a stackviewer and load the test stack.
self.sv = debugger.StackViewer(self.root, None, None)
self.sv.load_stack(self.stack)
def test_init(self):
# Test creation of StackViewer.
gui = None
flist = None
master_window = self.root
sv = debugger.StackViewer(master_window, flist, gui)
self.assertTrue(hasattr(sv, 'stack'))
def test_load_stack(self):
# Test the .load_stack() method against a fixed test stack.
# Check the test stack is assigned and the list contains the repr of them.
self.assertEqual(self.sv.stack, self.stack)
self.assertTrue('?.<module>(), line 1:' in self.sv.get(0))
self.assertEqual(self.sv.get(1), '?.<module>(), line 2: ')
def test_show_source(self):
# Test the .show_source() method against a fixed test stack.
# Patch out the file list to monitor it
self.sv.flist = Mock()
# Patch out isfile to pretend file exists.
with patch('idlelib.debugger.os.path.isfile', return_value=True) as isfile:
self.sv.show_source(1)
isfile.assert_called_once_with('test_stackviewer.py')
self.sv.flist.open.assert_called_once_with('test_stackviewer.py')
class NameSpaceTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
requires('gui')
cls.root = Tk()
cls.root.withdraw()
@@ -23,7 +293,5 @@ class NameSpaceTest(unittest.TestCase):
debugger.NamespaceViewer(self.root, 'Test')
# Other classes are Idb, Debugger, and StackViewer.
if __name__ == '__main__':
unittest.main(verbosity=2)

View File

@@ -37,7 +37,7 @@ class SequenceTreeItemTest(unittest.TestCase):
def test_keys(self):
ti = debugobj.SequenceTreeItem('label', 'abc')
self.assertEqual(list(ti.keys()), [0, 1, 2])
self.assertEqual(list(ti.keys()), [0, 1, 2]) # keys() is a range.
class DictTreeItemTest(unittest.TestCase):
@@ -50,7 +50,7 @@ class DictTreeItemTest(unittest.TestCase):
def test_keys(self):
ti = debugobj.DictTreeItem('label', {1:1, 0:0, 2:2})
self.assertEqual(ti.keys(), [0, 1, 2])
self.assertEqual(ti.keys(), [0, 1, 2]) # keys() is a sorted list.
if __name__ == '__main__':

View File

@@ -95,7 +95,7 @@ class GetLineIndentTest(unittest.TestCase):
def insert(text, string):
text.delete('1.0', 'end')
text.insert('end', string)
text.update() # Force update for colorizer to finish.
text.update_idletasks() # Force update for colorizer to finish.
class IndentAndNewlineTest(unittest.TestCase):

View File

@@ -1,4 +1,4 @@
"Test help, coverage 87%."
"Test help, coverage 94%."
from idlelib import help
import unittest
@@ -8,25 +8,27 @@ from os.path import abspath, dirname, join
from tkinter import Tk
class HelpFrameTest(unittest.TestCase):
class IdleDocTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
"By itself, this tests that file parsed without exception."
cls.root = root = Tk()
root.withdraw()
helpfile = join(dirname(dirname(abspath(__file__))), 'help.html')
cls.frame = help.HelpFrame(root, helpfile)
cls.window = help.show_idlehelp(root)
@classmethod
def tearDownClass(cls):
del cls.frame
del cls.window
cls.root.update_idletasks()
cls.root.destroy()
del cls.root
def test_line1(self):
text = self.frame.text
def test_1window(self):
self.assertIn('IDLE Doc', self.window.wm_title())
def test_4text(self):
text = self.window.frame.text
self.assertEqual(text.get('1.0', '1.end'), ' IDLE ')

View File

@@ -71,7 +71,7 @@ class LiveDialogTest(unittest.TestCase):
"""Test buttons that display files."""
dialog = self.dialog
button_sources = [(self.dialog.readme, 'README.txt', 'readme'),
(self.dialog.idle_news, 'NEWS.txt', 'news'),
(self.dialog.idle_news, 'News3.txt', 'news'),
(self.dialog.idle_credits, 'CREDITS.txt', 'credits')]
for button, filename, name in button_sources:

View File

@@ -1,6 +1,7 @@
"Test outwin, coverage 76%."
from idlelib import outwin
import sys
import unittest
from test.support import requires
from tkinter import Tk, Text
@@ -18,6 +19,10 @@ class OutputWindowTest(unittest.TestCase):
root.withdraw()
w = cls.window = outwin.OutputWindow(None, None, None, root)
cls.text = w.text = Text(root)
if sys.platform == 'darwin': # Issue 112938
cls.text.update = cls.text.update_idletasks
# Without this, test write, writelines, and goto... fail.
# The reasons and why macOS-specific are unclear.
@classmethod
def tearDownClass(cls):

View File

@@ -690,16 +690,22 @@ class ShellSidebarTest(unittest.TestCase):
last_lineno = get_end_linenumber(text)
self.assertIsNotNone(text.dlineinfo(text.index(f'{last_lineno}.0')))
# Scroll up using the <MouseWheel> event.
# The meaning of delta is platform-dependent.
delta = -1 if sys.platform == 'darwin' else 120
sidebar.canvas.event_generate('<MouseWheel>', x=0, y=0, delta=delta)
yield
if sys.platform != 'darwin': # .update_idletasks() does not work.
self.assertIsNone(text.dlineinfo(text.index(f'{last_lineno}.0')))
# Delta for <MouseWheel>, whose meaning is platform-dependent.
delta = 1 if sidebar.canvas._windowingsystem == 'aqua' else 120
# Scroll back down using the <Button-5> event.
sidebar.canvas.event_generate('<Button-5>', x=0, y=0)
# Scroll up.
if sidebar.canvas._windowingsystem == 'x11':
sidebar.canvas.event_generate('<Button-4>', x=0, y=0)
else:
sidebar.canvas.event_generate('<MouseWheel>', x=0, y=0, delta=delta)
yield
self.assertIsNone(text.dlineinfo(text.index(f'{last_lineno}.0')))
# Scroll back down.
if sidebar.canvas._windowingsystem == 'x11':
sidebar.canvas.event_generate('<Button-5>', x=0, y=0)
else:
sidebar.canvas.event_generate('<MouseWheel>', x=0, y=0, delta=-delta)
yield
self.assertIsNotNone(text.dlineinfo(text.index(f'{last_lineno}.0')))