Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/Icons/README.txt +51 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/Icons/idle.ico +0 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/debugger_r.py +390 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/debugobj.py +146 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/debugobj_r.py +41 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/delegator.py +34 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/dynoption.py +57 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/editor.py +1721 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/extend.txt +83 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/filelist.py +132 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/format.py +426 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/grep.py +223 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/help.html +865 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/help.py +343 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/help_about.py +211 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/history.py +106 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/hyperparser.py +312 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle.bat +4 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle.py +14 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle.pyw +17 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/README.txt +241 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/__init__.py +23 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/example_noext +4 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/example_stub.pyi +4 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/htest.py +442 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/mock_idle.py +61 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/mock_tk.py +307 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/template.py +30 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/test_autocomplete.py +305 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/test_autocomplete_w.py +32 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/test_autoexpand.py +155 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/test_browser.py +257 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/test_calltip.py +372 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/test_calltip_w.py +29 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/test_codecontext.py +455 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/test_colorizer.py +622 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/test_config.py +805 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/test_config_key.py +356 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/test_configdialog.py +1581 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/test_debugger.py +298 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/test_debugger_r.py +36 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/test_debugobj.py +57 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/test_debugobj_r.py +22 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/test_delegator.py +44 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/test_editmenu.py +74 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/test_editor.py +241 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/test_filelist.py +33 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/test_format.py +668 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/test_grep.py +157 -0
- miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/test_help.py +36 -0
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/Icons/README.txt
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
IDLE-PYTHON LOGOS
|
| 2 |
+
|
| 3 |
+
These are sent to tk on Windows, *NIX, and non-Aqua macOS
|
| 4 |
+
in pyshell following "# set application icon".
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
2006?: Andrew Clover made variously sized python icons for win23.
|
| 8 |
+
https://www.doxdesk.com/software/py/pyicons.html
|
| 9 |
+
|
| 10 |
+
2006: 16, 32, and 48 bit .png versions were copied to CPython
|
| 11 |
+
as Python application icons, maybe in PC/icons/py.ico.
|
| 12 |
+
https://github.com/python/cpython/issues/43372
|
| 13 |
+
|
| 14 |
+
2014: They were copied (perhaps a bit revised) to idlelib/Icons.
|
| 15 |
+
https://github.com/python/cpython/issues/64605
|
| 16 |
+
.gif versions were also added.
|
| 17 |
+
|
| 18 |
+
2020: Add Clover's 256-bit image.
|
| 19 |
+
https://github.com/python/cpython/issues/82620
|
| 20 |
+
Other fixups were done.
|
| 21 |
+
|
| 22 |
+
The idle.ico file used for Windows was created with ImageMagick:
|
| 23 |
+
$ convert idle_16.png idle_32.png idle_48.png idle_256.png idle.ico
|
| 24 |
+
** This needs redoing whenever files are changed.
|
| 25 |
+
?? Do Start, Desktop, and Taskbar use idlelib/Icons files?
|
| 26 |
+
|
| 27 |
+
Issue added Windows Store PC/icons/idlex44.png and .../idlex150.png.
|
| 28 |
+
https://github.com/python/cpython/pull/22817
|
| 29 |
+
?? Should these be updated with major changes?
|
| 30 |
+
|
| 31 |
+
2022: Optimize .png images in CPython repository with external program.
|
| 32 |
+
https://github.com/python/cpython/pull/21348
|
| 33 |
+
idle.ico (and idlex##) were not updated.
|
| 34 |
+
|
| 35 |
+
The idlexx.gif files are only needed for *nix running tcl/tk 8.5.
|
| 36 |
+
As of 2022, this was known true for 1 'major' Linux distribution.
|
| 37 |
+
(Same would be true for any non-Aqua macOS with 8.5, but now none?)
|
| 38 |
+
Can be deleted when we require 8.6 or it is known always used.
|
| 39 |
+
|
| 40 |
+
Future: Derivatives of Python logo should be submitted for approval.
|
| 41 |
+
PSF Trademark Working Group / Committee psf-trademarks@python.org
|
| 42 |
+
https://www.python.org/community/logos/ # Original files
|
| 43 |
+
https://www.python.org/psf/trademarks-faq/
|
| 44 |
+
https://www.python.org/psf/trademarks/ # Usage.
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
OTHER GIFS: These are used by browsers using idlelib.tree.
|
| 48 |
+
At least some will not be used when tree is replaced by ttk.Treeview.
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
Edited 2024 August 26 by TJR.
|
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/Icons/idle.ico
ADDED
|
|
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/debugger_r.py
ADDED
|
@@ -0,0 +1,390 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Support for remote Python debugging.
|
| 2 |
+
|
| 3 |
+
Some ASCII art to describe the structure:
|
| 4 |
+
|
| 5 |
+
IN PYTHON SUBPROCESS # IN IDLE PROCESS
|
| 6 |
+
#
|
| 7 |
+
# oid='gui_adapter'
|
| 8 |
+
+----------+ # +------------+ +-----+
|
| 9 |
+
| GUIProxy |--remote#call-->| GUIAdapter |--calls-->| GUI |
|
| 10 |
+
+-----+--calls-->+----------+ # +------------+ +-----+
|
| 11 |
+
| Idb | # /
|
| 12 |
+
+-----+<-calls--+------------+ # +----------+<--calls-/
|
| 13 |
+
| IdbAdapter |<--remote#call--| IdbProxy |
|
| 14 |
+
+------------+ # +----------+
|
| 15 |
+
oid='idb_adapter' #
|
| 16 |
+
|
| 17 |
+
The purpose of the Proxy and Adapter classes is to translate certain
|
| 18 |
+
arguments and return values that cannot be transported through the RPC
|
| 19 |
+
barrier, in particular frame and traceback objects.
|
| 20 |
+
|
| 21 |
+
"""
|
| 22 |
+
import reprlib
|
| 23 |
+
import types
|
| 24 |
+
from idlelib import debugger
|
| 25 |
+
|
| 26 |
+
debugging = 0
|
| 27 |
+
|
| 28 |
+
idb_adap_oid = "idb_adapter"
|
| 29 |
+
gui_adap_oid = "gui_adapter"
|
| 30 |
+
|
| 31 |
+
#=======================================
|
| 32 |
+
#
|
| 33 |
+
# In the PYTHON subprocess:
|
| 34 |
+
|
| 35 |
+
frametable = {}
|
| 36 |
+
dicttable = {}
|
| 37 |
+
codetable = {}
|
| 38 |
+
tracebacktable = {}
|
| 39 |
+
|
| 40 |
+
def wrap_frame(frame):
|
| 41 |
+
fid = id(frame)
|
| 42 |
+
frametable[fid] = frame
|
| 43 |
+
return fid
|
| 44 |
+
|
| 45 |
+
def wrap_info(info):
|
| 46 |
+
"replace info[2], a traceback instance, by its ID"
|
| 47 |
+
if info is None:
|
| 48 |
+
return None
|
| 49 |
+
else:
|
| 50 |
+
traceback = info[2]
|
| 51 |
+
assert isinstance(traceback, types.TracebackType)
|
| 52 |
+
traceback_id = id(traceback)
|
| 53 |
+
tracebacktable[traceback_id] = traceback
|
| 54 |
+
modified_info = (info[0], info[1], traceback_id)
|
| 55 |
+
return modified_info
|
| 56 |
+
|
| 57 |
+
class GUIProxy:
|
| 58 |
+
|
| 59 |
+
def __init__(self, conn, gui_adap_oid):
|
| 60 |
+
self.conn = conn
|
| 61 |
+
self.oid = gui_adap_oid
|
| 62 |
+
|
| 63 |
+
def interaction(self, message, frame, info=None):
|
| 64 |
+
# calls rpc.SocketIO.remotecall() via run.MyHandler instance
|
| 65 |
+
# pass frame and traceback object IDs instead of the objects themselves
|
| 66 |
+
self.conn.remotecall(self.oid, "interaction",
|
| 67 |
+
(message, wrap_frame(frame), wrap_info(info)),
|
| 68 |
+
{})
|
| 69 |
+
|
| 70 |
+
class IdbAdapter:
|
| 71 |
+
|
| 72 |
+
def __init__(self, idb):
|
| 73 |
+
self.idb = idb
|
| 74 |
+
|
| 75 |
+
#----------called by an IdbProxy----------
|
| 76 |
+
|
| 77 |
+
def set_step(self):
|
| 78 |
+
self.idb.set_step()
|
| 79 |
+
|
| 80 |
+
def set_quit(self):
|
| 81 |
+
self.idb.set_quit()
|
| 82 |
+
|
| 83 |
+
def set_continue(self):
|
| 84 |
+
self.idb.set_continue()
|
| 85 |
+
|
| 86 |
+
def set_next(self, fid):
|
| 87 |
+
frame = frametable[fid]
|
| 88 |
+
self.idb.set_next(frame)
|
| 89 |
+
|
| 90 |
+
def set_return(self, fid):
|
| 91 |
+
frame = frametable[fid]
|
| 92 |
+
self.idb.set_return(frame)
|
| 93 |
+
|
| 94 |
+
def get_stack(self, fid, tbid):
|
| 95 |
+
frame = frametable[fid]
|
| 96 |
+
if tbid is None:
|
| 97 |
+
tb = None
|
| 98 |
+
else:
|
| 99 |
+
tb = tracebacktable[tbid]
|
| 100 |
+
stack, i = self.idb.get_stack(frame, tb)
|
| 101 |
+
stack = [(wrap_frame(frame2), k) for frame2, k in stack]
|
| 102 |
+
return stack, i
|
| 103 |
+
|
| 104 |
+
def run(self, cmd):
|
| 105 |
+
import __main__
|
| 106 |
+
self.idb.run(cmd, __main__.__dict__)
|
| 107 |
+
|
| 108 |
+
def set_break(self, filename, lineno):
|
| 109 |
+
msg = self.idb.set_break(filename, lineno)
|
| 110 |
+
return msg
|
| 111 |
+
|
| 112 |
+
def clear_break(self, filename, lineno):
|
| 113 |
+
msg = self.idb.clear_break(filename, lineno)
|
| 114 |
+
return msg
|
| 115 |
+
|
| 116 |
+
def clear_all_file_breaks(self, filename):
|
| 117 |
+
msg = self.idb.clear_all_file_breaks(filename)
|
| 118 |
+
return msg
|
| 119 |
+
|
| 120 |
+
#----------called by a FrameProxy----------
|
| 121 |
+
|
| 122 |
+
def frame_attr(self, fid, name):
|
| 123 |
+
frame = frametable[fid]
|
| 124 |
+
return getattr(frame, name)
|
| 125 |
+
|
| 126 |
+
def frame_globals(self, fid):
|
| 127 |
+
frame = frametable[fid]
|
| 128 |
+
gdict = frame.f_globals
|
| 129 |
+
did = id(gdict)
|
| 130 |
+
dicttable[did] = gdict
|
| 131 |
+
return did
|
| 132 |
+
|
| 133 |
+
def frame_locals(self, fid):
|
| 134 |
+
frame = frametable[fid]
|
| 135 |
+
ldict = frame.f_locals
|
| 136 |
+
did = id(ldict)
|
| 137 |
+
dicttable[did] = ldict
|
| 138 |
+
return did
|
| 139 |
+
|
| 140 |
+
def frame_code(self, fid):
|
| 141 |
+
frame = frametable[fid]
|
| 142 |
+
code = frame.f_code
|
| 143 |
+
cid = id(code)
|
| 144 |
+
codetable[cid] = code
|
| 145 |
+
return cid
|
| 146 |
+
|
| 147 |
+
#----------called by a CodeProxy----------
|
| 148 |
+
|
| 149 |
+
def code_name(self, cid):
|
| 150 |
+
code = codetable[cid]
|
| 151 |
+
return code.co_name
|
| 152 |
+
|
| 153 |
+
def code_filename(self, cid):
|
| 154 |
+
code = codetable[cid]
|
| 155 |
+
return code.co_filename
|
| 156 |
+
|
| 157 |
+
#----------called by a DictProxy----------
|
| 158 |
+
|
| 159 |
+
def dict_keys(self, did):
|
| 160 |
+
raise NotImplementedError("dict_keys not public or pickleable")
|
| 161 |
+
## return dicttable[did].keys()
|
| 162 |
+
|
| 163 |
+
### Needed until dict_keys type is finished and pickleable.
|
| 164 |
+
# xxx finished. pickleable?
|
| 165 |
+
### Will probably need to extend rpc.py:SocketIO._proxify at that time.
|
| 166 |
+
def dict_keys_list(self, did):
|
| 167 |
+
return list(dicttable[did].keys())
|
| 168 |
+
|
| 169 |
+
def dict_item(self, did, key):
|
| 170 |
+
value = dicttable[did][key]
|
| 171 |
+
return reprlib.repr(value) # Can't pickle module 'builtins'.
|
| 172 |
+
|
| 173 |
+
#----------end class IdbAdapter----------
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
def start_debugger(rpchandler, gui_adap_oid):
|
| 177 |
+
"""Start the debugger and its RPC link in the Python subprocess
|
| 178 |
+
|
| 179 |
+
Start the subprocess side of the split debugger and set up that side of the
|
| 180 |
+
RPC link by instantiating the GUIProxy, Idb debugger, and IdbAdapter
|
| 181 |
+
objects and linking them together. Register the IdbAdapter with the
|
| 182 |
+
RPCServer to handle RPC requests from the split debugger GUI via the
|
| 183 |
+
IdbProxy.
|
| 184 |
+
|
| 185 |
+
"""
|
| 186 |
+
gui_proxy = GUIProxy(rpchandler, gui_adap_oid)
|
| 187 |
+
idb = debugger.Idb(gui_proxy)
|
| 188 |
+
idb_adap = IdbAdapter(idb)
|
| 189 |
+
rpchandler.register(idb_adap_oid, idb_adap)
|
| 190 |
+
return idb_adap_oid
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
#=======================================
|
| 194 |
+
#
|
| 195 |
+
# In the IDLE process:
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
class FrameProxy:
|
| 199 |
+
|
| 200 |
+
def __init__(self, conn, fid):
|
| 201 |
+
self._conn = conn
|
| 202 |
+
self._fid = fid
|
| 203 |
+
self._oid = "idb_adapter"
|
| 204 |
+
self._dictcache = {}
|
| 205 |
+
|
| 206 |
+
def __getattr__(self, name):
|
| 207 |
+
if name[:1] == "_":
|
| 208 |
+
raise AttributeError(name)
|
| 209 |
+
if name == "f_code":
|
| 210 |
+
return self._get_f_code()
|
| 211 |
+
if name == "f_globals":
|
| 212 |
+
return self._get_f_globals()
|
| 213 |
+
if name == "f_locals":
|
| 214 |
+
return self._get_f_locals()
|
| 215 |
+
return self._conn.remotecall(self._oid, "frame_attr",
|
| 216 |
+
(self._fid, name), {})
|
| 217 |
+
|
| 218 |
+
def _get_f_code(self):
|
| 219 |
+
cid = self._conn.remotecall(self._oid, "frame_code", (self._fid,), {})
|
| 220 |
+
return CodeProxy(self._conn, self._oid, cid)
|
| 221 |
+
|
| 222 |
+
def _get_f_globals(self):
|
| 223 |
+
did = self._conn.remotecall(self._oid, "frame_globals",
|
| 224 |
+
(self._fid,), {})
|
| 225 |
+
return self._get_dict_proxy(did)
|
| 226 |
+
|
| 227 |
+
def _get_f_locals(self):
|
| 228 |
+
did = self._conn.remotecall(self._oid, "frame_locals",
|
| 229 |
+
(self._fid,), {})
|
| 230 |
+
return self._get_dict_proxy(did)
|
| 231 |
+
|
| 232 |
+
def _get_dict_proxy(self, did):
|
| 233 |
+
if did in self._dictcache:
|
| 234 |
+
return self._dictcache[did]
|
| 235 |
+
dp = DictProxy(self._conn, self._oid, did)
|
| 236 |
+
self._dictcache[did] = dp
|
| 237 |
+
return dp
|
| 238 |
+
|
| 239 |
+
|
| 240 |
+
class CodeProxy:
|
| 241 |
+
|
| 242 |
+
def __init__(self, conn, oid, cid):
|
| 243 |
+
self._conn = conn
|
| 244 |
+
self._oid = oid
|
| 245 |
+
self._cid = cid
|
| 246 |
+
|
| 247 |
+
def __getattr__(self, name):
|
| 248 |
+
if name == "co_name":
|
| 249 |
+
return self._conn.remotecall(self._oid, "code_name",
|
| 250 |
+
(self._cid,), {})
|
| 251 |
+
if name == "co_filename":
|
| 252 |
+
return self._conn.remotecall(self._oid, "code_filename",
|
| 253 |
+
(self._cid,), {})
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
class DictProxy:
|
| 257 |
+
|
| 258 |
+
def __init__(self, conn, oid, did):
|
| 259 |
+
self._conn = conn
|
| 260 |
+
self._oid = oid
|
| 261 |
+
self._did = did
|
| 262 |
+
|
| 263 |
+
## def keys(self):
|
| 264 |
+
## return self._conn.remotecall(self._oid, "dict_keys", (self._did,), {})
|
| 265 |
+
|
| 266 |
+
# 'temporary' until dict_keys is a pickleable built-in type
|
| 267 |
+
def keys(self):
|
| 268 |
+
return self._conn.remotecall(self._oid,
|
| 269 |
+
"dict_keys_list", (self._did,), {})
|
| 270 |
+
|
| 271 |
+
def __getitem__(self, key):
|
| 272 |
+
return self._conn.remotecall(self._oid, "dict_item",
|
| 273 |
+
(self._did, key), {})
|
| 274 |
+
|
| 275 |
+
def __getattr__(self, name):
|
| 276 |
+
##print("*** Failed DictProxy.__getattr__:", name)
|
| 277 |
+
raise AttributeError(name)
|
| 278 |
+
|
| 279 |
+
|
| 280 |
+
class GUIAdapter:
|
| 281 |
+
|
| 282 |
+
def __init__(self, conn, gui):
|
| 283 |
+
self.conn = conn
|
| 284 |
+
self.gui = gui
|
| 285 |
+
|
| 286 |
+
def interaction(self, message, fid, modified_info):
|
| 287 |
+
##print("*** Interaction: (%s, %s, %s)" % (message, fid, modified_info))
|
| 288 |
+
frame = FrameProxy(self.conn, fid)
|
| 289 |
+
self.gui.interaction(message, frame, modified_info)
|
| 290 |
+
|
| 291 |
+
|
| 292 |
+
class IdbProxy:
|
| 293 |
+
|
| 294 |
+
def __init__(self, conn, shell, oid):
|
| 295 |
+
self.oid = oid
|
| 296 |
+
self.conn = conn
|
| 297 |
+
self.shell = shell
|
| 298 |
+
|
| 299 |
+
def call(self, methodname, /, *args, **kwargs):
|
| 300 |
+
##print("*** IdbProxy.call %s %s %s" % (methodname, args, kwargs))
|
| 301 |
+
value = self.conn.remotecall(self.oid, methodname, args, kwargs)
|
| 302 |
+
##print("*** IdbProxy.call %s returns %r" % (methodname, value))
|
| 303 |
+
return value
|
| 304 |
+
|
| 305 |
+
def run(self, cmd, locals):
|
| 306 |
+
# Ignores locals on purpose!
|
| 307 |
+
seq = self.conn.asyncqueue(self.oid, "run", (cmd,), {})
|
| 308 |
+
self.shell.interp.active_seq = seq
|
| 309 |
+
|
| 310 |
+
def get_stack(self, frame, tbid):
|
| 311 |
+
# passing frame and traceback IDs, not the objects themselves
|
| 312 |
+
stack, i = self.call("get_stack", frame._fid, tbid)
|
| 313 |
+
stack = [(FrameProxy(self.conn, fid), k) for fid, k in stack]
|
| 314 |
+
return stack, i
|
| 315 |
+
|
| 316 |
+
def set_continue(self):
|
| 317 |
+
self.call("set_continue")
|
| 318 |
+
|
| 319 |
+
def set_step(self):
|
| 320 |
+
self.call("set_step")
|
| 321 |
+
|
| 322 |
+
def set_next(self, frame):
|
| 323 |
+
self.call("set_next", frame._fid)
|
| 324 |
+
|
| 325 |
+
def set_return(self, frame):
|
| 326 |
+
self.call("set_return", frame._fid)
|
| 327 |
+
|
| 328 |
+
def set_quit(self):
|
| 329 |
+
self.call("set_quit")
|
| 330 |
+
|
| 331 |
+
def set_break(self, filename, lineno):
|
| 332 |
+
msg = self.call("set_break", filename, lineno)
|
| 333 |
+
return msg
|
| 334 |
+
|
| 335 |
+
def clear_break(self, filename, lineno):
|
| 336 |
+
msg = self.call("clear_break", filename, lineno)
|
| 337 |
+
return msg
|
| 338 |
+
|
| 339 |
+
def clear_all_file_breaks(self, filename):
|
| 340 |
+
msg = self.call("clear_all_file_breaks", filename)
|
| 341 |
+
return msg
|
| 342 |
+
|
| 343 |
+
def start_remote_debugger(rpcclt, pyshell):
|
| 344 |
+
"""Start the subprocess debugger, initialize the debugger GUI and RPC link
|
| 345 |
+
|
| 346 |
+
Request the RPCServer start the Python subprocess debugger and link. Set
|
| 347 |
+
up the Idle side of the split debugger by instantiating the IdbProxy,
|
| 348 |
+
debugger GUI, and debugger GUIAdapter objects and linking them together.
|
| 349 |
+
|
| 350 |
+
Register the GUIAdapter with the RPCClient to handle debugger GUI
|
| 351 |
+
interaction requests coming from the subprocess debugger via the GUIProxy.
|
| 352 |
+
|
| 353 |
+
The IdbAdapter will pass execution and environment requests coming from the
|
| 354 |
+
Idle debugger GUI to the subprocess debugger via the IdbProxy.
|
| 355 |
+
|
| 356 |
+
"""
|
| 357 |
+
global idb_adap_oid
|
| 358 |
+
|
| 359 |
+
idb_adap_oid = rpcclt.remotecall("exec", "start_the_debugger",\
|
| 360 |
+
(gui_adap_oid,), {})
|
| 361 |
+
idb_proxy = IdbProxy(rpcclt, pyshell, idb_adap_oid)
|
| 362 |
+
gui = debugger.Debugger(pyshell, idb_proxy)
|
| 363 |
+
gui_adap = GUIAdapter(rpcclt, gui)
|
| 364 |
+
rpcclt.register(gui_adap_oid, gui_adap)
|
| 365 |
+
return gui
|
| 366 |
+
|
| 367 |
+
def close_remote_debugger(rpcclt):
|
| 368 |
+
"""Shut down subprocess debugger and Idle side of debugger RPC link
|
| 369 |
+
|
| 370 |
+
Request that the RPCServer shut down the subprocess debugger and link.
|
| 371 |
+
Unregister the GUIAdapter, which will cause a GC on the Idle process
|
| 372 |
+
debugger and RPC link objects. (The second reference to the debugger GUI
|
| 373 |
+
is deleted in pyshell.close_remote_debugger().)
|
| 374 |
+
|
| 375 |
+
"""
|
| 376 |
+
close_subprocess_debugger(rpcclt)
|
| 377 |
+
rpcclt.unregister(gui_adap_oid)
|
| 378 |
+
|
| 379 |
+
def close_subprocess_debugger(rpcclt):
|
| 380 |
+
rpcclt.remotecall("exec", "stop_the_debugger", (idb_adap_oid,), {})
|
| 381 |
+
|
| 382 |
+
def restart_subprocess_debugger(rpcclt):
|
| 383 |
+
idb_adap_oid_ret = rpcclt.remotecall("exec", "start_the_debugger",\
|
| 384 |
+
(gui_adap_oid,), {})
|
| 385 |
+
assert idb_adap_oid_ret == idb_adap_oid, 'Idb restarted with different oid'
|
| 386 |
+
|
| 387 |
+
|
| 388 |
+
if __name__ == "__main__":
|
| 389 |
+
from unittest import main
|
| 390 |
+
main('idlelib.idle_test.test_debugger_r', verbosity=2, exit=False)
|
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/debugobj.py
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Define tree items for debug stackviewer, which is only user.
|
| 2 |
+
"""
|
| 3 |
+
# XXX TO DO:
|
| 4 |
+
# - popup menu
|
| 5 |
+
# - support partial or total redisplay
|
| 6 |
+
# - more doc strings
|
| 7 |
+
# - tooltips
|
| 8 |
+
|
| 9 |
+
# object browser
|
| 10 |
+
|
| 11 |
+
# XXX TO DO:
|
| 12 |
+
# - for classes/modules, add "open source" to object browser
|
| 13 |
+
from reprlib import Repr
|
| 14 |
+
|
| 15 |
+
from idlelib.tree import TreeItem, TreeNode, ScrolledCanvas
|
| 16 |
+
|
| 17 |
+
myrepr = Repr()
|
| 18 |
+
myrepr.maxstring = 100
|
| 19 |
+
myrepr.maxother = 100
|
| 20 |
+
|
| 21 |
+
class ObjectTreeItem(TreeItem):
|
| 22 |
+
def __init__(self, labeltext, object_, setfunction=None):
|
| 23 |
+
self.labeltext = labeltext
|
| 24 |
+
self.object = object_
|
| 25 |
+
self.setfunction = setfunction
|
| 26 |
+
def GetLabelText(self):
|
| 27 |
+
return self.labeltext
|
| 28 |
+
def GetText(self):
|
| 29 |
+
return myrepr.repr(self.object)
|
| 30 |
+
def GetIconName(self):
|
| 31 |
+
if not self.IsExpandable():
|
| 32 |
+
return "python"
|
| 33 |
+
def IsEditable(self):
|
| 34 |
+
return self.setfunction is not None
|
| 35 |
+
def SetText(self, text):
|
| 36 |
+
try:
|
| 37 |
+
value = eval(text)
|
| 38 |
+
self.setfunction(value)
|
| 39 |
+
except:
|
| 40 |
+
pass
|
| 41 |
+
else:
|
| 42 |
+
self.object = value
|
| 43 |
+
def IsExpandable(self):
|
| 44 |
+
return not not dir(self.object)
|
| 45 |
+
def GetSubList(self):
|
| 46 |
+
keys = dir(self.object)
|
| 47 |
+
sublist = []
|
| 48 |
+
for key in keys:
|
| 49 |
+
try:
|
| 50 |
+
value = getattr(self.object, key)
|
| 51 |
+
except AttributeError:
|
| 52 |
+
continue
|
| 53 |
+
item = make_objecttreeitem(
|
| 54 |
+
str(key) + " =",
|
| 55 |
+
value,
|
| 56 |
+
lambda value, key=key, object_=self.object:
|
| 57 |
+
setattr(object_, key, value))
|
| 58 |
+
sublist.append(item)
|
| 59 |
+
return sublist
|
| 60 |
+
|
| 61 |
+
class ClassTreeItem(ObjectTreeItem):
|
| 62 |
+
def IsExpandable(self):
|
| 63 |
+
return True
|
| 64 |
+
def GetSubList(self):
|
| 65 |
+
sublist = ObjectTreeItem.GetSubList(self)
|
| 66 |
+
if len(self.object.__bases__) == 1:
|
| 67 |
+
item = make_objecttreeitem("__bases__[0] =",
|
| 68 |
+
self.object.__bases__[0])
|
| 69 |
+
else:
|
| 70 |
+
item = make_objecttreeitem("__bases__ =", self.object.__bases__)
|
| 71 |
+
sublist.insert(0, item)
|
| 72 |
+
return sublist
|
| 73 |
+
|
| 74 |
+
class AtomicObjectTreeItem(ObjectTreeItem):
|
| 75 |
+
def IsExpandable(self):
|
| 76 |
+
return False
|
| 77 |
+
|
| 78 |
+
class SequenceTreeItem(ObjectTreeItem):
|
| 79 |
+
def IsExpandable(self):
|
| 80 |
+
return len(self.object) > 0
|
| 81 |
+
def keys(self):
|
| 82 |
+
return range(len(self.object))
|
| 83 |
+
def GetSubList(self):
|
| 84 |
+
sublist = []
|
| 85 |
+
for key in self.keys():
|
| 86 |
+
try:
|
| 87 |
+
value = self.object[key]
|
| 88 |
+
except KeyError:
|
| 89 |
+
continue
|
| 90 |
+
def setfunction(value, key=key, object_=self.object):
|
| 91 |
+
object_[key] = value
|
| 92 |
+
item = make_objecttreeitem(f"{key!r}:", value, setfunction)
|
| 93 |
+
sublist.append(item)
|
| 94 |
+
return sublist
|
| 95 |
+
|
| 96 |
+
class DictTreeItem(SequenceTreeItem):
|
| 97 |
+
def keys(self):
|
| 98 |
+
# TODO return sorted(self.object)
|
| 99 |
+
keys = list(self.object)
|
| 100 |
+
try:
|
| 101 |
+
keys.sort()
|
| 102 |
+
except:
|
| 103 |
+
pass
|
| 104 |
+
return keys
|
| 105 |
+
|
| 106 |
+
dispatch = {
|
| 107 |
+
int: AtomicObjectTreeItem,
|
| 108 |
+
float: AtomicObjectTreeItem,
|
| 109 |
+
str: AtomicObjectTreeItem,
|
| 110 |
+
tuple: SequenceTreeItem,
|
| 111 |
+
list: SequenceTreeItem,
|
| 112 |
+
dict: DictTreeItem,
|
| 113 |
+
type: ClassTreeItem,
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
def make_objecttreeitem(labeltext, object_, setfunction=None):
|
| 117 |
+
t = type(object_)
|
| 118 |
+
if t in dispatch:
|
| 119 |
+
c = dispatch[t]
|
| 120 |
+
else:
|
| 121 |
+
c = ObjectTreeItem
|
| 122 |
+
return c(labeltext, object_, setfunction)
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
def _debug_object_browser(parent): # htest #
|
| 126 |
+
import sys
|
| 127 |
+
from tkinter import Toplevel
|
| 128 |
+
top = Toplevel(parent)
|
| 129 |
+
top.title("Test debug object browser")
|
| 130 |
+
x, y = map(int, parent.geometry().split('+')[1:])
|
| 131 |
+
top.geometry("+%d+%d" % (x + 100, y + 175))
|
| 132 |
+
top.configure(bd=0, bg="yellow")
|
| 133 |
+
top.focus_set()
|
| 134 |
+
sc = ScrolledCanvas(top, bg="white", highlightthickness=0, takefocus=1)
|
| 135 |
+
sc.frame.pack(expand=1, fill="both")
|
| 136 |
+
item = make_objecttreeitem("sys", sys)
|
| 137 |
+
node = TreeNode(sc.canvas, None, item)
|
| 138 |
+
node.update()
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
if __name__ == '__main__':
|
| 142 |
+
from unittest import main
|
| 143 |
+
main('idlelib.idle_test.test_debugobj', verbosity=2, exit=False)
|
| 144 |
+
|
| 145 |
+
from idlelib.idle_test.htest import run
|
| 146 |
+
run(_debug_object_browser)
|
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/debugobj_r.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from idlelib import rpc
|
| 2 |
+
|
| 3 |
+
def remote_object_tree_item(item):
|
| 4 |
+
wrapper = WrappedObjectTreeItem(item)
|
| 5 |
+
oid = id(wrapper)
|
| 6 |
+
rpc.objecttable[oid] = wrapper
|
| 7 |
+
return oid
|
| 8 |
+
|
| 9 |
+
class WrappedObjectTreeItem:
|
| 10 |
+
# Lives in PYTHON subprocess
|
| 11 |
+
|
| 12 |
+
def __init__(self, item):
|
| 13 |
+
self.__item = item
|
| 14 |
+
|
| 15 |
+
def __getattr__(self, name):
|
| 16 |
+
value = getattr(self.__item, name)
|
| 17 |
+
return value
|
| 18 |
+
|
| 19 |
+
def _GetSubList(self):
|
| 20 |
+
sub_list = self.__item._GetSubList()
|
| 21 |
+
return list(map(remote_object_tree_item, sub_list))
|
| 22 |
+
|
| 23 |
+
class StubObjectTreeItem:
|
| 24 |
+
# Lives in IDLE process
|
| 25 |
+
|
| 26 |
+
def __init__(self, sockio, oid):
|
| 27 |
+
self.sockio = sockio
|
| 28 |
+
self.oid = oid
|
| 29 |
+
|
| 30 |
+
def __getattr__(self, name):
|
| 31 |
+
value = rpc.MethodProxy(self.sockio, self.oid, name)
|
| 32 |
+
return value
|
| 33 |
+
|
| 34 |
+
def _GetSubList(self):
|
| 35 |
+
sub_list = self.sockio.remotecall(self.oid, "_GetSubList", (), {})
|
| 36 |
+
return [StubObjectTreeItem(self.sockio, oid) for oid in sub_list]
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
if __name__ == '__main__':
|
| 40 |
+
from unittest import main
|
| 41 |
+
main('idlelib.idle_test.test_debugobj_r', verbosity=2)
|
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/delegator.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class Delegator:
|
| 2 |
+
|
| 3 |
+
def __init__(self, delegate=None):
|
| 4 |
+
self.delegate = delegate
|
| 5 |
+
self.__cache = set()
|
| 6 |
+
# Cache is used to only remove added attributes
|
| 7 |
+
# when changing the delegate.
|
| 8 |
+
|
| 9 |
+
def __getattr__(self, name):
|
| 10 |
+
attr = getattr(self.delegate, name) # May raise AttributeError
|
| 11 |
+
setattr(self, name, attr)
|
| 12 |
+
self.__cache.add(name)
|
| 13 |
+
return attr
|
| 14 |
+
|
| 15 |
+
def resetcache(self):
|
| 16 |
+
"Removes added attributes while leaving original attributes."
|
| 17 |
+
# Function is really about resetting delegator dict
|
| 18 |
+
# to original state. Cache is just a means
|
| 19 |
+
for key in self.__cache:
|
| 20 |
+
try:
|
| 21 |
+
delattr(self, key)
|
| 22 |
+
except AttributeError:
|
| 23 |
+
pass
|
| 24 |
+
self.__cache.clear()
|
| 25 |
+
|
| 26 |
+
def setdelegate(self, delegate):
|
| 27 |
+
"Reset attributes and change delegate."
|
| 28 |
+
self.resetcache()
|
| 29 |
+
self.delegate = delegate
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
if __name__ == '__main__':
|
| 33 |
+
from unittest import main
|
| 34 |
+
main('idlelib.idle_test.test_delegator', verbosity=2)
|
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/dynoption.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
OptionMenu widget modified to allow dynamic menu reconfiguration
|
| 3 |
+
and setting of highlightthickness
|
| 4 |
+
"""
|
| 5 |
+
from tkinter import OptionMenu, _setit, StringVar, Button
|
| 6 |
+
|
| 7 |
+
class DynOptionMenu(OptionMenu):
|
| 8 |
+
"""Add SetMenu and highlightthickness to OptionMenu.
|
| 9 |
+
|
| 10 |
+
Highlightthickness adds space around menu button.
|
| 11 |
+
"""
|
| 12 |
+
def __init__(self, master, variable, value, *values, **kwargs):
|
| 13 |
+
highlightthickness = kwargs.pop('highlightthickness', None)
|
| 14 |
+
OptionMenu.__init__(self, master, variable, value, *values, **kwargs)
|
| 15 |
+
self['highlightthickness'] = highlightthickness
|
| 16 |
+
self.variable = variable
|
| 17 |
+
self.command = kwargs.get('command')
|
| 18 |
+
|
| 19 |
+
def SetMenu(self,valueList,value=None):
|
| 20 |
+
"""
|
| 21 |
+
clear and reload the menu with a new set of options.
|
| 22 |
+
valueList - list of new options
|
| 23 |
+
value - initial value to set the optionmenu's menubutton to
|
| 24 |
+
"""
|
| 25 |
+
self['menu'].delete(0,'end')
|
| 26 |
+
for item in valueList:
|
| 27 |
+
self['menu'].add_command(label=item,
|
| 28 |
+
command=_setit(self.variable,item,self.command))
|
| 29 |
+
if value:
|
| 30 |
+
self.variable.set(value)
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def _dyn_option_menu(parent): # htest #
|
| 34 |
+
from tkinter import Toplevel # + StringVar, Button
|
| 35 |
+
|
| 36 |
+
top = Toplevel(parent)
|
| 37 |
+
top.title("Test dynamic option menu")
|
| 38 |
+
x, y = map(int, parent.geometry().split('+')[1:])
|
| 39 |
+
top.geometry("200x100+%d+%d" % (x + 250, y + 175))
|
| 40 |
+
top.focus_set()
|
| 41 |
+
|
| 42 |
+
var = StringVar(top)
|
| 43 |
+
var.set("Old option set") #Set the default value
|
| 44 |
+
dyn = DynOptionMenu(top, var, "old1","old2","old3","old4",
|
| 45 |
+
highlightthickness=5)
|
| 46 |
+
dyn.pack()
|
| 47 |
+
|
| 48 |
+
def update():
|
| 49 |
+
dyn.SetMenu(["new1","new2","new3","new4"], value="new option set")
|
| 50 |
+
button = Button(top, text="Change option set", command=update)
|
| 51 |
+
button.pack()
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
if __name__ == '__main__':
|
| 55 |
+
# Only module without unittests because of intention to replace.
|
| 56 |
+
from idlelib.idle_test.htest import run
|
| 57 |
+
run(_dyn_option_menu)
|
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/editor.py
ADDED
|
@@ -0,0 +1,1721 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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9 |
+
import traceback
|
| 10 |
+
import webbrowser
|
| 11 |
+
|
| 12 |
+
from tkinter import *
|
| 13 |
+
from tkinter.font import Font
|
| 14 |
+
from tkinter.ttk import Scrollbar
|
| 15 |
+
from tkinter import simpledialog
|
| 16 |
+
from tkinter import messagebox
|
| 17 |
+
|
| 18 |
+
from idlelib.config import idleConf
|
| 19 |
+
from idlelib import configdialog
|
| 20 |
+
from idlelib import grep
|
| 21 |
+
from idlelib import help
|
| 22 |
+
from idlelib import help_about
|
| 23 |
+
from idlelib import macosx
|
| 24 |
+
from idlelib.multicall import MultiCallCreator
|
| 25 |
+
from idlelib import pyparse
|
| 26 |
+
from idlelib import query
|
| 27 |
+
from idlelib import replace
|
| 28 |
+
from idlelib import search
|
| 29 |
+
from idlelib.tree import wheel_event
|
| 30 |
+
from idlelib.util import py_extensions
|
| 31 |
+
from idlelib import window
|
| 32 |
+
from idlelib.help import _get_dochome
|
| 33 |
+
|
| 34 |
+
# The default tab setting for a Text widget, in average-width characters.
|
| 35 |
+
TK_TABWIDTH_DEFAULT = 8
|
| 36 |
+
darwin = sys.platform == 'darwin'
|
| 37 |
+
|
| 38 |
+
class EditorWindow:
|
| 39 |
+
from idlelib.percolator import Percolator
|
| 40 |
+
from idlelib.colorizer import ColorDelegator, color_config
|
| 41 |
+
from idlelib.undo import UndoDelegator
|
| 42 |
+
from idlelib.iomenu import IOBinding, encoding
|
| 43 |
+
from idlelib import mainmenu
|
| 44 |
+
from idlelib.statusbar import MultiStatusBar
|
| 45 |
+
from idlelib.autocomplete import AutoComplete
|
| 46 |
+
from idlelib.autoexpand import AutoExpand
|
| 47 |
+
from idlelib.calltip import Calltip
|
| 48 |
+
from idlelib.codecontext import CodeContext
|
| 49 |
+
from idlelib.sidebar import LineNumbers
|
| 50 |
+
from idlelib.format import FormatParagraph, FormatRegion, Indents, Rstrip
|
| 51 |
+
from idlelib.parenmatch import ParenMatch
|
| 52 |
+
from idlelib.zoomheight import ZoomHeight
|
| 53 |
+
|
| 54 |
+
filesystemencoding = sys.getfilesystemencoding() # for file names
|
| 55 |
+
help_url = None
|
| 56 |
+
|
| 57 |
+
allow_code_context = True
|
| 58 |
+
allow_line_numbers = True
|
| 59 |
+
user_input_insert_tags = None
|
| 60 |
+
|
| 61 |
+
def __init__(self, flist=None, filename=None, key=None, root=None):
|
| 62 |
+
# Delay import: runscript imports pyshell imports EditorWindow.
|
| 63 |
+
from idlelib.runscript import ScriptBinding
|
| 64 |
+
|
| 65 |
+
if EditorWindow.help_url is None:
|
| 66 |
+
EditorWindow.help_url = _get_dochome()
|
| 67 |
+
self.flist = flist
|
| 68 |
+
root = root or flist.root
|
| 69 |
+
self.root = root
|
| 70 |
+
self.menubar = Menu(root)
|
| 71 |
+
self.top = top = window.ListedToplevel(root, menu=self.menubar)
|
| 72 |
+
if flist:
|
| 73 |
+
self.tkinter_vars = flist.vars
|
| 74 |
+
#self.top.instance_dict makes flist.inversedict available to
|
| 75 |
+
#configdialog.py so it can access all EditorWindow instances
|
| 76 |
+
self.top.instance_dict = flist.inversedict
|
| 77 |
+
else:
|
| 78 |
+
self.tkinter_vars = {} # keys: Tkinter event names
|
| 79 |
+
# values: Tkinter variable instances
|
| 80 |
+
self.top.instance_dict = {}
|
| 81 |
+
self.recent_files_path = idleConf.userdir and os.path.join(
|
| 82 |
+
idleConf.userdir, 'recent-files.lst')
|
| 83 |
+
|
| 84 |
+
self.prompt_last_line = '' # Override in PyShell
|
| 85 |
+
self.text_frame = text_frame = Frame(top)
|
| 86 |
+
self.vbar = vbar = Scrollbar(text_frame, name='vbar')
|
| 87 |
+
width = idleConf.GetOption('main', 'EditorWindow', 'width', type='int')
|
| 88 |
+
text_options = {
|
| 89 |
+
'name': 'text',
|
| 90 |
+
'padx': 5,
|
| 91 |
+
'wrap': 'none',
|
| 92 |
+
'highlightthickness': 0,
|
| 93 |
+
'width': width,
|
| 94 |
+
'tabstyle': 'wordprocessor', # new in 8.5
|
| 95 |
+
'height': idleConf.GetOption(
|
| 96 |
+
'main', 'EditorWindow', 'height', type='int'),
|
| 97 |
+
}
|
| 98 |
+
self.text = text = MultiCallCreator(Text)(text_frame, **text_options)
|
| 99 |
+
self.top.focused_widget = self.text
|
| 100 |
+
|
| 101 |
+
self.createmenubar()
|
| 102 |
+
self.apply_bindings()
|
| 103 |
+
|
| 104 |
+
self.top.protocol("WM_DELETE_WINDOW", self.close)
|
| 105 |
+
self.top.bind("<<close-window>>", self.close_event)
|
| 106 |
+
if macosx.isAquaTk():
|
| 107 |
+
# Command-W on editor windows doesn't work without this.
|
| 108 |
+
text.bind('<<close-window>>', self.close_event)
|
| 109 |
+
# Some OS X systems have only one mouse button, so use
|
| 110 |
+
# control-click for popup context menus there. For two
|
| 111 |
+
# buttons, AquaTk defines <2> as the right button, not <3>.
|
| 112 |
+
text.bind("<Control-Button-1>",self.right_menu_event)
|
| 113 |
+
text.bind("<2>", self.right_menu_event)
|
| 114 |
+
else:
|
| 115 |
+
# Elsewhere, use right-click for popup menus.
|
| 116 |
+
text.bind("<3>",self.right_menu_event)
|
| 117 |
+
|
| 118 |
+
text.bind('<MouseWheel>', wheel_event)
|
| 119 |
+
if text._windowingsystem == 'x11':
|
| 120 |
+
text.bind('<Button-4>', wheel_event)
|
| 121 |
+
text.bind('<Button-5>', wheel_event)
|
| 122 |
+
text.bind('<Configure>', self.handle_winconfig)
|
| 123 |
+
text.bind("<<cut>>", self.cut)
|
| 124 |
+
text.bind("<<copy>>", self.copy)
|
| 125 |
+
text.bind("<<paste>>", self.paste)
|
| 126 |
+
text.bind("<<center-insert>>", self.center_insert_event)
|
| 127 |
+
text.bind("<<help>>", self.help_dialog)
|
| 128 |
+
text.bind("<<python-docs>>", self.python_docs)
|
| 129 |
+
text.bind("<<about-idle>>", self.about_dialog)
|
| 130 |
+
text.bind("<<open-config-dialog>>", self.config_dialog)
|
| 131 |
+
text.bind("<<open-module>>", self.open_module_event)
|
| 132 |
+
text.bind("<<do-nothing>>", lambda event: "break")
|
| 133 |
+
text.bind("<<select-all>>", self.select_all)
|
| 134 |
+
text.bind("<<remove-selection>>", self.remove_selection)
|
| 135 |
+
text.bind("<<find>>", self.find_event)
|
| 136 |
+
text.bind("<<find-again>>", self.find_again_event)
|
| 137 |
+
text.bind("<<find-in-files>>", self.find_in_files_event)
|
| 138 |
+
text.bind("<<find-selection>>", self.find_selection_event)
|
| 139 |
+
text.bind("<<replace>>", self.replace_event)
|
| 140 |
+
text.bind("<<goto-line>>", self.goto_line_event)
|
| 141 |
+
text.bind("<<smart-backspace>>",self.smart_backspace_event)
|
| 142 |
+
text.bind("<<newline-and-indent>>",self.newline_and_indent_event)
|
| 143 |
+
text.bind("<<smart-indent>>",self.smart_indent_event)
|
| 144 |
+
self.fregion = fregion = self.FormatRegion(self)
|
| 145 |
+
# self.fregion used in smart_indent_event to access indent_region.
|
| 146 |
+
text.bind("<<indent-region>>", fregion.indent_region_event)
|
| 147 |
+
text.bind("<<dedent-region>>", fregion.dedent_region_event)
|
| 148 |
+
text.bind("<<comment-region>>", fregion.comment_region_event)
|
| 149 |
+
text.bind("<<uncomment-region>>", fregion.uncomment_region_event)
|
| 150 |
+
text.bind("<<tabify-region>>", fregion.tabify_region_event)
|
| 151 |
+
text.bind("<<untabify-region>>", fregion.untabify_region_event)
|
| 152 |
+
indents = self.Indents(self)
|
| 153 |
+
text.bind("<<toggle-tabs>>", indents.toggle_tabs_event)
|
| 154 |
+
text.bind("<<change-indentwidth>>", indents.change_indentwidth_event)
|
| 155 |
+
text.bind("<Left>", self.move_at_edge_if_selection(0))
|
| 156 |
+
text.bind("<Right>", self.move_at_edge_if_selection(1))
|
| 157 |
+
text.bind("<<del-word-left>>", self.del_word_left)
|
| 158 |
+
text.bind("<<del-word-right>>", self.del_word_right)
|
| 159 |
+
text.bind("<<beginning-of-line>>", self.home_callback)
|
| 160 |
+
|
| 161 |
+
if flist:
|
| 162 |
+
flist.inversedict[self] = key
|
| 163 |
+
if key:
|
| 164 |
+
flist.dict[key] = self
|
| 165 |
+
text.bind("<<open-new-window>>", self.new_callback)
|
| 166 |
+
text.bind("<<close-all-windows>>", self.flist.close_all_callback)
|
| 167 |
+
text.bind("<<open-class-browser>>", self.open_module_browser)
|
| 168 |
+
text.bind("<<open-path-browser>>", self.open_path_browser)
|
| 169 |
+
text.bind("<<open-turtle-demo>>", self.open_turtle_demo)
|
| 170 |
+
|
| 171 |
+
self.set_status_bar()
|
| 172 |
+
text_frame.pack(side=LEFT, fill=BOTH, expand=1)
|
| 173 |
+
text_frame.rowconfigure(1, weight=1)
|
| 174 |
+
text_frame.columnconfigure(1, weight=1)
|
| 175 |
+
vbar['command'] = self.handle_yview
|
| 176 |
+
vbar.grid(row=1, column=2, sticky=NSEW)
|
| 177 |
+
text['yscrollcommand'] = vbar.set
|
| 178 |
+
text['font'] = idleConf.GetFont(self.root, 'main', 'EditorWindow')
|
| 179 |
+
text.grid(row=1, column=1, sticky=NSEW)
|
| 180 |
+
text.focus_set()
|
| 181 |
+
self.set_width()
|
| 182 |
+
|
| 183 |
+
# usetabs true -> literal tab characters are used by indent and
|
| 184 |
+
# dedent cmds, possibly mixed with spaces if
|
| 185 |
+
# indentwidth is not a multiple of tabwidth,
|
| 186 |
+
# which will cause Tabnanny to nag!
|
| 187 |
+
# false -> tab characters are converted to spaces by indent
|
| 188 |
+
# and dedent cmds, and ditto TAB keystrokes
|
| 189 |
+
# Although use-spaces=0 can be configured manually in config-main.def,
|
| 190 |
+
# configuration of tabs v. spaces is not supported in the configuration
|
| 191 |
+
# dialog. IDLE promotes the preferred Python indentation: use spaces!
|
| 192 |
+
usespaces = idleConf.GetOption('main', 'Indent',
|
| 193 |
+
'use-spaces', type='bool')
|
| 194 |
+
self.usetabs = not usespaces
|
| 195 |
+
|
| 196 |
+
# tabwidth is the display width of a literal tab character.
|
| 197 |
+
# CAUTION: telling Tk to use anything other than its default
|
| 198 |
+
# tab setting causes it to use an entirely different tabbing algorithm,
|
| 199 |
+
# treating tab stops as fixed distances from the left margin.
|
| 200 |
+
# Nobody expects this, so for now tabwidth should never be changed.
|
| 201 |
+
self.tabwidth = 8 # must remain 8 until Tk is fixed.
|
| 202 |
+
|
| 203 |
+
# indentwidth is the number of screen characters per indent level.
|
| 204 |
+
# The recommended Python indentation is four spaces.
|
| 205 |
+
self.indentwidth = self.tabwidth
|
| 206 |
+
self.set_notabs_indentwidth()
|
| 207 |
+
|
| 208 |
+
# Store the current value of the insertofftime now so we can restore
|
| 209 |
+
# it if needed.
|
| 210 |
+
if not hasattr(idleConf, 'blink_off_time'):
|
| 211 |
+
idleConf.blink_off_time = self.text['insertofftime']
|
| 212 |
+
self.update_cursor_blink()
|
| 213 |
+
|
| 214 |
+
# When searching backwards for a reliable place to begin parsing,
|
| 215 |
+
# first start num_context_lines[0] lines back, then
|
| 216 |
+
# num_context_lines[1] lines back if that didn't work, and so on.
|
| 217 |
+
# The last value should be huge (larger than the # of lines in a
|
| 218 |
+
# conceivable file).
|
| 219 |
+
# Making the initial values larger slows things down more often.
|
| 220 |
+
self.num_context_lines = 50, 500, 5000000
|
| 221 |
+
self.per = per = self.Percolator(text)
|
| 222 |
+
self.undo = undo = self.UndoDelegator()
|
| 223 |
+
per.insertfilter(undo)
|
| 224 |
+
text.undo_block_start = undo.undo_block_start
|
| 225 |
+
text.undo_block_stop = undo.undo_block_stop
|
| 226 |
+
undo.set_saved_change_hook(self.saved_change_hook)
|
| 227 |
+
# IOBinding implements file I/O and printing functionality
|
| 228 |
+
self.io = io = self.IOBinding(self)
|
| 229 |
+
io.set_filename_change_hook(self.filename_change_hook)
|
| 230 |
+
self.good_load = False
|
| 231 |
+
self.set_indentation_params(False)
|
| 232 |
+
self.color = None # initialized below in self.ResetColorizer
|
| 233 |
+
self.code_context = None # optionally initialized later below
|
| 234 |
+
self.line_numbers = None # optionally initialized later below
|
| 235 |
+
if filename:
|
| 236 |
+
if os.path.exists(filename) and not os.path.isdir(filename):
|
| 237 |
+
if io.loadfile(filename):
|
| 238 |
+
self.good_load = True
|
| 239 |
+
is_py_src = self.ispythonsource(filename)
|
| 240 |
+
self.set_indentation_params(is_py_src)
|
| 241 |
+
else:
|
| 242 |
+
io.set_filename(filename)
|
| 243 |
+
self.good_load = True
|
| 244 |
+
|
| 245 |
+
self.ResetColorizer()
|
| 246 |
+
self.saved_change_hook()
|
| 247 |
+
self.update_recent_files_list()
|
| 248 |
+
self.load_extensions()
|
| 249 |
+
menu = self.menudict.get('window')
|
| 250 |
+
if menu:
|
| 251 |
+
end = menu.index("end")
|
| 252 |
+
if end is None:
|
| 253 |
+
end = -1
|
| 254 |
+
if end >= 0:
|
| 255 |
+
menu.add_separator()
|
| 256 |
+
end = end + 1
|
| 257 |
+
self.wmenu_end = end
|
| 258 |
+
window.register_callback(self.postwindowsmenu)
|
| 259 |
+
|
| 260 |
+
# Some abstractions so IDLE extensions are cross-IDE
|
| 261 |
+
self.askinteger = simpledialog.askinteger
|
| 262 |
+
self.askyesno = messagebox.askyesno
|
| 263 |
+
self.showerror = messagebox.showerror
|
| 264 |
+
|
| 265 |
+
# Add pseudoevents for former extension fixed keys.
|
| 266 |
+
# (This probably needs to be done once in the process.)
|
| 267 |
+
text.event_add('<<autocomplete>>', '<Key-Tab>')
|
| 268 |
+
text.event_add('<<try-open-completions>>', '<KeyRelease-period>',
|
| 269 |
+
'<KeyRelease-slash>', '<KeyRelease-backslash>')
|
| 270 |
+
text.event_add('<<try-open-calltip>>', '<KeyRelease-parenleft>')
|
| 271 |
+
text.event_add('<<refresh-calltip>>', '<KeyRelease-parenright>')
|
| 272 |
+
text.event_add('<<paren-closed>>', '<KeyRelease-parenright>',
|
| 273 |
+
'<KeyRelease-bracketright>', '<KeyRelease-braceright>')
|
| 274 |
+
|
| 275 |
+
# Former extension bindings depends on frame.text being packed
|
| 276 |
+
# (called from self.ResetColorizer()).
|
| 277 |
+
autocomplete = self.AutoComplete(self, self.user_input_insert_tags)
|
| 278 |
+
text.bind("<<autocomplete>>", autocomplete.autocomplete_event)
|
| 279 |
+
text.bind("<<try-open-completions>>",
|
| 280 |
+
autocomplete.try_open_completions_event)
|
| 281 |
+
text.bind("<<force-open-completions>>",
|
| 282 |
+
autocomplete.force_open_completions_event)
|
| 283 |
+
text.bind("<<expand-word>>", self.AutoExpand(self).expand_word_event)
|
| 284 |
+
text.bind("<<format-paragraph>>",
|
| 285 |
+
self.FormatParagraph(self).format_paragraph_event)
|
| 286 |
+
parenmatch = self.ParenMatch(self)
|
| 287 |
+
text.bind("<<flash-paren>>", parenmatch.flash_paren_event)
|
| 288 |
+
text.bind("<<paren-closed>>", parenmatch.paren_closed_event)
|
| 289 |
+
scriptbinding = ScriptBinding(self)
|
| 290 |
+
text.bind("<<check-module>>", scriptbinding.check_module_event)
|
| 291 |
+
text.bind("<<run-module>>", scriptbinding.run_module_event)
|
| 292 |
+
text.bind("<<run-custom>>", scriptbinding.run_custom_event)
|
| 293 |
+
text.bind("<<do-rstrip>>", self.Rstrip(self).do_rstrip)
|
| 294 |
+
self.ctip = ctip = self.Calltip(self)
|
| 295 |
+
text.bind("<<try-open-calltip>>", ctip.try_open_calltip_event)
|
| 296 |
+
#refresh-calltip must come after paren-closed to work right
|
| 297 |
+
text.bind("<<refresh-calltip>>", ctip.refresh_calltip_event)
|
| 298 |
+
text.bind("<<force-open-calltip>>", ctip.force_open_calltip_event)
|
| 299 |
+
text.bind("<<zoom-height>>", self.ZoomHeight(self).zoom_height_event)
|
| 300 |
+
if self.allow_code_context:
|
| 301 |
+
self.code_context = self.CodeContext(self)
|
| 302 |
+
text.bind("<<toggle-code-context>>",
|
| 303 |
+
self.code_context.toggle_code_context_event)
|
| 304 |
+
else:
|
| 305 |
+
self.update_menu_state('options', '*ode*ontext', 'disabled')
|
| 306 |
+
if self.allow_line_numbers:
|
| 307 |
+
self.line_numbers = self.LineNumbers(self)
|
| 308 |
+
if idleConf.GetOption('main', 'EditorWindow',
|
| 309 |
+
'line-numbers-default', type='bool'):
|
| 310 |
+
self.toggle_line_numbers_event()
|
| 311 |
+
text.bind("<<toggle-line-numbers>>", self.toggle_line_numbers_event)
|
| 312 |
+
else:
|
| 313 |
+
self.update_menu_state('options', '*ine*umbers', 'disabled')
|
| 314 |
+
|
| 315 |
+
def handle_winconfig(self, event=None):
|
| 316 |
+
self.set_width()
|
| 317 |
+
|
| 318 |
+
def set_width(self):
|
| 319 |
+
text = self.text
|
| 320 |
+
inner_padding = sum(map(text.tk.getint, [text.cget('border'),
|
| 321 |
+
text.cget('padx')]))
|
| 322 |
+
pixel_width = text.winfo_width() - 2 * inner_padding
|
| 323 |
+
|
| 324 |
+
# Divide the width of the Text widget by the font width,
|
| 325 |
+
# which is taken to be the width of '0' (zero).
|
| 326 |
+
# http://www.tcl.tk/man/tcl8.6/TkCmd/text.htm#M21
|
| 327 |
+
zero_char_width = \
|
| 328 |
+
Font(text, font=text.cget('font')).measure('0')
|
| 329 |
+
self.width = pixel_width // zero_char_width
|
| 330 |
+
|
| 331 |
+
def new_callback(self, event):
|
| 332 |
+
dirname, basename = self.io.defaultfilename()
|
| 333 |
+
self.flist.new(dirname)
|
| 334 |
+
return "break"
|
| 335 |
+
|
| 336 |
+
def home_callback(self, event):
|
| 337 |
+
if (event.state & 4) != 0 and event.keysym == "Home":
|
| 338 |
+
# state&4==Control. If <Control-Home>, use the Tk binding.
|
| 339 |
+
return None
|
| 340 |
+
if self.text.index("iomark") and \
|
| 341 |
+
self.text.compare("iomark", "<=", "insert lineend") and \
|
| 342 |
+
self.text.compare("insert linestart", "<=", "iomark"):
|
| 343 |
+
# In Shell on input line, go to just after prompt
|
| 344 |
+
insertpt = int(self.text.index("iomark").split(".")[1])
|
| 345 |
+
else:
|
| 346 |
+
line = self.text.get("insert linestart", "insert lineend")
|
| 347 |
+
for insertpt in range(len(line)):
|
| 348 |
+
if line[insertpt] not in (' ','\t'):
|
| 349 |
+
break
|
| 350 |
+
else:
|
| 351 |
+
insertpt=len(line)
|
| 352 |
+
lineat = int(self.text.index("insert").split('.')[1])
|
| 353 |
+
if insertpt == lineat:
|
| 354 |
+
insertpt = 0
|
| 355 |
+
dest = "insert linestart+"+str(insertpt)+"c"
|
| 356 |
+
if (event.state&1) == 0:
|
| 357 |
+
# shift was not pressed
|
| 358 |
+
self.text.tag_remove("sel", "1.0", "end")
|
| 359 |
+
else:
|
| 360 |
+
if not self.text.index("sel.first"):
|
| 361 |
+
# there was no previous selection
|
| 362 |
+
self.text.mark_set("my_anchor", "insert")
|
| 363 |
+
else:
|
| 364 |
+
if self.text.compare(self.text.index("sel.first"), "<",
|
| 365 |
+
self.text.index("insert")):
|
| 366 |
+
self.text.mark_set("my_anchor", "sel.first") # extend back
|
| 367 |
+
else:
|
| 368 |
+
self.text.mark_set("my_anchor", "sel.last") # extend forward
|
| 369 |
+
first = self.text.index(dest)
|
| 370 |
+
last = self.text.index("my_anchor")
|
| 371 |
+
if self.text.compare(first,">",last):
|
| 372 |
+
first,last = last,first
|
| 373 |
+
self.text.tag_remove("sel", "1.0", "end")
|
| 374 |
+
self.text.tag_add("sel", first, last)
|
| 375 |
+
self.text.mark_set("insert", dest)
|
| 376 |
+
self.text.see("insert")
|
| 377 |
+
return "break"
|
| 378 |
+
|
| 379 |
+
def set_status_bar(self):
|
| 380 |
+
self.status_bar = self.MultiStatusBar(self.top)
|
| 381 |
+
sep = Frame(self.top, height=1, borderwidth=1, background='grey75')
|
| 382 |
+
if sys.platform == "darwin":
|
| 383 |
+
# Insert some padding to avoid obscuring some of the statusbar
|
| 384 |
+
# by the resize widget.
|
| 385 |
+
self.status_bar.set_label('_padding1', ' ', side=RIGHT)
|
| 386 |
+
self.status_bar.set_label('column', 'Col: ?', side=RIGHT)
|
| 387 |
+
self.status_bar.set_label('line', 'Ln: ?', side=RIGHT)
|
| 388 |
+
self.status_bar.pack(side=BOTTOM, fill=X)
|
| 389 |
+
sep.pack(side=BOTTOM, fill=X)
|
| 390 |
+
self.text.bind("<<set-line-and-column>>", self.set_line_and_column)
|
| 391 |
+
self.text.event_add("<<set-line-and-column>>",
|
| 392 |
+
"<KeyRelease>", "<ButtonRelease>")
|
| 393 |
+
self.text.after_idle(self.set_line_and_column)
|
| 394 |
+
|
| 395 |
+
def set_line_and_column(self, event=None):
|
| 396 |
+
line, column = self.text.index(INSERT).split('.')
|
| 397 |
+
self.status_bar.set_label('column', 'Col: %s' % column)
|
| 398 |
+
self.status_bar.set_label('line', 'Ln: %s' % line)
|
| 399 |
+
|
| 400 |
+
|
| 401 |
+
""" Menu definitions and functions.
|
| 402 |
+
* self.menubar - the always visible horizontal menu bar.
|
| 403 |
+
* mainmenu.menudefs - a list of tuples, one for each menubar item.
|
| 404 |
+
Each tuple pairs a lower-case name and list of dropdown items.
|
| 405 |
+
Each item is a name, virtual event pair or None for separator.
|
| 406 |
+
* mainmenu.default_keydefs - maps events to keys.
|
| 407 |
+
* text.keydefs - same.
|
| 408 |
+
* cls.menu_specs - menubar name, titlecase display form pairs
|
| 409 |
+
with Alt-hotkey indicator. A subset of menudefs items.
|
| 410 |
+
* self.menudict - map menu name to dropdown menu.
|
| 411 |
+
* self.recent_files_menu - 2nd level cascade in the file cascade.
|
| 412 |
+
* self.wmenu_end - set in __init__ (purpose unclear).
|
| 413 |
+
|
| 414 |
+
createmenubar, postwindowsmenu, update_menu_label, update_menu_state,
|
| 415 |
+
ApplyKeybings (2nd part), reset_help_menu_entries,
|
| 416 |
+
_extra_help_callback, update_recent_files_list,
|
| 417 |
+
apply_bindings, fill_menus, (other functions?)
|
| 418 |
+
"""
|
| 419 |
+
|
| 420 |
+
menu_specs = [
|
| 421 |
+
("file", "_File"),
|
| 422 |
+
("edit", "_Edit"),
|
| 423 |
+
("format", "F_ormat"),
|
| 424 |
+
("run", "_Run"),
|
| 425 |
+
("options", "_Options"),
|
| 426 |
+
("window", "_Window"),
|
| 427 |
+
("help", "_Help"),
|
| 428 |
+
]
|
| 429 |
+
|
| 430 |
+
def createmenubar(self):
|
| 431 |
+
"""Populate the menu bar widget for the editor window.
|
| 432 |
+
|
| 433 |
+
Each option on the menubar is itself a cascade-type Menu widget
|
| 434 |
+
with the menubar as the parent. The names, labels, and menu
|
| 435 |
+
shortcuts for the menubar items are stored in menu_specs. Each
|
| 436 |
+
submenu is subsequently populated in fill_menus(), except for
|
| 437 |
+
'Recent Files' which is added to the File menu here.
|
| 438 |
+
|
| 439 |
+
Instance variables:
|
| 440 |
+
menubar: Menu widget containing first level menu items.
|
| 441 |
+
menudict: Dictionary of {menuname: Menu instance} items. The keys
|
| 442 |
+
represent the valid menu items for this window and may be a
|
| 443 |
+
subset of all the menudefs available.
|
| 444 |
+
recent_files_menu: Menu widget contained within the 'file' menudict.
|
| 445 |
+
"""
|
| 446 |
+
mbar = self.menubar
|
| 447 |
+
self.menudict = menudict = {}
|
| 448 |
+
for name, label in self.menu_specs:
|
| 449 |
+
underline, label = prepstr(label)
|
| 450 |
+
postcommand = getattr(self, f'{name}_menu_postcommand', None)
|
| 451 |
+
menudict[name] = menu = Menu(mbar, name=name, tearoff=0,
|
| 452 |
+
postcommand=postcommand)
|
| 453 |
+
mbar.add_cascade(label=label, menu=menu, underline=underline)
|
| 454 |
+
if macosx.isCarbonTk():
|
| 455 |
+
# Insert the application menu
|
| 456 |
+
menudict['application'] = menu = Menu(mbar, name='apple',
|
| 457 |
+
tearoff=0)
|
| 458 |
+
mbar.add_cascade(label='IDLE', menu=menu)
|
| 459 |
+
self.fill_menus()
|
| 460 |
+
self.recent_files_menu = Menu(self.menubar, tearoff=0)
|
| 461 |
+
self.menudict['file'].insert_cascade(3, label='Recent Files',
|
| 462 |
+
underline=0,
|
| 463 |
+
menu=self.recent_files_menu)
|
| 464 |
+
self.base_helpmenu_length = self.menudict['help'].index(END)
|
| 465 |
+
self.reset_help_menu_entries()
|
| 466 |
+
|
| 467 |
+
def postwindowsmenu(self):
|
| 468 |
+
"""Callback to register window.
|
| 469 |
+
|
| 470 |
+
Only called when Window menu exists.
|
| 471 |
+
"""
|
| 472 |
+
menu = self.menudict['window']
|
| 473 |
+
end = menu.index("end")
|
| 474 |
+
if end is None:
|
| 475 |
+
end = -1
|
| 476 |
+
if end > self.wmenu_end:
|
| 477 |
+
menu.delete(self.wmenu_end+1, end)
|
| 478 |
+
window.add_windows_to_menu(menu)
|
| 479 |
+
|
| 480 |
+
def update_menu_label(self, menu, index, label):
|
| 481 |
+
"Update label for menu item at index."
|
| 482 |
+
menuitem = self.menudict[menu]
|
| 483 |
+
menuitem.entryconfig(index, label=label)
|
| 484 |
+
|
| 485 |
+
def update_menu_state(self, menu, index, state):
|
| 486 |
+
"Update state for menu item at index."
|
| 487 |
+
menuitem = self.menudict[menu]
|
| 488 |
+
menuitem.entryconfig(index, state=state)
|
| 489 |
+
|
| 490 |
+
def handle_yview(self, event, *args):
|
| 491 |
+
"Handle scrollbar."
|
| 492 |
+
if event == 'moveto':
|
| 493 |
+
fraction = float(args[0])
|
| 494 |
+
lines = (round(self.getlineno('end') * fraction) -
|
| 495 |
+
self.getlineno('@0,0'))
|
| 496 |
+
event = 'scroll'
|
| 497 |
+
args = (lines, 'units')
|
| 498 |
+
self.text.yview(event, *args)
|
| 499 |
+
return 'break'
|
| 500 |
+
|
| 501 |
+
rmenu = None
|
| 502 |
+
|
| 503 |
+
def right_menu_event(self, event):
|
| 504 |
+
text = self.text
|
| 505 |
+
newdex = text.index(f'@{event.x},{event.y}')
|
| 506 |
+
try:
|
| 507 |
+
in_selection = (text.compare('sel.first', '<=', newdex) and
|
| 508 |
+
text.compare(newdex, '<=', 'sel.last'))
|
| 509 |
+
except TclError:
|
| 510 |
+
in_selection = False
|
| 511 |
+
if not in_selection:
|
| 512 |
+
text.tag_remove("sel", "1.0", "end")
|
| 513 |
+
text.mark_set("insert", newdex)
|
| 514 |
+
if not self.rmenu:
|
| 515 |
+
self.make_rmenu()
|
| 516 |
+
rmenu = self.rmenu
|
| 517 |
+
self.event = event
|
| 518 |
+
iswin = sys.platform[:3] == 'win'
|
| 519 |
+
if iswin:
|
| 520 |
+
text.config(cursor="arrow")
|
| 521 |
+
|
| 522 |
+
for item in self.rmenu_specs:
|
| 523 |
+
try:
|
| 524 |
+
label, eventname, verify_state = item
|
| 525 |
+
except ValueError: # see issue1207589
|
| 526 |
+
continue
|
| 527 |
+
|
| 528 |
+
if verify_state is None:
|
| 529 |
+
continue
|
| 530 |
+
state = getattr(self, verify_state)()
|
| 531 |
+
rmenu.entryconfigure(label, state=state)
|
| 532 |
+
|
| 533 |
+
rmenu.tk_popup(event.x_root, event.y_root)
|
| 534 |
+
if iswin:
|
| 535 |
+
self.text.config(cursor="ibeam")
|
| 536 |
+
return "break"
|
| 537 |
+
|
| 538 |
+
rmenu_specs = [
|
| 539 |
+
# ("Label", "<<virtual-event>>", "statefuncname"), ...
|
| 540 |
+
("Close", "<<close-window>>", None), # Example
|
| 541 |
+
]
|
| 542 |
+
|
| 543 |
+
def make_rmenu(self):
|
| 544 |
+
rmenu = Menu(self.text, tearoff=0)
|
| 545 |
+
for item in self.rmenu_specs:
|
| 546 |
+
label, eventname = item[0], item[1]
|
| 547 |
+
if label is not None:
|
| 548 |
+
def command(text=self.text, eventname=eventname):
|
| 549 |
+
text.event_generate(eventname)
|
| 550 |
+
rmenu.add_command(label=label, command=command)
|
| 551 |
+
else:
|
| 552 |
+
rmenu.add_separator()
|
| 553 |
+
self.rmenu = rmenu
|
| 554 |
+
|
| 555 |
+
def rmenu_check_cut(self):
|
| 556 |
+
return self.rmenu_check_copy()
|
| 557 |
+
|
| 558 |
+
def rmenu_check_copy(self):
|
| 559 |
+
try:
|
| 560 |
+
indx = self.text.index('sel.first')
|
| 561 |
+
except TclError:
|
| 562 |
+
return 'disabled'
|
| 563 |
+
else:
|
| 564 |
+
return 'normal' if indx else 'disabled'
|
| 565 |
+
|
| 566 |
+
def rmenu_check_paste(self):
|
| 567 |
+
try:
|
| 568 |
+
self.text.tk.call('tk::GetSelection', self.text, 'CLIPBOARD')
|
| 569 |
+
except TclError:
|
| 570 |
+
return 'disabled'
|
| 571 |
+
else:
|
| 572 |
+
return 'normal'
|
| 573 |
+
|
| 574 |
+
def about_dialog(self, event=None):
|
| 575 |
+
"Handle Help 'About IDLE' event."
|
| 576 |
+
# Synchronize with macosx.overrideRootMenu.about_dialog.
|
| 577 |
+
help_about.AboutDialog(self.top)
|
| 578 |
+
return "break"
|
| 579 |
+
|
| 580 |
+
def config_dialog(self, event=None):
|
| 581 |
+
"Handle Options 'Configure IDLE' event."
|
| 582 |
+
# Synchronize with macosx.overrideRootMenu.config_dialog.
|
| 583 |
+
configdialog.ConfigDialog(self.top,'Settings')
|
| 584 |
+
return "break"
|
| 585 |
+
|
| 586 |
+
def help_dialog(self, event=None):
|
| 587 |
+
"Handle Help 'IDLE Help' event."
|
| 588 |
+
# Synchronize with macosx.overrideRootMenu.help_dialog.
|
| 589 |
+
if self.root:
|
| 590 |
+
parent = self.root
|
| 591 |
+
else:
|
| 592 |
+
parent = self.top
|
| 593 |
+
help.show_idlehelp(parent)
|
| 594 |
+
return "break"
|
| 595 |
+
|
| 596 |
+
def python_docs(self, event=None):
|
| 597 |
+
if sys.platform[:3] == 'win':
|
| 598 |
+
try:
|
| 599 |
+
os.startfile(self.help_url)
|
| 600 |
+
except OSError as why:
|
| 601 |
+
messagebox.showerror(title='Document Start Failure',
|
| 602 |
+
message=str(why), parent=self.text)
|
| 603 |
+
else:
|
| 604 |
+
webbrowser.open(self.help_url)
|
| 605 |
+
return "break"
|
| 606 |
+
|
| 607 |
+
def cut(self,event):
|
| 608 |
+
self.text.event_generate("<<Cut>>")
|
| 609 |
+
return "break"
|
| 610 |
+
|
| 611 |
+
def copy(self,event):
|
| 612 |
+
if not self.text.tag_ranges("sel"):
|
| 613 |
+
# There is no selection, so do nothing and maybe interrupt.
|
| 614 |
+
return None
|
| 615 |
+
self.text.event_generate("<<Copy>>")
|
| 616 |
+
return "break"
|
| 617 |
+
|
| 618 |
+
def paste(self,event):
|
| 619 |
+
self.text.event_generate("<<Paste>>")
|
| 620 |
+
self.text.see("insert")
|
| 621 |
+
return "break"
|
| 622 |
+
|
| 623 |
+
def select_all(self, event=None):
|
| 624 |
+
self.text.tag_add("sel", "1.0", "end-1c")
|
| 625 |
+
self.text.mark_set("insert", "1.0")
|
| 626 |
+
self.text.see("insert")
|
| 627 |
+
return "break"
|
| 628 |
+
|
| 629 |
+
def remove_selection(self, event=None):
|
| 630 |
+
self.text.tag_remove("sel", "1.0", "end")
|
| 631 |
+
self.text.see("insert")
|
| 632 |
+
return "break"
|
| 633 |
+
|
| 634 |
+
def move_at_edge_if_selection(self, edge_index):
|
| 635 |
+
"""Cursor move begins at start or end of selection
|
| 636 |
+
|
| 637 |
+
When a left/right cursor key is pressed create and return to Tkinter a
|
| 638 |
+
function which causes a cursor move from the associated edge of the
|
| 639 |
+
selection.
|
| 640 |
+
|
| 641 |
+
"""
|
| 642 |
+
self_text_index = self.text.index
|
| 643 |
+
self_text_mark_set = self.text.mark_set
|
| 644 |
+
edges_table = ("sel.first+1c", "sel.last-1c")
|
| 645 |
+
def move_at_edge(event):
|
| 646 |
+
if (event.state & 5) == 0: # no shift(==1) or control(==4) pressed
|
| 647 |
+
try:
|
| 648 |
+
self_text_index("sel.first")
|
| 649 |
+
self_text_mark_set("insert", edges_table[edge_index])
|
| 650 |
+
except TclError:
|
| 651 |
+
pass
|
| 652 |
+
return move_at_edge
|
| 653 |
+
|
| 654 |
+
def del_word_left(self, event):
|
| 655 |
+
self.text.event_generate('<Meta-Delete>')
|
| 656 |
+
return "break"
|
| 657 |
+
|
| 658 |
+
def del_word_right(self, event):
|
| 659 |
+
self.text.event_generate('<Meta-d>')
|
| 660 |
+
return "break"
|
| 661 |
+
|
| 662 |
+
def find_event(self, event):
|
| 663 |
+
search.find(self.text)
|
| 664 |
+
return "break"
|
| 665 |
+
|
| 666 |
+
def find_again_event(self, event):
|
| 667 |
+
search.find_again(self.text)
|
| 668 |
+
return "break"
|
| 669 |
+
|
| 670 |
+
def find_selection_event(self, event):
|
| 671 |
+
search.find_selection(self.text)
|
| 672 |
+
return "break"
|
| 673 |
+
|
| 674 |
+
def find_in_files_event(self, event):
|
| 675 |
+
grep.grep(self.text, self.io, self.flist)
|
| 676 |
+
return "break"
|
| 677 |
+
|
| 678 |
+
def replace_event(self, event):
|
| 679 |
+
replace.replace(self.text)
|
| 680 |
+
return "break"
|
| 681 |
+
|
| 682 |
+
def goto_line_event(self, event):
|
| 683 |
+
text = self.text
|
| 684 |
+
lineno = query.Goto(
|
| 685 |
+
text, "Go To Line",
|
| 686 |
+
"Enter a positive integer\n"
|
| 687 |
+
"('big' = end of file):"
|
| 688 |
+
).result
|
| 689 |
+
if lineno is not None:
|
| 690 |
+
text.tag_remove("sel", "1.0", "end")
|
| 691 |
+
text.mark_set("insert", f'{lineno}.0')
|
| 692 |
+
text.see("insert")
|
| 693 |
+
self.set_line_and_column()
|
| 694 |
+
return "break"
|
| 695 |
+
|
| 696 |
+
def open_module(self):
|
| 697 |
+
"""Get module name from user and open it.
|
| 698 |
+
|
| 699 |
+
Return module path or None for calls by open_module_browser
|
| 700 |
+
when latter is not invoked in named editor window.
|
| 701 |
+
"""
|
| 702 |
+
# XXX This, open_module_browser, and open_path_browser
|
| 703 |
+
# would fit better in iomenu.IOBinding.
|
| 704 |
+
try:
|
| 705 |
+
name = self.text.get("sel.first", "sel.last").strip()
|
| 706 |
+
except TclError:
|
| 707 |
+
name = ''
|
| 708 |
+
file_path = query.ModuleName(
|
| 709 |
+
self.text, "Open Module",
|
| 710 |
+
"Enter the name of a Python module\n"
|
| 711 |
+
"to search on sys.path and open:",
|
| 712 |
+
name).result
|
| 713 |
+
if file_path is not None:
|
| 714 |
+
if self.flist:
|
| 715 |
+
self.flist.open(file_path)
|
| 716 |
+
else:
|
| 717 |
+
self.io.loadfile(file_path)
|
| 718 |
+
return file_path
|
| 719 |
+
|
| 720 |
+
def open_module_event(self, event):
|
| 721 |
+
self.open_module()
|
| 722 |
+
return "break"
|
| 723 |
+
|
| 724 |
+
def open_module_browser(self, event=None):
|
| 725 |
+
filename = self.io.filename
|
| 726 |
+
if not (self.__class__.__name__ == 'PyShellEditorWindow'
|
| 727 |
+
and filename):
|
| 728 |
+
filename = self.open_module()
|
| 729 |
+
if filename is None:
|
| 730 |
+
return "break"
|
| 731 |
+
from idlelib import browser
|
| 732 |
+
browser.ModuleBrowser(self.root, filename)
|
| 733 |
+
return "break"
|
| 734 |
+
|
| 735 |
+
def open_path_browser(self, event=None):
|
| 736 |
+
from idlelib import pathbrowser
|
| 737 |
+
pathbrowser.PathBrowser(self.root)
|
| 738 |
+
return "break"
|
| 739 |
+
|
| 740 |
+
def open_turtle_demo(self, event = None):
|
| 741 |
+
import subprocess
|
| 742 |
+
|
| 743 |
+
cmd = [sys.executable,
|
| 744 |
+
'-c',
|
| 745 |
+
'from turtledemo.__main__ import main; main()']
|
| 746 |
+
subprocess.Popen(cmd, shell=False)
|
| 747 |
+
return "break"
|
| 748 |
+
|
| 749 |
+
def gotoline(self, lineno):
|
| 750 |
+
if lineno is not None and lineno > 0:
|
| 751 |
+
self.text.mark_set("insert", "%d.0" % lineno)
|
| 752 |
+
self.text.tag_remove("sel", "1.0", "end")
|
| 753 |
+
self.text.tag_add("sel", "insert", "insert +1l")
|
| 754 |
+
self.center()
|
| 755 |
+
|
| 756 |
+
def ispythonsource(self, filename):
|
| 757 |
+
if not filename or os.path.isdir(filename):
|
| 758 |
+
return True
|
| 759 |
+
base, ext = os.path.splitext(os.path.basename(filename))
|
| 760 |
+
if os.path.normcase(ext) in py_extensions:
|
| 761 |
+
return True
|
| 762 |
+
line = self.text.get('1.0', '1.0 lineend')
|
| 763 |
+
return line.startswith('#!') and 'python' in line
|
| 764 |
+
|
| 765 |
+
def close_hook(self):
|
| 766 |
+
if self.flist:
|
| 767 |
+
self.flist.unregister_maybe_terminate(self)
|
| 768 |
+
self.flist = None
|
| 769 |
+
|
| 770 |
+
def set_close_hook(self, close_hook):
|
| 771 |
+
self.close_hook = close_hook
|
| 772 |
+
|
| 773 |
+
def filename_change_hook(self):
|
| 774 |
+
if self.flist:
|
| 775 |
+
self.flist.filename_changed_edit(self)
|
| 776 |
+
self.saved_change_hook()
|
| 777 |
+
self.top.update_windowlist_registry(self)
|
| 778 |
+
self.ResetColorizer()
|
| 779 |
+
|
| 780 |
+
def _addcolorizer(self):
|
| 781 |
+
if self.color:
|
| 782 |
+
return
|
| 783 |
+
if self.ispythonsource(self.io.filename):
|
| 784 |
+
self.color = self.ColorDelegator()
|
| 785 |
+
# can add more colorizers here...
|
| 786 |
+
if self.color:
|
| 787 |
+
self.per.insertfilterafter(filter=self.color, after=self.undo)
|
| 788 |
+
|
| 789 |
+
def _rmcolorizer(self):
|
| 790 |
+
if not self.color:
|
| 791 |
+
return
|
| 792 |
+
self.color.removecolors()
|
| 793 |
+
self.per.removefilter(self.color)
|
| 794 |
+
self.color = None
|
| 795 |
+
|
| 796 |
+
def ResetColorizer(self):
|
| 797 |
+
"Update the color theme"
|
| 798 |
+
# Called from self.filename_change_hook and from configdialog.py
|
| 799 |
+
self._rmcolorizer()
|
| 800 |
+
self._addcolorizer()
|
| 801 |
+
EditorWindow.color_config(self.text)
|
| 802 |
+
|
| 803 |
+
if self.code_context is not None:
|
| 804 |
+
self.code_context.update_highlight_colors()
|
| 805 |
+
|
| 806 |
+
if self.line_numbers is not None:
|
| 807 |
+
self.line_numbers.update_colors()
|
| 808 |
+
|
| 809 |
+
IDENTCHARS = string.ascii_letters + string.digits + "_"
|
| 810 |
+
|
| 811 |
+
def colorize_syntax_error(self, text, pos):
|
| 812 |
+
text.tag_add("ERROR", pos)
|
| 813 |
+
char = text.get(pos)
|
| 814 |
+
if char and char in self.IDENTCHARS:
|
| 815 |
+
text.tag_add("ERROR", pos + " wordstart", pos)
|
| 816 |
+
if '\n' == text.get(pos): # error at line end
|
| 817 |
+
text.mark_set("insert", pos)
|
| 818 |
+
else:
|
| 819 |
+
text.mark_set("insert", pos + "+1c")
|
| 820 |
+
text.see(pos)
|
| 821 |
+
|
| 822 |
+
def update_cursor_blink(self):
|
| 823 |
+
"Update the cursor blink configuration."
|
| 824 |
+
cursorblink = idleConf.GetOption(
|
| 825 |
+
'main', 'EditorWindow', 'cursor-blink', type='bool')
|
| 826 |
+
if not cursorblink:
|
| 827 |
+
self.text['insertofftime'] = 0
|
| 828 |
+
else:
|
| 829 |
+
# Restore the original value
|
| 830 |
+
self.text['insertofftime'] = idleConf.blink_off_time
|
| 831 |
+
|
| 832 |
+
def ResetFont(self):
|
| 833 |
+
"Update the text widgets' font if it is changed"
|
| 834 |
+
# Called from configdialog.py
|
| 835 |
+
|
| 836 |
+
# Update the code context widget first, since its height affects
|
| 837 |
+
# the height of the text widget. This avoids double re-rendering.
|
| 838 |
+
if self.code_context is not None:
|
| 839 |
+
self.code_context.update_font()
|
| 840 |
+
# Next, update the line numbers widget, since its width affects
|
| 841 |
+
# the width of the text widget.
|
| 842 |
+
if self.line_numbers is not None:
|
| 843 |
+
self.line_numbers.update_font()
|
| 844 |
+
# Finally, update the main text widget.
|
| 845 |
+
new_font = idleConf.GetFont(self.root, 'main', 'EditorWindow')
|
| 846 |
+
self.text['font'] = new_font
|
| 847 |
+
self.set_width()
|
| 848 |
+
|
| 849 |
+
def RemoveKeybindings(self):
|
| 850 |
+
"""Remove the virtual, configurable keybindings.
|
| 851 |
+
|
| 852 |
+
Leaves the default Tk Text keybindings.
|
| 853 |
+
"""
|
| 854 |
+
# Called from configdialog.deactivate_current_config.
|
| 855 |
+
self.mainmenu.default_keydefs = keydefs = idleConf.GetCurrentKeySet()
|
| 856 |
+
for event, keylist in keydefs.items():
|
| 857 |
+
self.text.event_delete(event, *keylist)
|
| 858 |
+
for extensionName in self.get_standard_extension_names():
|
| 859 |
+
xkeydefs = idleConf.GetExtensionBindings(extensionName)
|
| 860 |
+
if xkeydefs:
|
| 861 |
+
for event, keylist in xkeydefs.items():
|
| 862 |
+
self.text.event_delete(event, *keylist)
|
| 863 |
+
|
| 864 |
+
def ApplyKeybindings(self):
|
| 865 |
+
"""Apply the virtual, configurable keybindings.
|
| 866 |
+
|
| 867 |
+
Also update hotkeys to current keyset.
|
| 868 |
+
"""
|
| 869 |
+
# Called from configdialog.activate_config_changes.
|
| 870 |
+
self.mainmenu.default_keydefs = keydefs = idleConf.GetCurrentKeySet()
|
| 871 |
+
self.apply_bindings()
|
| 872 |
+
for extensionName in self.get_standard_extension_names():
|
| 873 |
+
xkeydefs = idleConf.GetExtensionBindings(extensionName)
|
| 874 |
+
if xkeydefs:
|
| 875 |
+
self.apply_bindings(xkeydefs)
|
| 876 |
+
|
| 877 |
+
# Update menu accelerators.
|
| 878 |
+
menuEventDict = {}
|
| 879 |
+
for menu in self.mainmenu.menudefs:
|
| 880 |
+
menuEventDict[menu[0]] = {}
|
| 881 |
+
for item in menu[1]:
|
| 882 |
+
if item:
|
| 883 |
+
menuEventDict[menu[0]][prepstr(item[0])[1]] = item[1]
|
| 884 |
+
for menubarItem in self.menudict:
|
| 885 |
+
menu = self.menudict[menubarItem]
|
| 886 |
+
end = menu.index(END)
|
| 887 |
+
if end is None:
|
| 888 |
+
# Skip empty menus
|
| 889 |
+
continue
|
| 890 |
+
end += 1
|
| 891 |
+
for index in range(0, end):
|
| 892 |
+
if menu.type(index) == 'command':
|
| 893 |
+
accel = menu.entrycget(index, 'accelerator')
|
| 894 |
+
if accel:
|
| 895 |
+
itemName = menu.entrycget(index, 'label')
|
| 896 |
+
event = ''
|
| 897 |
+
if menubarItem in menuEventDict:
|
| 898 |
+
if itemName in menuEventDict[menubarItem]:
|
| 899 |
+
event = menuEventDict[menubarItem][itemName]
|
| 900 |
+
if event:
|
| 901 |
+
accel = get_accelerator(keydefs, event)
|
| 902 |
+
menu.entryconfig(index, accelerator=accel)
|
| 903 |
+
|
| 904 |
+
def set_notabs_indentwidth(self):
|
| 905 |
+
"Update the indentwidth if changed and not using tabs in this window"
|
| 906 |
+
# Called from configdialog.py
|
| 907 |
+
if not self.usetabs:
|
| 908 |
+
self.indentwidth = idleConf.GetOption('main', 'Indent','num-spaces',
|
| 909 |
+
type='int')
|
| 910 |
+
|
| 911 |
+
def reset_help_menu_entries(self):
|
| 912 |
+
"""Update the additional help entries on the Help menu."""
|
| 913 |
+
help_list = idleConf.GetAllExtraHelpSourcesList()
|
| 914 |
+
helpmenu = self.menudict['help']
|
| 915 |
+
# First delete the extra help entries, if any.
|
| 916 |
+
helpmenu_length = helpmenu.index(END)
|
| 917 |
+
if helpmenu_length > self.base_helpmenu_length:
|
| 918 |
+
helpmenu.delete((self.base_helpmenu_length + 1), helpmenu_length)
|
| 919 |
+
# Then rebuild them.
|
| 920 |
+
if help_list:
|
| 921 |
+
helpmenu.add_separator()
|
| 922 |
+
for entry in help_list:
|
| 923 |
+
cmd = self._extra_help_callback(entry[1])
|
| 924 |
+
helpmenu.add_command(label=entry[0], command=cmd)
|
| 925 |
+
# And update the menu dictionary.
|
| 926 |
+
self.menudict['help'] = helpmenu
|
| 927 |
+
|
| 928 |
+
def _extra_help_callback(self, resource):
|
| 929 |
+
"""Return a callback that loads resource (file or web page)."""
|
| 930 |
+
def display_extra_help(helpfile=resource):
|
| 931 |
+
if not helpfile.startswith(('www', 'http')):
|
| 932 |
+
helpfile = os.path.normpath(helpfile)
|
| 933 |
+
if sys.platform[:3] == 'win':
|
| 934 |
+
try:
|
| 935 |
+
os.startfile(helpfile)
|
| 936 |
+
except OSError as why:
|
| 937 |
+
messagebox.showerror(title='Document Start Failure',
|
| 938 |
+
message=str(why), parent=self.text)
|
| 939 |
+
else:
|
| 940 |
+
webbrowser.open(helpfile)
|
| 941 |
+
return display_extra_help
|
| 942 |
+
|
| 943 |
+
def update_recent_files_list(self, new_file=None):
|
| 944 |
+
"Load and update the recent files list and menus"
|
| 945 |
+
# TODO: move to iomenu.
|
| 946 |
+
rf_list = []
|
| 947 |
+
file_path = self.recent_files_path
|
| 948 |
+
if file_path and os.path.exists(file_path):
|
| 949 |
+
with open(file_path,
|
| 950 |
+
encoding='utf_8', errors='replace') as rf_list_file:
|
| 951 |
+
rf_list = rf_list_file.readlines()
|
| 952 |
+
if new_file:
|
| 953 |
+
new_file = os.path.abspath(new_file) + '\n'
|
| 954 |
+
if new_file in rf_list:
|
| 955 |
+
rf_list.remove(new_file) # move to top
|
| 956 |
+
rf_list.insert(0, new_file)
|
| 957 |
+
# clean and save the recent files list
|
| 958 |
+
bad_paths = []
|
| 959 |
+
for path in rf_list:
|
| 960 |
+
if '\0' in path or not os.path.exists(path[0:-1]):
|
| 961 |
+
bad_paths.append(path)
|
| 962 |
+
rf_list = [path for path in rf_list if path not in bad_paths]
|
| 963 |
+
ulchars = "1234567890ABCDEFGHIJK"
|
| 964 |
+
rf_list = rf_list[0:len(ulchars)]
|
| 965 |
+
if file_path:
|
| 966 |
+
try:
|
| 967 |
+
with open(file_path, 'w',
|
| 968 |
+
encoding='utf_8', errors='replace') as rf_file:
|
| 969 |
+
rf_file.writelines(rf_list)
|
| 970 |
+
except OSError as err:
|
| 971 |
+
if not getattr(self.root, "recentfiles_message", False):
|
| 972 |
+
self.root.recentfiles_message = True
|
| 973 |
+
messagebox.showwarning(title='IDLE Warning',
|
| 974 |
+
message="Cannot save Recent Files list to disk.\n"
|
| 975 |
+
f" {err}\n"
|
| 976 |
+
"Select OK to continue.",
|
| 977 |
+
parent=self.text)
|
| 978 |
+
# for each edit window instance, construct the recent files menu
|
| 979 |
+
for instance in self.top.instance_dict:
|
| 980 |
+
menu = instance.recent_files_menu
|
| 981 |
+
menu.delete(0, END) # clear, and rebuild:
|
| 982 |
+
for i, file_name in enumerate(rf_list):
|
| 983 |
+
file_name = file_name.rstrip() # zap \n
|
| 984 |
+
callback = instance.__recent_file_callback(file_name)
|
| 985 |
+
menu.add_command(label=ulchars[i] + " " + file_name,
|
| 986 |
+
command=callback,
|
| 987 |
+
underline=0)
|
| 988 |
+
|
| 989 |
+
def __recent_file_callback(self, file_name):
|
| 990 |
+
def open_recent_file(fn_closure=file_name):
|
| 991 |
+
self.io.open(editFile=fn_closure)
|
| 992 |
+
return open_recent_file
|
| 993 |
+
|
| 994 |
+
def saved_change_hook(self):
|
| 995 |
+
short = self.short_title()
|
| 996 |
+
long = self.long_title()
|
| 997 |
+
_py_version = ' (%s)' % platform.python_version()
|
| 998 |
+
if short and long and not macosx.isCocoaTk():
|
| 999 |
+
# Don't use both values on macOS because
|
| 1000 |
+
# that doesn't match platform conventions.
|
| 1001 |
+
title = short + " - " + long + _py_version
|
| 1002 |
+
elif short:
|
| 1003 |
+
if short == "IDLE Shell":
|
| 1004 |
+
title = short + " " + platform.python_version()
|
| 1005 |
+
else:
|
| 1006 |
+
title = short + _py_version
|
| 1007 |
+
elif long:
|
| 1008 |
+
title = long
|
| 1009 |
+
else:
|
| 1010 |
+
title = "untitled"
|
| 1011 |
+
icon = short or long or title
|
| 1012 |
+
if not self.get_saved():
|
| 1013 |
+
title = "*%s*" % title
|
| 1014 |
+
icon = "*%s" % icon
|
| 1015 |
+
self.top.wm_title(title)
|
| 1016 |
+
self.top.wm_iconname(icon)
|
| 1017 |
+
|
| 1018 |
+
if macosx.isCocoaTk():
|
| 1019 |
+
# Add a proxy icon to the window title
|
| 1020 |
+
self.top.wm_attributes("-titlepath", long)
|
| 1021 |
+
|
| 1022 |
+
# Maintain the modification status for the window
|
| 1023 |
+
self.top.wm_attributes("-modified", not self.get_saved())
|
| 1024 |
+
|
| 1025 |
+
def get_saved(self):
|
| 1026 |
+
return self.undo.get_saved()
|
| 1027 |
+
|
| 1028 |
+
def set_saved(self, flag):
|
| 1029 |
+
self.undo.set_saved(flag)
|
| 1030 |
+
|
| 1031 |
+
def reset_undo(self):
|
| 1032 |
+
self.undo.reset_undo()
|
| 1033 |
+
|
| 1034 |
+
def short_title(self):
|
| 1035 |
+
filename = self.io.filename
|
| 1036 |
+
return os.path.basename(filename) if filename else "untitled"
|
| 1037 |
+
|
| 1038 |
+
def long_title(self):
|
| 1039 |
+
return self.io.filename or ""
|
| 1040 |
+
|
| 1041 |
+
def center_insert_event(self, event):
|
| 1042 |
+
self.center()
|
| 1043 |
+
return "break"
|
| 1044 |
+
|
| 1045 |
+
def center(self, mark="insert"):
|
| 1046 |
+
text = self.text
|
| 1047 |
+
top, bot = self.getwindowlines()
|
| 1048 |
+
lineno = self.getlineno(mark)
|
| 1049 |
+
height = bot - top
|
| 1050 |
+
newtop = max(1, lineno - height//2)
|
| 1051 |
+
text.yview(float(newtop))
|
| 1052 |
+
|
| 1053 |
+
def getwindowlines(self):
|
| 1054 |
+
text = self.text
|
| 1055 |
+
top = self.getlineno("@0,0")
|
| 1056 |
+
bot = self.getlineno("@0,65535")
|
| 1057 |
+
if top == bot and text.winfo_height() == 1:
|
| 1058 |
+
# Geometry manager hasn't run yet
|
| 1059 |
+
height = int(text['height'])
|
| 1060 |
+
bot = top + height - 1
|
| 1061 |
+
return top, bot
|
| 1062 |
+
|
| 1063 |
+
def getlineno(self, mark="insert"):
|
| 1064 |
+
text = self.text
|
| 1065 |
+
return int(float(text.index(mark)))
|
| 1066 |
+
|
| 1067 |
+
def get_geometry(self):
|
| 1068 |
+
"Return (width, height, x, y)"
|
| 1069 |
+
geom = self.top.wm_geometry()
|
| 1070 |
+
m = re.match(r"(\d+)x(\d+)\+(-?\d+)\+(-?\d+)", geom)
|
| 1071 |
+
return list(map(int, m.groups()))
|
| 1072 |
+
|
| 1073 |
+
def close_event(self, event):
|
| 1074 |
+
self.close()
|
| 1075 |
+
return "break"
|
| 1076 |
+
|
| 1077 |
+
def maybesave(self):
|
| 1078 |
+
if self.io:
|
| 1079 |
+
if not self.get_saved():
|
| 1080 |
+
if self.top.state()!='normal':
|
| 1081 |
+
self.top.deiconify()
|
| 1082 |
+
self.top.lower()
|
| 1083 |
+
self.top.lift()
|
| 1084 |
+
return self.io.maybesave()
|
| 1085 |
+
|
| 1086 |
+
def close(self):
|
| 1087 |
+
try:
|
| 1088 |
+
reply = self.maybesave()
|
| 1089 |
+
if str(reply) != "cancel":
|
| 1090 |
+
self._close()
|
| 1091 |
+
return reply
|
| 1092 |
+
except AttributeError: # bpo-35379: close called twice
|
| 1093 |
+
pass
|
| 1094 |
+
|
| 1095 |
+
def _close(self):
|
| 1096 |
+
if self.io.filename:
|
| 1097 |
+
self.update_recent_files_list(new_file=self.io.filename)
|
| 1098 |
+
window.unregister_callback(self.postwindowsmenu)
|
| 1099 |
+
self.unload_extensions()
|
| 1100 |
+
self.io.close()
|
| 1101 |
+
self.io = None
|
| 1102 |
+
self.undo = None
|
| 1103 |
+
if self.color:
|
| 1104 |
+
self.color.close()
|
| 1105 |
+
self.color = None
|
| 1106 |
+
self.text = None
|
| 1107 |
+
self.tkinter_vars = None
|
| 1108 |
+
self.per.close()
|
| 1109 |
+
self.per = None
|
| 1110 |
+
self.top.destroy()
|
| 1111 |
+
if self.close_hook:
|
| 1112 |
+
# unless override: unregister from flist, terminate if last window
|
| 1113 |
+
self.close_hook()
|
| 1114 |
+
|
| 1115 |
+
def load_extensions(self):
|
| 1116 |
+
self.extensions = {}
|
| 1117 |
+
self.load_standard_extensions()
|
| 1118 |
+
|
| 1119 |
+
def unload_extensions(self):
|
| 1120 |
+
for ins in list(self.extensions.values()):
|
| 1121 |
+
if hasattr(ins, "close"):
|
| 1122 |
+
ins.close()
|
| 1123 |
+
self.extensions = {}
|
| 1124 |
+
|
| 1125 |
+
def load_standard_extensions(self):
|
| 1126 |
+
for name in self.get_standard_extension_names():
|
| 1127 |
+
try:
|
| 1128 |
+
self.load_extension(name)
|
| 1129 |
+
except:
|
| 1130 |
+
print("Failed to load extension", repr(name))
|
| 1131 |
+
traceback.print_exc()
|
| 1132 |
+
|
| 1133 |
+
def get_standard_extension_names(self):
|
| 1134 |
+
return idleConf.GetExtensions(editor_only=True)
|
| 1135 |
+
|
| 1136 |
+
extfiles = { # Map built-in config-extension section names to file names.
|
| 1137 |
+
'ZzDummy': 'zzdummy',
|
| 1138 |
+
}
|
| 1139 |
+
|
| 1140 |
+
def load_extension(self, name):
|
| 1141 |
+
fname = self.extfiles.get(name, name)
|
| 1142 |
+
try:
|
| 1143 |
+
try:
|
| 1144 |
+
mod = importlib.import_module('.' + fname, package=__package__)
|
| 1145 |
+
except (ImportError, TypeError):
|
| 1146 |
+
mod = importlib.import_module(fname)
|
| 1147 |
+
except ImportError:
|
| 1148 |
+
print("\nFailed to import extension: ", name)
|
| 1149 |
+
raise
|
| 1150 |
+
cls = getattr(mod, name)
|
| 1151 |
+
keydefs = idleConf.GetExtensionBindings(name)
|
| 1152 |
+
if hasattr(cls, "menudefs"):
|
| 1153 |
+
self.fill_menus(cls.menudefs, keydefs)
|
| 1154 |
+
ins = cls(self)
|
| 1155 |
+
self.extensions[name] = ins
|
| 1156 |
+
if keydefs:
|
| 1157 |
+
self.apply_bindings(keydefs)
|
| 1158 |
+
for vevent in keydefs:
|
| 1159 |
+
methodname = vevent.replace("-", "_")
|
| 1160 |
+
while methodname[:1] == '<':
|
| 1161 |
+
methodname = methodname[1:]
|
| 1162 |
+
while methodname[-1:] == '>':
|
| 1163 |
+
methodname = methodname[:-1]
|
| 1164 |
+
methodname = methodname + "_event"
|
| 1165 |
+
if hasattr(ins, methodname):
|
| 1166 |
+
self.text.bind(vevent, getattr(ins, methodname))
|
| 1167 |
+
|
| 1168 |
+
def apply_bindings(self, keydefs=None):
|
| 1169 |
+
"""Add events with keys to self.text."""
|
| 1170 |
+
if keydefs is None:
|
| 1171 |
+
keydefs = self.mainmenu.default_keydefs
|
| 1172 |
+
text = self.text
|
| 1173 |
+
text.keydefs = keydefs
|
| 1174 |
+
for event, keylist in keydefs.items():
|
| 1175 |
+
if keylist:
|
| 1176 |
+
text.event_add(event, *keylist)
|
| 1177 |
+
|
| 1178 |
+
def fill_menus(self, menudefs=None, keydefs=None):
|
| 1179 |
+
"""Fill in dropdown menus used by this window.
|
| 1180 |
+
|
| 1181 |
+
Items whose name begins with '!' become checkbuttons.
|
| 1182 |
+
Other names indicate commands. None becomes a separator.
|
| 1183 |
+
"""
|
| 1184 |
+
if menudefs is None:
|
| 1185 |
+
menudefs = self.mainmenu.menudefs
|
| 1186 |
+
if keydefs is None:
|
| 1187 |
+
keydefs = self.mainmenu.default_keydefs
|
| 1188 |
+
menudict = self.menudict
|
| 1189 |
+
text = self.text
|
| 1190 |
+
for mname, entrylist in menudefs:
|
| 1191 |
+
menu = menudict.get(mname)
|
| 1192 |
+
if not menu:
|
| 1193 |
+
continue
|
| 1194 |
+
for entry in entrylist:
|
| 1195 |
+
if entry is None:
|
| 1196 |
+
menu.add_separator()
|
| 1197 |
+
else:
|
| 1198 |
+
label, eventname = entry
|
| 1199 |
+
checkbutton = (label[:1] == '!')
|
| 1200 |
+
if checkbutton:
|
| 1201 |
+
label = label[1:]
|
| 1202 |
+
underline, label = prepstr(label)
|
| 1203 |
+
accelerator = get_accelerator(keydefs, eventname)
|
| 1204 |
+
def command(text=text, eventname=eventname):
|
| 1205 |
+
text.event_generate(eventname)
|
| 1206 |
+
if checkbutton:
|
| 1207 |
+
var = self.get_var_obj(eventname, BooleanVar)
|
| 1208 |
+
menu.add_checkbutton(label=label, underline=underline,
|
| 1209 |
+
command=command, accelerator=accelerator,
|
| 1210 |
+
variable=var)
|
| 1211 |
+
else:
|
| 1212 |
+
menu.add_command(label=label, underline=underline,
|
| 1213 |
+
command=command,
|
| 1214 |
+
accelerator=accelerator)
|
| 1215 |
+
|
| 1216 |
+
def getvar(self, name):
|
| 1217 |
+
var = self.get_var_obj(name)
|
| 1218 |
+
if var:
|
| 1219 |
+
value = var.get()
|
| 1220 |
+
return value
|
| 1221 |
+
else:
|
| 1222 |
+
raise NameError(name)
|
| 1223 |
+
|
| 1224 |
+
def setvar(self, name, value, vartype=None):
|
| 1225 |
+
var = self.get_var_obj(name, vartype)
|
| 1226 |
+
if var:
|
| 1227 |
+
var.set(value)
|
| 1228 |
+
else:
|
| 1229 |
+
raise NameError(name)
|
| 1230 |
+
|
| 1231 |
+
def get_var_obj(self, eventname, vartype=None):
|
| 1232 |
+
"""Return a tkinter variable instance for the event.
|
| 1233 |
+
"""
|
| 1234 |
+
var = self.tkinter_vars.get(eventname)
|
| 1235 |
+
if not var and vartype:
|
| 1236 |
+
# Create a Tkinter variable object.
|
| 1237 |
+
self.tkinter_vars[eventname] = var = vartype(self.text)
|
| 1238 |
+
return var
|
| 1239 |
+
|
| 1240 |
+
# Tk implementations of "virtual text methods" -- each platform
|
| 1241 |
+
# reusing IDLE's support code needs to define these for its GUI's
|
| 1242 |
+
# flavor of widget.
|
| 1243 |
+
|
| 1244 |
+
# Is character at text_index in a Python string? Return 0 for
|
| 1245 |
+
# "guaranteed no", true for anything else. This info is expensive
|
| 1246 |
+
# to compute ab initio, but is probably already known by the
|
| 1247 |
+
# platform's colorizer.
|
| 1248 |
+
|
| 1249 |
+
def is_char_in_string(self, text_index):
|
| 1250 |
+
if self.color:
|
| 1251 |
+
# Return true iff colorizer hasn't (re)gotten this far
|
| 1252 |
+
# yet, or the character is tagged as being in a string
|
| 1253 |
+
return self.text.tag_prevrange("TODO", text_index) or \
|
| 1254 |
+
"STRING" in self.text.tag_names(text_index)
|
| 1255 |
+
else:
|
| 1256 |
+
# The colorizer is missing: assume the worst
|
| 1257 |
+
return 1
|
| 1258 |
+
|
| 1259 |
+
# If a selection is defined in the text widget, return (start,
|
| 1260 |
+
# end) as Tkinter text indices, otherwise return (None, None)
|
| 1261 |
+
def get_selection_indices(self):
|
| 1262 |
+
try:
|
| 1263 |
+
first = self.text.index("sel.first")
|
| 1264 |
+
last = self.text.index("sel.last")
|
| 1265 |
+
return first, last
|
| 1266 |
+
except TclError:
|
| 1267 |
+
return None, None
|
| 1268 |
+
|
| 1269 |
+
# Return the text widget's current view of what a tab stop means
|
| 1270 |
+
# (equivalent width in spaces).
|
| 1271 |
+
|
| 1272 |
+
def get_tk_tabwidth(self):
|
| 1273 |
+
current = self.text['tabs'] or TK_TABWIDTH_DEFAULT
|
| 1274 |
+
return int(current)
|
| 1275 |
+
|
| 1276 |
+
# Set the text widget's current view of what a tab stop means.
|
| 1277 |
+
|
| 1278 |
+
def set_tk_tabwidth(self, newtabwidth):
|
| 1279 |
+
text = self.text
|
| 1280 |
+
if self.get_tk_tabwidth() != newtabwidth:
|
| 1281 |
+
# Set text widget tab width
|
| 1282 |
+
pixels = text.tk.call("font", "measure", text["font"],
|
| 1283 |
+
"-displayof", text.master,
|
| 1284 |
+
"n" * newtabwidth)
|
| 1285 |
+
text.configure(tabs=pixels)
|
| 1286 |
+
|
| 1287 |
+
### begin autoindent code ### (configuration was moved to beginning of class)
|
| 1288 |
+
|
| 1289 |
+
def set_indentation_params(self, is_py_src, guess=True):
|
| 1290 |
+
if is_py_src and guess:
|
| 1291 |
+
i = self.guess_indent()
|
| 1292 |
+
if 2 <= i <= 8:
|
| 1293 |
+
self.indentwidth = i
|
| 1294 |
+
if self.indentwidth != self.tabwidth:
|
| 1295 |
+
self.usetabs = False
|
| 1296 |
+
self.set_tk_tabwidth(self.tabwidth)
|
| 1297 |
+
|
| 1298 |
+
def smart_backspace_event(self, event):
|
| 1299 |
+
text = self.text
|
| 1300 |
+
first, last = self.get_selection_indices()
|
| 1301 |
+
if first and last:
|
| 1302 |
+
text.delete(first, last)
|
| 1303 |
+
text.mark_set("insert", first)
|
| 1304 |
+
return "break"
|
| 1305 |
+
# Delete whitespace left, until hitting a real char or closest
|
| 1306 |
+
# preceding virtual tab stop.
|
| 1307 |
+
chars = text.get("insert linestart", "insert")
|
| 1308 |
+
if chars == '':
|
| 1309 |
+
if text.compare("insert", ">", "1.0"):
|
| 1310 |
+
# easy: delete preceding newline
|
| 1311 |
+
text.delete("insert-1c")
|
| 1312 |
+
else:
|
| 1313 |
+
text.bell() # at start of buffer
|
| 1314 |
+
return "break"
|
| 1315 |
+
if chars[-1] not in " \t":
|
| 1316 |
+
# easy: delete preceding real char
|
| 1317 |
+
text.delete("insert-1c")
|
| 1318 |
+
return "break"
|
| 1319 |
+
# Ick. It may require *inserting* spaces if we back up over a
|
| 1320 |
+
# tab character! This is written to be clear, not fast.
|
| 1321 |
+
tabwidth = self.tabwidth
|
| 1322 |
+
have = len(chars.expandtabs(tabwidth))
|
| 1323 |
+
assert have > 0
|
| 1324 |
+
want = ((have - 1) // self.indentwidth) * self.indentwidth
|
| 1325 |
+
# Debug prompt is multilined....
|
| 1326 |
+
ncharsdeleted = 0
|
| 1327 |
+
while True:
|
| 1328 |
+
chars = chars[:-1]
|
| 1329 |
+
ncharsdeleted = ncharsdeleted + 1
|
| 1330 |
+
have = len(chars.expandtabs(tabwidth))
|
| 1331 |
+
if have <= want or chars[-1] not in " \t":
|
| 1332 |
+
break
|
| 1333 |
+
text.undo_block_start()
|
| 1334 |
+
text.delete("insert-%dc" % ncharsdeleted, "insert")
|
| 1335 |
+
if have < want:
|
| 1336 |
+
text.insert("insert", ' ' * (want - have),
|
| 1337 |
+
self.user_input_insert_tags)
|
| 1338 |
+
text.undo_block_stop()
|
| 1339 |
+
return "break"
|
| 1340 |
+
|
| 1341 |
+
def smart_indent_event(self, event):
|
| 1342 |
+
# if intraline selection:
|
| 1343 |
+
# delete it
|
| 1344 |
+
# elif multiline selection:
|
| 1345 |
+
# do indent-region
|
| 1346 |
+
# else:
|
| 1347 |
+
# indent one level
|
| 1348 |
+
text = self.text
|
| 1349 |
+
first, last = self.get_selection_indices()
|
| 1350 |
+
text.undo_block_start()
|
| 1351 |
+
try:
|
| 1352 |
+
if first and last:
|
| 1353 |
+
if index2line(first) != index2line(last):
|
| 1354 |
+
return self.fregion.indent_region_event(event)
|
| 1355 |
+
text.delete(first, last)
|
| 1356 |
+
text.mark_set("insert", first)
|
| 1357 |
+
prefix = text.get("insert linestart", "insert")
|
| 1358 |
+
raw, effective = get_line_indent(prefix, self.tabwidth)
|
| 1359 |
+
if raw == len(prefix):
|
| 1360 |
+
# only whitespace to the left
|
| 1361 |
+
self.reindent_to(effective + self.indentwidth)
|
| 1362 |
+
else:
|
| 1363 |
+
# tab to the next 'stop' within or to right of line's text:
|
| 1364 |
+
if self.usetabs:
|
| 1365 |
+
pad = '\t'
|
| 1366 |
+
else:
|
| 1367 |
+
effective = len(prefix.expandtabs(self.tabwidth))
|
| 1368 |
+
n = self.indentwidth
|
| 1369 |
+
pad = ' ' * (n - effective % n)
|
| 1370 |
+
text.insert("insert", pad, self.user_input_insert_tags)
|
| 1371 |
+
text.see("insert")
|
| 1372 |
+
return "break"
|
| 1373 |
+
finally:
|
| 1374 |
+
text.undo_block_stop()
|
| 1375 |
+
|
| 1376 |
+
def newline_and_indent_event(self, event):
|
| 1377 |
+
"""Insert a newline and indentation after Enter keypress event.
|
| 1378 |
+
|
| 1379 |
+
Properly position the cursor on the new line based on information
|
| 1380 |
+
from the current line. This takes into account if the current line
|
| 1381 |
+
is a shell prompt, is empty, has selected text, contains a block
|
| 1382 |
+
opener, contains a block closer, is a continuation line, or
|
| 1383 |
+
is inside a string.
|
| 1384 |
+
"""
|
| 1385 |
+
text = self.text
|
| 1386 |
+
first, last = self.get_selection_indices()
|
| 1387 |
+
text.undo_block_start()
|
| 1388 |
+
try: # Close undo block and expose new line in finally clause.
|
| 1389 |
+
if first and last:
|
| 1390 |
+
text.delete(first, last)
|
| 1391 |
+
text.mark_set("insert", first)
|
| 1392 |
+
line = text.get("insert linestart", "insert")
|
| 1393 |
+
|
| 1394 |
+
# Count leading whitespace for indent size.
|
| 1395 |
+
i, n = 0, len(line)
|
| 1396 |
+
while i < n and line[i] in " \t":
|
| 1397 |
+
i += 1
|
| 1398 |
+
if i == n:
|
| 1399 |
+
# The cursor is in or at leading indentation in a continuation
|
| 1400 |
+
# line; just inject an empty line at the start.
|
| 1401 |
+
text.insert("insert linestart", '\n',
|
| 1402 |
+
self.user_input_insert_tags)
|
| 1403 |
+
return "break"
|
| 1404 |
+
indent = line[:i]
|
| 1405 |
+
|
| 1406 |
+
# Strip whitespace before insert point unless it's in the prompt.
|
| 1407 |
+
i = 0
|
| 1408 |
+
while line and line[-1] in " \t":
|
| 1409 |
+
line = line[:-1]
|
| 1410 |
+
i += 1
|
| 1411 |
+
if i:
|
| 1412 |
+
text.delete("insert - %d chars" % i, "insert")
|
| 1413 |
+
|
| 1414 |
+
# Strip whitespace after insert point.
|
| 1415 |
+
while text.get("insert") in " \t":
|
| 1416 |
+
text.delete("insert")
|
| 1417 |
+
|
| 1418 |
+
# Insert new line.
|
| 1419 |
+
text.insert("insert", '\n', self.user_input_insert_tags)
|
| 1420 |
+
|
| 1421 |
+
# Adjust indentation for continuations and block open/close.
|
| 1422 |
+
# First need to find the last statement.
|
| 1423 |
+
lno = index2line(text.index('insert'))
|
| 1424 |
+
y = pyparse.Parser(self.indentwidth, self.tabwidth)
|
| 1425 |
+
if not self.prompt_last_line:
|
| 1426 |
+
for context in self.num_context_lines:
|
| 1427 |
+
startat = max(lno - context, 1)
|
| 1428 |
+
startatindex = repr(startat) + ".0"
|
| 1429 |
+
rawtext = text.get(startatindex, "insert")
|
| 1430 |
+
y.set_code(rawtext)
|
| 1431 |
+
bod = y.find_good_parse_start(
|
| 1432 |
+
self._build_char_in_string_func(startatindex))
|
| 1433 |
+
if bod is not None or startat == 1:
|
| 1434 |
+
break
|
| 1435 |
+
y.set_lo(bod or 0)
|
| 1436 |
+
else:
|
| 1437 |
+
r = text.tag_prevrange("console", "insert")
|
| 1438 |
+
if r:
|
| 1439 |
+
startatindex = r[1]
|
| 1440 |
+
else:
|
| 1441 |
+
startatindex = "1.0"
|
| 1442 |
+
rawtext = text.get(startatindex, "insert")
|
| 1443 |
+
y.set_code(rawtext)
|
| 1444 |
+
y.set_lo(0)
|
| 1445 |
+
|
| 1446 |
+
c = y.get_continuation_type()
|
| 1447 |
+
if c != pyparse.C_NONE:
|
| 1448 |
+
# The current statement hasn't ended yet.
|
| 1449 |
+
if c == pyparse.C_STRING_FIRST_LINE:
|
| 1450 |
+
# After the first line of a string do not indent at all.
|
| 1451 |
+
pass
|
| 1452 |
+
elif c == pyparse.C_STRING_NEXT_LINES:
|
| 1453 |
+
# Inside a string which started before this line;
|
| 1454 |
+
# just mimic the current indent.
|
| 1455 |
+
text.insert("insert", indent, self.user_input_insert_tags)
|
| 1456 |
+
elif c == pyparse.C_BRACKET:
|
| 1457 |
+
# Line up with the first (if any) element of the
|
| 1458 |
+
# last open bracket structure; else indent one
|
| 1459 |
+
# level beyond the indent of the line with the
|
| 1460 |
+
# last open bracket.
|
| 1461 |
+
self.reindent_to(y.compute_bracket_indent())
|
| 1462 |
+
elif c == pyparse.C_BACKSLASH:
|
| 1463 |
+
# If more than one line in this statement already, just
|
| 1464 |
+
# mimic the current indent; else if initial line
|
| 1465 |
+
# has a start on an assignment stmt, indent to
|
| 1466 |
+
# beyond leftmost =; else to beyond first chunk of
|
| 1467 |
+
# non-whitespace on initial line.
|
| 1468 |
+
if y.get_num_lines_in_stmt() > 1:
|
| 1469 |
+
text.insert("insert", indent,
|
| 1470 |
+
self.user_input_insert_tags)
|
| 1471 |
+
else:
|
| 1472 |
+
self.reindent_to(y.compute_backslash_indent())
|
| 1473 |
+
else:
|
| 1474 |
+
assert 0, f"bogus continuation type {c!r}"
|
| 1475 |
+
return "break"
|
| 1476 |
+
|
| 1477 |
+
# This line starts a brand new statement; indent relative to
|
| 1478 |
+
# indentation of initial line of closest preceding
|
| 1479 |
+
# interesting statement.
|
| 1480 |
+
indent = y.get_base_indent_string()
|
| 1481 |
+
text.insert("insert", indent, self.user_input_insert_tags)
|
| 1482 |
+
if y.is_block_opener():
|
| 1483 |
+
self.smart_indent_event(event)
|
| 1484 |
+
elif indent and y.is_block_closer():
|
| 1485 |
+
self.smart_backspace_event(event)
|
| 1486 |
+
return "break"
|
| 1487 |
+
finally:
|
| 1488 |
+
text.see("insert")
|
| 1489 |
+
text.undo_block_stop()
|
| 1490 |
+
|
| 1491 |
+
# Our editwin provides an is_char_in_string function that works
|
| 1492 |
+
# with a Tk text index, but PyParse only knows about offsets into
|
| 1493 |
+
# a string. This builds a function for PyParse that accepts an
|
| 1494 |
+
# offset.
|
| 1495 |
+
|
| 1496 |
+
def _build_char_in_string_func(self, startindex):
|
| 1497 |
+
def inner(offset, _startindex=startindex,
|
| 1498 |
+
_icis=self.is_char_in_string):
|
| 1499 |
+
return _icis(_startindex + "+%dc" % offset)
|
| 1500 |
+
return inner
|
| 1501 |
+
|
| 1502 |
+
# XXX this isn't bound to anything -- see tabwidth comments
|
| 1503 |
+
## def change_tabwidth_event(self, event):
|
| 1504 |
+
## new = self._asktabwidth()
|
| 1505 |
+
## if new != self.tabwidth:
|
| 1506 |
+
## self.tabwidth = new
|
| 1507 |
+
## self.set_indentation_params(0, guess=0)
|
| 1508 |
+
## return "break"
|
| 1509 |
+
|
| 1510 |
+
# Make string that displays as n leading blanks.
|
| 1511 |
+
|
| 1512 |
+
def _make_blanks(self, n):
|
| 1513 |
+
if self.usetabs:
|
| 1514 |
+
ntabs, nspaces = divmod(n, self.tabwidth)
|
| 1515 |
+
return '\t' * ntabs + ' ' * nspaces
|
| 1516 |
+
else:
|
| 1517 |
+
return ' ' * n
|
| 1518 |
+
|
| 1519 |
+
# Delete from beginning of line to insert point, then reinsert
|
| 1520 |
+
# column logical (meaning use tabs if appropriate) spaces.
|
| 1521 |
+
|
| 1522 |
+
def reindent_to(self, column):
|
| 1523 |
+
text = self.text
|
| 1524 |
+
text.undo_block_start()
|
| 1525 |
+
if text.compare("insert linestart", "!=", "insert"):
|
| 1526 |
+
text.delete("insert linestart", "insert")
|
| 1527 |
+
if column:
|
| 1528 |
+
text.insert("insert", self._make_blanks(column),
|
| 1529 |
+
self.user_input_insert_tags)
|
| 1530 |
+
text.undo_block_stop()
|
| 1531 |
+
|
| 1532 |
+
# Guess indentwidth from text content.
|
| 1533 |
+
# Return guessed indentwidth. This should not be believed unless
|
| 1534 |
+
# it's in a reasonable range (e.g., it will be 0 if no indented
|
| 1535 |
+
# blocks are found).
|
| 1536 |
+
|
| 1537 |
+
def guess_indent(self):
|
| 1538 |
+
opener, indented = IndentSearcher(self.text).run()
|
| 1539 |
+
if opener and indented:
|
| 1540 |
+
raw, indentsmall = get_line_indent(opener, self.tabwidth)
|
| 1541 |
+
raw, indentlarge = get_line_indent(indented, self.tabwidth)
|
| 1542 |
+
else:
|
| 1543 |
+
indentsmall = indentlarge = 0
|
| 1544 |
+
return indentlarge - indentsmall
|
| 1545 |
+
|
| 1546 |
+
def toggle_line_numbers_event(self, event=None):
|
| 1547 |
+
if self.line_numbers is None:
|
| 1548 |
+
return
|
| 1549 |
+
|
| 1550 |
+
if self.line_numbers.is_shown:
|
| 1551 |
+
self.line_numbers.hide_sidebar()
|
| 1552 |
+
menu_label = "Show"
|
| 1553 |
+
else:
|
| 1554 |
+
self.line_numbers.show_sidebar()
|
| 1555 |
+
menu_label = "Hide"
|
| 1556 |
+
self.update_menu_label(menu='options', index='*ine*umbers',
|
| 1557 |
+
label=f'{menu_label} Line Numbers')
|
| 1558 |
+
|
| 1559 |
+
# "line.col" -> line, as an int
|
| 1560 |
+
def index2line(index):
|
| 1561 |
+
return int(float(index))
|
| 1562 |
+
|
| 1563 |
+
|
| 1564 |
+
_line_indent_re = re.compile(r'[ \t]*')
|
| 1565 |
+
def get_line_indent(line, tabwidth):
|
| 1566 |
+
"""Return a line's indentation as (# chars, effective # of spaces).
|
| 1567 |
+
|
| 1568 |
+
The effective # of spaces is the length after properly "expanding"
|
| 1569 |
+
the tabs into spaces, as done by str.expandtabs(tabwidth).
|
| 1570 |
+
"""
|
| 1571 |
+
m = _line_indent_re.match(line)
|
| 1572 |
+
return m.end(), len(m.group().expandtabs(tabwidth))
|
| 1573 |
+
|
| 1574 |
+
|
| 1575 |
+
class IndentSearcher:
|
| 1576 |
+
"Manage initial indent guess, returned by run method."
|
| 1577 |
+
|
| 1578 |
+
def __init__(self, text):
|
| 1579 |
+
self.text = text
|
| 1580 |
+
self.i = self.finished = 0
|
| 1581 |
+
self.blkopenline = self.indentedline = None
|
| 1582 |
+
|
| 1583 |
+
def readline(self):
|
| 1584 |
+
if self.finished:
|
| 1585 |
+
return ""
|
| 1586 |
+
i = self.i = self.i + 1
|
| 1587 |
+
mark = repr(i) + ".0"
|
| 1588 |
+
if self.text.compare(mark, ">=", "end"):
|
| 1589 |
+
return ""
|
| 1590 |
+
return self.text.get(mark, mark + " lineend+1c")
|
| 1591 |
+
|
| 1592 |
+
def tokeneater(self, type, token, start, end, line,
|
| 1593 |
+
INDENT=tokenize.INDENT,
|
| 1594 |
+
NAME=tokenize.NAME,
|
| 1595 |
+
OPENERS=('class', 'def', 'for', 'if', 'match', 'try',
|
| 1596 |
+
'while', 'with')):
|
| 1597 |
+
if self.finished:
|
| 1598 |
+
pass
|
| 1599 |
+
elif type == NAME and token in OPENERS:
|
| 1600 |
+
self.blkopenline = line
|
| 1601 |
+
elif type == INDENT and self.blkopenline:
|
| 1602 |
+
self.indentedline = line
|
| 1603 |
+
self.finished = 1
|
| 1604 |
+
|
| 1605 |
+
def run(self):
|
| 1606 |
+
"""Return 2 lines containing block opener and indent.
|
| 1607 |
+
|
| 1608 |
+
Either the indent line or both may be None.
|
| 1609 |
+
"""
|
| 1610 |
+
try:
|
| 1611 |
+
tokens = tokenize.generate_tokens(self.readline)
|
| 1612 |
+
for token in tokens:
|
| 1613 |
+
self.tokeneater(*token)
|
| 1614 |
+
except (tokenize.TokenError, SyntaxError):
|
| 1615 |
+
# Stopping the tokenizer early can trigger spurious errors.
|
| 1616 |
+
pass
|
| 1617 |
+
return self.blkopenline, self.indentedline
|
| 1618 |
+
|
| 1619 |
+
### end autoindent code ###
|
| 1620 |
+
|
| 1621 |
+
|
| 1622 |
+
def prepstr(s):
|
| 1623 |
+
"""Extract the underscore from a string.
|
| 1624 |
+
|
| 1625 |
+
For example, prepstr("Co_py") returns (2, "Copy").
|
| 1626 |
+
|
| 1627 |
+
Args:
|
| 1628 |
+
s: String with underscore.
|
| 1629 |
+
|
| 1630 |
+
Returns:
|
| 1631 |
+
Tuple of (position of underscore, string without underscore).
|
| 1632 |
+
"""
|
| 1633 |
+
i = s.find('_')
|
| 1634 |
+
if i >= 0:
|
| 1635 |
+
s = s[:i] + s[i+1:]
|
| 1636 |
+
return i, s
|
| 1637 |
+
|
| 1638 |
+
|
| 1639 |
+
keynames = {
|
| 1640 |
+
'bracketleft': '[',
|
| 1641 |
+
'bracketright': ']',
|
| 1642 |
+
'slash': '/',
|
| 1643 |
+
}
|
| 1644 |
+
|
| 1645 |
+
def get_accelerator(keydefs, eventname):
|
| 1646 |
+
"""Return a formatted string for the keybinding of an event.
|
| 1647 |
+
|
| 1648 |
+
Convert the first keybinding for a given event to a form that
|
| 1649 |
+
can be displayed as an accelerator on the menu.
|
| 1650 |
+
|
| 1651 |
+
Args:
|
| 1652 |
+
keydefs: Dictionary of valid events to keybindings.
|
| 1653 |
+
eventname: Event to retrieve keybinding for.
|
| 1654 |
+
|
| 1655 |
+
Returns:
|
| 1656 |
+
Formatted string of the keybinding.
|
| 1657 |
+
"""
|
| 1658 |
+
keylist = keydefs.get(eventname)
|
| 1659 |
+
# issue10940: temporary workaround to prevent hang with OS X Cocoa Tk 8.5
|
| 1660 |
+
# if not keylist:
|
| 1661 |
+
if (not keylist) or (macosx.isCocoaTk() and eventname in {
|
| 1662 |
+
"<<open-module>>",
|
| 1663 |
+
"<<goto-line>>",
|
| 1664 |
+
"<<change-indentwidth>>"}):
|
| 1665 |
+
return ""
|
| 1666 |
+
s = keylist[0]
|
| 1667 |
+
# Convert strings of the form -singlelowercase to -singleuppercase.
|
| 1668 |
+
s = re.sub(r"-[a-z]\b", lambda m: m.group().upper(), s)
|
| 1669 |
+
# Convert certain keynames to their symbol.
|
| 1670 |
+
s = re.sub(r"\b\w+\b", lambda m: keynames.get(m.group(), m.group()), s)
|
| 1671 |
+
# Remove Key- from string.
|
| 1672 |
+
s = re.sub("Key-", "", s)
|
| 1673 |
+
# Convert Cancel to Ctrl-Break.
|
| 1674 |
+
s = re.sub("Cancel", "Ctrl-Break", s) # dscherer@cmu.edu
|
| 1675 |
+
# Convert Control to Ctrl-.
|
| 1676 |
+
s = re.sub("Control-", "Ctrl-", s)
|
| 1677 |
+
# Change - to +.
|
| 1678 |
+
s = re.sub("-", "+", s)
|
| 1679 |
+
# Change >< to space.
|
| 1680 |
+
s = re.sub("><", " ", s)
|
| 1681 |
+
# Remove <.
|
| 1682 |
+
s = re.sub("<", "", s)
|
| 1683 |
+
# Remove >.
|
| 1684 |
+
s = re.sub(">", "", s)
|
| 1685 |
+
return s
|
| 1686 |
+
|
| 1687 |
+
|
| 1688 |
+
def fixwordbreaks(root):
|
| 1689 |
+
# On Windows, tcl/tk breaks 'words' only on spaces, as in Command Prompt.
|
| 1690 |
+
# We want Motif style everywhere. See #21474, msg218992 and followup.
|
| 1691 |
+
tk = root.tk
|
| 1692 |
+
tk.call('tcl_wordBreakAfter', 'a b', 0) # make sure word.tcl is loaded
|
| 1693 |
+
tk.call('set', 'tcl_wordchars', r'\w')
|
| 1694 |
+
tk.call('set', 'tcl_nonwordchars', r'\W')
|
| 1695 |
+
|
| 1696 |
+
|
| 1697 |
+
def _editor_window(parent): # htest #
|
| 1698 |
+
# error if close master window first - timer event, after script
|
| 1699 |
+
root = parent
|
| 1700 |
+
fixwordbreaks(root)
|
| 1701 |
+
if sys.argv[1:]:
|
| 1702 |
+
filename = sys.argv[1]
|
| 1703 |
+
else:
|
| 1704 |
+
filename = None
|
| 1705 |
+
macosx.setupApp(root, None)
|
| 1706 |
+
edit = EditorWindow(root=root, filename=filename)
|
| 1707 |
+
text = edit.text
|
| 1708 |
+
text['height'] = 10
|
| 1709 |
+
for i in range(20):
|
| 1710 |
+
text.insert('insert', ' '*i + str(i) + '\n')
|
| 1711 |
+
# text.bind("<<close-all-windows>>", edit.close_event)
|
| 1712 |
+
# Does not stop error, neither does following
|
| 1713 |
+
# edit.text.bind("<<close-window>>", edit.close_event)
|
| 1714 |
+
|
| 1715 |
+
|
| 1716 |
+
if __name__ == '__main__':
|
| 1717 |
+
from unittest import main
|
| 1718 |
+
main('idlelib.idle_test.test_editor', verbosity=2, exit=False)
|
| 1719 |
+
|
| 1720 |
+
from idlelib.idle_test.htest import run
|
| 1721 |
+
run(_editor_window)
|
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/extend.txt
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Writing an IDLE extension
|
| 2 |
+
=========================
|
| 3 |
+
|
| 4 |
+
An IDLE extension can define new key bindings and menu entries for IDLE
|
| 5 |
+
edit windows. There is a simple mechanism to load extensions when IDLE
|
| 6 |
+
starts up and to attach them to each edit window. (It is also possible
|
| 7 |
+
to make other changes to IDLE, but this must be done by editing the IDLE
|
| 8 |
+
source code.)
|
| 9 |
+
|
| 10 |
+
The list of extensions loaded at startup time is configured by editing
|
| 11 |
+
the file config-extensions.def. See below for details.
|
| 12 |
+
|
| 13 |
+
An IDLE extension is defined by a class. Methods of the class define
|
| 14 |
+
actions that are invoked by event bindings or menu entries. Class (or
|
| 15 |
+
instance) variables define the bindings and menu additions; these are
|
| 16 |
+
automatically applied by IDLE when the extension is linked to an edit
|
| 17 |
+
window.
|
| 18 |
+
|
| 19 |
+
An IDLE extension class is instantiated with a single argument,
|
| 20 |
+
`editwin', an EditorWindow instance. The extension cannot assume much
|
| 21 |
+
about this argument, but it is guaranteed to have the following instance
|
| 22 |
+
variables:
|
| 23 |
+
|
| 24 |
+
text a Text instance (a widget)
|
| 25 |
+
io an IOBinding instance (more about this later)
|
| 26 |
+
flist the FileList instance (shared by all edit windows)
|
| 27 |
+
|
| 28 |
+
(There are a few more, but they are rarely useful.)
|
| 29 |
+
|
| 30 |
+
The extension class must not directly bind Window Manager (e.g. X) events.
|
| 31 |
+
Rather, it must define one or more virtual events, e.g. <<z-in>>, and
|
| 32 |
+
corresponding methods, e.g. z_in_event(). The virtual events will be
|
| 33 |
+
bound to the corresponding methods, and Window Manager events can then be bound
|
| 34 |
+
to the virtual events. (This indirection is done so that the key bindings can
|
| 35 |
+
easily be changed, and so that other sources of virtual events can exist, such
|
| 36 |
+
as menu entries.)
|
| 37 |
+
|
| 38 |
+
An extension can define menu entries. This is done with a class or instance
|
| 39 |
+
variable named menudefs; it should be a list of pairs, where each pair is a
|
| 40 |
+
menu name (lowercase) and a list of menu entries. Each menu entry is either
|
| 41 |
+
None (to insert a separator entry) or a pair of strings (menu_label,
|
| 42 |
+
virtual_event). Here, menu_label is the label of the menu entry, and
|
| 43 |
+
virtual_event is the virtual event to be generated when the entry is selected.
|
| 44 |
+
An underscore in the menu label is removed; the character following the
|
| 45 |
+
underscore is displayed underlined, to indicate the shortcut character (for
|
| 46 |
+
Windows).
|
| 47 |
+
|
| 48 |
+
At the moment, extensions cannot define whole new menus; they must define
|
| 49 |
+
entries in existing menus. Some menus are not present on some windows; such
|
| 50 |
+
entry definitions are then ignored, but key bindings are still applied. (This
|
| 51 |
+
should probably be refined in the future.)
|
| 52 |
+
|
| 53 |
+
Extensions are not required to define menu entries for all the events they
|
| 54 |
+
implement. (They are also not required to create keybindings, but in that
|
| 55 |
+
case there must be empty bindings in config-extensions.def)
|
| 56 |
+
|
| 57 |
+
Here is a partial example from zzdummy.py:
|
| 58 |
+
|
| 59 |
+
class ZzDummy:
|
| 60 |
+
|
| 61 |
+
menudefs = [
|
| 62 |
+
('format', [
|
| 63 |
+
('Z in', '<<z-in>>'),
|
| 64 |
+
('Z out', '<<z-out>>'),
|
| 65 |
+
] )
|
| 66 |
+
]
|
| 67 |
+
|
| 68 |
+
def __init__(self, editwin):
|
| 69 |
+
self.editwin = editwin
|
| 70 |
+
|
| 71 |
+
def z_in_event(self, event=None):
|
| 72 |
+
"...Do what you want here..."
|
| 73 |
+
|
| 74 |
+
The final piece of the puzzle is the file "config-extensions.def", which is
|
| 75 |
+
used to configure the loading of extensions and to establish key (or, more
|
| 76 |
+
generally, event) bindings to the virtual events defined in the extensions.
|
| 77 |
+
|
| 78 |
+
See the comments at the top of config-extensions.def for information. It's
|
| 79 |
+
currently necessary to manually modify that file to change IDLE's extension
|
| 80 |
+
loading or extension key bindings.
|
| 81 |
+
|
| 82 |
+
For further information on binding refer to the Tkinter Resources web page at
|
| 83 |
+
python.org and to the Tk Command "bind" man page.
|
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/filelist.py
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"idlelib.filelist"
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
from tkinter import messagebox
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class FileList:
|
| 8 |
+
|
| 9 |
+
# N.B. this import overridden in PyShellFileList.
|
| 10 |
+
from idlelib.editor import EditorWindow
|
| 11 |
+
|
| 12 |
+
def __init__(self, root):
|
| 13 |
+
self.root = root
|
| 14 |
+
self.dict = {}
|
| 15 |
+
self.inversedict = {}
|
| 16 |
+
self.vars = {} # For EditorWindow.getrawvar (shared Tcl variables)
|
| 17 |
+
|
| 18 |
+
def open(self, filename, action=None):
|
| 19 |
+
assert filename
|
| 20 |
+
filename = self.canonize(filename)
|
| 21 |
+
if os.path.isdir(filename):
|
| 22 |
+
# This can happen when bad filename is passed on command line:
|
| 23 |
+
messagebox.showerror(
|
| 24 |
+
"File Error",
|
| 25 |
+
f"{filename!r} is a directory.",
|
| 26 |
+
master=self.root)
|
| 27 |
+
return None
|
| 28 |
+
key = os.path.normcase(filename)
|
| 29 |
+
if key in self.dict:
|
| 30 |
+
edit = self.dict[key]
|
| 31 |
+
edit.top.wakeup()
|
| 32 |
+
return edit
|
| 33 |
+
if action:
|
| 34 |
+
# Don't create window, perform 'action', e.g. open in same window
|
| 35 |
+
return action(filename)
|
| 36 |
+
else:
|
| 37 |
+
edit = self.EditorWindow(self, filename, key)
|
| 38 |
+
if edit.good_load:
|
| 39 |
+
return edit
|
| 40 |
+
else:
|
| 41 |
+
edit._close()
|
| 42 |
+
return None
|
| 43 |
+
|
| 44 |
+
def gotofileline(self, filename, lineno=None):
|
| 45 |
+
edit = self.open(filename)
|
| 46 |
+
if edit is not None and lineno is not None:
|
| 47 |
+
edit.gotoline(lineno)
|
| 48 |
+
|
| 49 |
+
def new(self, filename=None):
|
| 50 |
+
return self.EditorWindow(self, filename)
|
| 51 |
+
|
| 52 |
+
def close_all_callback(self, *args, **kwds):
|
| 53 |
+
for edit in list(self.inversedict):
|
| 54 |
+
reply = edit.close()
|
| 55 |
+
if reply == "cancel":
|
| 56 |
+
break
|
| 57 |
+
return "break"
|
| 58 |
+
|
| 59 |
+
def unregister_maybe_terminate(self, edit):
|
| 60 |
+
try:
|
| 61 |
+
key = self.inversedict[edit]
|
| 62 |
+
except KeyError:
|
| 63 |
+
print("Don't know this EditorWindow object. (close)")
|
| 64 |
+
return
|
| 65 |
+
if key:
|
| 66 |
+
del self.dict[key]
|
| 67 |
+
del self.inversedict[edit]
|
| 68 |
+
if not self.inversedict:
|
| 69 |
+
self.root.quit()
|
| 70 |
+
|
| 71 |
+
def filename_changed_edit(self, edit):
|
| 72 |
+
edit.saved_change_hook()
|
| 73 |
+
try:
|
| 74 |
+
key = self.inversedict[edit]
|
| 75 |
+
except KeyError:
|
| 76 |
+
print("Don't know this EditorWindow object. (rename)")
|
| 77 |
+
return
|
| 78 |
+
filename = edit.io.filename
|
| 79 |
+
if not filename:
|
| 80 |
+
if key:
|
| 81 |
+
del self.dict[key]
|
| 82 |
+
self.inversedict[edit] = None
|
| 83 |
+
return
|
| 84 |
+
filename = self.canonize(filename)
|
| 85 |
+
newkey = os.path.normcase(filename)
|
| 86 |
+
if newkey == key:
|
| 87 |
+
return
|
| 88 |
+
if newkey in self.dict:
|
| 89 |
+
conflict = self.dict[newkey]
|
| 90 |
+
self.inversedict[conflict] = None
|
| 91 |
+
messagebox.showerror(
|
| 92 |
+
"Name Conflict",
|
| 93 |
+
f"You now have multiple edit windows open for {filename!r}",
|
| 94 |
+
master=self.root)
|
| 95 |
+
self.dict[newkey] = edit
|
| 96 |
+
self.inversedict[edit] = newkey
|
| 97 |
+
if key:
|
| 98 |
+
try:
|
| 99 |
+
del self.dict[key]
|
| 100 |
+
except KeyError:
|
| 101 |
+
pass
|
| 102 |
+
|
| 103 |
+
def canonize(self, filename):
|
| 104 |
+
if not os.path.isabs(filename):
|
| 105 |
+
try:
|
| 106 |
+
pwd = os.getcwd()
|
| 107 |
+
except OSError:
|
| 108 |
+
pass
|
| 109 |
+
else:
|
| 110 |
+
filename = os.path.join(pwd, filename)
|
| 111 |
+
return os.path.normpath(filename)
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
def _test(): # TODO check and convert to htest
|
| 115 |
+
from tkinter import Tk
|
| 116 |
+
from idlelib.editor import fixwordbreaks
|
| 117 |
+
from idlelib.run import fix_scaling
|
| 118 |
+
root = Tk()
|
| 119 |
+
fix_scaling(root)
|
| 120 |
+
fixwordbreaks(root)
|
| 121 |
+
root.withdraw()
|
| 122 |
+
flist = FileList(root)
|
| 123 |
+
flist.new()
|
| 124 |
+
if flist.inversedict:
|
| 125 |
+
root.mainloop()
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
if __name__ == '__main__':
|
| 129 |
+
from unittest import main
|
| 130 |
+
main('idlelib.idle_test.test_filelist', verbosity=2)
|
| 131 |
+
|
| 132 |
+
# _test()
|
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/format.py
ADDED
|
@@ -0,0 +1,426 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Format all or a selected region (line slice) of text.
|
| 2 |
+
|
| 3 |
+
Region formatting options: paragraph, comment block, indent, deindent,
|
| 4 |
+
comment, uncomment, tabify, and untabify.
|
| 5 |
+
|
| 6 |
+
File renamed from paragraph.py with functions added from editor.py.
|
| 7 |
+
"""
|
| 8 |
+
import re
|
| 9 |
+
from tkinter.messagebox import askyesno
|
| 10 |
+
from tkinter.simpledialog import askinteger
|
| 11 |
+
from idlelib.config import idleConf
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class FormatParagraph:
|
| 15 |
+
"""Format a paragraph, comment block, or selection to a max width.
|
| 16 |
+
|
| 17 |
+
Does basic, standard text formatting, and also understands Python
|
| 18 |
+
comment blocks. Thus, for editing Python source code, this
|
| 19 |
+
extension is really only suitable for reformatting these comment
|
| 20 |
+
blocks or triple-quoted strings.
|
| 21 |
+
|
| 22 |
+
Known problems with comment reformatting:
|
| 23 |
+
* If there is a selection marked, and the first line of the
|
| 24 |
+
selection is not complete, the block will probably not be detected
|
| 25 |
+
as comments, and will have the normal "text formatting" rules
|
| 26 |
+
applied.
|
| 27 |
+
* If a comment block has leading whitespace that mixes tabs and
|
| 28 |
+
spaces, they will not be considered part of the same block.
|
| 29 |
+
* Fancy comments, like this bulleted list, aren't handled :-)
|
| 30 |
+
"""
|
| 31 |
+
def __init__(self, editwin):
|
| 32 |
+
self.editwin = editwin
|
| 33 |
+
|
| 34 |
+
@classmethod
|
| 35 |
+
def reload(cls):
|
| 36 |
+
cls.max_width = idleConf.GetOption('extensions', 'FormatParagraph',
|
| 37 |
+
'max-width', type='int', default=72)
|
| 38 |
+
|
| 39 |
+
def close(self):
|
| 40 |
+
self.editwin = None
|
| 41 |
+
|
| 42 |
+
def format_paragraph_event(self, event, limit=None):
|
| 43 |
+
"""Formats paragraph to a max width specified in idleConf.
|
| 44 |
+
|
| 45 |
+
If text is selected, format_paragraph_event will start breaking lines
|
| 46 |
+
at the max width, starting from the beginning selection.
|
| 47 |
+
|
| 48 |
+
If no text is selected, format_paragraph_event uses the current
|
| 49 |
+
cursor location to determine the paragraph (lines of text surrounded
|
| 50 |
+
by blank lines) and formats it.
|
| 51 |
+
|
| 52 |
+
The length limit parameter is for testing with a known value.
|
| 53 |
+
"""
|
| 54 |
+
limit = self.max_width if limit is None else limit
|
| 55 |
+
text = self.editwin.text
|
| 56 |
+
first, last = self.editwin.get_selection_indices()
|
| 57 |
+
if first and last:
|
| 58 |
+
data = text.get(first, last)
|
| 59 |
+
comment_header = get_comment_header(data)
|
| 60 |
+
else:
|
| 61 |
+
first, last, comment_header, data = \
|
| 62 |
+
find_paragraph(text, text.index("insert"))
|
| 63 |
+
if comment_header:
|
| 64 |
+
newdata = reformat_comment(data, limit, comment_header)
|
| 65 |
+
else:
|
| 66 |
+
newdata = reformat_paragraph(data, limit)
|
| 67 |
+
text.tag_remove("sel", "1.0", "end")
|
| 68 |
+
|
| 69 |
+
if newdata != data:
|
| 70 |
+
text.mark_set("insert", first)
|
| 71 |
+
text.undo_block_start()
|
| 72 |
+
text.delete(first, last)
|
| 73 |
+
text.insert(first, newdata)
|
| 74 |
+
text.undo_block_stop()
|
| 75 |
+
else:
|
| 76 |
+
text.mark_set("insert", last)
|
| 77 |
+
text.see("insert")
|
| 78 |
+
return "break"
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
FormatParagraph.reload()
|
| 82 |
+
|
| 83 |
+
def find_paragraph(text, mark):
|
| 84 |
+
"""Returns the start/stop indices enclosing the paragraph that mark is in.
|
| 85 |
+
|
| 86 |
+
Also returns the comment format string, if any, and paragraph of text
|
| 87 |
+
between the start/stop indices.
|
| 88 |
+
"""
|
| 89 |
+
lineno, col = map(int, mark.split("."))
|
| 90 |
+
line = text.get("%d.0" % lineno, "%d.end" % lineno)
|
| 91 |
+
|
| 92 |
+
# Look for start of next paragraph if the index passed in is a blank line
|
| 93 |
+
while text.compare("%d.0" % lineno, "<", "end") and is_all_white(line):
|
| 94 |
+
lineno = lineno + 1
|
| 95 |
+
line = text.get("%d.0" % lineno, "%d.end" % lineno)
|
| 96 |
+
first_lineno = lineno
|
| 97 |
+
comment_header = get_comment_header(line)
|
| 98 |
+
comment_header_len = len(comment_header)
|
| 99 |
+
|
| 100 |
+
# Once start line found, search for end of paragraph (a blank line)
|
| 101 |
+
while get_comment_header(line)==comment_header and \
|
| 102 |
+
not is_all_white(line[comment_header_len:]):
|
| 103 |
+
lineno = lineno + 1
|
| 104 |
+
line = text.get("%d.0" % lineno, "%d.end" % lineno)
|
| 105 |
+
last = "%d.0" % lineno
|
| 106 |
+
|
| 107 |
+
# Search back to beginning of paragraph (first blank line before)
|
| 108 |
+
lineno = first_lineno - 1
|
| 109 |
+
line = text.get("%d.0" % lineno, "%d.end" % lineno)
|
| 110 |
+
while lineno > 0 and \
|
| 111 |
+
get_comment_header(line)==comment_header and \
|
| 112 |
+
not is_all_white(line[comment_header_len:]):
|
| 113 |
+
lineno = lineno - 1
|
| 114 |
+
line = text.get("%d.0" % lineno, "%d.end" % lineno)
|
| 115 |
+
first = "%d.0" % (lineno+1)
|
| 116 |
+
|
| 117 |
+
return first, last, comment_header, text.get(first, last)
|
| 118 |
+
|
| 119 |
+
# This should perhaps be replaced with textwrap.wrap
|
| 120 |
+
def reformat_paragraph(data, limit):
|
| 121 |
+
"""Return data reformatted to specified width (limit)."""
|
| 122 |
+
lines = data.split("\n")
|
| 123 |
+
i = 0
|
| 124 |
+
n = len(lines)
|
| 125 |
+
while i < n and is_all_white(lines[i]):
|
| 126 |
+
i = i+1
|
| 127 |
+
if i >= n:
|
| 128 |
+
return data
|
| 129 |
+
indent1 = get_indent(lines[i])
|
| 130 |
+
if i+1 < n and not is_all_white(lines[i+1]):
|
| 131 |
+
indent2 = get_indent(lines[i+1])
|
| 132 |
+
else:
|
| 133 |
+
indent2 = indent1
|
| 134 |
+
new = lines[:i]
|
| 135 |
+
partial = indent1
|
| 136 |
+
while i < n and not is_all_white(lines[i]):
|
| 137 |
+
# XXX Should take double space after period (etc.) into account
|
| 138 |
+
words = re.split(r"(\s+)", lines[i])
|
| 139 |
+
for j in range(0, len(words), 2):
|
| 140 |
+
word = words[j]
|
| 141 |
+
if not word:
|
| 142 |
+
continue # Can happen when line ends in whitespace
|
| 143 |
+
if len((partial + word).expandtabs()) > limit and \
|
| 144 |
+
partial != indent1:
|
| 145 |
+
new.append(partial.rstrip())
|
| 146 |
+
partial = indent2
|
| 147 |
+
partial = partial + word + " "
|
| 148 |
+
if j+1 < len(words) and words[j+1] != " ":
|
| 149 |
+
partial = partial + " "
|
| 150 |
+
i = i+1
|
| 151 |
+
new.append(partial.rstrip())
|
| 152 |
+
# XXX Should reformat remaining paragraphs as well
|
| 153 |
+
new.extend(lines[i:])
|
| 154 |
+
return "\n".join(new)
|
| 155 |
+
|
| 156 |
+
def reformat_comment(data, limit, comment_header):
|
| 157 |
+
"""Return data reformatted to specified width with comment header."""
|
| 158 |
+
|
| 159 |
+
# Remove header from the comment lines
|
| 160 |
+
lc = len(comment_header)
|
| 161 |
+
data = "\n".join(line[lc:] for line in data.split("\n"))
|
| 162 |
+
# Reformat to maxformatwidth chars or a 20 char width,
|
| 163 |
+
# whichever is greater.
|
| 164 |
+
format_width = max(limit - len(comment_header), 20)
|
| 165 |
+
newdata = reformat_paragraph(data, format_width)
|
| 166 |
+
# re-split and re-insert the comment header.
|
| 167 |
+
newdata = newdata.split("\n")
|
| 168 |
+
# If the block ends in a \n, we don't want the comment prefix
|
| 169 |
+
# inserted after it. (Im not sure it makes sense to reformat a
|
| 170 |
+
# comment block that is not made of complete lines, but whatever!)
|
| 171 |
+
# Can't think of a clean solution, so we hack away
|
| 172 |
+
block_suffix = ""
|
| 173 |
+
if not newdata[-1]:
|
| 174 |
+
block_suffix = "\n"
|
| 175 |
+
newdata = newdata[:-1]
|
| 176 |
+
return '\n'.join(comment_header+line for line in newdata) + block_suffix
|
| 177 |
+
|
| 178 |
+
def is_all_white(line):
|
| 179 |
+
"""Return True if line is empty or all whitespace."""
|
| 180 |
+
|
| 181 |
+
return re.match(r"^\s*$", line) is not None
|
| 182 |
+
|
| 183 |
+
def get_indent(line):
|
| 184 |
+
"""Return the initial space or tab indent of line."""
|
| 185 |
+
return re.match(r"^([ \t]*)", line).group()
|
| 186 |
+
|
| 187 |
+
def get_comment_header(line):
|
| 188 |
+
"""Return string with leading whitespace and '#' from line or ''.
|
| 189 |
+
|
| 190 |
+
A null return indicates that the line is not a comment line. A non-
|
| 191 |
+
null return, such as ' #', will be used to find the other lines of
|
| 192 |
+
a comment block with the same indent.
|
| 193 |
+
"""
|
| 194 |
+
m = re.match(r"^([ \t]*#*)", line)
|
| 195 |
+
if m is None: return ""
|
| 196 |
+
return m.group(1)
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
# Copied from editor.py; importing it would cause an import cycle.
|
| 200 |
+
_line_indent_re = re.compile(r'[ \t]*')
|
| 201 |
+
|
| 202 |
+
def get_line_indent(line, tabwidth):
|
| 203 |
+
"""Return a line's indentation as (# chars, effective # of spaces).
|
| 204 |
+
|
| 205 |
+
The effective # of spaces is the length after properly "expanding"
|
| 206 |
+
the tabs into spaces, as done by str.expandtabs(tabwidth).
|
| 207 |
+
"""
|
| 208 |
+
m = _line_indent_re.match(line)
|
| 209 |
+
return m.end(), len(m.group().expandtabs(tabwidth))
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
class FormatRegion:
|
| 213 |
+
"Format selected text (region)."
|
| 214 |
+
|
| 215 |
+
def __init__(self, editwin):
|
| 216 |
+
self.editwin = editwin
|
| 217 |
+
|
| 218 |
+
def get_region(self):
|
| 219 |
+
"""Return line information about the selected text region.
|
| 220 |
+
|
| 221 |
+
If text is selected, the first and last indices will be
|
| 222 |
+
for the selection. If there is no text selected, the
|
| 223 |
+
indices will be the current cursor location.
|
| 224 |
+
|
| 225 |
+
Return a tuple containing (first index, last index,
|
| 226 |
+
string representation of text, list of text lines).
|
| 227 |
+
"""
|
| 228 |
+
text = self.editwin.text
|
| 229 |
+
first, last = self.editwin.get_selection_indices()
|
| 230 |
+
if first and last:
|
| 231 |
+
head = text.index(first + " linestart")
|
| 232 |
+
tail = text.index(last + "-1c lineend +1c")
|
| 233 |
+
else:
|
| 234 |
+
head = text.index("insert linestart")
|
| 235 |
+
tail = text.index("insert lineend +1c")
|
| 236 |
+
chars = text.get(head, tail)
|
| 237 |
+
lines = chars.split("\n")
|
| 238 |
+
return head, tail, chars, lines
|
| 239 |
+
|
| 240 |
+
def set_region(self, head, tail, chars, lines):
|
| 241 |
+
"""Replace the text between the given indices.
|
| 242 |
+
|
| 243 |
+
Args:
|
| 244 |
+
head: Starting index of text to replace.
|
| 245 |
+
tail: Ending index of text to replace.
|
| 246 |
+
chars: Expected to be string of current text
|
| 247 |
+
between head and tail.
|
| 248 |
+
lines: List of new lines to insert between head
|
| 249 |
+
and tail.
|
| 250 |
+
"""
|
| 251 |
+
text = self.editwin.text
|
| 252 |
+
newchars = "\n".join(lines)
|
| 253 |
+
if newchars == chars:
|
| 254 |
+
text.bell()
|
| 255 |
+
return
|
| 256 |
+
text.tag_remove("sel", "1.0", "end")
|
| 257 |
+
text.mark_set("insert", head)
|
| 258 |
+
text.undo_block_start()
|
| 259 |
+
text.delete(head, tail)
|
| 260 |
+
text.insert(head, newchars)
|
| 261 |
+
text.undo_block_stop()
|
| 262 |
+
text.tag_add("sel", head, "insert")
|
| 263 |
+
|
| 264 |
+
def indent_region_event(self, event=None):
|
| 265 |
+
"Indent region by indentwidth spaces."
|
| 266 |
+
head, tail, chars, lines = self.get_region()
|
| 267 |
+
for pos in range(len(lines)):
|
| 268 |
+
line = lines[pos]
|
| 269 |
+
if line:
|
| 270 |
+
raw, effective = get_line_indent(line, self.editwin.tabwidth)
|
| 271 |
+
effective = effective + self.editwin.indentwidth
|
| 272 |
+
lines[pos] = self.editwin._make_blanks(effective) + line[raw:]
|
| 273 |
+
self.set_region(head, tail, chars, lines)
|
| 274 |
+
return "break"
|
| 275 |
+
|
| 276 |
+
def dedent_region_event(self, event=None):
|
| 277 |
+
"Dedent region by indentwidth spaces."
|
| 278 |
+
head, tail, chars, lines = self.get_region()
|
| 279 |
+
for pos in range(len(lines)):
|
| 280 |
+
line = lines[pos]
|
| 281 |
+
if line:
|
| 282 |
+
raw, effective = get_line_indent(line, self.editwin.tabwidth)
|
| 283 |
+
effective = max(effective - self.editwin.indentwidth, 0)
|
| 284 |
+
lines[pos] = self.editwin._make_blanks(effective) + line[raw:]
|
| 285 |
+
self.set_region(head, tail, chars, lines)
|
| 286 |
+
return "break"
|
| 287 |
+
|
| 288 |
+
def comment_region_event(self, event=None):
|
| 289 |
+
"""Comment out each line in region.
|
| 290 |
+
|
| 291 |
+
## is appended to the beginning of each line to comment it out.
|
| 292 |
+
"""
|
| 293 |
+
head, tail, chars, lines = self.get_region()
|
| 294 |
+
for pos in range(len(lines) - 1):
|
| 295 |
+
line = lines[pos]
|
| 296 |
+
lines[pos] = '##' + line
|
| 297 |
+
self.set_region(head, tail, chars, lines)
|
| 298 |
+
return "break"
|
| 299 |
+
|
| 300 |
+
def uncomment_region_event(self, event=None):
|
| 301 |
+
"""Uncomment each line in region.
|
| 302 |
+
|
| 303 |
+
Remove ## or # in the first positions of a line. If the comment
|
| 304 |
+
is not in the beginning position, this command will have no effect.
|
| 305 |
+
"""
|
| 306 |
+
head, tail, chars, lines = self.get_region()
|
| 307 |
+
for pos in range(len(lines)):
|
| 308 |
+
line = lines[pos]
|
| 309 |
+
if not line:
|
| 310 |
+
continue
|
| 311 |
+
if line[:2] == '##':
|
| 312 |
+
line = line[2:]
|
| 313 |
+
elif line[:1] == '#':
|
| 314 |
+
line = line[1:]
|
| 315 |
+
lines[pos] = line
|
| 316 |
+
self.set_region(head, tail, chars, lines)
|
| 317 |
+
return "break"
|
| 318 |
+
|
| 319 |
+
def tabify_region_event(self, event=None):
|
| 320 |
+
"Convert leading spaces to tabs for each line in selected region."
|
| 321 |
+
head, tail, chars, lines = self.get_region()
|
| 322 |
+
tabwidth = self._asktabwidth()
|
| 323 |
+
if tabwidth is None:
|
| 324 |
+
return
|
| 325 |
+
for pos in range(len(lines)):
|
| 326 |
+
line = lines[pos]
|
| 327 |
+
if line:
|
| 328 |
+
raw, effective = get_line_indent(line, tabwidth)
|
| 329 |
+
ntabs, nspaces = divmod(effective, tabwidth)
|
| 330 |
+
lines[pos] = '\t' * ntabs + ' ' * nspaces + line[raw:]
|
| 331 |
+
self.set_region(head, tail, chars, lines)
|
| 332 |
+
return "break"
|
| 333 |
+
|
| 334 |
+
def untabify_region_event(self, event=None):
|
| 335 |
+
"Expand tabs to spaces for each line in region."
|
| 336 |
+
head, tail, chars, lines = self.get_region()
|
| 337 |
+
tabwidth = self._asktabwidth()
|
| 338 |
+
if tabwidth is None:
|
| 339 |
+
return
|
| 340 |
+
for pos in range(len(lines)):
|
| 341 |
+
lines[pos] = lines[pos].expandtabs(tabwidth)
|
| 342 |
+
self.set_region(head, tail, chars, lines)
|
| 343 |
+
return "break"
|
| 344 |
+
|
| 345 |
+
def _asktabwidth(self):
|
| 346 |
+
"Return value for tab width."
|
| 347 |
+
return askinteger(
|
| 348 |
+
"Tab width",
|
| 349 |
+
"Columns per tab? (2-16)",
|
| 350 |
+
parent=self.editwin.text,
|
| 351 |
+
initialvalue=self.editwin.indentwidth,
|
| 352 |
+
minvalue=2,
|
| 353 |
+
maxvalue=16)
|
| 354 |
+
|
| 355 |
+
|
| 356 |
+
class Indents:
|
| 357 |
+
"Change future indents."
|
| 358 |
+
|
| 359 |
+
def __init__(self, editwin):
|
| 360 |
+
self.editwin = editwin
|
| 361 |
+
|
| 362 |
+
def toggle_tabs_event(self, event):
|
| 363 |
+
editwin = self.editwin
|
| 364 |
+
usetabs = editwin.usetabs
|
| 365 |
+
if askyesno(
|
| 366 |
+
"Toggle tabs",
|
| 367 |
+
"Turn tabs " + ("on", "off")[usetabs] +
|
| 368 |
+
"?\nIndent width " +
|
| 369 |
+
("will be", "remains at")[usetabs] + " 8." +
|
| 370 |
+
"\n Note: a tab is always 8 columns",
|
| 371 |
+
parent=editwin.text):
|
| 372 |
+
editwin.usetabs = not usetabs
|
| 373 |
+
# Try to prevent inconsistent indentation.
|
| 374 |
+
# User must change indent width manually after using tabs.
|
| 375 |
+
editwin.indentwidth = 8
|
| 376 |
+
return "break"
|
| 377 |
+
|
| 378 |
+
def change_indentwidth_event(self, event):
|
| 379 |
+
editwin = self.editwin
|
| 380 |
+
new = askinteger(
|
| 381 |
+
"Indent width",
|
| 382 |
+
"New indent width (2-16)\n(Always use 8 when using tabs)",
|
| 383 |
+
parent=editwin.text,
|
| 384 |
+
initialvalue=editwin.indentwidth,
|
| 385 |
+
minvalue=2,
|
| 386 |
+
maxvalue=16)
|
| 387 |
+
if new and new != editwin.indentwidth and not editwin.usetabs:
|
| 388 |
+
editwin.indentwidth = new
|
| 389 |
+
return "break"
|
| 390 |
+
|
| 391 |
+
|
| 392 |
+
class Rstrip: # 'Strip Trailing Whitespace" on "Format" menu.
|
| 393 |
+
def __init__(self, editwin):
|
| 394 |
+
self.editwin = editwin
|
| 395 |
+
|
| 396 |
+
def do_rstrip(self, event=None):
|
| 397 |
+
text = self.editwin.text
|
| 398 |
+
undo = self.editwin.undo
|
| 399 |
+
undo.undo_block_start()
|
| 400 |
+
|
| 401 |
+
end_line = int(float(text.index('end')))
|
| 402 |
+
for cur in range(1, end_line):
|
| 403 |
+
txt = text.get('%i.0' % cur, '%i.end' % cur)
|
| 404 |
+
raw = len(txt)
|
| 405 |
+
cut = len(txt.rstrip())
|
| 406 |
+
# Since text.delete() marks file as changed, even if not,
|
| 407 |
+
# only call it when needed to actually delete something.
|
| 408 |
+
if cut < raw:
|
| 409 |
+
text.delete('%i.%i' % (cur, cut), '%i.end' % cur)
|
| 410 |
+
|
| 411 |
+
if (text.get('end-2c') == '\n' # File ends with at least 1 newline;
|
| 412 |
+
and not hasattr(self.editwin, 'interp')): # & is not Shell.
|
| 413 |
+
# Delete extra user endlines.
|
| 414 |
+
while (text.index('end-1c') > '1.0' # Stop if file empty.
|
| 415 |
+
and text.get('end-3c') == '\n'):
|
| 416 |
+
text.delete('end-3c')
|
| 417 |
+
# Because tk indexes are slice indexes and never raise,
|
| 418 |
+
# a file with only newlines will be emptied.
|
| 419 |
+
# patchcheck.py does the same.
|
| 420 |
+
|
| 421 |
+
undo.undo_block_stop()
|
| 422 |
+
|
| 423 |
+
|
| 424 |
+
if __name__ == "__main__":
|
| 425 |
+
from unittest import main
|
| 426 |
+
main('idlelib.idle_test.test_format', verbosity=2, exit=False)
|
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/grep.py
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
| 6 |
+
import fnmatch
|
| 7 |
+
import os
|
| 8 |
+
import sys
|
| 9 |
+
|
| 10 |
+
from tkinter import StringVar, BooleanVar
|
| 11 |
+
from tkinter.ttk import Checkbutton # Frame imported in ...Base
|
| 12 |
+
|
| 13 |
+
from idlelib.searchbase import SearchDialogBase
|
| 14 |
+
from idlelib import searchengine
|
| 15 |
+
|
| 16 |
+
# Importing OutputWindow here fails due to import loop
|
| 17 |
+
# EditorWindow -> GrepDialog -> OutputWindow -> EditorWindow
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def grep(text, io=None, flist=None):
|
| 21 |
+
"""Open the Find in Files dialog.
|
| 22 |
+
|
| 23 |
+
Module-level function to access the singleton GrepDialog
|
| 24 |
+
instance and open the dialog. If text is selected, it is
|
| 25 |
+
used as the search phrase; otherwise, the previous entry
|
| 26 |
+
is used.
|
| 27 |
+
|
| 28 |
+
Args:
|
| 29 |
+
text: Text widget that contains the selected text for
|
| 30 |
+
default search phrase.
|
| 31 |
+
io: iomenu.IOBinding instance with default path to search.
|
| 32 |
+
flist: filelist.FileList instance for OutputWindow parent.
|
| 33 |
+
"""
|
| 34 |
+
root = text._root()
|
| 35 |
+
engine = searchengine.get(root)
|
| 36 |
+
if not hasattr(engine, "_grepdialog"):
|
| 37 |
+
engine._grepdialog = GrepDialog(root, engine, flist)
|
| 38 |
+
dialog = engine._grepdialog
|
| 39 |
+
searchphrase = text.get("sel.first", "sel.last")
|
| 40 |
+
dialog.open(text, searchphrase, io)
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def walk_error(msg):
|
| 44 |
+
"Handle os.walk error."
|
| 45 |
+
print(msg)
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def findfiles(folder, pattern, recursive):
|
| 49 |
+
"""Generate file names in dir that match pattern.
|
| 50 |
+
|
| 51 |
+
Args:
|
| 52 |
+
folder: Root directory to search.
|
| 53 |
+
pattern: File pattern to match.
|
| 54 |
+
recursive: True to include subdirectories.
|
| 55 |
+
"""
|
| 56 |
+
for dirpath, _, filenames in os.walk(folder, onerror=walk_error):
|
| 57 |
+
yield from (os.path.join(dirpath, name)
|
| 58 |
+
for name in filenames
|
| 59 |
+
if fnmatch.fnmatch(name, pattern))
|
| 60 |
+
if not recursive:
|
| 61 |
+
break
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
class GrepDialog(SearchDialogBase):
|
| 65 |
+
"Dialog for searching multiple files."
|
| 66 |
+
|
| 67 |
+
title = "Find in Files Dialog"
|
| 68 |
+
icon = "Grep"
|
| 69 |
+
needwrapbutton = 0
|
| 70 |
+
|
| 71 |
+
def __init__(self, root, engine, flist):
|
| 72 |
+
"""Create search dialog for searching for a phrase in the file system.
|
| 73 |
+
|
| 74 |
+
Uses SearchDialogBase as the basis for the GUI and a
|
| 75 |
+
searchengine instance to prepare the search.
|
| 76 |
+
|
| 77 |
+
Attributes:
|
| 78 |
+
flist: filelist.Filelist instance for OutputWindow parent.
|
| 79 |
+
globvar: String value of Entry widget for path to search.
|
| 80 |
+
globent: Entry widget for globvar. Created in
|
| 81 |
+
create_entries().
|
| 82 |
+
recvar: Boolean value of Checkbutton widget for
|
| 83 |
+
traversing through subdirectories.
|
| 84 |
+
"""
|
| 85 |
+
super().__init__(root, engine)
|
| 86 |
+
self.flist = flist
|
| 87 |
+
self.globvar = StringVar(root)
|
| 88 |
+
self.recvar = BooleanVar(root)
|
| 89 |
+
|
| 90 |
+
def open(self, text, searchphrase, io=None):
|
| 91 |
+
"""Make dialog visible on top of others and ready to use.
|
| 92 |
+
|
| 93 |
+
Extend the SearchDialogBase open() to set the initial value
|
| 94 |
+
for globvar.
|
| 95 |
+
|
| 96 |
+
Args:
|
| 97 |
+
text: Multicall object containing the text information.
|
| 98 |
+
searchphrase: String phrase to search.
|
| 99 |
+
io: iomenu.IOBinding instance containing file path.
|
| 100 |
+
"""
|
| 101 |
+
SearchDialogBase.open(self, text, searchphrase)
|
| 102 |
+
if io:
|
| 103 |
+
path = io.filename or ""
|
| 104 |
+
else:
|
| 105 |
+
path = ""
|
| 106 |
+
dir, base = os.path.split(path)
|
| 107 |
+
head, tail = os.path.splitext(base)
|
| 108 |
+
if not tail:
|
| 109 |
+
tail = ".py"
|
| 110 |
+
self.globvar.set(os.path.join(dir, "*" + tail))
|
| 111 |
+
|
| 112 |
+
def create_entries(self):
|
| 113 |
+
"Create base entry widgets and add widget for search path."
|
| 114 |
+
SearchDialogBase.create_entries(self)
|
| 115 |
+
self.globent = self.make_entry("In files:", self.globvar)[0]
|
| 116 |
+
|
| 117 |
+
def create_other_buttons(self):
|
| 118 |
+
"Add check button to recurse down subdirectories."
|
| 119 |
+
btn = Checkbutton(
|
| 120 |
+
self.make_frame()[0], variable=self.recvar,
|
| 121 |
+
text="Recurse down subdirectories")
|
| 122 |
+
btn.pack(side="top", fill="both")
|
| 123 |
+
|
| 124 |
+
def create_command_buttons(self):
|
| 125 |
+
"Create base command buttons and add button for Search Files."
|
| 126 |
+
SearchDialogBase.create_command_buttons(self)
|
| 127 |
+
self.make_button("Search Files", self.default_command, isdef=True)
|
| 128 |
+
|
| 129 |
+
def default_command(self, event=None):
|
| 130 |
+
"""Grep for search pattern in file path. The default command is bound
|
| 131 |
+
to <Return>.
|
| 132 |
+
|
| 133 |
+
If entry values are populated, set OutputWindow as stdout
|
| 134 |
+
and perform search. The search dialog is closed automatically
|
| 135 |
+
when the search begins.
|
| 136 |
+
"""
|
| 137 |
+
prog = self.engine.getprog()
|
| 138 |
+
if not prog:
|
| 139 |
+
return
|
| 140 |
+
path = self.globvar.get()
|
| 141 |
+
if not path:
|
| 142 |
+
self.top.bell()
|
| 143 |
+
return
|
| 144 |
+
from idlelib.outwin import OutputWindow # leave here!
|
| 145 |
+
save = sys.stdout
|
| 146 |
+
try:
|
| 147 |
+
sys.stdout = OutputWindow(self.flist)
|
| 148 |
+
self.grep_it(prog, path)
|
| 149 |
+
finally:
|
| 150 |
+
sys.stdout = save
|
| 151 |
+
|
| 152 |
+
def grep_it(self, prog, path):
|
| 153 |
+
"""Search for prog within the lines of the files in path.
|
| 154 |
+
|
| 155 |
+
For the each file in the path directory, open the file and
|
| 156 |
+
search each line for the matching pattern. If the pattern is
|
| 157 |
+
found, write the file and line information to stdout (which
|
| 158 |
+
is an OutputWindow).
|
| 159 |
+
|
| 160 |
+
Args:
|
| 161 |
+
prog: The compiled, cooked search pattern.
|
| 162 |
+
path: String containing the search path.
|
| 163 |
+
"""
|
| 164 |
+
folder, filepat = os.path.split(path)
|
| 165 |
+
if not folder:
|
| 166 |
+
folder = os.curdir
|
| 167 |
+
filelist = sorted(findfiles(folder, filepat, self.recvar.get()))
|
| 168 |
+
self.close()
|
| 169 |
+
pat = self.engine.getpat()
|
| 170 |
+
print(f"Searching {pat!r} in {path} ...")
|
| 171 |
+
hits = 0
|
| 172 |
+
try:
|
| 173 |
+
for fn in filelist:
|
| 174 |
+
try:
|
| 175 |
+
with open(fn, errors='replace') as f:
|
| 176 |
+
for lineno, line in enumerate(f, 1):
|
| 177 |
+
if line[-1:] == '\n':
|
| 178 |
+
line = line[:-1]
|
| 179 |
+
if prog.search(line):
|
| 180 |
+
sys.stdout.write(f"{fn}: {lineno}: {line}\n")
|
| 181 |
+
hits += 1
|
| 182 |
+
except OSError as msg:
|
| 183 |
+
print(msg)
|
| 184 |
+
print(f"Hits found: {hits}\n(Hint: right-click to open locations.)"
|
| 185 |
+
if hits else "No hits.")
|
| 186 |
+
except AttributeError:
|
| 187 |
+
# Tk window has been closed, OutputWindow.text = None,
|
| 188 |
+
# so in OW.write, OW.text.insert fails.
|
| 189 |
+
pass
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
def _grep_dialog(parent): # htest #
|
| 193 |
+
from tkinter import Toplevel, Text, SEL
|
| 194 |
+
from tkinter.ttk import Frame, Button
|
| 195 |
+
from idlelib.pyshell import PyShellFileList
|
| 196 |
+
|
| 197 |
+
top = Toplevel(parent)
|
| 198 |
+
top.title("Test GrepDialog")
|
| 199 |
+
x, y = map(int, parent.geometry().split('+')[1:])
|
| 200 |
+
top.geometry(f"+{x}+{y + 175}")
|
| 201 |
+
|
| 202 |
+
flist = PyShellFileList(top)
|
| 203 |
+
frame = Frame(top)
|
| 204 |
+
frame.pack()
|
| 205 |
+
text = Text(frame, height=5)
|
| 206 |
+
text.pack()
|
| 207 |
+
text.insert('1.0', 'import grep')
|
| 208 |
+
|
| 209 |
+
def show_grep_dialog():
|
| 210 |
+
text.tag_add(SEL, "1.0", '1.end')
|
| 211 |
+
grep(text, flist=flist)
|
| 212 |
+
text.tag_remove(SEL, "1.0", '1.end')
|
| 213 |
+
|
| 214 |
+
button = Button(frame, text="Show GrepDialog", command=show_grep_dialog)
|
| 215 |
+
button.pack()
|
| 216 |
+
|
| 217 |
+
|
| 218 |
+
if __name__ == "__main__":
|
| 219 |
+
from unittest import main
|
| 220 |
+
main('idlelib.idle_test.test_grep', verbosity=2, exit=False)
|
| 221 |
+
|
| 222 |
+
from idlelib.idle_test.htest import run
|
| 223 |
+
run(_grep_dialog)
|
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/help.html
ADDED
|
@@ -0,0 +1,865 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<section id="idle">
|
| 2 |
+
<span id="idle-python-editor-and-shell"></span><h1>IDLE — Python editor and shell<a class="headerlink" href="#idle" title="Link to this heading">¶</a></h1>
|
| 3 |
+
<p><strong>Source code:</strong> <a class="extlink-source reference external" href="https://github.com/python/cpython/tree/main/Lib/idlelib/">Lib/idlelib/</a></p>
|
| 4 |
+
<span class="target" id="index-0"></span><hr class="docutils" />
|
| 5 |
+
<p>IDLE is Python’s Integrated Development and Learning Environment.</p>
|
| 6 |
+
<p>IDLE has the following features:</p>
|
| 7 |
+
<ul class="simple">
|
| 8 |
+
<li><p>cross-platform: works mostly the same on Windows, Unix, and macOS</p></li>
|
| 9 |
+
<li><p>Python shell window (interactive interpreter) with colorizing
|
| 10 |
+
of code input, output, and error messages</p></li>
|
| 11 |
+
<li><p>multi-window text editor with multiple undo, Python colorizing,
|
| 12 |
+
smart indent, call tips, auto completion, and other features</p></li>
|
| 13 |
+
<li><p>search within any window, replace within editor windows, and search
|
| 14 |
+
through multiple files (grep)</p></li>
|
| 15 |
+
<li><p>debugger with persistent breakpoints, stepping, and viewing
|
| 16 |
+
of global and local namespaces</p></li>
|
| 17 |
+
<li><p>configuration, browsers, and other dialogs</p></li>
|
| 18 |
+
</ul>
|
| 19 |
+
<p>The IDLE application is implemented in the <a class="reference internal" href="#module-idlelib" title="idlelib: Implementation package for the IDLE shell/editor."><code class="xref py py-mod docutils literal notranslate"><span class="pre">idlelib</span></code></a> package.</p>
|
| 20 |
+
<p>This is an optional module. If it is missing from your copy of CPython, look for documentation from your distributor (that is, whoever provided Python to you).
|
| 21 |
+
If you are the distributor, see Requirements for optional modules.</p>
|
| 22 |
+
<section id="menus">
|
| 23 |
+
<h2>Menus<a class="headerlink" href="#menus" title="Link to this heading">¶</a></h2>
|
| 24 |
+
<p>IDLE has two main window types, the Shell window and the Editor window. It is
|
| 25 |
+
possible to have multiple editor windows simultaneously. On Windows and
|
| 26 |
+
Linux, each has its own top menu. Each menu documented below indicates
|
| 27 |
+
which window type it is associated with.</p>
|
| 28 |
+
<p>Output windows, such as used for Edit => Find in Files, are a subtype of editor
|
| 29 |
+
window. They currently have the same top menu but a different
|
| 30 |
+
default title and context menu.</p>
|
| 31 |
+
<p>On macOS, there is one application menu. It dynamically changes according
|
| 32 |
+
to the window currently selected. It has an IDLE menu, and some entries
|
| 33 |
+
described below are moved around to conform to Apple guidelines.</p>
|
| 34 |
+
<section id="file-menu-shell-and-editor">
|
| 35 |
+
<h3>File menu (Shell and Editor)<a class="headerlink" href="#file-menu-shell-and-editor" title="Link to this heading">¶</a></h3>
|
| 36 |
+
<dl class="simple">
|
| 37 |
+
<dt>New File</dt><dd><p>Create a new file editing window.</p>
|
| 38 |
+
</dd>
|
| 39 |
+
<dt>Open…</dt><dd><p>Open an existing file with an Open dialog.</p>
|
| 40 |
+
</dd>
|
| 41 |
+
<dt>Open Module…</dt><dd><p>Open an existing module (searches sys.path).</p>
|
| 42 |
+
</dd>
|
| 43 |
+
<dt>Recent Files</dt><dd><p>Open a list of recent files. Click one to open it.</p>
|
| 44 |
+
</dd>
|
| 45 |
+
</dl>
|
| 46 |
+
<dl class="simple" id="index-1">
|
| 47 |
+
<dt>Module Browser</dt><dd><p>Show functions, classes, and methods in the current Editor file in a
|
| 48 |
+
tree structure. In the shell, open a module first.</p>
|
| 49 |
+
</dd>
|
| 50 |
+
<dt>Path Browser</dt><dd><p>Show sys.path directories, modules, functions, classes and methods in a
|
| 51 |
+
tree structure.</p>
|
| 52 |
+
</dd>
|
| 53 |
+
<dt>Save</dt><dd><p>Save the current window to the associated file, if there is one. Windows
|
| 54 |
+
that have been changed since being opened or last saved have a * before
|
| 55 |
+
and after the window title. If there is no associated file,
|
| 56 |
+
do Save As instead.</p>
|
| 57 |
+
</dd>
|
| 58 |
+
<dt>Save As…</dt><dd><p>Save the current window with a Save As dialog. The file saved becomes the
|
| 59 |
+
new associated file for the window. (If your file manager is set to hide
|
| 60 |
+
extensions, the current extension will be omitted in the file name box.
|
| 61 |
+
If the new filename has no ‘.’, ‘.py’ and ‘.txt’ will be added for Python
|
| 62 |
+
and text files, except that on macOS Aqua,’.py’ is added for all files.)</p>
|
| 63 |
+
</dd>
|
| 64 |
+
<dt>Save Copy As…</dt><dd><p>Save the current window to different file without changing the associated
|
| 65 |
+
file. (See Save As note above about filename extensions.)</p>
|
| 66 |
+
</dd>
|
| 67 |
+
<dt>Print Window</dt><dd><p>Print the current window to the default printer.</p>
|
| 68 |
+
</dd>
|
| 69 |
+
<dt>Close Window</dt><dd><p>Close the current window (if an unsaved editor, ask to save; if an unsaved
|
| 70 |
+
Shell, ask to quit execution). Calling <code class="docutils literal notranslate"><span class="pre">exit()</span></code> or <code class="docutils literal notranslate"><span class="pre">close()</span></code> in the Shell
|
| 71 |
+
window also closes Shell. If this is the only window, also exit IDLE.</p>
|
| 72 |
+
</dd>
|
| 73 |
+
<dt>Exit IDLE</dt><dd><p>Close all windows and quit IDLE (ask to save unsaved edit windows).</p>
|
| 74 |
+
</dd>
|
| 75 |
+
</dl>
|
| 76 |
+
</section>
|
| 77 |
+
<section id="edit-menu-shell-and-editor">
|
| 78 |
+
<h3>Edit menu (Shell and Editor)<a class="headerlink" href="#edit-menu-shell-and-editor" title="Link to this heading">¶</a></h3>
|
| 79 |
+
<dl class="simple">
|
| 80 |
+
<dt>Undo</dt><dd><p>Undo the last change to the current window. A maximum of 1000 changes may
|
| 81 |
+
be undone.</p>
|
| 82 |
+
</dd>
|
| 83 |
+
<dt>Redo</dt><dd><p>Redo the last undone change to the current window.</p>
|
| 84 |
+
</dd>
|
| 85 |
+
<dt>Select All</dt><dd><p>Select the entire contents of the current window.</p>
|
| 86 |
+
</dd>
|
| 87 |
+
<dt>Cut</dt><dd><p>Copy selection into the system-wide clipboard; then delete the selection.</p>
|
| 88 |
+
</dd>
|
| 89 |
+
<dt>Copy</dt><dd><p>Copy selection into the system-wide clipboard.</p>
|
| 90 |
+
</dd>
|
| 91 |
+
<dt>Paste</dt><dd><p>Insert contents of the system-wide clipboard into the current window.</p>
|
| 92 |
+
</dd>
|
| 93 |
+
</dl>
|
| 94 |
+
<p>The clipboard functions are also available in context menus.</p>
|
| 95 |
+
<dl class="simple">
|
| 96 |
+
<dt>Find…</dt><dd><p>Open a search dialog with many options</p>
|
| 97 |
+
</dd>
|
| 98 |
+
<dt>Find Again</dt><dd><p>Repeat the last search, if there is one.</p>
|
| 99 |
+
</dd>
|
| 100 |
+
<dt>Find Selection</dt><dd><p>Search for the currently selected string, if there is one.</p>
|
| 101 |
+
</dd>
|
| 102 |
+
<dt>Find in Files…</dt><dd><p>Open a file search dialog. Put results in a new output window.</p>
|
| 103 |
+
</dd>
|
| 104 |
+
<dt>Replace…</dt><dd><p>Open a search-and-replace dialog.</p>
|
| 105 |
+
</dd>
|
| 106 |
+
<dt>Go to Line</dt><dd><p>Move the cursor to the beginning of the line requested and make that
|
| 107 |
+
line visible. A request past the end of the file goes to the end.
|
| 108 |
+
Clear any selection and update the line and column status.</p>
|
| 109 |
+
</dd>
|
| 110 |
+
<dt>Show Completions</dt><dd><p>Open a scrollable list allowing selection of existing names. See
|
| 111 |
+
<a class="reference internal" href="#completions"><span class="std std-ref">Completions</span></a> in the Editing and Navigation section below.</p>
|
| 112 |
+
</dd>
|
| 113 |
+
<dt>Expand Word</dt><dd><p>Expand a prefix you have typed to match a full word in the same window;
|
| 114 |
+
repeat to get a different expansion.</p>
|
| 115 |
+
</dd>
|
| 116 |
+
<dt>Show Call Tip</dt><dd><p>After an unclosed parenthesis for a function, open a small window with
|
| 117 |
+
function parameter hints. See <a class="reference internal" href="#calltips"><span class="std std-ref">Calltips</span></a> in the
|
| 118 |
+
Editing and Navigation section below.</p>
|
| 119 |
+
</dd>
|
| 120 |
+
<dt>Show Surrounding Parens</dt><dd><p>Highlight the surrounding parenthesis.</p>
|
| 121 |
+
</dd>
|
| 122 |
+
</dl>
|
| 123 |
+
</section>
|
| 124 |
+
<section id="format-menu-editor-window-only">
|
| 125 |
+
<span id="format-menu"></span><h3>Format menu (Editor window only)<a class="headerlink" href="#format-menu-editor-window-only" title="Link to this heading">¶</a></h3>
|
| 126 |
+
<dl class="simple">
|
| 127 |
+
<dt>Format Paragraph</dt><dd><p>Rewrap the text block containing the text insert cursor.
|
| 128 |
+
Avoid code lines. See <a class="reference internal" href="#format-block"><span class="std std-ref">Format block</span></a> in the
|
| 129 |
+
Editing and Navigation section below.</p>
|
| 130 |
+
</dd>
|
| 131 |
+
<dt>Indent Region</dt><dd><p>Shift selected lines right by the indent width (default 4 spaces).</p>
|
| 132 |
+
</dd>
|
| 133 |
+
<dt>Dedent Region</dt><dd><p>Shift selected lines left by the indent width (default 4 spaces).</p>
|
| 134 |
+
</dd>
|
| 135 |
+
<dt>Comment Out Region</dt><dd><p>Insert ## in front of selected lines.</p>
|
| 136 |
+
</dd>
|
| 137 |
+
<dt>Uncomment Region</dt><dd><p>Remove leading # or ## from selected lines.</p>
|
| 138 |
+
</dd>
|
| 139 |
+
<dt>Tabify Region</dt><dd><p>Turn <em>leading</em> stretches of spaces into tabs. (Note: We recommend using
|
| 140 |
+
4 space blocks to indent Python code.)</p>
|
| 141 |
+
</dd>
|
| 142 |
+
<dt>Untabify Region</dt><dd><p>Turn <em>all</em> tabs into the correct number of spaces.</p>
|
| 143 |
+
</dd>
|
| 144 |
+
<dt>Toggle Tabs</dt><dd><p>Open a dialog to switch between indenting with spaces and tabs.</p>
|
| 145 |
+
</dd>
|
| 146 |
+
<dt>New Indent Width</dt><dd><p>Open a dialog to change indent width. The accepted default by the Python
|
| 147 |
+
community is 4 spaces.</p>
|
| 148 |
+
</dd>
|
| 149 |
+
<dt>Strip Trailing Whitespace</dt><dd><p>Remove trailing space and other whitespace characters after the last
|
| 150 |
+
non-whitespace character of a line by applying <a class="reference internal" href="stdtypes.html#str.rstrip" title="str.rstrip"><code class="xref py py-meth docutils literal notranslate"><span class="pre">str.rstrip()</span></code></a> to each line,
|
| 151 |
+
including lines within multiline strings. Except for Shell windows,
|
| 152 |
+
remove extra newlines at the end of the file.</p>
|
| 153 |
+
</dd>
|
| 154 |
+
</dl>
|
| 155 |
+
</section>
|
| 156 |
+
<section id="run-menu-editor-window-only">
|
| 157 |
+
<span id="index-2"></span><h3>Run menu (Editor window only)<a class="headerlink" href="#run-menu-editor-window-only" title="Link to this heading">¶</a></h3>
|
| 158 |
+
<dl class="simple" id="run-module">
|
| 159 |
+
<dt>Run Module</dt><dd><p>Do <a class="reference internal" href="#check-module"><span class="std std-ref">Check Module</span></a>. If no error, restart the shell to clean the
|
| 160 |
+
environment, then execute the module. Output is displayed in the Shell
|
| 161 |
+
window. Note that output requires use of <code class="docutils literal notranslate"><span class="pre">print</span></code> or <code class="docutils literal notranslate"><span class="pre">write</span></code>.
|
| 162 |
+
When execution is complete, the Shell retains focus and displays a prompt.
|
| 163 |
+
At this point, one may interactively explore the result of execution.
|
| 164 |
+
This is similar to executing a file with <code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">-i</span> <span class="pre">file</span></code> at a command
|
| 165 |
+
line.</p>
|
| 166 |
+
</dd>
|
| 167 |
+
</dl>
|
| 168 |
+
<dl class="simple" id="run-custom">
|
| 169 |
+
<dt>Run… Customized</dt><dd><p>Same as <a class="reference internal" href="#run-module"><span class="std std-ref">Run Module</span></a>, but run the module with customized
|
| 170 |
+
settings. <em>Command Line Arguments</em> extend <a class="reference internal" href="sys.html#sys.argv" title="sys.argv"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.argv</span></code></a> as if passed
|
| 171 |
+
on a command line. The module can be run in the Shell without restarting.</p>
|
| 172 |
+
</dd>
|
| 173 |
+
</dl>
|
| 174 |
+
<dl class="simple" id="check-module">
|
| 175 |
+
<dt>Check Module</dt><dd><p>Check the syntax of the module currently open in the Editor window. If the
|
| 176 |
+
module has not been saved IDLE will either prompt the user to save or
|
| 177 |
+
autosave, as selected in the General tab of the Idle Settings dialog. If
|
| 178 |
+
there is a syntax error, the approximate location is indicated in the
|
| 179 |
+
Editor window.</p>
|
| 180 |
+
</dd>
|
| 181 |
+
</dl>
|
| 182 |
+
<dl class="simple" id="python-shell">
|
| 183 |
+
<dt>Python Shell</dt><dd><p>Open or wake up the Python Shell window.</p>
|
| 184 |
+
</dd>
|
| 185 |
+
</dl>
|
| 186 |
+
</section>
|
| 187 |
+
<section id="shell-menu-shell-window-only">
|
| 188 |
+
<h3>Shell menu (Shell window only)<a class="headerlink" href="#shell-menu-shell-window-only" title="Link to this heading">¶</a></h3>
|
| 189 |
+
<dl class="simple">
|
| 190 |
+
<dt>View Last Restart</dt><dd><p>Scroll the shell window to the last Shell restart.</p>
|
| 191 |
+
</dd>
|
| 192 |
+
<dt>Restart Shell</dt><dd><p>Restart the shell to clean the environment and reset display and exception handling.</p>
|
| 193 |
+
</dd>
|
| 194 |
+
<dt>Previous History</dt><dd><p>Cycle through earlier commands in history which match the current entry.</p>
|
| 195 |
+
</dd>
|
| 196 |
+
<dt>Next History</dt><dd><p>Cycle through later commands in history which match the current entry.</p>
|
| 197 |
+
</dd>
|
| 198 |
+
<dt>Interrupt Execution</dt><dd><p>Stop a running program.</p>
|
| 199 |
+
</dd>
|
| 200 |
+
</dl>
|
| 201 |
+
</section>
|
| 202 |
+
<section id="debug-menu-shell-window-only">
|
| 203 |
+
<h3>Debug menu (Shell window only)<a class="headerlink" href="#debug-menu-shell-window-only" title="Link to this heading">¶</a></h3>
|
| 204 |
+
<dl class="simple">
|
| 205 |
+
<dt>Go to File/Line</dt><dd><p>Look on the current line. with the cursor, and the line above for a filename
|
| 206 |
+
and line number. If found, open the file if not already open, and show the
|
| 207 |
+
line. Use this to view source lines referenced in an exception traceback
|
| 208 |
+
and lines found by Find in Files. Also available in the context menu of
|
| 209 |
+
the Shell window and Output windows.</p>
|
| 210 |
+
</dd>
|
| 211 |
+
</dl>
|
| 212 |
+
<dl class="simple" id="index-3">
|
| 213 |
+
<dt>Debugger (toggle)</dt><dd><p>When activated, code entered in the Shell or run from an Editor will run
|
| 214 |
+
under the debugger. In the Editor, breakpoints can be set with the context
|
| 215 |
+
menu. This feature is still incomplete and somewhat experimental.</p>
|
| 216 |
+
</dd>
|
| 217 |
+
<dt>Stack Viewer</dt><dd><p>Show the stack traceback of the last exception in a tree widget, with
|
| 218 |
+
access to locals and globals.</p>
|
| 219 |
+
</dd>
|
| 220 |
+
<dt>Auto-open Stack Viewer</dt><dd><p>Toggle automatically opening the stack viewer on an unhandled exception.</p>
|
| 221 |
+
</dd>
|
| 222 |
+
</dl>
|
| 223 |
+
</section>
|
| 224 |
+
<section id="options-menu-shell-and-editor">
|
| 225 |
+
<h3>Options menu (Shell and Editor)<a class="headerlink" href="#options-menu-shell-and-editor" title="Link to this heading">¶</a></h3>
|
| 226 |
+
<dl class="simple">
|
| 227 |
+
<dt>Configure IDLE</dt><dd><p>Open a configuration dialog and change preferences for the following:
|
| 228 |
+
fonts, indentation, keybindings, text color themes, startup windows and
|
| 229 |
+
size, additional help sources, and extensions. On macOS, open the
|
| 230 |
+
configuration dialog by selecting Preferences in the application
|
| 231 |
+
menu. For more details, see
|
| 232 |
+
<a class="reference internal" href="#preferences"><span class="std std-ref">Setting preferences</span></a> under Help and preferences.</p>
|
| 233 |
+
</dd>
|
| 234 |
+
</dl>
|
| 235 |
+
<p>Most configuration options apply to all windows or all future windows.
|
| 236 |
+
The option items below only apply to the active window.</p>
|
| 237 |
+
<dl class="simple">
|
| 238 |
+
<dt>Show/Hide Code Context (Editor Window only)</dt><dd><p>Open a pane at the top of the edit window which shows the block context
|
| 239 |
+
of the code which has scrolled above the top of the window. See
|
| 240 |
+
<a class="reference internal" href="#code-context"><span class="std std-ref">Code Context</span></a> in the Editing and Navigation section
|
| 241 |
+
below.</p>
|
| 242 |
+
</dd>
|
| 243 |
+
<dt>Show/Hide Line Numbers (Editor Window only)</dt><dd><p>Open a column to the left of the edit window which shows the number
|
| 244 |
+
of each line of text. The default is off, which may be changed in the
|
| 245 |
+
preferences (see <a class="reference internal" href="#preferences"><span class="std std-ref">Setting preferences</span></a>).</p>
|
| 246 |
+
</dd>
|
| 247 |
+
<dt>Zoom/Restore Height</dt><dd><p>Toggles the window between normal size and maximum height. The initial size
|
| 248 |
+
defaults to 40 lines by 80 chars unless changed on the General tab of the
|
| 249 |
+
Configure IDLE dialog. The maximum height for a screen is determined by
|
| 250 |
+
momentarily maximizing a window the first time one is zoomed on the screen.
|
| 251 |
+
Changing screen settings may invalidate the saved height. This toggle has
|
| 252 |
+
no effect when a window is maximized.</p>
|
| 253 |
+
</dd>
|
| 254 |
+
</dl>
|
| 255 |
+
</section>
|
| 256 |
+
<section id="window-menu-shell-and-editor">
|
| 257 |
+
<h3>Window menu (Shell and Editor)<a class="headerlink" href="#window-menu-shell-and-editor" title="Link to this heading">¶</a></h3>
|
| 258 |
+
<p>Lists the names of all open windows; select one to bring it to the foreground
|
| 259 |
+
(deiconifying it if necessary).</p>
|
| 260 |
+
</section>
|
| 261 |
+
<section id="help-menu-shell-and-editor">
|
| 262 |
+
<h3>Help menu (Shell and Editor)<a class="headerlink" href="#help-menu-shell-and-editor" title="Link to this heading">¶</a></h3>
|
| 263 |
+
<dl class="simple">
|
| 264 |
+
<dt>About IDLE</dt><dd><p>Display version, copyright, license, credits, and more.</p>
|
| 265 |
+
</dd>
|
| 266 |
+
<dt>IDLE Help</dt><dd><p>Display this IDLE document, detailing the menu options, basic editing and
|
| 267 |
+
navigation, and other tips.</p>
|
| 268 |
+
</dd>
|
| 269 |
+
<dt>Python Docs</dt><dd><p>Access local Python documentation, if installed, or start a web browser
|
| 270 |
+
and open docs.python.org showing the latest Python documentation.</p>
|
| 271 |
+
</dd>
|
| 272 |
+
<dt>Turtle Demo</dt><dd><p>Run the turtledemo module with example Python code and turtle drawings.</p>
|
| 273 |
+
</dd>
|
| 274 |
+
</dl>
|
| 275 |
+
<p>Additional help sources may be added here with the Configure IDLE dialog under
|
| 276 |
+
the General tab. See the <a class="reference internal" href="#help-sources"><span class="std std-ref">Help sources</span></a> subsection below
|
| 277 |
+
for more on Help menu choices.</p>
|
| 278 |
+
</section>
|
| 279 |
+
<section id="context-menus">
|
| 280 |
+
<span id="index-4"></span><h3>Context menus<a class="headerlink" href="#context-menus" title="Link to this heading">¶</a></h3>
|
| 281 |
+
<p>Open a context menu by right-clicking in a window (Control-click on macOS).
|
| 282 |
+
Context menus have the standard clipboard functions also on the Edit menu.</p>
|
| 283 |
+
<dl class="simple">
|
| 284 |
+
<dt>Cut</dt><dd><p>Copy selection into the system-wide clipboard; then delete the selection.</p>
|
| 285 |
+
</dd>
|
| 286 |
+
<dt>Copy</dt><dd><p>Copy selection into the system-wide clipboard.</p>
|
| 287 |
+
</dd>
|
| 288 |
+
<dt>Paste</dt><dd><p>Insert contents of the system-wide clipboard into the current window.</p>
|
| 289 |
+
</dd>
|
| 290 |
+
</dl>
|
| 291 |
+
<p>Editor windows also have breakpoint functions. Lines with a breakpoint set are
|
| 292 |
+
specially marked. Breakpoints only have an effect when running under the
|
| 293 |
+
debugger. Breakpoints for a file are saved in the user’s <code class="docutils literal notranslate"><span class="pre">.idlerc</span></code>
|
| 294 |
+
directory.</p>
|
| 295 |
+
<dl class="simple">
|
| 296 |
+
<dt>Set Breakpoint</dt><dd><p>Set a breakpoint on the current line.</p>
|
| 297 |
+
</dd>
|
| 298 |
+
<dt>Clear Breakpoint</dt><dd><p>Clear the breakpoint on that line.</p>
|
| 299 |
+
</dd>
|
| 300 |
+
</dl>
|
| 301 |
+
<p>Shell and Output windows also have the following.</p>
|
| 302 |
+
<dl class="simple">
|
| 303 |
+
<dt>Go to file/line</dt><dd><p>Same as in Debug menu.</p>
|
| 304 |
+
</dd>
|
| 305 |
+
</dl>
|
| 306 |
+
<p>The Shell window also has an output squeezing facility explained in the <em>Python
|
| 307 |
+
Shell window</em> subsection below.</p>
|
| 308 |
+
<dl class="simple">
|
| 309 |
+
<dt>Squeeze</dt><dd><p>If the cursor is over an output line, squeeze all the output between
|
| 310 |
+
the code above and the prompt below down to a ‘Squeezed text’ label.</p>
|
| 311 |
+
</dd>
|
| 312 |
+
</dl>
|
| 313 |
+
</section>
|
| 314 |
+
</section>
|
| 315 |
+
<section id="editing-and-navigation">
|
| 316 |
+
<span id="id1"></span><h2>Editing and Navigation<a class="headerlink" href="#editing-and-navigation" title="Link to this heading">¶</a></h2>
|
| 317 |
+
<section id="editor-windows">
|
| 318 |
+
<h3>Editor windows<a class="headerlink" href="#editor-windows" title="Link to this heading">¶</a></h3>
|
| 319 |
+
<p>IDLE may open editor windows when it starts, depending on settings
|
| 320 |
+
and how you start IDLE. Thereafter, use the File menu. There can be only
|
| 321 |
+
one open editor window for a given file.</p>
|
| 322 |
+
<p>The title bar contains the name of the file, the full path, and the version
|
| 323 |
+
of Python and IDLE running the window. The status bar contains the line
|
| 324 |
+
number (‘Ln’) and column number (‘Col’). Line numbers start with 1;
|
| 325 |
+
column numbers with 0.</p>
|
| 326 |
+
<p>IDLE assumes that files with a known .py* extension contain Python code
|
| 327 |
+
and that other files do not. Run Python code with the Run menu.</p>
|
| 328 |
+
</section>
|
| 329 |
+
<section id="key-bindings">
|
| 330 |
+
<h3>Key bindings<a class="headerlink" href="#key-bindings" title="Link to this heading">¶</a></h3>
|
| 331 |
+
<p>The IDLE insertion cursor is a thin vertical bar between character
|
| 332 |
+
positions. When characters are entered, the insertion cursor and
|
| 333 |
+
everything to its right moves right one character and
|
| 334 |
+
the new character is entered in the new space.</p>
|
| 335 |
+
<p>Several non-character keys move the cursor and possibly
|
| 336 |
+
delete characters. Deletion does not puts text on the clipboard,
|
| 337 |
+
but IDLE has an undo list. Wherever this doc discusses keys,
|
| 338 |
+
‘C’ refers to the <kbd class="kbd docutils literal notranslate">Control</kbd> key on Windows and
|
| 339 |
+
Unix and the <kbd class="kbd docutils literal notranslate">Command</kbd> key on macOS. (And all such discussions
|
| 340 |
+
assume that the keys have not been re-bound to something else.)</p>
|
| 341 |
+
<ul class="simple">
|
| 342 |
+
<li><p>Arrow keys move the cursor one character or line.</p></li>
|
| 343 |
+
<li><p><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">LeftArrow</kbd> and <kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">RightArrow</kbd> moves left or right one word.</p></li>
|
| 344 |
+
<li><p><kbd class="kbd docutils literal notranslate">Home</kbd> and <kbd class="kbd docutils literal notranslate">End</kbd> go to the beginning or end of the line.</p></li>
|
| 345 |
+
<li><p><kbd class="kbd docutils literal notranslate">Page Up</kbd> and <kbd class="kbd docutils literal notranslate">Page Down</kbd> go up or down one screen.</p></li>
|
| 346 |
+
<li><p><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">Home</kbd> and <kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">End</kbd> go to beginning or end of the file.</p></li>
|
| 347 |
+
<li><p><kbd class="kbd docutils literal notranslate">Backspace</kbd> and <kbd class="kbd docutils literal notranslate">Del</kbd> (or <kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">d</kbd>) delete the previous
|
| 348 |
+
or next character.</p></li>
|
| 349 |
+
<li><p><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">Backspace</kbd> and <kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">Del</kbd> delete one word left or right.</p></li>
|
| 350 |
+
<li><p><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">k</kbd> deletes (‘kills’) everything to the right.</p></li>
|
| 351 |
+
</ul>
|
| 352 |
+
<p>Standard keybindings (like <kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">c</kbd> to copy and <kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">v</kbd> to paste)
|
| 353 |
+
may work. Keybindings are selected in the Configure IDLE dialog.</p>
|
| 354 |
+
</section>
|
| 355 |
+
<section id="automatic-indentation">
|
| 356 |
+
<h3>Automatic indentation<a class="headerlink" href="#automatic-indentation" title="Link to this heading">¶</a></h3>
|
| 357 |
+
<p>After a block-opening statement, the next line is indented by 4 spaces (in the
|
| 358 |
+
Python Shell window by one tab). After certain keywords (break, return etc.)
|
| 359 |
+
the next line is dedented. In leading indentation, <kbd class="kbd docutils literal notranslate">Backspace</kbd> deletes up
|
| 360 |
+
to 4 spaces if they are there. <kbd class="kbd docutils literal notranslate">Tab</kbd> inserts spaces (in the Python
|
| 361 |
+
Shell window one tab), number depends on Indent width. Currently, tabs
|
| 362 |
+
are restricted to four spaces due to Tcl/Tk limitations.</p>
|
| 363 |
+
<p>See also the indent/dedent region commands on the
|
| 364 |
+
<a class="reference internal" href="#format-menu"><span class="std std-ref">Format menu</span></a>.</p>
|
| 365 |
+
</section>
|
| 366 |
+
<section id="search-and-replace">
|
| 367 |
+
<h3>Search and Replace<a class="headerlink" href="#search-and-replace" title="Link to this heading">¶</a></h3>
|
| 368 |
+
<p>Any selection becomes a search target. However, only selections within
|
| 369 |
+
a line work because searches are only performed within lines with the
|
| 370 |
+
terminal newline removed. If <code class="docutils literal notranslate"><span class="pre">[x]</span> <span class="pre">Regular</span> <span class="pre">expression</span></code> is checked, the
|
| 371 |
+
target is interpreted according to the Python re module.</p>
|
| 372 |
+
</section>
|
| 373 |
+
<section id="completions">
|
| 374 |
+
<span id="id2"></span><h3>Completions<a class="headerlink" href="#completions" title="Link to this heading">¶</a></h3>
|
| 375 |
+
<p>Completions are supplied, when requested and available, for module
|
| 376 |
+
names, attributes of classes or functions, or filenames. Each request
|
| 377 |
+
method displays a completion box with existing names. (See tab
|
| 378 |
+
completions below for an exception.) For any box, change the name
|
| 379 |
+
being completed and the item highlighted in the box by
|
| 380 |
+
typing and deleting characters; by hitting <kbd class="kbd docutils literal notranslate">Up</kbd>, <kbd class="kbd docutils literal notranslate">Down</kbd>,
|
| 381 |
+
<kbd class="kbd docutils literal notranslate">PageUp</kbd>, <kbd class="kbd docutils literal notranslate">PageDown</kbd>, <kbd class="kbd docutils literal notranslate">Home</kbd>, and <kbd class="kbd docutils literal notranslate">End</kbd> keys;
|
| 382 |
+
and by a single click within the box. Close the box with <kbd class="kbd docutils literal notranslate">Escape</kbd>,
|
| 383 |
+
<kbd class="kbd docutils literal notranslate">Enter</kbd>, and double <kbd class="kbd docutils literal notranslate">Tab</kbd> keys or clicks outside the box.
|
| 384 |
+
A double click within the box selects and closes.</p>
|
| 385 |
+
<p>One way to open a box is to type a key character and wait for a
|
| 386 |
+
predefined interval. This defaults to 2 seconds; customize it
|
| 387 |
+
in the settings dialog. (To prevent auto popups, set the delay to a
|
| 388 |
+
large number of milliseconds, such as 100000000.) For imported module
|
| 389 |
+
names or class or function attributes, type ‘.’.
|
| 390 |
+
For filenames in the root directory, type <a class="reference internal" href="os.html#os.sep" title="os.sep"><code class="xref py py-data docutils literal notranslate"><span class="pre">os.sep</span></code></a> or
|
| 391 |
+
<a class="reference internal" href="os.html#os.altsep" title="os.altsep"><code class="xref py py-data docutils literal notranslate"><span class="pre">os.altsep</span></code></a> immediately after an opening quote. (On Windows,
|
| 392 |
+
one can specify a drive first.) Move into subdirectories by typing a
|
| 393 |
+
directory name and a separator.</p>
|
| 394 |
+
<p>Instead of waiting, or after a box is closed, open a completion box
|
| 395 |
+
immediately with Show Completions on the Edit menu. The default hot
|
| 396 |
+
key is <kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">space</kbd>. If one types a prefix for the desired name
|
| 397 |
+
before opening the box, the first match or near miss is made visible.
|
| 398 |
+
The result is the same as if one enters a prefix
|
| 399 |
+
after the box is displayed. Show Completions after a quote completes
|
| 400 |
+
filenames in the current directory instead of a root directory.</p>
|
| 401 |
+
<p>Hitting <kbd class="kbd docutils literal notranslate">Tab</kbd> after a prefix usually has the same effect as Show
|
| 402 |
+
Completions. (With no prefix, it indents.) However, if there is only
|
| 403 |
+
one match to the prefix, that match is immediately added to the editor
|
| 404 |
+
text without opening a box.</p>
|
| 405 |
+
<p>Invoking ‘Show Completions’, or hitting <kbd class="kbd docutils literal notranslate">Tab</kbd> after a prefix,
|
| 406 |
+
outside of a string and without a preceding ‘.’ opens a box with
|
| 407 |
+
keywords, builtin names, and available module-level names.</p>
|
| 408 |
+
<p>When editing code in an editor (as oppose to Shell), increase the
|
| 409 |
+
available module-level names by running your code
|
| 410 |
+
and not restarting the Shell thereafter. This is especially useful
|
| 411 |
+
after adding imports at the top of a file. This also increases
|
| 412 |
+
possible attribute completions.</p>
|
| 413 |
+
<p>Completion boxes initially exclude names beginning with ‘_’ or, for
|
| 414 |
+
modules, not included in ‘__all__’. The hidden names can be accessed
|
| 415 |
+
by typing ‘_’ after ‘.’, either before or after the box is opened.</p>
|
| 416 |
+
</section>
|
| 417 |
+
<section id="calltips">
|
| 418 |
+
<span id="id3"></span><h3>Calltips<a class="headerlink" href="#calltips" title="Link to this heading">¶</a></h3>
|
| 419 |
+
<p>A calltip is shown automatically when one types <kbd class="kbd docutils literal notranslate">(</kbd> after the name
|
| 420 |
+
of an <em>accessible</em> function. A function name expression may include
|
| 421 |
+
dots and subscripts. A calltip remains until it is clicked, the cursor
|
| 422 |
+
is moved out of the argument area, or <kbd class="kbd docutils literal notranslate">)</kbd> is typed. Whenever the
|
| 423 |
+
cursor is in the argument part of a definition, select Edit and “Show
|
| 424 |
+
Call Tip” on the menu or enter its shortcut to display a calltip.</p>
|
| 425 |
+
<p>The calltip consists of the function’s signature and docstring up to
|
| 426 |
+
the latter’s first blank line or the fifth non-blank line. (Some builtin
|
| 427 |
+
functions lack an accessible signature.) A ‘/’ or ‘*’ in the signature
|
| 428 |
+
indicates that the preceding or following arguments are passed by
|
| 429 |
+
position or name (keyword) only. Details are subject to change.</p>
|
| 430 |
+
<p>In Shell, the accessible functions depends on what modules have been
|
| 431 |
+
imported into the user process, including those imported by Idle itself,
|
| 432 |
+
and which definitions have been run, all since the last restart.</p>
|
| 433 |
+
<p>For example, restart the Shell and enter <code class="docutils literal notranslate"><span class="pre">itertools.count(</span></code>. A calltip
|
| 434 |
+
appears because Idle imports itertools into the user process for its own
|
| 435 |
+
use. (This could change.) Enter <code class="docutils literal notranslate"><span class="pre">turtle.write(</span></code> and nothing appears.
|
| 436 |
+
Idle does not itself import turtle. The menu entry and shortcut also do
|
| 437 |
+
nothing. Enter <code class="docutils literal notranslate"><span class="pre">import</span> <span class="pre">turtle</span></code>. Thereafter, <code class="docutils literal notranslate"><span class="pre">turtle.write(</span></code>
|
| 438 |
+
will display a calltip.</p>
|
| 439 |
+
<p>In an editor, import statements have no effect until one runs the file.
|
| 440 |
+
One might want to run a file after writing import statements, after
|
| 441 |
+
adding function definitions, or after opening an existing file.</p>
|
| 442 |
+
</section>
|
| 443 |
+
<section id="format-block">
|
| 444 |
+
<span id="id4"></span><h3>Format block<a class="headerlink" href="#format-block" title="Link to this heading">¶</a></h3>
|
| 445 |
+
<p>Reformat Paragraph rewraps a block (‘paragraph’) of contiguous equally
|
| 446 |
+
indented non-blank comments, a similar block of text within a multiline
|
| 447 |
+
string, or a selected subset of either.
|
| 448 |
+
If needed, add a blank line to separate string from code.
|
| 449 |
+
Partial lines in a selection expand to complete lines.
|
| 450 |
+
The resulting lines have the same indent as before
|
| 451 |
+
but have maximum total length of N columns (characters).
|
| 452 |
+
Change the default N of 72 on the Window tab of IDLE Settings.</p>
|
| 453 |
+
</section>
|
| 454 |
+
<section id="code-context">
|
| 455 |
+
<span id="id5"></span><h3>Code Context<a class="headerlink" href="#code-context" title="Link to this heading">¶</a></h3>
|
| 456 |
+
<p>Within an editor window containing Python code, code context can be toggled
|
| 457 |
+
in order to show or hide a pane at the top of the window. When shown, this
|
| 458 |
+
pane freezes the opening lines for block code, such as those beginning with
|
| 459 |
+
<code class="docutils literal notranslate"><span class="pre">class</span></code>, <code class="docutils literal notranslate"><span class="pre">def</span></code>, or <code class="docutils literal notranslate"><span class="pre">if</span></code> keywords, that would have otherwise scrolled
|
| 460 |
+
out of view. The size of the pane will be expanded and contracted as needed
|
| 461 |
+
to show the all current levels of context, up to the maximum number of
|
| 462 |
+
lines defined in the Configure IDLE dialog (which defaults to 15). If there
|
| 463 |
+
are no current context lines and the feature is toggled on, a single blank
|
| 464 |
+
line will display. Clicking on a line in the context pane will move that
|
| 465 |
+
line to the top of the editor.</p>
|
| 466 |
+
<p>The text and background colors for the context pane can be configured under
|
| 467 |
+
the Highlights tab in the Configure IDLE dialog.</p>
|
| 468 |
+
</section>
|
| 469 |
+
<section id="shell-window">
|
| 470 |
+
<h3>Shell window<a class="headerlink" href="#shell-window" title="Link to this heading">¶</a></h3>
|
| 471 |
+
<p>In IDLE’s Shell, enter, edit, and recall complete statements. (Most
|
| 472 |
+
consoles and terminals only work with a single physical line at a time).</p>
|
| 473 |
+
<p>Submit a single-line statement for execution by hitting <kbd class="kbd docutils literal notranslate">Return</kbd>
|
| 474 |
+
with the cursor anywhere on the line. If a line is extended with
|
| 475 |
+
Backslash (<kbd class="kbd docutils literal notranslate">\</kbd>), the cursor must be on the last physical line.
|
| 476 |
+
Submit a multi-line compound statement by entering a blank line after
|
| 477 |
+
the statement.</p>
|
| 478 |
+
<p>When one pastes code into Shell, it is not compiled and possibly executed
|
| 479 |
+
until one hits <kbd class="kbd docutils literal notranslate">Return</kbd>, as specified above.
|
| 480 |
+
One may edit pasted code first.
|
| 481 |
+
If one pastes more than one statement into Shell, the result will be a
|
| 482 |
+
<a class="reference internal" href="exceptions.html#SyntaxError" title="SyntaxError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxError</span></code></a> when multiple statements are compiled as if they were one.</p>
|
| 483 |
+
<p>Lines containing <code class="docutils literal notranslate"><span class="pre">RESTART</span></code> mean that the user execution process has been
|
| 484 |
+
re-started. This occurs when the user execution process has crashed,
|
| 485 |
+
when one requests a restart on the Shell menu, or when one runs code
|
| 486 |
+
in an editor window.</p>
|
| 487 |
+
<p>The editing features described in previous subsections work when entering
|
| 488 |
+
code interactively. IDLE’s Shell window also responds to the following:</p>
|
| 489 |
+
<ul class="simple">
|
| 490 |
+
<li><p><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">c</kbd> attempts to interrupt statement execution (but may fail).</p></li>
|
| 491 |
+
<li><p><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">d</kbd> closes Shell if typed at a <code class="docutils literal notranslate"><span class="pre">>>></span></code> prompt.</p></li>
|
| 492 |
+
<li><p><kbd class="kbd docutils literal notranslate">Alt</kbd>-<kbd class="kbd docutils literal notranslate">p</kbd> and <kbd class="kbd docutils literal notranslate">Alt</kbd>-<kbd class="kbd docutils literal notranslate">n</kbd> (<kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">p</kbd> and <kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">n</kbd> on macOS)
|
| 493 |
+
retrieve to the current prompt the previous or next previously
|
| 494 |
+
entered statement that matches anything already typed.</p></li>
|
| 495 |
+
<li><p><kbd class="kbd docutils literal notranslate">Return</kbd> while the cursor is on any previous statement
|
| 496 |
+
appends the latter to anything already typed at the prompt.</p></li>
|
| 497 |
+
</ul>
|
| 498 |
+
</section>
|
| 499 |
+
<section id="text-colors">
|
| 500 |
+
<h3>Text colors<a class="headerlink" href="#text-colors" title="Link to this heading">¶</a></h3>
|
| 501 |
+
<p>Idle defaults to black on white text, but colors text with special meanings.
|
| 502 |
+
For the shell, these are shell output, shell error, user output, and
|
| 503 |
+
user error. For Python code, at the shell prompt or in an editor, these are
|
| 504 |
+
keywords, builtin class and function names, names following <code class="docutils literal notranslate"><span class="pre">class</span></code> and
|
| 505 |
+
<code class="docutils literal notranslate"><span class="pre">def</span></code>, strings, and comments. For any text window, these are the cursor (when
|
| 506 |
+
present), found text (when possible), and selected text.</p>
|
| 507 |
+
<p>IDLE also highlights the <a class="reference internal" href="../reference/lexical_analysis.html#soft-keywords"><span class="std std-ref">soft keywords</span></a> <a class="reference internal" href="../reference/compound_stmts.html#match"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">match</span></code></a>,
|
| 508 |
+
<a class="reference internal" href="../reference/compound_stmts.html#match"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">case</span></code></a>, and <a class="reference internal" href="../reference/compound_stmts.html#wildcard-patterns"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">_</span></code></a> in
|
| 509 |
+
pattern-matching statements. However, this highlighting is not perfect and
|
| 510 |
+
will be incorrect in some rare cases, including some <code class="docutils literal notranslate"><span class="pre">_</span></code>-s in <code class="docutils literal notranslate"><span class="pre">case</span></code>
|
| 511 |
+
patterns.</p>
|
| 512 |
+
<p>Text coloring is done in the background, so uncolorized text is occasionally
|
| 513 |
+
visible. To change the color scheme, use the Configure IDLE dialog
|
| 514 |
+
Highlighting tab. The marking of debugger breakpoint lines in the editor and
|
| 515 |
+
text in popups and dialogs is not user-configurable.</p>
|
| 516 |
+
</section>
|
| 517 |
+
</section>
|
| 518 |
+
<section id="startup-and-code-execution">
|
| 519 |
+
<h2>Startup and Code Execution<a class="headerlink" href="#startup-and-code-execution" title="Link to this heading">¶</a></h2>
|
| 520 |
+
<p>Upon startup with the <code class="docutils literal notranslate"><span class="pre">-s</span></code> option, IDLE will execute the file referenced by
|
| 521 |
+
the environment variables <span class="target" id="index-5"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">IDLESTARTUP</span></code> or <span class="target" id="index-6"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONSTARTUP"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONSTARTUP</span></code></a>.
|
| 522 |
+
IDLE first checks for <code class="docutils literal notranslate"><span class="pre">IDLESTARTUP</span></code>; if <code class="docutils literal notranslate"><span class="pre">IDLESTARTUP</span></code> is present the file
|
| 523 |
+
referenced is run. If <code class="docutils literal notranslate"><span class="pre">IDLESTARTUP</span></code> is not present, IDLE checks for
|
| 524 |
+
<code class="docutils literal notranslate"><span class="pre">PYTHONSTARTUP</span></code>. Files referenced by these environment variables are
|
| 525 |
+
convenient places to store functions that are used frequently from the IDLE
|
| 526 |
+
shell, or for executing import statements to import common modules.</p>
|
| 527 |
+
<p>In addition, <code class="docutils literal notranslate"><span class="pre">Tk</span></code> also loads a startup file if it is present. Note that the
|
| 528 |
+
Tk file is loaded unconditionally. This additional file is <code class="docutils literal notranslate"><span class="pre">.Idle.py</span></code> and is
|
| 529 |
+
looked for in the user’s home directory. Statements in this file will be
|
| 530 |
+
executed in the Tk namespace, so this file is not useful for importing
|
| 531 |
+
functions to be used from IDLE’s Python shell.</p>
|
| 532 |
+
<section id="command-line-usage">
|
| 533 |
+
<span id="idlelib-cli"></span><h3>Command-line usage<a class="headerlink" href="#command-line-usage" title="Link to this heading">¶</a></h3>
|
| 534 |
+
<p>IDLE can be invoked from the command line with various options. The general syntax is:</p>
|
| 535 |
+
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>python<span class="w"> </span>-m<span class="w"> </span>idlelib<span class="w"> </span><span class="o">[</span>options<span class="o">]</span><span class="w"> </span><span class="o">[</span>file<span class="w"> </span>...<span class="o">]</span>
|
| 536 |
+
</pre></div>
|
| 537 |
+
</div>
|
| 538 |
+
<p>The following options are available:</p>
|
| 539 |
+
<dl class="std option">
|
| 540 |
+
<dt class="sig sig-object std" id="cmdoption-idle-c">
|
| 541 |
+
<span class="sig-name descname"><span class="pre">-c</span></span><span class="sig-prename descclassname"> <span class="pre"><command></span></span><a class="headerlink" href="#cmdoption-idle-c" title="Link to this definition">¶</a></dt>
|
| 542 |
+
<dd><p>Run the specified Python command in the shell window.
|
| 543 |
+
For example, pass <code class="docutils literal notranslate"><span class="pre">-c</span> <span class="pre">"print('Hello,</span> <span class="pre">World!')"</span></code>.
|
| 544 |
+
On Windows, the outer quotes must be double quotes as shown.</p>
|
| 545 |
+
</dd></dl>
|
| 546 |
+
|
| 547 |
+
<dl class="std option">
|
| 548 |
+
<dt class="sig sig-object std" id="cmdoption-idle-d">
|
| 549 |
+
<span class="sig-name descname"><span class="pre">-d</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-idle-d" title="Link to this definition">¶</a></dt>
|
| 550 |
+
<dd><p>Enable the debugger and open the shell window.</p>
|
| 551 |
+
</dd></dl>
|
| 552 |
+
|
| 553 |
+
<dl class="std option">
|
| 554 |
+
<dt class="sig sig-object std" id="cmdoption-idle-e">
|
| 555 |
+
<span class="sig-name descname"><span class="pre">-e</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-idle-e" title="Link to this definition">¶</a></dt>
|
| 556 |
+
<dd><p>Open an editor window.</p>
|
| 557 |
+
</dd></dl>
|
| 558 |
+
|
| 559 |
+
<dl class="std option">
|
| 560 |
+
<dt class="sig sig-object std" id="cmdoption-idle-h">
|
| 561 |
+
<span class="sig-name descname"><span class="pre">-h</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-idle-h" title="Link to this definition">¶</a></dt>
|
| 562 |
+
<dd><p>Print a help message with legal combinations of options and exit.</p>
|
| 563 |
+
</dd></dl>
|
| 564 |
+
|
| 565 |
+
<dl class="std option">
|
| 566 |
+
<dt class="sig sig-object std" id="cmdoption-idle-i">
|
| 567 |
+
<span class="sig-name descname"><span class="pre">-i</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-idle-i" title="Link to this definition">¶</a></dt>
|
| 568 |
+
<dd><p>Open a shell window.</p>
|
| 569 |
+
</dd></dl>
|
| 570 |
+
|
| 571 |
+
<dl class="std option">
|
| 572 |
+
<dt class="sig sig-object std" id="cmdoption-idle-r">
|
| 573 |
+
<span class="sig-name descname"><span class="pre">-r</span></span><span class="sig-prename descclassname"> <span class="pre"><file></span></span><a class="headerlink" href="#cmdoption-idle-r" title="Link to this definition">¶</a></dt>
|
| 574 |
+
<dd><p>Run the specified file in the shell window.</p>
|
| 575 |
+
</dd></dl>
|
| 576 |
+
|
| 577 |
+
<dl class="std option">
|
| 578 |
+
<dt class="sig sig-object std" id="cmdoption-idle-s">
|
| 579 |
+
<span class="sig-name descname"><span class="pre">-s</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-idle-s" title="Link to this definition">¶</a></dt>
|
| 580 |
+
<dd><p>Run the startup file (as defined by the environment variables <span class="target" id="index-7"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">IDLESTARTUP</span></code> or <span class="target" id="index-8"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONSTARTUP"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONSTARTUP</span></code></a>) before opening the shell window.</p>
|
| 581 |
+
</dd></dl>
|
| 582 |
+
|
| 583 |
+
<dl class="std option">
|
| 584 |
+
<dt class="sig sig-object std" id="cmdoption-idle-t">
|
| 585 |
+
<span class="sig-name descname"><span class="pre">-t</span></span><span class="sig-prename descclassname"> <span class="pre"><title></span></span><a class="headerlink" href="#cmdoption-idle-t" title="Link to this definition">¶</a></dt>
|
| 586 |
+
<dd><p>Set the title of the shell window.</p>
|
| 587 |
+
</dd></dl>
|
| 588 |
+
|
| 589 |
+
<dl class="std option">
|
| 590 |
+
<dt class="sig sig-object std" id="cmdoption-idle-0">
|
| 591 |
+
<span class="sig-name descname"><span class="pre">-</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-idle-0" title="Link to this definition">¶</a></dt>
|
| 592 |
+
<dd><p>Read and execute standard input in the shell window. This option must be the last one before any arguments.</p>
|
| 593 |
+
</dd></dl>
|
| 594 |
+
|
| 595 |
+
<p>If arguments are provided:</p>
|
| 596 |
+
<ul class="simple">
|
| 597 |
+
<li><p>If <code class="docutils literal notranslate"><span class="pre">-</span></code>, <code class="docutils literal notranslate"><span class="pre">-c</span></code>, or <code class="docutils literal notranslate"><span class="pre">-r</span></code> is used, all arguments are placed in <code class="docutils literal notranslate"><span class="pre">sys.argv[1:]</span></code>,
|
| 598 |
+
and <code class="docutils literal notranslate"><span class="pre">sys.argv[0]</span></code> is set to <code class="docutils literal notranslate"><span class="pre">''</span></code>, <code class="docutils literal notranslate"><span class="pre">'-c'</span></code>, or <code class="docutils literal notranslate"><span class="pre">'-r'</span></code> respectively.
|
| 599 |
+
No editor window is opened, even if that is the default set in the <em>Options</em> dialog.</p></li>
|
| 600 |
+
<li><p>Otherwise, arguments are treated as files to be opened for editing, and <code class="docutils literal notranslate"><span class="pre">sys.argv</span></code> reflects the arguments passed to IDLE itself.</p></li>
|
| 601 |
+
</ul>
|
| 602 |
+
</section>
|
| 603 |
+
<section id="startup-failure">
|
| 604 |
+
<h3>Startup failure<a class="headerlink" href="#startup-failure" title="Link to this heading">¶</a></h3>
|
| 605 |
+
<p>IDLE uses a socket to communicate between the IDLE GUI process and the user
|
| 606 |
+
code execution process. A connection must be established whenever the Shell
|
| 607 |
+
starts or restarts. (The latter is indicated by a divider line that says
|
| 608 |
+
‘RESTART’). If the user process fails to connect to the GUI process, it
|
| 609 |
+
usually displays a <code class="docutils literal notranslate"><span class="pre">Tk</span></code> error box with a ‘cannot connect’ message
|
| 610 |
+
that directs the user here. It then exits.</p>
|
| 611 |
+
<p>One specific connection failure on Unix systems results from
|
| 612 |
+
misconfigured masquerading rules somewhere in a system’s network setup.
|
| 613 |
+
When IDLE is started from a terminal, one will see a message starting
|
| 614 |
+
with <code class="docutils literal notranslate"><span class="pre">**</span> <span class="pre">Invalid</span> <span class="pre">host:</span></code>.
|
| 615 |
+
The valid value is <code class="docutils literal notranslate"><span class="pre">127.0.0.1</span> <span class="pre">(idlelib.rpc.LOCALHOST)</span></code>.
|
| 616 |
+
One can diagnose with <code class="docutils literal notranslate"><span class="pre">tcpconnect</span> <span class="pre">-irv</span> <span class="pre">127.0.0.1</span> <span class="pre">6543</span></code> in one
|
| 617 |
+
terminal window and <code class="docutils literal notranslate"><span class="pre">tcplisten</span> <span class="pre"><same</span> <span class="pre">args></span></code> in another.</p>
|
| 618 |
+
<p>A common cause of failure is a user-written file with the same name as a
|
| 619 |
+
standard library module, such as <em>random.py</em> and <em>tkinter.py</em>. When such a
|
| 620 |
+
file is located in the same directory as a file that is about to be run,
|
| 621 |
+
IDLE cannot import the stdlib file. The current fix is to rename the
|
| 622 |
+
user file.</p>
|
| 623 |
+
<p>Though less common than in the past, an antivirus or firewall program may
|
| 624 |
+
stop the connection. If the program cannot be taught to allow the
|
| 625 |
+
connection, then it must be turned off for IDLE to work. It is safe to
|
| 626 |
+
allow this internal connection because no data is visible on external
|
| 627 |
+
ports. A similar problem is a network mis-configuration that blocks
|
| 628 |
+
connections.</p>
|
| 629 |
+
<p>Python installation issues occasionally stop IDLE: multiple versions can
|
| 630 |
+
clash, or a single installation might need admin access. If one undo the
|
| 631 |
+
clash, or cannot or does not want to run as admin, it might be easiest to
|
| 632 |
+
completely remove Python and start over.</p>
|
| 633 |
+
<p>A zombie pythonw.exe process could be a problem. On Windows, use Task
|
| 634 |
+
Manager to check for one and stop it if there is. Sometimes a restart
|
| 635 |
+
initiated by a program crash or Keyboard Interrupt (control-C) may fail
|
| 636 |
+
to connect. Dismissing the error box or using Restart Shell on the Shell
|
| 637 |
+
menu may fix a temporary problem.</p>
|
| 638 |
+
<p>When IDLE first starts, it attempts to read user configuration files in
|
| 639 |
+
<code class="docutils literal notranslate"><span class="pre">~/.idlerc/</span></code> (~ is one’s home directory). If there is a problem, an error
|
| 640 |
+
message should be displayed. Leaving aside random disk glitches, this can
|
| 641 |
+
be prevented by never editing the files by hand. Instead, use the
|
| 642 |
+
configuration dialog, under Options. Once there is an error in a user
|
| 643 |
+
configuration file, the best solution may be to delete it and start over
|
| 644 |
+
with the settings dialog.</p>
|
| 645 |
+
<p>If IDLE quits with no message, and it was not started from a console, try
|
| 646 |
+
starting it from a console or terminal (<code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">-m</span> <span class="pre">idlelib</span></code>) and see if
|
| 647 |
+
this results in an error message.</p>
|
| 648 |
+
<p>On Unix-based systems with tcl/tk older than <code class="docutils literal notranslate"><span class="pre">8.6.11</span></code> (see
|
| 649 |
+
<code class="docutils literal notranslate"><span class="pre">About</span> <span class="pre">IDLE</span></code>) certain characters of certain fonts can cause
|
| 650 |
+
a tk failure with a message to the terminal. This can happen either
|
| 651 |
+
if one starts IDLE to edit a file with such a character or later
|
| 652 |
+
when entering such a character. If one cannot upgrade tcl/tk,
|
| 653 |
+
then re-configure IDLE to use a font that works better.</p>
|
| 654 |
+
</section>
|
| 655 |
+
<section id="running-user-code">
|
| 656 |
+
<h3>Running user code<a class="headerlink" href="#running-user-code" title="Link to this heading">¶</a></h3>
|
| 657 |
+
<p>With rare exceptions, the result of executing Python code with IDLE is
|
| 658 |
+
intended to be the same as executing the same code by the default method,
|
| 659 |
+
directly with Python in a text-mode system console or terminal window.
|
| 660 |
+
However, the different interface and operation occasionally affect
|
| 661 |
+
visible results. For instance, <code class="docutils literal notranslate"><span class="pre">sys.modules</span></code> starts with more entries,
|
| 662 |
+
and <code class="docutils literal notranslate"><span class="pre">threading.active_count()</span></code> returns 2 instead of 1.</p>
|
| 663 |
+
<p>By default, IDLE runs user code in a separate OS process rather than in
|
| 664 |
+
the user interface process that runs the shell and editor. In the execution
|
| 665 |
+
process, it replaces <code class="docutils literal notranslate"><span class="pre">sys.stdin</span></code>, <code class="docutils literal notranslate"><span class="pre">sys.stdout</span></code>, and <code class="docutils literal notranslate"><span class="pre">sys.stderr</span></code>
|
| 666 |
+
with objects that get input from and send output to the Shell window.
|
| 667 |
+
The original values stored in <code class="docutils literal notranslate"><span class="pre">sys.__stdin__</span></code>, <code class="docutils literal notranslate"><span class="pre">sys.__stdout__</span></code>, and
|
| 668 |
+
<code class="docutils literal notranslate"><span class="pre">sys.__stderr__</span></code> are not touched, but may be <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>
|
| 669 |
+
<p>Sending print output from one process to a text widget in another is
|
| 670 |
+
slower than printing to a system terminal in the same process.
|
| 671 |
+
This has the most effect when printing multiple arguments, as the string
|
| 672 |
+
for each argument, each separator, the newline are sent separately.
|
| 673 |
+
For development, this is usually not a problem, but if one wants to
|
| 674 |
+
print faster in IDLE, format and join together everything one wants
|
| 675 |
+
displayed together and then print a single string. Both format strings
|
| 676 |
+
and <a class="reference internal" href="stdtypes.html#str.join" title="str.join"><code class="xref py py-meth docutils literal notranslate"><span class="pre">str.join()</span></code></a> can help combine fields and lines.</p>
|
| 677 |
+
<p>IDLE’s standard stream replacements are not inherited by subprocesses
|
| 678 |
+
created in the execution process, whether directly by user code or by
|
| 679 |
+
modules such as multiprocessing. If such subprocess use <code class="docutils literal notranslate"><span class="pre">input</span></code> from
|
| 680 |
+
sys.stdin or <code class="docutils literal notranslate"><span class="pre">print</span></code> or <code class="docutils literal notranslate"><span class="pre">write</span></code> to sys.stdout or sys.stderr,
|
| 681 |
+
IDLE should be started in a command line window. (On Windows,
|
| 682 |
+
use <code class="docutils literal notranslate"><span class="pre">python</span></code> or <code class="docutils literal notranslate"><span class="pre">py</span></code> rather than <code class="docutils literal notranslate"><span class="pre">pythonw</span></code> or <code class="docutils literal notranslate"><span class="pre">pyw</span></code>.)
|
| 683 |
+
The secondary subprocess
|
| 684 |
+
will then be attached to that window for input and output.</p>
|
| 685 |
+
<p>If <code class="docutils literal notranslate"><span class="pre">sys</span></code> is reset by user code, such as with <code class="docutils literal notranslate"><span class="pre">importlib.reload(sys)</span></code>,
|
| 686 |
+
IDLE’s changes are lost and input from the keyboard and output to the screen
|
| 687 |
+
will not work correctly.</p>
|
| 688 |
+
<p>When Shell has the focus, it controls the keyboard and screen. This is
|
| 689 |
+
normally transparent, but functions that directly access the keyboard
|
| 690 |
+
and screen will not work. These include system-specific functions that
|
| 691 |
+
determine whether a key has been pressed and if so, which.</p>
|
| 692 |
+
<p>The IDLE code running in the execution process adds frames to the call stack
|
| 693 |
+
that would not be there otherwise. IDLE wraps <code class="docutils literal notranslate"><span class="pre">sys.getrecursionlimit</span></code> and
|
| 694 |
+
<code class="docutils literal notranslate"><span class="pre">sys.setrecursionlimit</span></code> to reduce the effect of the additional stack
|
| 695 |
+
frames.</p>
|
| 696 |
+
<p>When user code raises SystemExit either directly or by calling sys.exit,
|
| 697 |
+
IDLE returns to a Shell prompt instead of exiting.</p>
|
| 698 |
+
</section>
|
| 699 |
+
<section id="user-output-in-shell">
|
| 700 |
+
<h3>User output in Shell<a class="headerlink" href="#user-output-in-shell" title="Link to this heading">¶</a></h3>
|
| 701 |
+
<p>When a program outputs text, the result is determined by the
|
| 702 |
+
corresponding output device. When IDLE executes user code, <code class="docutils literal notranslate"><span class="pre">sys.stdout</span></code>
|
| 703 |
+
and <code class="docutils literal notranslate"><span class="pre">sys.stderr</span></code> are connected to the display area of IDLE’s Shell. Some of
|
| 704 |
+
its features are inherited from the underlying Tk Text widget. Others
|
| 705 |
+
are programmed additions. Where it matters, Shell is designed for development
|
| 706 |
+
rather than production runs.</p>
|
| 707 |
+
<p>For instance, Shell never throws away output. A program that sends unlimited
|
| 708 |
+
output to Shell will eventually fill memory, resulting in a memory error.
|
| 709 |
+
In contrast, some system text windows only keep the last n lines of output.
|
| 710 |
+
A Windows console, for instance, keeps a user-settable 1 to 9999 lines,
|
| 711 |
+
with 300 the default.</p>
|
| 712 |
+
<p>A Tk Text widget, and hence IDLE’s Shell, displays characters (codepoints) in
|
| 713 |
+
the BMP (Basic Multilingual Plane) subset of Unicode. Which characters are
|
| 714 |
+
displayed with a proper glyph and which with a replacement box depends on the
|
| 715 |
+
operating system and installed fonts. Tab characters cause the following text
|
| 716 |
+
to begin after the next tab stop. (They occur every 8 ‘characters’). Newline
|
| 717 |
+
characters cause following text to appear on a new line. Other control
|
| 718 |
+
characters are ignored or displayed as a space, box, or something else,
|
| 719 |
+
depending on the operating system and font. (Moving the text cursor through
|
| 720 |
+
such output with arrow keys may exhibit some surprising spacing behavior.)</p>
|
| 721 |
+
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">s</span> <span class="o">=</span> <span class="s1">'a</span><span class="se">\t</span><span class="s1">b</span><span class="se">\a</span><span class="s1"><</span><span class="se">\x02</span><span class="s1">><</span><span class="se">\r</span><span class="s1">></span><span class="se">\b</span><span class="s1">c</span><span class="se">\n</span><span class="s1">d'</span> <span class="c1"># Enter 22 chars.</span>
|
| 722 |
+
<span class="gp">>>> </span><span class="nb">len</span><span class="p">(</span><span class="n">s</span><span class="p">)</span>
|
| 723 |
+
<span class="go">14</span>
|
| 724 |
+
<span class="gp">>>> </span><span class="n">s</span> <span class="c1"># Display repr(s)</span>
|
| 725 |
+
<span class="go">'a\tb\x07<\x02><\r>\x08c\nd'</span>
|
| 726 |
+
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">end</span><span class="o">=</span><span class="s1">''</span><span class="p">)</span> <span class="c1"># Display s as is.</span>
|
| 727 |
+
<span class="go"># Result varies by OS and font. Try it.</span>
|
| 728 |
+
</pre></div>
|
| 729 |
+
</div>
|
| 730 |
+
<p>The <code class="docutils literal notranslate"><span class="pre">repr</span></code> function is used for interactive echo of expression
|
| 731 |
+
values. It returns an altered version of the input string in which
|
| 732 |
+
control codes, some BMP codepoints, and all non-BMP codepoints are
|
| 733 |
+
replaced with escape codes. As demonstrated above, it allows one to
|
| 734 |
+
identify the characters in a string, regardless of how they are displayed.</p>
|
| 735 |
+
<p>Normal and error output are generally kept separate (on separate lines)
|
| 736 |
+
from code input and each other. They each get different highlight colors.</p>
|
| 737 |
+
<p>For SyntaxError tracebacks, the normal ‘^’ marking where the error was
|
| 738 |
+
detected is replaced by coloring the text with an error highlight.
|
| 739 |
+
When code run from a file causes other exceptions, one may right click
|
| 740 |
+
on a traceback line to jump to the corresponding line in an IDLE editor.
|
| 741 |
+
The file will be opened if necessary.</p>
|
| 742 |
+
<p>Shell has a special facility for squeezing output lines down to a
|
| 743 |
+
‘Squeezed text’ label. This is done automatically
|
| 744 |
+
for output over N lines (N = 50 by default).
|
| 745 |
+
N can be changed in the PyShell section of the General
|
| 746 |
+
page of the Settings dialog. Output with fewer lines can be squeezed by
|
| 747 |
+
right clicking on the output. This can be useful lines long enough to slow
|
| 748 |
+
down scrolling.</p>
|
| 749 |
+
<p>Squeezed output is expanded in place by double-clicking the label.
|
| 750 |
+
It can also be sent to the clipboard or a separate view window by
|
| 751 |
+
right-clicking the label.</p>
|
| 752 |
+
</section>
|
| 753 |
+
<section id="developing-tkinter-applications">
|
| 754 |
+
<h3>Developing tkinter applications<a class="headerlink" href="#developing-tkinter-applications" title="Link to this heading">¶</a></h3>
|
| 755 |
+
<p>IDLE is intentionally different from standard Python in order to
|
| 756 |
+
facilitate development of tkinter programs. Enter <code class="docutils literal notranslate"><span class="pre">import</span> <span class="pre">tkinter</span> <span class="pre">as</span> <span class="pre">tk;</span>
|
| 757 |
+
<span class="pre">root</span> <span class="pre">=</span> <span class="pre">tk.Tk()</span></code> in standard Python and nothing appears. Enter the same
|
| 758 |
+
in IDLE and a tk window appears. In standard Python, one must also enter
|
| 759 |
+
<code class="docutils literal notranslate"><span class="pre">root.update()</span></code> to see the window. IDLE does the equivalent in the
|
| 760 |
+
background, about 20 times a second, which is about every 50 milliseconds.
|
| 761 |
+
Next enter <code class="docutils literal notranslate"><span class="pre">b</span> <span class="pre">=</span> <span class="pre">tk.Button(root,</span> <span class="pre">text='button');</span> <span class="pre">b.pack()</span></code>. Again,
|
| 762 |
+
nothing visibly changes in standard Python until one enters <code class="docutils literal notranslate"><span class="pre">root.update()</span></code>.</p>
|
| 763 |
+
<p>Most tkinter programs run <code class="docutils literal notranslate"><span class="pre">root.mainloop()</span></code>, which usually does not
|
| 764 |
+
return until the tk app is destroyed. If the program is run with
|
| 765 |
+
<code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">-i</span></code> or from an IDLE editor, a <code class="docutils literal notranslate"><span class="pre">>>></span></code> shell prompt does not
|
| 766 |
+
appear until <code class="docutils literal notranslate"><span class="pre">mainloop()</span></code> returns, at which time there is nothing left
|
| 767 |
+
to interact with.</p>
|
| 768 |
+
<p>When running a tkinter program from an IDLE editor, one can comment out
|
| 769 |
+
the mainloop call. One then gets a shell prompt immediately and can
|
| 770 |
+
interact with the live application. One just has to remember to
|
| 771 |
+
re-enable the mainloop call when running in standard Python.</p>
|
| 772 |
+
</section>
|
| 773 |
+
<section id="running-without-a-subprocess">
|
| 774 |
+
<h3>Running without a subprocess<a class="headerlink" href="#running-without-a-subprocess" title="Link to this heading">¶</a></h3>
|
| 775 |
+
<p>By default, IDLE executes user code in a separate subprocess via a socket,
|
| 776 |
+
which uses the internal loopback interface. This connection is not
|
| 777 |
+
externally visible and no data is sent to or received from the internet.
|
| 778 |
+
If firewall software complains anyway, you can ignore it.</p>
|
| 779 |
+
<p>If the attempt to make the socket connection fails, Idle will notify you.
|
| 780 |
+
Such failures are sometimes transient, but if persistent, the problem
|
| 781 |
+
may be either a firewall blocking the connection or misconfiguration of
|
| 782 |
+
a particular system. Until the problem is fixed, one can run Idle with
|
| 783 |
+
the -n command line switch.</p>
|
| 784 |
+
<p>If IDLE is started with the -n command line switch it will run in a
|
| 785 |
+
single process and will not create the subprocess which runs the RPC
|
| 786 |
+
Python execution server. This can be useful if Python cannot create
|
| 787 |
+
the subprocess or the RPC socket interface on your platform. However,
|
| 788 |
+
in this mode user code is not isolated from IDLE itself. Also, the
|
| 789 |
+
environment is not restarted when Run/Run Module (F5) is selected. If
|
| 790 |
+
your code has been modified, you must reload() the affected modules and
|
| 791 |
+
re-import any specific items (e.g. from foo import baz) if the changes
|
| 792 |
+
are to take effect. For these reasons, it is preferable to run IDLE
|
| 793 |
+
with the default subprocess if at all possible.</p>
|
| 794 |
+
<div class="deprecated">
|
| 795 |
+
<p><span class="versionmodified deprecated">Deprecated since version 3.4.</span></p>
|
| 796 |
+
</div>
|
| 797 |
+
</section>
|
| 798 |
+
</section>
|
| 799 |
+
<section id="help-and-preferences">
|
| 800 |
+
<h2>Help and Preferences<a class="headerlink" href="#help-and-preferences" title="Link to this heading">¶</a></h2>
|
| 801 |
+
<section id="help-sources">
|
| 802 |
+
<span id="id6"></span><h3>Help sources<a class="headerlink" href="#help-sources" title="Link to this heading">¶</a></h3>
|
| 803 |
+
<p>Help menu entry “IDLE Help” displays a formatted html version of the
|
| 804 |
+
IDLE chapter of the Library Reference. The result, in a read-only
|
| 805 |
+
tkinter text window, is close to what one sees in a web browser.
|
| 806 |
+
Navigate through the text with a mousewheel,
|
| 807 |
+
the scrollbar, or up and down arrow keys held down.
|
| 808 |
+
Or click the TOC (Table of Contents) button and select a section
|
| 809 |
+
header in the opened box.</p>
|
| 810 |
+
<p>Help menu entry “Python Docs” opens the extensive sources of help,
|
| 811 |
+
including tutorials, available at <code class="docutils literal notranslate"><span class="pre">docs.python.org/x.y</span></code>, where ‘x.y’
|
| 812 |
+
is the currently running Python version. If your system
|
| 813 |
+
has an off-line copy of the docs (this may be an installation option),
|
| 814 |
+
that will be opened instead.</p>
|
| 815 |
+
<p>Selected URLs can be added or removed from the help menu at any time using the
|
| 816 |
+
General tab of the Configure IDLE dialog.</p>
|
| 817 |
+
</section>
|
| 818 |
+
<section id="setting-preferences">
|
| 819 |
+
<span id="preferences"></span><h3>Setting preferences<a class="headerlink" href="#setting-preferences" title="Link to this heading">¶</a></h3>
|
| 820 |
+
<p>The font preferences, highlighting, keys, and general preferences can be
|
| 821 |
+
changed via Configure IDLE on the Option menu.
|
| 822 |
+
Non-default user settings are saved in a <code class="docutils literal notranslate"><span class="pre">.idlerc</span></code> directory in the user’s
|
| 823 |
+
home directory. Problems caused by bad user configuration files are solved
|
| 824 |
+
by editing or deleting one or more of the files in <code class="docutils literal notranslate"><span class="pre">.idlerc</span></code>.</p>
|
| 825 |
+
<p>On the Font tab, see the text sample for the effect of font face and size
|
| 826 |
+
on multiple characters in multiple languages. Edit the sample to add
|
| 827 |
+
other characters of personal interest. Use the sample to select
|
| 828 |
+
monospaced fonts. If particular characters have problems in Shell or an
|
| 829 |
+
editor, add them to the top of the sample and try changing first size
|
| 830 |
+
and then font.</p>
|
| 831 |
+
<p>On the Highlights and Keys tab, select a built-in or custom color theme
|
| 832 |
+
and key set. To use a newer built-in color theme or key set with older
|
| 833 |
+
IDLEs, save it as a new custom theme or key set and it well be accessible
|
| 834 |
+
to older IDLEs.</p>
|
| 835 |
+
</section>
|
| 836 |
+
<section id="idle-on-macos">
|
| 837 |
+
<h3>IDLE on macOS<a class="headerlink" href="#idle-on-macos" title="Link to this heading">¶</a></h3>
|
| 838 |
+
<p>Under System Preferences: Dock, one can set “Prefer tabs when opening
|
| 839 |
+
documents” to “Always”. This setting is not compatible with the tk/tkinter
|
| 840 |
+
GUI framework used by IDLE, and it breaks a few IDLE features.</p>
|
| 841 |
+
</section>
|
| 842 |
+
<section id="extensions">
|
| 843 |
+
<h3>Extensions<a class="headerlink" href="#extensions" title="Link to this heading">¶</a></h3>
|
| 844 |
+
<p>IDLE contains an extension facility. Preferences for extensions can be
|
| 845 |
+
changed with the Extensions tab of the preferences dialog. See the
|
| 846 |
+
beginning of config-extensions.def in the idlelib directory for further
|
| 847 |
+
information. The only current default extension is zzdummy, an example
|
| 848 |
+
also used for testing.</p>
|
| 849 |
+
</section>
|
| 850 |
+
</section>
|
| 851 |
+
<section id="module-idlelib">
|
| 852 |
+
<span id="idlelib-implementation-of-idle-application"></span><h2>idlelib — implementation of IDLE application<a class="headerlink" href="#module-idlelib" title="Link to this heading">¶</a></h2>
|
| 853 |
+
<p><strong>Source code:</strong> <a class="extlink-source reference external" href="https://github.com/python/cpython/tree/main/Lib/idlelib">Lib/idlelib</a></p>
|
| 854 |
+
<hr class="docutils" />
|
| 855 |
+
<p>The Lib/idlelib package implements the IDLE application. See the rest
|
| 856 |
+
of this page for how to use IDLE.</p>
|
| 857 |
+
<p>The files in idlelib are described in idlelib/README.txt. Access it
|
| 858 |
+
either in idlelib or click Help => About IDLE on the IDLE menu. This
|
| 859 |
+
file also maps IDLE menu items to the code that implements the item.
|
| 860 |
+
Except for files listed under ‘Startup’, the idlelib code is ‘private’ in
|
| 861 |
+
sense that feature changes can be backported (see <span class="target" id="index-9"></span><a class="pep reference external" href="https://peps.python.org/pep-0434/"><strong>PEP 434</strong></a>).</p>
|
| 862 |
+
</section>
|
| 863 |
+
</section>
|
| 864 |
+
|
| 865 |
+
|
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/help.py
ADDED
|
@@ -0,0 +1,343 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
""" help.py: Implement the Idle help menu.
|
| 2 |
+
Contents are subject to revision at any time, without notice.
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
Help => About IDLE: display About Idle dialog
|
| 6 |
+
|
| 7 |
+
<to be moved here from help_about.py>
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
Help => IDLE Help: Display help.html with proper formatting.
|
| 11 |
+
Doc/library/idle.rst (Sphinx)=> Doc/build/html/library/idle.html
|
| 12 |
+
(help.copy_strip)=> Lib/idlelib/help.html
|
| 13 |
+
|
| 14 |
+
HelpParser - Parse help.html and render to tk Text.
|
| 15 |
+
|
| 16 |
+
HelpText - Display formatted help.html.
|
| 17 |
+
|
| 18 |
+
HelpFrame - Contain text, scrollbar, and table-of-contents.
|
| 19 |
+
(This will be needed for display in a future tabbed window.)
|
| 20 |
+
|
| 21 |
+
HelpWindow - Display HelpFrame in a standalone window.
|
| 22 |
+
|
| 23 |
+
copy_strip - Copy the text part of idle.html to help.html while rstripping each line.
|
| 24 |
+
|
| 25 |
+
show_idlehelp - Create HelpWindow. Called in EditorWindow.help_dialog.
|
| 26 |
+
|
| 27 |
+
_get_dochome() - Return path to docs on user's system if present,
|
| 28 |
+
otherwise return link to docs.python.org.
|
| 29 |
+
"""
|
| 30 |
+
import os
|
| 31 |
+
import sys
|
| 32 |
+
from html.parser import HTMLParser
|
| 33 |
+
from os.path import abspath, dirname, isfile, join
|
| 34 |
+
from platform import python_version
|
| 35 |
+
|
| 36 |
+
from tkinter import Toplevel, Text, Menu
|
| 37 |
+
from tkinter.ttk import Frame, Menubutton, Scrollbar, Style
|
| 38 |
+
from tkinter import font as tkfont
|
| 39 |
+
|
| 40 |
+
from idlelib.config import idleConf
|
| 41 |
+
from idlelib.colorizer import color_config
|
| 42 |
+
|
| 43 |
+
## About IDLE ##
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
## IDLE Help ##
|
| 47 |
+
|
| 48 |
+
class HelpParser(HTMLParser):
|
| 49 |
+
"""Render help.html into a text widget.
|
| 50 |
+
|
| 51 |
+
The overridden handle_xyz methods handle a subset of html tags.
|
| 52 |
+
The supplied text should have the needed tag configurations.
|
| 53 |
+
The behavior for unsupported tags, such as table, is undefined.
|
| 54 |
+
If the tags generated by Sphinx change, this class, especially
|
| 55 |
+
the handle_starttag and handle_endtags methods, might have to also.
|
| 56 |
+
"""
|
| 57 |
+
def __init__(self, text):
|
| 58 |
+
HTMLParser.__init__(self, convert_charrefs=True)
|
| 59 |
+
self.text = text # Text widget we're rendering into.
|
| 60 |
+
self.tags = '' # Current block level text tags to apply.
|
| 61 |
+
self.chartags = '' # Current character level text tags.
|
| 62 |
+
self.hdrlink = False # Exclude html header links.
|
| 63 |
+
self.level = 0 # Track indentation level.
|
| 64 |
+
self.pre = False # Displaying preformatted text?
|
| 65 |
+
self.hprefix = '' # Heading prefix (like '25.5'?) to remove.
|
| 66 |
+
self.nested_dl = False # In a nested <dl>?
|
| 67 |
+
self.simplelist = False # In a simple list (no double spacing)?
|
| 68 |
+
self.toc = [] # Pair headers with text indexes for toc.
|
| 69 |
+
self.header = '' # Text within header tags for toc.
|
| 70 |
+
self.prevtag = None # Previous tag info (opener?, tag).
|
| 71 |
+
|
| 72 |
+
def indent(self, amt=1):
|
| 73 |
+
"Change indent (+1, 0, -1) and tags."
|
| 74 |
+
self.level += amt
|
| 75 |
+
self.tags = '' if self.level == 0 else 'l'+str(self.level)
|
| 76 |
+
|
| 77 |
+
def handle_starttag(self, tag, attrs):
|
| 78 |
+
"Handle starttags in help.html."
|
| 79 |
+
class_ = ''
|
| 80 |
+
for a, v in attrs:
|
| 81 |
+
if a == 'class':
|
| 82 |
+
class_ = v
|
| 83 |
+
s = ''
|
| 84 |
+
if tag == 'p' and self.prevtag and not self.prevtag[0]:
|
| 85 |
+
# Begin a new block for <p> tags after a closed tag.
|
| 86 |
+
# Avoid extra lines, e.g. after <pre> tags.
|
| 87 |
+
lastline = self.text.get('end-1c linestart', 'end-1c')
|
| 88 |
+
s = '\n\n' if lastline and not lastline.isspace() else '\n'
|
| 89 |
+
elif tag == 'span' and class_ == 'pre':
|
| 90 |
+
self.chartags = 'pre'
|
| 91 |
+
elif tag == 'span' and class_ == 'versionmodified':
|
| 92 |
+
self.chartags = 'em'
|
| 93 |
+
elif tag == 'em':
|
| 94 |
+
self.chartags = 'em'
|
| 95 |
+
elif tag in ['ul', 'ol']:
|
| 96 |
+
if class_.find('simple') != -1:
|
| 97 |
+
s = '\n'
|
| 98 |
+
self.simplelist = True
|
| 99 |
+
else:
|
| 100 |
+
self.simplelist = False
|
| 101 |
+
self.indent()
|
| 102 |
+
elif tag == 'dl':
|
| 103 |
+
if self.level > 0:
|
| 104 |
+
self.nested_dl = True
|
| 105 |
+
elif tag == 'li':
|
| 106 |
+
s = '\n* '
|
| 107 |
+
elif tag == 'dt':
|
| 108 |
+
s = '\n\n' if not self.nested_dl else '\n' # Avoid extra line.
|
| 109 |
+
self.nested_dl = False
|
| 110 |
+
elif tag == 'dd':
|
| 111 |
+
self.indent()
|
| 112 |
+
s = '\n'
|
| 113 |
+
elif tag == 'pre':
|
| 114 |
+
self.pre = True
|
| 115 |
+
self.text.insert('end', '\n\n')
|
| 116 |
+
self.tags = 'preblock'
|
| 117 |
+
elif tag == 'a' and class_ == 'headerlink':
|
| 118 |
+
self.hdrlink = True
|
| 119 |
+
elif tag == 'h1':
|
| 120 |
+
self.tags = tag
|
| 121 |
+
elif tag in ['h2', 'h3']:
|
| 122 |
+
self.header = ''
|
| 123 |
+
self.text.insert('end', '\n\n')
|
| 124 |
+
self.tags = tag
|
| 125 |
+
self.text.insert('end', s, (self.tags, self.chartags))
|
| 126 |
+
self.prevtag = (True, tag)
|
| 127 |
+
|
| 128 |
+
def handle_endtag(self, tag):
|
| 129 |
+
"Handle endtags in help.html."
|
| 130 |
+
if tag in ['h1', 'h2', 'h3']:
|
| 131 |
+
assert self.level == 0
|
| 132 |
+
indent = (' ' if tag == 'h3' else
|
| 133 |
+
' ' if tag == 'h2' else
|
| 134 |
+
'')
|
| 135 |
+
self.toc.append((indent+self.header, self.text.index('insert')))
|
| 136 |
+
self.tags = ''
|
| 137 |
+
elif tag in ['span', 'em']:
|
| 138 |
+
self.chartags = ''
|
| 139 |
+
elif tag == 'a':
|
| 140 |
+
self.hdrlink = False
|
| 141 |
+
elif tag == 'pre':
|
| 142 |
+
self.pre = False
|
| 143 |
+
self.tags = ''
|
| 144 |
+
elif tag in ['ul', 'dd', 'ol']:
|
| 145 |
+
self.indent(-1)
|
| 146 |
+
self.prevtag = (False, tag)
|
| 147 |
+
|
| 148 |
+
def handle_data(self, data):
|
| 149 |
+
"Handle date segments in help.html."
|
| 150 |
+
if not self.hdrlink:
|
| 151 |
+
d = data if self.pre else data.replace('\n', ' ')
|
| 152 |
+
if self.tags == 'h1':
|
| 153 |
+
try:
|
| 154 |
+
self.hprefix = d[:d.index(' ')]
|
| 155 |
+
if not self.hprefix.isdigit():
|
| 156 |
+
self.hprefix = ''
|
| 157 |
+
except ValueError:
|
| 158 |
+
self.hprefix = ''
|
| 159 |
+
if self.tags in ['h1', 'h2', 'h3']:
|
| 160 |
+
if (self.hprefix != '' and
|
| 161 |
+
d[0:len(self.hprefix)] == self.hprefix):
|
| 162 |
+
d = d[len(self.hprefix):]
|
| 163 |
+
self.header += d.strip()
|
| 164 |
+
self.text.insert('end', d, (self.tags, self.chartags))
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
class HelpText(Text):
|
| 168 |
+
"Display help.html."
|
| 169 |
+
def __init__(self, parent, filename):
|
| 170 |
+
"Configure tags and feed file to parser."
|
| 171 |
+
uwide = idleConf.GetOption('main', 'EditorWindow', 'width', type='int')
|
| 172 |
+
uhigh = idleConf.GetOption('main', 'EditorWindow', 'height', type='int')
|
| 173 |
+
uhigh = 3 * uhigh // 4 # Lines average 4/3 of editor line height.
|
| 174 |
+
Text.__init__(self, parent, wrap='word', highlightthickness=0,
|
| 175 |
+
padx=5, borderwidth=0, width=uwide, height=uhigh)
|
| 176 |
+
|
| 177 |
+
normalfont = self.findfont(['TkDefaultFont', 'arial', 'helvetica'])
|
| 178 |
+
fixedfont = self.findfont(['TkFixedFont', 'monaco', 'courier'])
|
| 179 |
+
color_config(self)
|
| 180 |
+
self['font'] = (normalfont, 12)
|
| 181 |
+
self.tag_configure('em', font=(normalfont, 12, 'italic'))
|
| 182 |
+
self.tag_configure('h1', font=(normalfont, 20, 'bold'))
|
| 183 |
+
self.tag_configure('h2', font=(normalfont, 18, 'bold'))
|
| 184 |
+
self.tag_configure('h3', font=(normalfont, 15, 'bold'))
|
| 185 |
+
self.tag_configure('pre', font=(fixedfont, 12))
|
| 186 |
+
preback = self['selectbackground']
|
| 187 |
+
self.tag_configure('preblock', font=(fixedfont, 10), lmargin1=25,
|
| 188 |
+
background=preback)
|
| 189 |
+
self.tag_configure('l1', lmargin1=25, lmargin2=25)
|
| 190 |
+
self.tag_configure('l2', lmargin1=50, lmargin2=50)
|
| 191 |
+
self.tag_configure('l3', lmargin1=75, lmargin2=75)
|
| 192 |
+
self.tag_configure('l4', lmargin1=100, lmargin2=100)
|
| 193 |
+
|
| 194 |
+
self.parser = HelpParser(self)
|
| 195 |
+
with open(filename, encoding='utf-8') as f:
|
| 196 |
+
contents = f.read()
|
| 197 |
+
self.parser.feed(contents)
|
| 198 |
+
self['state'] = 'disabled'
|
| 199 |
+
|
| 200 |
+
def findfont(self, names):
|
| 201 |
+
"Return name of first font family derived from names."
|
| 202 |
+
for name in names:
|
| 203 |
+
if name.lower() in (x.lower() for x in tkfont.names(root=self)):
|
| 204 |
+
font = tkfont.Font(name=name, exists=True, root=self)
|
| 205 |
+
return font.actual()['family']
|
| 206 |
+
elif name.lower() in (x.lower()
|
| 207 |
+
for x in tkfont.families(root=self)):
|
| 208 |
+
return name
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
class HelpFrame(Frame):
|
| 212 |
+
"Display html text, scrollbar, and toc."
|
| 213 |
+
def __init__(self, parent, filename):
|
| 214 |
+
Frame.__init__(self, parent)
|
| 215 |
+
self.text = text = HelpText(self, filename)
|
| 216 |
+
self.style = Style(parent)
|
| 217 |
+
self['style'] = 'helpframe.TFrame'
|
| 218 |
+
self.style.configure('helpframe.TFrame', background=text['background'])
|
| 219 |
+
self.toc = toc = self.toc_menu(text)
|
| 220 |
+
self.scroll = scroll = Scrollbar(self, command=text.yview)
|
| 221 |
+
text['yscrollcommand'] = scroll.set
|
| 222 |
+
|
| 223 |
+
self.rowconfigure(0, weight=1)
|
| 224 |
+
self.columnconfigure(1, weight=1) # Only expand the text widget.
|
| 225 |
+
toc.grid(row=0, column=0, sticky='nw')
|
| 226 |
+
text.grid(row=0, column=1, sticky='nsew')
|
| 227 |
+
scroll.grid(row=0, column=2, sticky='ns')
|
| 228 |
+
|
| 229 |
+
def toc_menu(self, text):
|
| 230 |
+
"Create table of contents as drop-down menu."
|
| 231 |
+
toc = Menubutton(self, text='TOC')
|
| 232 |
+
drop = Menu(toc, tearoff=False)
|
| 233 |
+
for lbl, dex in text.parser.toc:
|
| 234 |
+
drop.add_command(label=lbl, command=lambda dex=dex:text.yview(dex))
|
| 235 |
+
toc['menu'] = drop
|
| 236 |
+
return toc
|
| 237 |
+
|
| 238 |
+
|
| 239 |
+
class HelpWindow(Toplevel):
|
| 240 |
+
"Display frame with rendered html."
|
| 241 |
+
def __init__(self, parent, filename, title):
|
| 242 |
+
Toplevel.__init__(self, parent)
|
| 243 |
+
self.wm_title(title)
|
| 244 |
+
self.protocol("WM_DELETE_WINDOW", self.destroy)
|
| 245 |
+
self.frame = HelpFrame(self, filename)
|
| 246 |
+
self.frame.grid(column=0, row=0, sticky='nsew')
|
| 247 |
+
self.grid_columnconfigure(0, weight=1)
|
| 248 |
+
self.grid_rowconfigure(0, weight=1)
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
def copy_strip(): # pragma: no cover
|
| 252 |
+
"""Copy the text part of idle.html to idlelib/help.html while stripping trailing whitespace.
|
| 253 |
+
|
| 254 |
+
Files with trailing whitespace cannot be pushed to the git cpython
|
| 255 |
+
repository. For 3.x (on Windows), help.html is generated, after
|
| 256 |
+
editing idle.rst on the master branch, with
|
| 257 |
+
sphinx-build -bhtml . build/html
|
| 258 |
+
python_d.exe -c "from idlelib.help import copy_strip; copy_strip()"
|
| 259 |
+
Check build/html/library/idle.html, the help.html diff, and the text
|
| 260 |
+
displayed by Help => IDLE Help. Add a blurb and create a PR.
|
| 261 |
+
|
| 262 |
+
It can be worthwhile to occasionally generate help.html without
|
| 263 |
+
touching idle.rst. Changes to the master version and to the doc
|
| 264 |
+
build system may result in changes that should not change
|
| 265 |
+
the displayed text, but might break HelpParser.
|
| 266 |
+
|
| 267 |
+
As long as master and maintenance versions of idle.rst remain the
|
| 268 |
+
same, help.html can be backported. The internal Python version
|
| 269 |
+
number is not displayed. If maintenance idle.rst diverges from
|
| 270 |
+
the master version, then instead of backporting help.html from
|
| 271 |
+
master, repeat the procedure above to generate a maintenance
|
| 272 |
+
version.
|
| 273 |
+
"""
|
| 274 |
+
src = join(abspath(dirname(dirname(dirname(__file__)))),
|
| 275 |
+
'Doc', 'build', 'html', 'library', 'idle.html')
|
| 276 |
+
dst = join(abspath(dirname(__file__)), 'help.html')
|
| 277 |
+
|
| 278 |
+
with open(src, 'r', encoding="utf-8") as inn, open(dst, 'w', encoding="utf-8") as out:
|
| 279 |
+
copy = False
|
| 280 |
+
for line in inn:
|
| 281 |
+
if '<section id="idle">' in line: copy = True
|
| 282 |
+
if '<div class="clearer">' in line: break
|
| 283 |
+
if copy: out.write(line.strip() + '\n')
|
| 284 |
+
|
| 285 |
+
print(f'{src} copied to {dst}')
|
| 286 |
+
|
| 287 |
+
|
| 288 |
+
def show_idlehelp(parent):
|
| 289 |
+
"Create HelpWindow; called from Idle Help event handler."
|
| 290 |
+
filename = join(abspath(dirname(__file__)), 'help.html')
|
| 291 |
+
if not isfile(filename): # pragma: no cover
|
| 292 |
+
# Try copy_strip, present message.
|
| 293 |
+
return
|
| 294 |
+
return HelpWindow(parent, filename, 'IDLE Doc (%s)' % python_version())
|
| 295 |
+
|
| 296 |
+
|
| 297 |
+
def _get_dochome():
|
| 298 |
+
"Return path to local docs if present, otherwise link to docs.python.org."
|
| 299 |
+
|
| 300 |
+
dochome = os.path.join(sys.base_prefix, 'Doc', 'index.html')
|
| 301 |
+
if sys.platform.count('linux'):
|
| 302 |
+
# look for html docs in a couple of standard places
|
| 303 |
+
pyver = 'python-docs-' + '%s.%s.%s' % sys.version_info[:3]
|
| 304 |
+
if os.path.isdir('/var/www/html/python/'): # rpm package manager
|
| 305 |
+
dochome = '/var/www/html/python/index.html'
|
| 306 |
+
else:
|
| 307 |
+
basepath = '/usr/share/doc/' # dnf/apt package managers
|
| 308 |
+
dochome = os.path.join(basepath, pyver, 'Doc', 'index.html')
|
| 309 |
+
|
| 310 |
+
elif sys.platform[:3] == 'win':
|
| 311 |
+
import winreg # Windows only, block only executed once.
|
| 312 |
+
docfile = ''
|
| 313 |
+
KEY = (rf"Software\Python\PythonCore\{sys.winver}"
|
| 314 |
+
r"\Help\Main Python Documentation")
|
| 315 |
+
try:
|
| 316 |
+
docfile = winreg.QueryValue(winreg.HKEY_CURRENT_USER, KEY)
|
| 317 |
+
except FileNotFoundError:
|
| 318 |
+
try:
|
| 319 |
+
docfile = winreg.QueryValue(winreg.HKEY_LOCAL_MACHINE, KEY)
|
| 320 |
+
except FileNotFoundError:
|
| 321 |
+
pass
|
| 322 |
+
if os.path.isfile(docfile):
|
| 323 |
+
dochome = docfile
|
| 324 |
+
elif sys.platform == 'darwin':
|
| 325 |
+
# documentation may be stored inside a python framework
|
| 326 |
+
dochome = os.path.join(sys.base_prefix,
|
| 327 |
+
'Resources/English.lproj/Documentation/index.html')
|
| 328 |
+
dochome = os.path.normpath(dochome)
|
| 329 |
+
if os.path.isfile(dochome):
|
| 330 |
+
if sys.platform == 'darwin':
|
| 331 |
+
# Safari requires real file:-URLs
|
| 332 |
+
return 'file://' + dochome
|
| 333 |
+
return dochome
|
| 334 |
+
else:
|
| 335 |
+
return "https://docs.python.org/%d.%d/" % sys.version_info[:2]
|
| 336 |
+
|
| 337 |
+
|
| 338 |
+
if __name__ == '__main__':
|
| 339 |
+
from unittest import main
|
| 340 |
+
main('idlelib.idle_test.test_help', verbosity=2, exit=False)
|
| 341 |
+
|
| 342 |
+
from idlelib.idle_test.htest import run
|
| 343 |
+
run(show_idlehelp)
|
miniconda3/pkgs/python-3.13.12-hb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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""About Dialog for IDLE
|
| 2 |
+
|
| 3 |
+
"""
|
| 4 |
+
import os
|
| 5 |
+
import sys
|
| 6 |
+
import webbrowser
|
| 7 |
+
from platform import python_version, architecture
|
| 8 |
+
|
| 9 |
+
from tkinter import Toplevel, Frame, Label, Button, PhotoImage
|
| 10 |
+
from tkinter import SUNKEN, TOP, BOTTOM, LEFT, X, BOTH, W, EW, NSEW, E
|
| 11 |
+
|
| 12 |
+
from idlelib import textview
|
| 13 |
+
|
| 14 |
+
pyver = python_version()
|
| 15 |
+
|
| 16 |
+
if sys.platform == 'darwin':
|
| 17 |
+
bits = '64' if sys.maxsize > 2**32 else '32'
|
| 18 |
+
else:
|
| 19 |
+
bits = architecture()[0][:2]
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
class AboutDialog(Toplevel):
|
| 23 |
+
"""Modal about dialog for idle
|
| 24 |
+
|
| 25 |
+
"""
|
| 26 |
+
def __init__(self, parent, title=None, *, _htest=False, _utest=False):
|
| 27 |
+
"""Create popup, do not return until tk widget destroyed.
|
| 28 |
+
|
| 29 |
+
parent - parent of this dialog
|
| 30 |
+
title - string which is title of popup dialog
|
| 31 |
+
_htest - bool, change box location when running htest
|
| 32 |
+
_utest - bool, don't wait_window when running unittest
|
| 33 |
+
"""
|
| 34 |
+
Toplevel.__init__(self, parent)
|
| 35 |
+
self.configure(borderwidth=5)
|
| 36 |
+
# place dialog below parent if running htest
|
| 37 |
+
self.geometry("+%d+%d" % (
|
| 38 |
+
parent.winfo_rootx()+30,
|
| 39 |
+
parent.winfo_rooty()+(30 if not _htest else 100)))
|
| 40 |
+
self.bg = "#bbbbbb"
|
| 41 |
+
self.fg = "#000000"
|
| 42 |
+
self.create_widgets()
|
| 43 |
+
self.resizable(height=False, width=False)
|
| 44 |
+
self.title(title or
|
| 45 |
+
f'About IDLE {pyver} ({bits} bit)')
|
| 46 |
+
self.transient(parent)
|
| 47 |
+
self.grab_set()
|
| 48 |
+
self.protocol("WM_DELETE_WINDOW", self.ok)
|
| 49 |
+
self.parent = parent
|
| 50 |
+
self.button_ok.focus_set()
|
| 51 |
+
self.bind('<Return>', self.ok) # dismiss dialog
|
| 52 |
+
self.bind('<Escape>', self.ok) # dismiss dialog
|
| 53 |
+
self._current_textview = None
|
| 54 |
+
self._utest = _utest
|
| 55 |
+
|
| 56 |
+
if not _utest:
|
| 57 |
+
self.deiconify()
|
| 58 |
+
self.wait_window()
|
| 59 |
+
|
| 60 |
+
def create_widgets(self):
|
| 61 |
+
frame = Frame(self, borderwidth=2, relief=SUNKEN)
|
| 62 |
+
frame_buttons = Frame(self)
|
| 63 |
+
frame_buttons.pack(side=BOTTOM, fill=X)
|
| 64 |
+
frame.pack(side=TOP, expand=True, fill=BOTH)
|
| 65 |
+
self.button_ok = Button(frame_buttons, text='Close',
|
| 66 |
+
command=self.ok)
|
| 67 |
+
self.button_ok.pack(padx=5, pady=5)
|
| 68 |
+
|
| 69 |
+
frame_background = Frame(frame, bg=self.bg)
|
| 70 |
+
frame_background.pack(expand=True, fill=BOTH)
|
| 71 |
+
|
| 72 |
+
header = Label(frame_background, text='IDLE', fg=self.fg,
|
| 73 |
+
bg=self.bg, font=('courier', 24, 'bold'))
|
| 74 |
+
header.grid(row=0, column=0, sticky=E, padx=10, pady=10)
|
| 75 |
+
|
| 76 |
+
tkpatch = self._root().getvar('tk_patchLevel')
|
| 77 |
+
ext = '.png' if tkpatch >= '8.6' else '.gif'
|
| 78 |
+
icon = os.path.join(os.path.abspath(os.path.dirname(__file__)),
|
| 79 |
+
'Icons', f'idle_48{ext}')
|
| 80 |
+
self.icon_image = PhotoImage(master=self._root(), file=icon)
|
| 81 |
+
logo = Label(frame_background, image=self.icon_image, bg=self.bg)
|
| 82 |
+
logo.grid(row=0, column=0, sticky=W, rowspan=2, padx=10, pady=10)
|
| 83 |
+
|
| 84 |
+
byline_text = "Python's Integrated Development\nand Learning Environment" + 5*'\n'
|
| 85 |
+
byline = Label(frame_background, text=byline_text, justify=LEFT,
|
| 86 |
+
fg=self.fg, bg=self.bg)
|
| 87 |
+
byline.grid(row=2, column=0, sticky=W, columnspan=3, padx=10, pady=5)
|
| 88 |
+
|
| 89 |
+
forums_url = "https://discuss.python.org"
|
| 90 |
+
forums = Button(frame_background, text='Python (and IDLE) Discussion', width=35,
|
| 91 |
+
highlightbackground=self.bg,
|
| 92 |
+
command=lambda: webbrowser.open(forums_url))
|
| 93 |
+
forums.grid(row=6, column=0, sticky=W, padx=10, pady=10)
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
docs_url = ("https://docs.python.org/%d.%d/library/idle.html" %
|
| 97 |
+
sys.version_info[:2])
|
| 98 |
+
docs = Button(frame_background, text='IDLE Documentation', width=35,
|
| 99 |
+
highlightbackground=self.bg,
|
| 100 |
+
command=lambda: webbrowser.open(docs_url))
|
| 101 |
+
docs.grid(row=7, column=0, columnspan=2, sticky=W, padx=10, pady=10)
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
Frame(frame_background, borderwidth=1, relief=SUNKEN,
|
| 105 |
+
height=2, bg=self.bg).grid(row=8, column=0, sticky=EW,
|
| 106 |
+
columnspan=3, padx=5, pady=5)
|
| 107 |
+
|
| 108 |
+
tclver = str(self.info_patchlevel())
|
| 109 |
+
tkver = ' and ' + tkpatch if tkpatch != tclver else ''
|
| 110 |
+
versions = f"Python {pyver} with tcl/tk {tclver}{tkver}"
|
| 111 |
+
vers = Label(frame_background, text=versions, fg=self.fg, bg=self.bg)
|
| 112 |
+
vers.grid(row=9, column=0, sticky=W, padx=10, pady=0)
|
| 113 |
+
py_buttons = Frame(frame_background, bg=self.bg)
|
| 114 |
+
py_buttons.grid(row=10, column=0, columnspan=2, sticky=NSEW)
|
| 115 |
+
self.py_license = Button(py_buttons, text='License', width=8,
|
| 116 |
+
highlightbackground=self.bg,
|
| 117 |
+
command=self.show_py_license)
|
| 118 |
+
self.py_license.pack(side=LEFT, padx=10, pady=10)
|
| 119 |
+
self.py_copyright = Button(py_buttons, text='Copyright', width=8,
|
| 120 |
+
highlightbackground=self.bg,
|
| 121 |
+
command=self.show_py_copyright)
|
| 122 |
+
self.py_copyright.pack(side=LEFT, padx=10, pady=10)
|
| 123 |
+
self.py_credits = Button(py_buttons, text='Credits', width=8,
|
| 124 |
+
highlightbackground=self.bg,
|
| 125 |
+
command=self.show_py_credits)
|
| 126 |
+
self.py_credits.pack(side=LEFT, padx=10, pady=10)
|
| 127 |
+
|
| 128 |
+
Frame(frame_background, borderwidth=1, relief=SUNKEN,
|
| 129 |
+
height=2, bg=self.bg).grid(row=11, column=0, sticky=EW,
|
| 130 |
+
columnspan=3, padx=5, pady=5)
|
| 131 |
+
|
| 132 |
+
idle = Label(frame_background, text='IDLE', fg=self.fg, bg=self.bg)
|
| 133 |
+
idle.grid(row=12, column=0, sticky=W, padx=10, pady=0)
|
| 134 |
+
idle_buttons = Frame(frame_background, bg=self.bg)
|
| 135 |
+
idle_buttons.grid(row=13, column=0, columnspan=3, sticky=NSEW)
|
| 136 |
+
self.readme = Button(idle_buttons, text='Readme', width=8,
|
| 137 |
+
highlightbackground=self.bg,
|
| 138 |
+
command=self.show_readme)
|
| 139 |
+
self.readme.pack(side=LEFT, padx=10, pady=10)
|
| 140 |
+
self.idle_news = Button(idle_buttons, text='News', width=8,
|
| 141 |
+
highlightbackground=self.bg,
|
| 142 |
+
command=self.show_idle_news)
|
| 143 |
+
self.idle_news.pack(side=LEFT, padx=10, pady=10)
|
| 144 |
+
self.idle_credits = Button(idle_buttons, text='Credits', width=8,
|
| 145 |
+
highlightbackground=self.bg,
|
| 146 |
+
command=self.show_idle_credits)
|
| 147 |
+
self.idle_credits.pack(side=LEFT, padx=10, pady=10)
|
| 148 |
+
|
| 149 |
+
# License, copyright, and credits are of type _sitebuiltins._Printer
|
| 150 |
+
def show_py_license(self):
|
| 151 |
+
"Handle License button event."
|
| 152 |
+
self.display_printer_text('About - License', license)
|
| 153 |
+
|
| 154 |
+
def show_py_copyright(self):
|
| 155 |
+
"Handle Copyright button event."
|
| 156 |
+
self.display_printer_text('About - Copyright', copyright)
|
| 157 |
+
|
| 158 |
+
def show_py_credits(self):
|
| 159 |
+
"Handle Python Credits button event."
|
| 160 |
+
self.display_printer_text('About - Python Credits', credits)
|
| 161 |
+
|
| 162 |
+
# Encode CREDITS.txt to utf-8 for proper version of Loewis.
|
| 163 |
+
# Specify others as ascii until need utf-8, so catch errors.
|
| 164 |
+
def show_idle_credits(self):
|
| 165 |
+
"Handle Idle Credits button event."
|
| 166 |
+
self.display_file_text('About - Credits', 'CREDITS.txt', 'utf-8')
|
| 167 |
+
|
| 168 |
+
def show_readme(self):
|
| 169 |
+
"Handle Readme button event."
|
| 170 |
+
self.display_file_text('About - Readme', 'README.txt', 'ascii')
|
| 171 |
+
|
| 172 |
+
def show_idle_news(self):
|
| 173 |
+
"Handle News button event."
|
| 174 |
+
self.display_file_text('About - News', 'News3.txt', 'utf-8')
|
| 175 |
+
|
| 176 |
+
def display_printer_text(self, title, printer):
|
| 177 |
+
"""Create textview for built-in constants.
|
| 178 |
+
|
| 179 |
+
Built-in constants have type _sitebuiltins._Printer. The
|
| 180 |
+
text is extracted from the built-in and then sent to a text
|
| 181 |
+
viewer with self as the parent and title as the title of
|
| 182 |
+
the popup.
|
| 183 |
+
"""
|
| 184 |
+
printer._Printer__setup()
|
| 185 |
+
text = '\n'.join(printer._Printer__lines)
|
| 186 |
+
self._current_textview = textview.view_text(
|
| 187 |
+
self, title, text, _utest=self._utest)
|
| 188 |
+
|
| 189 |
+
def display_file_text(self, title, filename, encoding=None):
|
| 190 |
+
"""Create textview for filename.
|
| 191 |
+
|
| 192 |
+
The filename needs to be in the current directory. The path
|
| 193 |
+
is sent to a text viewer with self as the parent, title as
|
| 194 |
+
the title of the popup, and the file encoding.
|
| 195 |
+
"""
|
| 196 |
+
fn = os.path.join(os.path.abspath(os.path.dirname(__file__)), filename)
|
| 197 |
+
self._current_textview = textview.view_file(
|
| 198 |
+
self, title, fn, encoding, _utest=self._utest)
|
| 199 |
+
|
| 200 |
+
def ok(self, event=None):
|
| 201 |
+
"Dismiss help_about dialog."
|
| 202 |
+
self.grab_release()
|
| 203 |
+
self.destroy()
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
if __name__ == '__main__':
|
| 207 |
+
from unittest import main
|
| 208 |
+
main('idlelib.idle_test.test_help_about', verbosity=2, exit=False)
|
| 209 |
+
|
| 210 |
+
from idlelib.idle_test.htest import run
|
| 211 |
+
run(AboutDialog)
|
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/history.py
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"Implement Idle Shell history mechanism with History class"
|
| 2 |
+
|
| 3 |
+
from idlelib.config import idleConf
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class History:
|
| 7 |
+
''' Implement Idle Shell history mechanism.
|
| 8 |
+
|
| 9 |
+
store - Store source statement (called from pyshell.resetoutput).
|
| 10 |
+
fetch - Fetch stored statement matching prefix already entered.
|
| 11 |
+
history_next - Bound to <<history-next>> event (default Alt-N).
|
| 12 |
+
history_prev - Bound to <<history-prev>> event (default Alt-P).
|
| 13 |
+
'''
|
| 14 |
+
def __init__(self, text):
|
| 15 |
+
'''Initialize data attributes and bind event methods.
|
| 16 |
+
|
| 17 |
+
.text - Idle wrapper of tk Text widget, with .bell().
|
| 18 |
+
.history - source statements, possibly with multiple lines.
|
| 19 |
+
.prefix - source already entered at prompt; filters history list.
|
| 20 |
+
.pointer - index into history.
|
| 21 |
+
.cyclic - wrap around history list (or not).
|
| 22 |
+
'''
|
| 23 |
+
self.text = text
|
| 24 |
+
self.history = []
|
| 25 |
+
self.prefix = None
|
| 26 |
+
self.pointer = None
|
| 27 |
+
self.cyclic = idleConf.GetOption("main", "History", "cyclic", 1, "bool")
|
| 28 |
+
text.bind("<<history-previous>>", self.history_prev)
|
| 29 |
+
text.bind("<<history-next>>", self.history_next)
|
| 30 |
+
|
| 31 |
+
def history_next(self, event):
|
| 32 |
+
"Fetch later statement; start with earliest if cyclic."
|
| 33 |
+
self.fetch(reverse=False)
|
| 34 |
+
return "break"
|
| 35 |
+
|
| 36 |
+
def history_prev(self, event):
|
| 37 |
+
"Fetch earlier statement; start with most recent."
|
| 38 |
+
self.fetch(reverse=True)
|
| 39 |
+
return "break"
|
| 40 |
+
|
| 41 |
+
def fetch(self, reverse):
|
| 42 |
+
'''Fetch statement and replace current line in text widget.
|
| 43 |
+
|
| 44 |
+
Set prefix and pointer as needed for successive fetches.
|
| 45 |
+
Reset them to None, None when returning to the start line.
|
| 46 |
+
Sound bell when return to start line or cannot leave a line
|
| 47 |
+
because cyclic is False.
|
| 48 |
+
'''
|
| 49 |
+
nhist = len(self.history)
|
| 50 |
+
pointer = self.pointer
|
| 51 |
+
prefix = self.prefix
|
| 52 |
+
if pointer is not None and prefix is not None:
|
| 53 |
+
if self.text.compare("insert", "!=", "end-1c") or \
|
| 54 |
+
self.text.get("iomark", "end-1c") != self.history[pointer]:
|
| 55 |
+
pointer = prefix = None
|
| 56 |
+
self.text.mark_set("insert", "end-1c") # != after cursor move
|
| 57 |
+
if pointer is None or prefix is None:
|
| 58 |
+
prefix = self.text.get("iomark", "end-1c")
|
| 59 |
+
if reverse:
|
| 60 |
+
pointer = nhist # will be decremented
|
| 61 |
+
else:
|
| 62 |
+
if self.cyclic:
|
| 63 |
+
pointer = -1 # will be incremented
|
| 64 |
+
else: # abort history_next
|
| 65 |
+
self.text.bell()
|
| 66 |
+
return
|
| 67 |
+
nprefix = len(prefix)
|
| 68 |
+
while True:
|
| 69 |
+
pointer += -1 if reverse else 1
|
| 70 |
+
if pointer < 0 or pointer >= nhist:
|
| 71 |
+
self.text.bell()
|
| 72 |
+
if not self.cyclic and pointer < 0: # abort history_prev
|
| 73 |
+
return
|
| 74 |
+
else:
|
| 75 |
+
if self.text.get("iomark", "end-1c") != prefix:
|
| 76 |
+
self.text.delete("iomark", "end-1c")
|
| 77 |
+
self.text.insert("iomark", prefix, "stdin")
|
| 78 |
+
pointer = prefix = None
|
| 79 |
+
break
|
| 80 |
+
item = self.history[pointer]
|
| 81 |
+
if item[:nprefix] == prefix and len(item) > nprefix:
|
| 82 |
+
self.text.delete("iomark", "end-1c")
|
| 83 |
+
self.text.insert("iomark", item, "stdin")
|
| 84 |
+
break
|
| 85 |
+
self.text.see("insert")
|
| 86 |
+
self.text.tag_remove("sel", "1.0", "end")
|
| 87 |
+
self.pointer = pointer
|
| 88 |
+
self.prefix = prefix
|
| 89 |
+
|
| 90 |
+
def store(self, source):
|
| 91 |
+
"Store Shell input statement into history list."
|
| 92 |
+
source = source.strip()
|
| 93 |
+
if len(source) > 2:
|
| 94 |
+
# avoid duplicates
|
| 95 |
+
try:
|
| 96 |
+
self.history.remove(source)
|
| 97 |
+
except ValueError:
|
| 98 |
+
pass
|
| 99 |
+
self.history.append(source)
|
| 100 |
+
self.pointer = None
|
| 101 |
+
self.prefix = None
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
if __name__ == "__main__":
|
| 105 |
+
from unittest import main
|
| 106 |
+
main('idlelib.idle_test.test_history', verbosity=2, exit=False)
|
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/hyperparser.py
ADDED
|
@@ -0,0 +1,312 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Provide advanced parsing abilities for ParenMatch and other extensions.
|
| 2 |
+
|
| 3 |
+
HyperParser uses PyParser. PyParser mostly gives information on the
|
| 4 |
+
proper indentation of code. HyperParser gives additional information on
|
| 5 |
+
the structure of code.
|
| 6 |
+
"""
|
| 7 |
+
from keyword import iskeyword
|
| 8 |
+
import string
|
| 9 |
+
|
| 10 |
+
from idlelib import pyparse
|
| 11 |
+
|
| 12 |
+
# all ASCII chars that may be in an identifier
|
| 13 |
+
_ASCII_ID_CHARS = frozenset(string.ascii_letters + string.digits + "_")
|
| 14 |
+
# all ASCII chars that may be the first char of an identifier
|
| 15 |
+
_ASCII_ID_FIRST_CHARS = frozenset(string.ascii_letters + "_")
|
| 16 |
+
|
| 17 |
+
# lookup table for whether 7-bit ASCII chars are valid in a Python identifier
|
| 18 |
+
_IS_ASCII_ID_CHAR = [(chr(x) in _ASCII_ID_CHARS) for x in range(128)]
|
| 19 |
+
# lookup table for whether 7-bit ASCII chars are valid as the first
|
| 20 |
+
# char in a Python identifier
|
| 21 |
+
_IS_ASCII_ID_FIRST_CHAR = \
|
| 22 |
+
[(chr(x) in _ASCII_ID_FIRST_CHARS) for x in range(128)]
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
class HyperParser:
|
| 26 |
+
def __init__(self, editwin, index):
|
| 27 |
+
"To initialize, analyze the surroundings of the given index."
|
| 28 |
+
|
| 29 |
+
self.editwin = editwin
|
| 30 |
+
self.text = text = editwin.text
|
| 31 |
+
|
| 32 |
+
parser = pyparse.Parser(editwin.indentwidth, editwin.tabwidth)
|
| 33 |
+
|
| 34 |
+
def index2line(index):
|
| 35 |
+
return int(float(index))
|
| 36 |
+
lno = index2line(text.index(index))
|
| 37 |
+
|
| 38 |
+
if not editwin.prompt_last_line:
|
| 39 |
+
for context in editwin.num_context_lines:
|
| 40 |
+
startat = max(lno - context, 1)
|
| 41 |
+
startatindex = repr(startat) + ".0"
|
| 42 |
+
stopatindex = "%d.end" % lno
|
| 43 |
+
# We add the newline because PyParse requires a newline
|
| 44 |
+
# at end. We add a space so that index won't be at end
|
| 45 |
+
# of line, so that its status will be the same as the
|
| 46 |
+
# char before it, if should.
|
| 47 |
+
parser.set_code(text.get(startatindex, stopatindex)+' \n')
|
| 48 |
+
bod = parser.find_good_parse_start(
|
| 49 |
+
editwin._build_char_in_string_func(startatindex))
|
| 50 |
+
if bod is not None or startat == 1:
|
| 51 |
+
break
|
| 52 |
+
parser.set_lo(bod or 0)
|
| 53 |
+
else:
|
| 54 |
+
r = text.tag_prevrange("console", index)
|
| 55 |
+
if r:
|
| 56 |
+
startatindex = r[1]
|
| 57 |
+
else:
|
| 58 |
+
startatindex = "1.0"
|
| 59 |
+
stopatindex = "%d.end" % lno
|
| 60 |
+
# We add the newline because PyParse requires it. We add a
|
| 61 |
+
# space so that index won't be at end of line, so that its
|
| 62 |
+
# status will be the same as the char before it, if should.
|
| 63 |
+
parser.set_code(text.get(startatindex, stopatindex)+' \n')
|
| 64 |
+
parser.set_lo(0)
|
| 65 |
+
|
| 66 |
+
# We want what the parser has, minus the last newline and space.
|
| 67 |
+
self.rawtext = parser.code[:-2]
|
| 68 |
+
# Parser.code apparently preserves the statement we are in, so
|
| 69 |
+
# that stopatindex can be used to synchronize the string with
|
| 70 |
+
# the text box indices.
|
| 71 |
+
self.stopatindex = stopatindex
|
| 72 |
+
self.bracketing = parser.get_last_stmt_bracketing()
|
| 73 |
+
# find which pairs of bracketing are openers. These always
|
| 74 |
+
# correspond to a character of rawtext.
|
| 75 |
+
self.isopener = [i>0 and self.bracketing[i][1] >
|
| 76 |
+
self.bracketing[i-1][1]
|
| 77 |
+
for i in range(len(self.bracketing))]
|
| 78 |
+
|
| 79 |
+
self.set_index(index)
|
| 80 |
+
|
| 81 |
+
def set_index(self, index):
|
| 82 |
+
"""Set the index to which the functions relate.
|
| 83 |
+
|
| 84 |
+
The index must be in the same statement.
|
| 85 |
+
"""
|
| 86 |
+
indexinrawtext = (len(self.rawtext) -
|
| 87 |
+
len(self.text.get(index, self.stopatindex)))
|
| 88 |
+
if indexinrawtext < 0:
|
| 89 |
+
raise ValueError("Index %s precedes the analyzed statement"
|
| 90 |
+
% index)
|
| 91 |
+
self.indexinrawtext = indexinrawtext
|
| 92 |
+
# find the rightmost bracket to which index belongs
|
| 93 |
+
self.indexbracket = 0
|
| 94 |
+
while (self.indexbracket < len(self.bracketing)-1 and
|
| 95 |
+
self.bracketing[self.indexbracket+1][0] < self.indexinrawtext):
|
| 96 |
+
self.indexbracket += 1
|
| 97 |
+
if (self.indexbracket < len(self.bracketing)-1 and
|
| 98 |
+
self.bracketing[self.indexbracket+1][0] == self.indexinrawtext and
|
| 99 |
+
not self.isopener[self.indexbracket+1]):
|
| 100 |
+
self.indexbracket += 1
|
| 101 |
+
|
| 102 |
+
def is_in_string(self):
|
| 103 |
+
"""Is the index given to the HyperParser in a string?"""
|
| 104 |
+
# The bracket to which we belong should be an opener.
|
| 105 |
+
# If it's an opener, it has to have a character.
|
| 106 |
+
return (self.isopener[self.indexbracket] and
|
| 107 |
+
self.rawtext[self.bracketing[self.indexbracket][0]]
|
| 108 |
+
in ('"', "'"))
|
| 109 |
+
|
| 110 |
+
def is_in_code(self):
|
| 111 |
+
"""Is the index given to the HyperParser in normal code?"""
|
| 112 |
+
return (not self.isopener[self.indexbracket] or
|
| 113 |
+
self.rawtext[self.bracketing[self.indexbracket][0]]
|
| 114 |
+
not in ('#', '"', "'"))
|
| 115 |
+
|
| 116 |
+
def get_surrounding_brackets(self, openers='([{', mustclose=False):
|
| 117 |
+
"""Return bracket indexes or None.
|
| 118 |
+
|
| 119 |
+
If the index given to the HyperParser is surrounded by a
|
| 120 |
+
bracket defined in openers (or at least has one before it),
|
| 121 |
+
return the indices of the opening bracket and the closing
|
| 122 |
+
bracket (or the end of line, whichever comes first).
|
| 123 |
+
|
| 124 |
+
If it is not surrounded by brackets, or the end of line comes
|
| 125 |
+
before the closing bracket and mustclose is True, returns None.
|
| 126 |
+
"""
|
| 127 |
+
|
| 128 |
+
bracketinglevel = self.bracketing[self.indexbracket][1]
|
| 129 |
+
before = self.indexbracket
|
| 130 |
+
while (not self.isopener[before] or
|
| 131 |
+
self.rawtext[self.bracketing[before][0]] not in openers or
|
| 132 |
+
self.bracketing[before][1] > bracketinglevel):
|
| 133 |
+
before -= 1
|
| 134 |
+
if before < 0:
|
| 135 |
+
return None
|
| 136 |
+
bracketinglevel = min(bracketinglevel, self.bracketing[before][1])
|
| 137 |
+
after = self.indexbracket + 1
|
| 138 |
+
while (after < len(self.bracketing) and
|
| 139 |
+
self.bracketing[after][1] >= bracketinglevel):
|
| 140 |
+
after += 1
|
| 141 |
+
|
| 142 |
+
beforeindex = self.text.index("%s-%dc" %
|
| 143 |
+
(self.stopatindex, len(self.rawtext)-self.bracketing[before][0]))
|
| 144 |
+
if (after >= len(self.bracketing) or
|
| 145 |
+
self.bracketing[after][0] > len(self.rawtext)):
|
| 146 |
+
if mustclose:
|
| 147 |
+
return None
|
| 148 |
+
afterindex = self.stopatindex
|
| 149 |
+
else:
|
| 150 |
+
# We are after a real char, so it is a ')' and we give the
|
| 151 |
+
# index before it.
|
| 152 |
+
afterindex = self.text.index(
|
| 153 |
+
"%s-%dc" % (self.stopatindex,
|
| 154 |
+
len(self.rawtext)-(self.bracketing[after][0]-1)))
|
| 155 |
+
|
| 156 |
+
return beforeindex, afterindex
|
| 157 |
+
|
| 158 |
+
# the set of built-in identifiers which are also keywords,
|
| 159 |
+
# i.e. keyword.iskeyword() returns True for them
|
| 160 |
+
_ID_KEYWORDS = frozenset({"True", "False", "None"})
|
| 161 |
+
|
| 162 |
+
@classmethod
|
| 163 |
+
def _eat_identifier(cls, str, limit, pos):
|
| 164 |
+
"""Given a string and pos, return the number of chars in the
|
| 165 |
+
identifier which ends at pos, or 0 if there is no such one.
|
| 166 |
+
|
| 167 |
+
This ignores non-identifier eywords are not identifiers.
|
| 168 |
+
"""
|
| 169 |
+
is_ascii_id_char = _IS_ASCII_ID_CHAR
|
| 170 |
+
|
| 171 |
+
# Start at the end (pos) and work backwards.
|
| 172 |
+
i = pos
|
| 173 |
+
|
| 174 |
+
# Go backwards as long as the characters are valid ASCII
|
| 175 |
+
# identifier characters. This is an optimization, since it
|
| 176 |
+
# is faster in the common case where most of the characters
|
| 177 |
+
# are ASCII.
|
| 178 |
+
while i > limit and (
|
| 179 |
+
ord(str[i - 1]) < 128 and
|
| 180 |
+
is_ascii_id_char[ord(str[i - 1])]
|
| 181 |
+
):
|
| 182 |
+
i -= 1
|
| 183 |
+
|
| 184 |
+
# If the above loop ended due to reaching a non-ASCII
|
| 185 |
+
# character, continue going backwards using the most generic
|
| 186 |
+
# test for whether a string contains only valid identifier
|
| 187 |
+
# characters.
|
| 188 |
+
if i > limit and ord(str[i - 1]) >= 128:
|
| 189 |
+
while i - 4 >= limit and ('a' + str[i - 4:pos]).isidentifier():
|
| 190 |
+
i -= 4
|
| 191 |
+
if i - 2 >= limit and ('a' + str[i - 2:pos]).isidentifier():
|
| 192 |
+
i -= 2
|
| 193 |
+
if i - 1 >= limit and ('a' + str[i - 1:pos]).isidentifier():
|
| 194 |
+
i -= 1
|
| 195 |
+
|
| 196 |
+
# The identifier candidate starts here. If it isn't a valid
|
| 197 |
+
# identifier, don't eat anything. At this point that is only
|
| 198 |
+
# possible if the first character isn't a valid first
|
| 199 |
+
# character for an identifier.
|
| 200 |
+
if not str[i:pos].isidentifier():
|
| 201 |
+
return 0
|
| 202 |
+
elif i < pos:
|
| 203 |
+
# All characters in str[i:pos] are valid ASCII identifier
|
| 204 |
+
# characters, so it is enough to check that the first is
|
| 205 |
+
# valid as the first character of an identifier.
|
| 206 |
+
if not _IS_ASCII_ID_FIRST_CHAR[ord(str[i])]:
|
| 207 |
+
return 0
|
| 208 |
+
|
| 209 |
+
# All keywords are valid identifiers, but should not be
|
| 210 |
+
# considered identifiers here, except for True, False and None.
|
| 211 |
+
if i < pos and (
|
| 212 |
+
iskeyword(str[i:pos]) and
|
| 213 |
+
str[i:pos] not in cls._ID_KEYWORDS
|
| 214 |
+
):
|
| 215 |
+
return 0
|
| 216 |
+
|
| 217 |
+
return pos - i
|
| 218 |
+
|
| 219 |
+
# This string includes all chars that may be in a white space
|
| 220 |
+
_whitespace_chars = " \t\n\\"
|
| 221 |
+
|
| 222 |
+
def get_expression(self):
|
| 223 |
+
"""Return a string with the Python expression which ends at the
|
| 224 |
+
given index, which is empty if there is no real one.
|
| 225 |
+
"""
|
| 226 |
+
if not self.is_in_code():
|
| 227 |
+
raise ValueError("get_expression should only be called "
|
| 228 |
+
"if index is inside a code.")
|
| 229 |
+
|
| 230 |
+
rawtext = self.rawtext
|
| 231 |
+
bracketing = self.bracketing
|
| 232 |
+
|
| 233 |
+
brck_index = self.indexbracket
|
| 234 |
+
brck_limit = bracketing[brck_index][0]
|
| 235 |
+
pos = self.indexinrawtext
|
| 236 |
+
|
| 237 |
+
last_identifier_pos = pos
|
| 238 |
+
postdot_phase = True
|
| 239 |
+
|
| 240 |
+
while True:
|
| 241 |
+
# Eat whitespaces, comments, and if postdot_phase is False - a dot
|
| 242 |
+
while True:
|
| 243 |
+
if pos>brck_limit and rawtext[pos-1] in self._whitespace_chars:
|
| 244 |
+
# Eat a whitespace
|
| 245 |
+
pos -= 1
|
| 246 |
+
elif (not postdot_phase and
|
| 247 |
+
pos > brck_limit and rawtext[pos-1] == '.'):
|
| 248 |
+
# Eat a dot
|
| 249 |
+
pos -= 1
|
| 250 |
+
postdot_phase = True
|
| 251 |
+
# The next line will fail if we are *inside* a comment,
|
| 252 |
+
# but we shouldn't be.
|
| 253 |
+
elif (pos == brck_limit and brck_index > 0 and
|
| 254 |
+
rawtext[bracketing[brck_index-1][0]] == '#'):
|
| 255 |
+
# Eat a comment
|
| 256 |
+
brck_index -= 2
|
| 257 |
+
brck_limit = bracketing[brck_index][0]
|
| 258 |
+
pos = bracketing[brck_index+1][0]
|
| 259 |
+
else:
|
| 260 |
+
# If we didn't eat anything, quit.
|
| 261 |
+
break
|
| 262 |
+
|
| 263 |
+
if not postdot_phase:
|
| 264 |
+
# We didn't find a dot, so the expression end at the
|
| 265 |
+
# last identifier pos.
|
| 266 |
+
break
|
| 267 |
+
|
| 268 |
+
ret = self._eat_identifier(rawtext, brck_limit, pos)
|
| 269 |
+
if ret:
|
| 270 |
+
# There is an identifier to eat
|
| 271 |
+
pos = pos - ret
|
| 272 |
+
last_identifier_pos = pos
|
| 273 |
+
# Now, to continue the search, we must find a dot.
|
| 274 |
+
postdot_phase = False
|
| 275 |
+
# (the loop continues now)
|
| 276 |
+
|
| 277 |
+
elif pos == brck_limit:
|
| 278 |
+
# We are at a bracketing limit. If it is a closing
|
| 279 |
+
# bracket, eat the bracket, otherwise, stop the search.
|
| 280 |
+
level = bracketing[brck_index][1]
|
| 281 |
+
while brck_index > 0 and bracketing[brck_index-1][1] > level:
|
| 282 |
+
brck_index -= 1
|
| 283 |
+
if bracketing[brck_index][0] == brck_limit:
|
| 284 |
+
# We were not at the end of a closing bracket
|
| 285 |
+
break
|
| 286 |
+
pos = bracketing[brck_index][0]
|
| 287 |
+
brck_index -= 1
|
| 288 |
+
brck_limit = bracketing[brck_index][0]
|
| 289 |
+
last_identifier_pos = pos
|
| 290 |
+
if rawtext[pos] in "([":
|
| 291 |
+
# [] and () may be used after an identifier, so we
|
| 292 |
+
# continue. postdot_phase is True, so we don't allow a dot.
|
| 293 |
+
pass
|
| 294 |
+
else:
|
| 295 |
+
# We can't continue after other types of brackets
|
| 296 |
+
if rawtext[pos] in "'\"":
|
| 297 |
+
# Scan a string prefix
|
| 298 |
+
while pos > 0 and rawtext[pos - 1] in "rRbBuU":
|
| 299 |
+
pos -= 1
|
| 300 |
+
last_identifier_pos = pos
|
| 301 |
+
break
|
| 302 |
+
|
| 303 |
+
else:
|
| 304 |
+
# We've found an operator or something.
|
| 305 |
+
break
|
| 306 |
+
|
| 307 |
+
return rawtext[last_identifier_pos:self.indexinrawtext]
|
| 308 |
+
|
| 309 |
+
|
| 310 |
+
if __name__ == '__main__':
|
| 311 |
+
from unittest import main
|
| 312 |
+
main('idlelib.idle_test.test_hyperparser', verbosity=2)
|
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle.bat
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@echo off
|
| 2 |
+
rem Start IDLE using the appropriate Python interpreter
|
| 3 |
+
set CURRDIR=%~dp0
|
| 4 |
+
start "IDLE" "%CURRDIR%..\..\pythonw.exe" "%CURRDIR%idle.pyw" %1 %2 %3 %4 %5 %6 %7 %8 %9
|
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os.path
|
| 2 |
+
import sys
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
# Enable running IDLE with idlelib in a non-standard location.
|
| 6 |
+
# This was once used to run development versions of IDLE.
|
| 7 |
+
# Because PEP 434 declared idle.py a public interface,
|
| 8 |
+
# removal should require deprecation.
|
| 9 |
+
idlelib_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
| 10 |
+
if idlelib_dir not in sys.path:
|
| 11 |
+
sys.path.insert(0, idlelib_dir)
|
| 12 |
+
|
| 13 |
+
from idlelib.pyshell import main # This is subject to change
|
| 14 |
+
main()
|
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle.pyw
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
try:
|
| 2 |
+
import idlelib.pyshell
|
| 3 |
+
except ImportError:
|
| 4 |
+
# IDLE is not installed, but maybe pyshell is on sys.path:
|
| 5 |
+
from . import pyshell
|
| 6 |
+
import os
|
| 7 |
+
idledir = os.path.dirname(os.path.abspath(pyshell.__file__))
|
| 8 |
+
if idledir != os.getcwd():
|
| 9 |
+
# We're not in the IDLE directory, help the subprocess find run.py
|
| 10 |
+
pypath = os.environ.get('PYTHONPATH', '')
|
| 11 |
+
if pypath:
|
| 12 |
+
os.environ['PYTHONPATH'] = pypath + ':' + idledir
|
| 13 |
+
else:
|
| 14 |
+
os.environ['PYTHONPATH'] = idledir
|
| 15 |
+
pyshell.main()
|
| 16 |
+
else:
|
| 17 |
+
idlelib.pyshell.main()
|
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/README.txt
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
README FOR IDLE TESTS IN IDLELIB.IDLE_TEST
|
| 2 |
+
|
| 3 |
+
0. Quick Start
|
| 4 |
+
|
| 5 |
+
Automated unit tests were added in 3.3 for Python 3.x.
|
| 6 |
+
To run the tests from a command line:
|
| 7 |
+
|
| 8 |
+
python -m test.test_idle
|
| 9 |
+
|
| 10 |
+
Human-mediated tests were added later in 3.4.
|
| 11 |
+
|
| 12 |
+
python -m idlelib.idle_test.htest
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
1. Test Files
|
| 16 |
+
|
| 17 |
+
The idle directory, idlelib, has over 60 xyz.py files. The idle_test
|
| 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.
|
| 22 |
+
|
| 23 |
+
Remove the imports of requires and tkinter if not needed. Otherwise,
|
| 24 |
+
add to the tkinter imports as needed.
|
| 25 |
+
|
| 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.
|
| 30 |
+
|
| 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.
|
| 33 |
+
|
| 34 |
+
if __name__ == "__main__":
|
| 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.
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
2. GUI Tests
|
| 43 |
+
|
| 44 |
+
When run as part of the Python test suite, Idle GUI tests need to run
|
| 45 |
+
test.support.requires('gui'). A test is a GUI test if it creates a
|
| 46 |
+
tkinter.Tk root or master object either directly or indirectly by
|
| 47 |
+
instantiating a tkinter or idle class. GUI tests cannot run in test
|
| 48 |
+
processes that either have no graphical environment available or are not
|
| 49 |
+
allowed to use it.
|
| 50 |
+
|
| 51 |
+
To guard a module consisting entirely of GUI tests, start with
|
| 52 |
+
|
| 53 |
+
from test.support import requires
|
| 54 |
+
requires('gui')
|
| 55 |
+
|
| 56 |
+
To guard a test class, put "requires('gui')" in its setUpClass function.
|
| 57 |
+
The template.py file does this.
|
| 58 |
+
|
| 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.
|
| 65 |
+
|
| 66 |
+
@classmethod
|
| 67 |
+
def setUpClass(cls):
|
| 68 |
+
requires('gui')
|
| 69 |
+
cls.root = tk.Tk()
|
| 70 |
+
cls.text = tk.Text(root)
|
| 71 |
+
|
| 72 |
+
@classmethod
|
| 73 |
+
def tearDownClass(cls):
|
| 74 |
+
del cls.text
|
| 75 |
+
cls.root.update_idletasks()
|
| 76 |
+
cls.root.destroy()
|
| 77 |
+
del cls.root
|
| 78 |
+
|
| 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 |
+
|
| 83 |
+
can't invoke "event" command: application has been destroyed
|
| 84 |
+
...
|
| 85 |
+
"ttk::ThemeChanged"
|
| 86 |
+
|
| 87 |
+
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 |
+
|
| 96 |
+
Requires('gui') causes the test(s) it guards to be skipped if any of
|
| 97 |
+
these conditions are met:
|
| 98 |
+
|
| 99 |
+
- The tests are being run by regrtest.py, and it was started without
|
| 100 |
+
enabling the "gui" resource with the "-u" command line option.
|
| 101 |
+
|
| 102 |
+
- The tests are being run on Windows by a service that is not allowed
|
| 103 |
+
to interact with the graphical environment.
|
| 104 |
+
|
| 105 |
+
- The tests are being run on Linux and X Windows is not available.
|
| 106 |
+
|
| 107 |
+
- The tests are being run on Mac OSX in a process that cannot make a
|
| 108 |
+
window manager connection.
|
| 109 |
+
|
| 110 |
+
- tkinter.Tk cannot be successfully instantiated for some reason.
|
| 111 |
+
|
| 112 |
+
- test.support.use_resources has been set by something other than
|
| 113 |
+
regrtest.py and does not contain "gui".
|
| 114 |
+
|
| 115 |
+
Tests of non-GUI operations should avoid creating tk widgets. Incidental
|
| 116 |
+
uses of tk variables and messageboxes can be replaced by the mock
|
| 117 |
+
classes in idle_test/mock_tk.py. The mock text handles some uses of the
|
| 118 |
+
tk Text widget.
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
3. Running Unit Tests
|
| 122 |
+
|
| 123 |
+
Assume that xyz.py and test_xyz.py both end with a unittest.main() call.
|
| 124 |
+
Running either from an Idle editor runs all tests in the test_xyz file
|
| 125 |
+
with the version of Python running Idle. Test output appears in the
|
| 126 |
+
Shell window. The 'verbosity=2' option lists all test methods in the
|
| 127 |
+
file, which is appropriate when developing tests. The 'exit=False'
|
| 128 |
+
option is needed in xyx.py files when an htest follows.
|
| 129 |
+
|
| 130 |
+
The following command lines also run all test methods, including
|
| 131 |
+
GUI tests, in test_xyz.py. (Both '-m idlelib' and '-m idlelib.idle'
|
| 132 |
+
start Idle and so cannot run tests.)
|
| 133 |
+
|
| 134 |
+
python -m idlelib.xyz
|
| 135 |
+
python -m idlelib.idle_test.test_xyz
|
| 136 |
+
|
| 137 |
+
The following runs all idle_test/test_*.py tests interactively.
|
| 138 |
+
|
| 139 |
+
>>> import unittest
|
| 140 |
+
>>> unittest.main('idlelib.idle_test', verbosity=2)
|
| 141 |
+
|
| 142 |
+
The following run all Idle tests at a command line. Option '-v' is the
|
| 143 |
+
same as 'verbosity=2'.
|
| 144 |
+
|
| 145 |
+
python -m unittest -v idlelib.idle_test
|
| 146 |
+
python -m test -v -ugui test_idle
|
| 147 |
+
python -m test.test_idle
|
| 148 |
+
|
| 149 |
+
IDLE tests are 'discovered' by idlelib.idle_test.__init__.load_tests
|
| 150 |
+
when this is imported into test.test_idle. Normally, neither file
|
| 151 |
+
should be changed when working on individual test modules. The third
|
| 152 |
+
command runs unittest indirectly through regrtest. The same happens when
|
| 153 |
+
the entire test suite is run with 'python -m test'. So that command must
|
| 154 |
+
work for buildbots to stay green. IDLE tests must not disturb the
|
| 155 |
+
environment in a way that makes other tests fail (GH-62281).
|
| 156 |
+
|
| 157 |
+
To test subsets of modules, see idlelib.idle_test.__init__. This
|
| 158 |
+
can be used to find refleaks or possible sources of "Theme changed"
|
| 159 |
+
tcl messages (GH-71383).
|
| 160 |
+
|
| 161 |
+
To run an individual Testcase or test method, extend the dotted name
|
| 162 |
+
given to unittest on the command line or use the test -m option. The
|
| 163 |
+
latter allows use of other regrtest options. When using the latter,
|
| 164 |
+
all components of the pattern must be present, but any can be replaced
|
| 165 |
+
by '*'.
|
| 166 |
+
|
| 167 |
+
python -m unittest -v idlelib.idle_test.test_xyz.Test_case.test_meth
|
| 168 |
+
python -m test -m idlelib.idle_test.text_xyz.Test_case.test_meth test_idle
|
| 169 |
+
|
| 170 |
+
The test suite can be run in an IDLE user process from Shell.
|
| 171 |
+
>>> import test.autotest # Issue 25588, 2017/10/13, 3.6.4, 3.7.0a2.
|
| 172 |
+
There are currently failures not usually present, and this does not
|
| 173 |
+
work when run from the editor.
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
4. Human-mediated Tests
|
| 177 |
+
|
| 178 |
+
Human-mediated tests are widget tests that cannot be automated but need
|
| 179 |
+
human verification. They are contained in idlelib/idle_test/htest.py,
|
| 180 |
+
which has instructions. (Some modules need an auxiliary function,
|
| 181 |
+
identified with "# htest # on the header line.) The set is about
|
| 182 |
+
complete, though some tests need improvement. To run all htests, run the
|
| 183 |
+
htest file from an editor or from the command line with:
|
| 184 |
+
|
| 185 |
+
python -m idlelib.idle_test.htest
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
5. Test Coverage
|
| 189 |
+
|
| 190 |
+
Install the coverage package into your Python 3.6 site-packages
|
| 191 |
+
directory. (Its exact location depends on the OS).
|
| 192 |
+
> python3 -m pip install coverage
|
| 193 |
+
(On Windows, replace 'python3 with 'py -3.6' or perhaps just 'python'.)
|
| 194 |
+
|
| 195 |
+
The problem with running coverage with repository python is that
|
| 196 |
+
coverage uses absolute imports for its submodules, hence it needs to be
|
| 197 |
+
in a directory in sys.path. One solution: copy the package to the
|
| 198 |
+
directory containing the cpython repository. Call it 'dev'. Then run
|
| 199 |
+
coverage either directly or from a script in that directory so that
|
| 200 |
+
'dev' is prepended to sys.path.
|
| 201 |
+
|
| 202 |
+
Either edit or add dev/.coveragerc so it looks something like this.
|
| 203 |
+
---
|
| 204 |
+
# .coveragerc sets coverage options.
|
| 205 |
+
[run]
|
| 206 |
+
branch = True
|
| 207 |
+
|
| 208 |
+
[report]
|
| 209 |
+
# Regexes for lines to exclude from consideration
|
| 210 |
+
exclude_lines =
|
| 211 |
+
# Don't complain if non-runnable code isn't run:
|
| 212 |
+
if 0:
|
| 213 |
+
if __name__ == .__main__.:
|
| 214 |
+
|
| 215 |
+
.*# htest #
|
| 216 |
+
if not _utest:
|
| 217 |
+
if _htest:
|
| 218 |
+
---
|
| 219 |
+
The additions for IDLE are 'branch = True', to test coverage both ways,
|
| 220 |
+
and the last three exclude lines, to exclude things peculiar to IDLE
|
| 221 |
+
that are not executed during tests.
|
| 222 |
+
|
| 223 |
+
A script like the following cover.bat (for Windows) is very handy.
|
| 224 |
+
---
|
| 225 |
+
@echo off
|
| 226 |
+
rem Usage: cover filename [test_ suffix] # proper case required by coverage
|
| 227 |
+
rem filename without .py, 2nd parameter if test is not test_filename
|
| 228 |
+
setlocal
|
| 229 |
+
set py=f:\dev\3x\pcbuild\win32\python_d.exe
|
| 230 |
+
set src=idlelib.%1
|
| 231 |
+
if "%2" EQU "" set tst=f:/dev/3x/Lib/idlelib/idle_test/test_%1.py
|
| 232 |
+
if "%2" NEQ "" set tst=f:/dev/ex/Lib/idlelib/idle_test/test_%2.py
|
| 233 |
+
|
| 234 |
+
%py% -m coverage run --pylib --source=%src% %tst%
|
| 235 |
+
%py% -m coverage report --show-missing
|
| 236 |
+
%py% -m coverage html
|
| 237 |
+
start htmlcov\3x_Lib_idlelib_%1_py.html
|
| 238 |
+
rem Above opens new report; htmlcov\index.html displays report index
|
| 239 |
+
---
|
| 240 |
+
The second parameter was added for tests of module x not named test_x.
|
| 241 |
+
(There were several before modules were renamed, now only one is left.)
|
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/__init__.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""idlelib.idle_test implements test.test_idle, which tests the IDLE
|
| 2 |
+
application as part of the stdlib test suite.
|
| 3 |
+
Run IDLE tests alone with "python -m test.test_idle (-v)".
|
| 4 |
+
|
| 5 |
+
This package and its contained modules are subject to change and
|
| 6 |
+
any direct use is at your own risk.
|
| 7 |
+
"""
|
| 8 |
+
from os.path import dirname
|
| 9 |
+
|
| 10 |
+
# test_idle imports load_tests for test discovery (default all).
|
| 11 |
+
# To run subsets of idlelib module tests, insert '[<chars>]' after '_'.
|
| 12 |
+
# Example: insert '[ac]' for modules beginning with 'a' or 'c'.
|
| 13 |
+
# Additional .discover/.addTest pairs with separate inserts work.
|
| 14 |
+
# Example: pairs with 'c' and 'g' test c* files and grep.
|
| 15 |
+
|
| 16 |
+
def load_tests(loader, standard_tests, pattern):
|
| 17 |
+
this_dir = dirname(__file__)
|
| 18 |
+
top_dir = dirname(dirname(this_dir))
|
| 19 |
+
module_tests = loader.discover(start_dir=this_dir,
|
| 20 |
+
pattern='test_*.py', # Insert here.
|
| 21 |
+
top_level_dir=top_dir)
|
| 22 |
+
standard_tests.addTests(module_tests)
|
| 23 |
+
return standard_tests
|
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/example_noext
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!usr/bin/env python
|
| 2 |
+
|
| 3 |
+
def example_function(some_argument):
|
| 4 |
+
pass
|
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/example_stub.pyi
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# An example file to test recognition of a .pyi file as Python source code.
|
| 2 |
+
|
| 3 |
+
class Example:
|
| 4 |
+
def method(self, argument1: str, argument2: list[int]) -> None: ...
|
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/htest.py
ADDED
|
@@ -0,0 +1,442 @@
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Run human tests of Idle's window, dialog, and popup widgets.
|
| 2 |
+
|
| 3 |
+
run(*tests) Create a master Tk() htest window. Within that, run each
|
| 4 |
+
callable in tests after finding the matching test spec in this file. If
|
| 5 |
+
tests is empty, run an htest for each spec dict in this file after
|
| 6 |
+
finding the matching callable in the module named in the spec. Close
|
| 7 |
+
the master window to end testing.
|
| 8 |
+
|
| 9 |
+
In a tested module, let X be a global name bound to a callable (class or
|
| 10 |
+
function) whose .__name__ attribute is also X (the usual situation). The
|
| 11 |
+
first parameter of X must be 'parent' or 'master'. When called, the
|
| 12 |
+
first argument will be the root window. X must create a child
|
| 13 |
+
Toplevel(parent/master) (or subclass thereof). The Toplevel may be a
|
| 14 |
+
test widget or dialog, in which case the callable is the corresponding
|
| 15 |
+
class. Or the Toplevel may contain the widget to be tested or set up a
|
| 16 |
+
context in which a test widget is invoked. In this latter case, the
|
| 17 |
+
callable is a wrapper function that sets up the Toplevel and other
|
| 18 |
+
objects. Wrapper function names, such as _editor_window', should start
|
| 19 |
+
with '_' and be lowercase.
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
End the module with
|
| 23 |
+
|
| 24 |
+
if __name__ == '__main__':
|
| 25 |
+
<run unittest.main with 'exit=False'>
|
| 26 |
+
from idlelib.idle_test.htest import run
|
| 27 |
+
run(callable) # There could be multiple comma-separated callables.
|
| 28 |
+
|
| 29 |
+
To have wrapper functions ignored by coverage reports, tag the def
|
| 30 |
+
header like so: "def _wrapper(parent): # htest #". Use the same tag
|
| 31 |
+
for htest lines in widget code. Make sure that the 'if __name__' line
|
| 32 |
+
matches the above. Then have make sure that .coveragerc includes the
|
| 33 |
+
following:
|
| 34 |
+
|
| 35 |
+
[report]
|
| 36 |
+
exclude_lines =
|
| 37 |
+
.*# htest #
|
| 38 |
+
if __name__ == .__main__.:
|
| 39 |
+
|
| 40 |
+
(The "." instead of "'" is intentional and necessary.)
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
To run any X, this file must contain a matching instance of the
|
| 44 |
+
following template, with X.__name__ prepended to '_spec'.
|
| 45 |
+
When all tests are run, the prefix is use to get X.
|
| 46 |
+
|
| 47 |
+
callable_spec = {
|
| 48 |
+
'file': '',
|
| 49 |
+
'kwds': {'title': ''},
|
| 50 |
+
'msg': ""
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
file (no .py): run() imports file.py.
|
| 54 |
+
kwds: augmented with {'parent':root} and passed to X as **kwds.
|
| 55 |
+
title: an example kwd; some widgets need this, delete line if not.
|
| 56 |
+
msg: master window hints about testing the widget.
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
TODO test these modules and classes:
|
| 60 |
+
autocomplete_w.AutoCompleteWindow
|
| 61 |
+
debugger.Debugger
|
| 62 |
+
outwin.OutputWindow (indirectly being tested with grep test)
|
| 63 |
+
pyshell.PyShellEditorWindow
|
| 64 |
+
"""
|
| 65 |
+
|
| 66 |
+
import idlelib.pyshell # Set Windows DPI awareness before Tk().
|
| 67 |
+
from importlib import import_module
|
| 68 |
+
import textwrap
|
| 69 |
+
import tkinter as tk
|
| 70 |
+
from tkinter.ttk import Scrollbar
|
| 71 |
+
tk.NoDefaultRoot()
|
| 72 |
+
|
| 73 |
+
AboutDialog_spec = {
|
| 74 |
+
'file': 'help_about',
|
| 75 |
+
'kwds': {'title': 'help_about test',
|
| 76 |
+
'_htest': True,
|
| 77 |
+
},
|
| 78 |
+
'msg': "Click on URL to open in default browser.\n"
|
| 79 |
+
"Verify x.y.z versions and test each button, including Close.\n "
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
# TODO implement ^\; adding '<Control-Key-\\>' to function does not work.
|
| 83 |
+
_calltip_window_spec = {
|
| 84 |
+
'file': 'calltip_w',
|
| 85 |
+
'kwds': {},
|
| 86 |
+
'msg': "Typing '(' should display a calltip.\n"
|
| 87 |
+
"Typing ') should hide the calltip.\n"
|
| 88 |
+
"So should moving cursor out of argument area.\n"
|
| 89 |
+
"Force-open-calltip does not work here.\n"
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
_color_delegator_spec = {
|
| 93 |
+
'file': 'colorizer',
|
| 94 |
+
'kwds': {},
|
| 95 |
+
'msg': "The text is sample Python code.\n"
|
| 96 |
+
"Ensure components like comments, keywords, builtins,\n"
|
| 97 |
+
"string, definitions, and break are correctly colored.\n"
|
| 98 |
+
"The default color scheme is in idlelib/config-highlight.def"
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
ConfigDialog_spec = {
|
| 102 |
+
'file': 'configdialog',
|
| 103 |
+
'kwds': {'title': 'ConfigDialogTest',
|
| 104 |
+
'_htest': True,},
|
| 105 |
+
'msg': "IDLE preferences dialog.\n"
|
| 106 |
+
"In the 'Fonts/Tabs' tab, changing font face, should update the "
|
| 107 |
+
"font face of the text in the area below it.\nIn the "
|
| 108 |
+
"'Highlighting' tab, try different color schemes. Clicking "
|
| 109 |
+
"items in the sample program should update the choices above it."
|
| 110 |
+
"\nIn the 'Keys', 'General' and 'Extensions' tabs, test settings "
|
| 111 |
+
"of interest."
|
| 112 |
+
"\n[Ok] to close the dialog.[Apply] to apply the settings and "
|
| 113 |
+
"and [Cancel] to revert all changes.\nRe-run the test to ensure "
|
| 114 |
+
"changes made have persisted."
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
CustomRun_spec = {
|
| 118 |
+
'file': 'query',
|
| 119 |
+
'kwds': {'title': 'Customize query.py Run',
|
| 120 |
+
'_htest': True},
|
| 121 |
+
'msg': "Enter with <Return> or [OK]. Print valid entry to Shell\n"
|
| 122 |
+
"Arguments are parsed into a list\n"
|
| 123 |
+
"Mode is currently restart True or False\n"
|
| 124 |
+
"Close dialog with valid entry, <Escape>, [Cancel], [X]"
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
_debug_object_browser_spec = {
|
| 128 |
+
'file': 'debugobj',
|
| 129 |
+
'kwds': {},
|
| 130 |
+
'msg': "Double click on items up to the lowest level.\n"
|
| 131 |
+
"Attributes of the objects and related information "
|
| 132 |
+
"will be displayed side-by-side at each level."
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
# TODO Improve message
|
| 136 |
+
_dyn_option_menu_spec = {
|
| 137 |
+
'file': 'dynoption',
|
| 138 |
+
'kwds': {},
|
| 139 |
+
'msg': "Select one of the many options in the 'old option set'.\n"
|
| 140 |
+
"Click the button to change the option set.\n"
|
| 141 |
+
"Select one of the many options in the 'new option set'."
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
# TODO edit wrapper
|
| 145 |
+
_editor_window_spec = {
|
| 146 |
+
'file': 'editor',
|
| 147 |
+
'kwds': {},
|
| 148 |
+
'msg': "Test editor functions of interest.\n"
|
| 149 |
+
"Best to close editor first."
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
GetKeysWindow_spec = {
|
| 153 |
+
'file': 'config_key',
|
| 154 |
+
'kwds': {'title': 'Test keybindings',
|
| 155 |
+
'action': 'find-again',
|
| 156 |
+
'current_key_sequences': [['<Control-Key-g>', '<Key-F3>', '<Control-Key-G>']],
|
| 157 |
+
'_htest': True,
|
| 158 |
+
},
|
| 159 |
+
'msg': "Test for different key modifier sequences.\n"
|
| 160 |
+
"<nothing> is invalid.\n"
|
| 161 |
+
"No modifier key is invalid.\n"
|
| 162 |
+
"Shift key with [a-z],[0-9], function key, move key, tab, space "
|
| 163 |
+
"is invalid.\nNo validity checking if advanced key binding "
|
| 164 |
+
"entry is used."
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
_grep_dialog_spec = {
|
| 168 |
+
'file': 'grep',
|
| 169 |
+
'kwds': {},
|
| 170 |
+
'msg': "Click the 'Show GrepDialog' button.\n"
|
| 171 |
+
"Test the various 'Find-in-files' functions.\n"
|
| 172 |
+
"The results should be displayed in a new '*Output*' window.\n"
|
| 173 |
+
"'Right-click'->'Go to file/line' in the search results\n "
|
| 174 |
+
"should open that file in a new EditorWindow."
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
HelpSource_spec = {
|
| 178 |
+
'file': 'query',
|
| 179 |
+
'kwds': {'title': 'Help name and source',
|
| 180 |
+
'menuitem': 'test',
|
| 181 |
+
'filepath': __file__,
|
| 182 |
+
'used_names': {'abc'},
|
| 183 |
+
'_htest': True},
|
| 184 |
+
'msg': "Enter menu item name and help file path\n"
|
| 185 |
+
"'', > than 30 chars, and 'abc' are invalid menu item names.\n"
|
| 186 |
+
"'' and file does not exist are invalid path items.\n"
|
| 187 |
+
"Any url ('www...', 'http...') is accepted.\n"
|
| 188 |
+
"Test Browse with and without path, as cannot unittest.\n"
|
| 189 |
+
"[Ok] or <Return> prints valid entry to shell\n"
|
| 190 |
+
"<Escape>, [Cancel], or [X] prints None to shell"
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
_io_binding_spec = {
|
| 194 |
+
'file': 'iomenu',
|
| 195 |
+
'kwds': {},
|
| 196 |
+
'msg': "Test the following bindings.\n"
|
| 197 |
+
"<Control-o> to open file from dialog.\n"
|
| 198 |
+
"Edit the file.\n"
|
| 199 |
+
"<Control-p> to print the file.\n"
|
| 200 |
+
"<Control-s> to save the file.\n"
|
| 201 |
+
"<Alt-s> to save-as another file.\n"
|
| 202 |
+
"<Control-c> to save-copy-as another file.\n"
|
| 203 |
+
"Check that changes were saved by opening the file elsewhere."
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
_multi_call_spec = {
|
| 207 |
+
'file': 'multicall',
|
| 208 |
+
'kwds': {},
|
| 209 |
+
'msg': "The following should trigger a print to console or IDLE Shell.\n"
|
| 210 |
+
"Entering and leaving the text area, key entry, <Control-Key>,\n"
|
| 211 |
+
"<Alt-Key-a>, <Control-Key-a>, <Alt-Control-Key-a>, \n"
|
| 212 |
+
"<Control-Button-1>, <Alt-Button-1> and focusing elsewhere."
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
_module_browser_spec = {
|
| 216 |
+
'file': 'browser',
|
| 217 |
+
'kwds': {},
|
| 218 |
+
'msg': textwrap.dedent("""
|
| 219 |
+
"Inspect names of module, class(with superclass if applicable),
|
| 220 |
+
"methods and functions. Toggle nested items. Double clicking
|
| 221 |
+
"on items prints a traceback for an exception that is ignored.""")
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
_multistatus_bar_spec = {
|
| 225 |
+
'file': 'statusbar',
|
| 226 |
+
'kwds': {},
|
| 227 |
+
'msg': "Ensure presence of multi-status bar below text area.\n"
|
| 228 |
+
"Click 'Update Status' to change the status text"
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
PathBrowser_spec = {
|
| 232 |
+
'file': 'pathbrowser',
|
| 233 |
+
'kwds': {'_htest': True},
|
| 234 |
+
'msg': "Test for correct display of all paths in sys.path.\n"
|
| 235 |
+
"Toggle nested items out to the lowest level.\n"
|
| 236 |
+
"Double clicking on an item prints a traceback\n"
|
| 237 |
+
"for an exception that is ignored."
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
_percolator_spec = {
|
| 241 |
+
'file': 'percolator',
|
| 242 |
+
'kwds': {},
|
| 243 |
+
'msg': "There are two tracers which can be toggled using a checkbox.\n"
|
| 244 |
+
"Toggling a tracer 'on' by checking it should print tracer "
|
| 245 |
+
"output to the console or to the IDLE shell.\n"
|
| 246 |
+
"If both the tracers are 'on', the output from the tracer which "
|
| 247 |
+
"was switched 'on' later, should be printed first\n"
|
| 248 |
+
"Test for actions like text entry, and removal."
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
Query_spec = {
|
| 252 |
+
'file': 'query',
|
| 253 |
+
'kwds': {'title': 'Query',
|
| 254 |
+
'message': 'Enter something',
|
| 255 |
+
'text0': 'Go',
|
| 256 |
+
'_htest': True},
|
| 257 |
+
'msg': "Enter with <Return> or [Ok]. Print valid entry to Shell\n"
|
| 258 |
+
"Blank line, after stripping, is ignored\n"
|
| 259 |
+
"Close dialog with valid entry, <Escape>, [Cancel], [X]"
|
| 260 |
+
}
|
| 261 |
+
|
| 262 |
+
|
| 263 |
+
_replace_dialog_spec = {
|
| 264 |
+
'file': 'replace',
|
| 265 |
+
'kwds': {},
|
| 266 |
+
'msg': "Click the 'Replace' button.\n"
|
| 267 |
+
"Test various replace options in the 'Replace dialog'.\n"
|
| 268 |
+
"Click [Close] or [X] to close the 'Replace Dialog'."
|
| 269 |
+
}
|
| 270 |
+
|
| 271 |
+
_scrolled_list_spec = {
|
| 272 |
+
'file': 'scrolledlist',
|
| 273 |
+
'kwds': {},
|
| 274 |
+
'msg': "You should see a scrollable list of items\n"
|
| 275 |
+
"Selecting (clicking) or double clicking an item "
|
| 276 |
+
"prints the name to the console or Idle shell.\n"
|
| 277 |
+
"Right clicking an item will display a popup."
|
| 278 |
+
}
|
| 279 |
+
|
| 280 |
+
_search_dialog_spec = {
|
| 281 |
+
'file': 'search',
|
| 282 |
+
'kwds': {},
|
| 283 |
+
'msg': "Click the 'Search' button.\n"
|
| 284 |
+
"Test various search options in the 'Search dialog'.\n"
|
| 285 |
+
"Click [Close] or [X] to close the 'Search Dialog'."
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
_searchbase_spec = {
|
| 289 |
+
'file': 'searchbase',
|
| 290 |
+
'kwds': {},
|
| 291 |
+
'msg': "Check the appearance of the base search dialog\n"
|
| 292 |
+
"Its only action is to close."
|
| 293 |
+
}
|
| 294 |
+
|
| 295 |
+
show_idlehelp_spec = {
|
| 296 |
+
'file': 'help',
|
| 297 |
+
'kwds': {},
|
| 298 |
+
'msg': "If the help text displays, this works.\n"
|
| 299 |
+
"Text is selectable. Window is scrollable."
|
| 300 |
+
}
|
| 301 |
+
|
| 302 |
+
_sidebar_number_scrolling_spec = {
|
| 303 |
+
'file': 'sidebar',
|
| 304 |
+
'kwds': {},
|
| 305 |
+
'msg': textwrap.dedent("""\
|
| 306 |
+
1. Click on the line numbers and drag down below the edge of the
|
| 307 |
+
window, moving the mouse a bit and then leaving it there for a
|
| 308 |
+
while. The text and line numbers should gradually scroll down,
|
| 309 |
+
with the selection updated continuously.
|
| 310 |
+
|
| 311 |
+
2. With the lines still selected, click on a line number above
|
| 312 |
+
or below the selected lines. Only the line whose number was
|
| 313 |
+
clicked should be selected.
|
| 314 |
+
|
| 315 |
+
3. Repeat step #1, dragging to above the window. The text and
|
| 316 |
+
line numbers should gradually scroll up, with the selection
|
| 317 |
+
updated continuously.
|
| 318 |
+
|
| 319 |
+
4. Repeat step #2, clicking a line number below the selection."""),
|
| 320 |
+
}
|
| 321 |
+
|
| 322 |
+
_stackbrowser_spec = {
|
| 323 |
+
'file': 'stackviewer',
|
| 324 |
+
'kwds': {},
|
| 325 |
+
'msg': "A stacktrace for a NameError exception.\n"
|
| 326 |
+
"Should have NameError and 1 traceback line."
|
| 327 |
+
}
|
| 328 |
+
|
| 329 |
+
_tooltip_spec = {
|
| 330 |
+
'file': 'tooltip',
|
| 331 |
+
'kwds': {},
|
| 332 |
+
'msg': "Place mouse cursor over both the buttons\n"
|
| 333 |
+
"A tooltip should appear with some text."
|
| 334 |
+
}
|
| 335 |
+
|
| 336 |
+
_tree_widget_spec = {
|
| 337 |
+
'file': 'tree',
|
| 338 |
+
'kwds': {},
|
| 339 |
+
'msg': "The canvas is scrollable.\n"
|
| 340 |
+
"Click on folders up to the lowest level."
|
| 341 |
+
}
|
| 342 |
+
|
| 343 |
+
_undo_delegator_spec = {
|
| 344 |
+
'file': 'undo',
|
| 345 |
+
'kwds': {},
|
| 346 |
+
'msg': "Click [Undo] to undo any action.\n"
|
| 347 |
+
"Click [Redo] to redo any action.\n"
|
| 348 |
+
"Click [Dump] to dump the current state "
|
| 349 |
+
"by printing to the console or the IDLE shell.\n"
|
| 350 |
+
}
|
| 351 |
+
|
| 352 |
+
ViewWindow_spec = {
|
| 353 |
+
'file': 'textview',
|
| 354 |
+
'kwds': {'title': 'Test textview',
|
| 355 |
+
'contents': 'The quick brown fox jumps over the lazy dog.\n'*35,
|
| 356 |
+
'_htest': True},
|
| 357 |
+
'msg': "Test for read-only property of text.\n"
|
| 358 |
+
"Select text, scroll window, close"
|
| 359 |
+
}
|
| 360 |
+
|
| 361 |
+
_widget_redirector_spec = {
|
| 362 |
+
'file': 'redirector',
|
| 363 |
+
'kwds': {},
|
| 364 |
+
'msg': "Every text insert should be printed to the console "
|
| 365 |
+
"or the IDLE shell."
|
| 366 |
+
}
|
| 367 |
+
|
| 368 |
+
def run(*tests):
|
| 369 |
+
"Run callables in tests."
|
| 370 |
+
root = tk.Tk()
|
| 371 |
+
root.title('IDLE htest')
|
| 372 |
+
root.resizable(0, 0)
|
| 373 |
+
|
| 374 |
+
# A scrollable Label-like constant width text widget.
|
| 375 |
+
frameLabel = tk.Frame(root, padx=10)
|
| 376 |
+
frameLabel.pack()
|
| 377 |
+
text = tk.Text(frameLabel, wrap='word')
|
| 378 |
+
text.configure(bg=root.cget('bg'), relief='flat', height=4, width=70)
|
| 379 |
+
scrollbar = Scrollbar(frameLabel, command=text.yview)
|
| 380 |
+
text.config(yscrollcommand=scrollbar.set)
|
| 381 |
+
scrollbar.pack(side='right', fill='y', expand=False)
|
| 382 |
+
text.pack(side='left', fill='both', expand=True)
|
| 383 |
+
|
| 384 |
+
test_list = [] # Make list of (spec, callable) tuples.
|
| 385 |
+
if tests:
|
| 386 |
+
for test in tests:
|
| 387 |
+
test_spec = globals()[test.__name__ + '_spec']
|
| 388 |
+
test_spec['name'] = test.__name__
|
| 389 |
+
test_list.append((test_spec, test))
|
| 390 |
+
else:
|
| 391 |
+
for key, dic in globals().items():
|
| 392 |
+
if key.endswith('_spec'):
|
| 393 |
+
test_name = key[:-5]
|
| 394 |
+
test_spec = dic
|
| 395 |
+
test_spec['name'] = test_name
|
| 396 |
+
mod = import_module('idlelib.' + test_spec['file'])
|
| 397 |
+
test = getattr(mod, test_name)
|
| 398 |
+
test_list.append((test_spec, test))
|
| 399 |
+
test_list.reverse() # So can pop in proper order in next_test.
|
| 400 |
+
|
| 401 |
+
test_name = tk.StringVar(root)
|
| 402 |
+
callable_object = None
|
| 403 |
+
test_kwds = None
|
| 404 |
+
|
| 405 |
+
def next_test():
|
| 406 |
+
nonlocal test_name, callable_object, test_kwds
|
| 407 |
+
if len(test_list) == 1:
|
| 408 |
+
next_button.pack_forget()
|
| 409 |
+
test_spec, callable_object = test_list.pop()
|
| 410 |
+
test_kwds = test_spec['kwds']
|
| 411 |
+
test_name.set('Test ' + test_spec['name'])
|
| 412 |
+
|
| 413 |
+
text['state'] = 'normal' # Enable text replacement.
|
| 414 |
+
text.delete('1.0', 'end')
|
| 415 |
+
text.insert("1.0", test_spec['msg'])
|
| 416 |
+
text['state'] = 'disabled' # Restore read-only property.
|
| 417 |
+
|
| 418 |
+
def run_test(_=None):
|
| 419 |
+
widget = callable_object(root, **test_kwds)
|
| 420 |
+
try:
|
| 421 |
+
print(widget.result) # Only true for query classes(?).
|
| 422 |
+
except AttributeError:
|
| 423 |
+
pass
|
| 424 |
+
|
| 425 |
+
def close(_=None):
|
| 426 |
+
root.destroy()
|
| 427 |
+
|
| 428 |
+
button = tk.Button(root, textvariable=test_name,
|
| 429 |
+
default='active', command=run_test)
|
| 430 |
+
next_button = tk.Button(root, text="Next", command=next_test)
|
| 431 |
+
button.pack()
|
| 432 |
+
next_button.pack()
|
| 433 |
+
next_button.focus_set()
|
| 434 |
+
root.bind('<Key-Return>', run_test)
|
| 435 |
+
root.bind('<Key-Escape>', close)
|
| 436 |
+
|
| 437 |
+
next_test()
|
| 438 |
+
root.mainloop()
|
| 439 |
+
|
| 440 |
+
|
| 441 |
+
if __name__ == '__main__':
|
| 442 |
+
run()
|
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/mock_idle.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''Mock classes that imitate idlelib modules or classes.
|
| 2 |
+
|
| 3 |
+
Attributes and methods will be added as needed for tests.
|
| 4 |
+
'''
|
| 5 |
+
|
| 6 |
+
from idlelib.idle_test.mock_tk import Text
|
| 7 |
+
|
| 8 |
+
class Func:
|
| 9 |
+
'''Record call, capture args, return/raise result set by test.
|
| 10 |
+
|
| 11 |
+
When mock function is called, set or use attributes:
|
| 12 |
+
self.called - increment call number even if no args, kwds passed.
|
| 13 |
+
self.args - capture positional arguments.
|
| 14 |
+
self.kwds - capture keyword arguments.
|
| 15 |
+
self.result - return or raise value set in __init__.
|
| 16 |
+
self.return_self - return self instead, to mock query class return.
|
| 17 |
+
|
| 18 |
+
Most common use will probably be to mock instance methods.
|
| 19 |
+
Given class instance, can set and delete as instance attribute.
|
| 20 |
+
Mock_tk.Var and Mbox_func are special variants of this.
|
| 21 |
+
'''
|
| 22 |
+
def __init__(self, result=None, return_self=False):
|
| 23 |
+
self.called = 0
|
| 24 |
+
self.result = result
|
| 25 |
+
self.return_self = return_self
|
| 26 |
+
self.args = None
|
| 27 |
+
self.kwds = None
|
| 28 |
+
def __call__(self, *args, **kwds):
|
| 29 |
+
self.called += 1
|
| 30 |
+
self.args = args
|
| 31 |
+
self.kwds = kwds
|
| 32 |
+
if isinstance(self.result, BaseException):
|
| 33 |
+
raise self.result
|
| 34 |
+
elif self.return_self:
|
| 35 |
+
return self
|
| 36 |
+
else:
|
| 37 |
+
return self.result
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
class Editor:
|
| 41 |
+
'''Minimally imitate editor.EditorWindow class.
|
| 42 |
+
'''
|
| 43 |
+
def __init__(self, flist=None, filename=None, key=None, root=None,
|
| 44 |
+
text=None): # Allow real Text with mock Editor.
|
| 45 |
+
self.text = text or Text()
|
| 46 |
+
self.undo = UndoDelegator()
|
| 47 |
+
|
| 48 |
+
def get_selection_indices(self):
|
| 49 |
+
first = self.text.index('1.0')
|
| 50 |
+
last = self.text.index('end')
|
| 51 |
+
return first, last
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
class UndoDelegator:
|
| 55 |
+
'''Minimally imitate undo.UndoDelegator class.
|
| 56 |
+
'''
|
| 57 |
+
# A real undo block is only needed for user interaction.
|
| 58 |
+
def undo_block_start(*args):
|
| 59 |
+
pass
|
| 60 |
+
def undo_block_stop(*args):
|
| 61 |
+
pass
|
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/mock_tk.py
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Classes that replace tkinter gui objects used by an object being tested.
|
| 2 |
+
|
| 3 |
+
A gui object is anything with a master or parent parameter, which is
|
| 4 |
+
typically required in spite of what the doc strings say.
|
| 5 |
+
"""
|
| 6 |
+
import re
|
| 7 |
+
from _tkinter import TclError
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class Event:
|
| 11 |
+
'''Minimal mock with attributes for testing event handlers.
|
| 12 |
+
|
| 13 |
+
This is not a gui object, but is used as an argument for callbacks
|
| 14 |
+
that access attributes of the event passed. If a callback ignores
|
| 15 |
+
the event, other than the fact that is happened, pass 'event'.
|
| 16 |
+
|
| 17 |
+
Keyboard, mouse, window, and other sources generate Event instances.
|
| 18 |
+
Event instances have the following attributes: serial (number of
|
| 19 |
+
event), time (of event), type (of event as number), widget (in which
|
| 20 |
+
event occurred), and x,y (position of mouse). There are other
|
| 21 |
+
attributes for specific events, such as keycode for key events.
|
| 22 |
+
tkinter.Event.__doc__ has more but is still not complete.
|
| 23 |
+
'''
|
| 24 |
+
def __init__(self, **kwds):
|
| 25 |
+
"Create event with attributes needed for test"
|
| 26 |
+
self.__dict__.update(kwds)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
class Var:
|
| 30 |
+
"Use for String/Int/BooleanVar: incomplete"
|
| 31 |
+
def __init__(self, master=None, value=None, name=None):
|
| 32 |
+
self.master = master
|
| 33 |
+
self.value = value
|
| 34 |
+
self.name = name
|
| 35 |
+
def set(self, value):
|
| 36 |
+
self.value = value
|
| 37 |
+
def get(self):
|
| 38 |
+
return self.value
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
class Mbox_func:
|
| 42 |
+
"""Generic mock for messagebox functions, which all have the same signature.
|
| 43 |
+
|
| 44 |
+
Instead of displaying a message box, the mock's call method saves the
|
| 45 |
+
arguments as instance attributes, which test functions can then examine.
|
| 46 |
+
The test can set the result returned to ask function
|
| 47 |
+
"""
|
| 48 |
+
def __init__(self, result=None):
|
| 49 |
+
self.result = result # Return None for all show funcs
|
| 50 |
+
def __call__(self, title, message, *args, **kwds):
|
| 51 |
+
# Save all args for possible examination by tester
|
| 52 |
+
self.title = title
|
| 53 |
+
self.message = message
|
| 54 |
+
self.args = args
|
| 55 |
+
self.kwds = kwds
|
| 56 |
+
return self.result # Set by tester for ask functions
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
class Mbox:
|
| 60 |
+
"""Mock for tkinter.messagebox with an Mbox_func for each function.
|
| 61 |
+
|
| 62 |
+
Example usage in test_module.py for testing functions in module.py:
|
| 63 |
+
---
|
| 64 |
+
from idlelib.idle_test.mock_tk import Mbox
|
| 65 |
+
import module
|
| 66 |
+
|
| 67 |
+
orig_mbox = module.messagebox
|
| 68 |
+
showerror = Mbox.showerror # example, for attribute access in test methods
|
| 69 |
+
|
| 70 |
+
class Test(unittest.TestCase):
|
| 71 |
+
|
| 72 |
+
@classmethod
|
| 73 |
+
def setUpClass(cls):
|
| 74 |
+
module.messagebox = Mbox
|
| 75 |
+
|
| 76 |
+
@classmethod
|
| 77 |
+
def tearDownClass(cls):
|
| 78 |
+
module.messagebox = orig_mbox
|
| 79 |
+
---
|
| 80 |
+
For 'ask' functions, set func.result return value before calling the method
|
| 81 |
+
that uses the message function. When messagebox functions are the
|
| 82 |
+
only GUI calls in a method, this replacement makes the method GUI-free,
|
| 83 |
+
"""
|
| 84 |
+
askokcancel = Mbox_func() # True or False
|
| 85 |
+
askquestion = Mbox_func() # 'yes' or 'no'
|
| 86 |
+
askretrycancel = Mbox_func() # True or False
|
| 87 |
+
askyesno = Mbox_func() # True or False
|
| 88 |
+
askyesnocancel = Mbox_func() # True, False, or None
|
| 89 |
+
showerror = Mbox_func() # None
|
| 90 |
+
showinfo = Mbox_func() # None
|
| 91 |
+
showwarning = Mbox_func() # None
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
class Text:
|
| 95 |
+
"""A semi-functional non-gui replacement for tkinter.Text text editors.
|
| 96 |
+
|
| 97 |
+
The mock's data model is that a text is a list of \n-terminated lines.
|
| 98 |
+
The mock adds an empty string at the beginning of the list so that the
|
| 99 |
+
index of actual lines start at 1, as with Tk. The methods never see this.
|
| 100 |
+
Tk initializes files with a terminal \n that cannot be deleted. It is
|
| 101 |
+
invisible in the sense that one cannot move the cursor beyond it.
|
| 102 |
+
|
| 103 |
+
This class is only tested (and valid) with strings of ascii chars.
|
| 104 |
+
For testing, we are not concerned with Tk Text's treatment of,
|
| 105 |
+
for instance, 0-width characters or character + accent.
|
| 106 |
+
"""
|
| 107 |
+
def __init__(self, master=None, cnf={}, **kw):
|
| 108 |
+
'''Initialize mock, non-gui, text-only Text widget.
|
| 109 |
+
|
| 110 |
+
At present, all args are ignored. Almost all affect visual behavior.
|
| 111 |
+
There are just a few Text-only options that affect text behavior.
|
| 112 |
+
'''
|
| 113 |
+
self.data = ['', '\n']
|
| 114 |
+
|
| 115 |
+
def index(self, index):
|
| 116 |
+
"Return string version of index decoded according to current text."
|
| 117 |
+
return "%s.%s" % self._decode(index, endflag=1)
|
| 118 |
+
|
| 119 |
+
def _decode(self, index, endflag=0):
|
| 120 |
+
"""Return a (line, char) tuple of int indexes into self.data.
|
| 121 |
+
|
| 122 |
+
This implements .index without converting the result back to a string.
|
| 123 |
+
The result is constrained by the number of lines and linelengths of
|
| 124 |
+
self.data. For many indexes, the result is initially (1, 0).
|
| 125 |
+
|
| 126 |
+
The input index may have any of several possible forms:
|
| 127 |
+
* line.char float: converted to 'line.char' string;
|
| 128 |
+
* 'line.char' string, where line and char are decimal integers;
|
| 129 |
+
* 'line.char lineend', where lineend='lineend' (and char is ignored);
|
| 130 |
+
* 'line.end', where end='end' (same as above);
|
| 131 |
+
* 'insert', the positions before terminal \n;
|
| 132 |
+
* 'end', whose meaning depends on the endflag passed to ._endex.
|
| 133 |
+
* 'sel.first' or 'sel.last', where sel is a tag -- not implemented.
|
| 134 |
+
"""
|
| 135 |
+
if isinstance(index, (float, bytes)):
|
| 136 |
+
index = str(index)
|
| 137 |
+
try:
|
| 138 |
+
index=index.lower()
|
| 139 |
+
except AttributeError:
|
| 140 |
+
raise TclError('bad text index "%s"' % index) from None
|
| 141 |
+
|
| 142 |
+
lastline = len(self.data) - 1 # same as number of text lines
|
| 143 |
+
if index == 'insert':
|
| 144 |
+
return lastline, len(self.data[lastline]) - 1
|
| 145 |
+
elif index == 'end':
|
| 146 |
+
return self._endex(endflag)
|
| 147 |
+
|
| 148 |
+
line, char = index.split('.')
|
| 149 |
+
line = int(line)
|
| 150 |
+
|
| 151 |
+
# Out of bounds line becomes first or last ('end') index
|
| 152 |
+
if line < 1:
|
| 153 |
+
return 1, 0
|
| 154 |
+
elif line > lastline:
|
| 155 |
+
return self._endex(endflag)
|
| 156 |
+
|
| 157 |
+
linelength = len(self.data[line]) -1 # position before/at \n
|
| 158 |
+
if char.endswith(' lineend') or char == 'end':
|
| 159 |
+
return line, linelength
|
| 160 |
+
# Tk requires that ignored chars before ' lineend' be valid int
|
| 161 |
+
if m := re.fullmatch(r'end-(\d*)c', char, re.A): # Used by hyperparser.
|
| 162 |
+
return line, linelength - int(m.group(1))
|
| 163 |
+
|
| 164 |
+
# Out of bounds char becomes first or last index of line
|
| 165 |
+
char = int(char)
|
| 166 |
+
if char < 0:
|
| 167 |
+
char = 0
|
| 168 |
+
elif char > linelength:
|
| 169 |
+
char = linelength
|
| 170 |
+
return line, char
|
| 171 |
+
|
| 172 |
+
def _endex(self, endflag):
|
| 173 |
+
'''Return position for 'end' or line overflow corresponding to endflag.
|
| 174 |
+
|
| 175 |
+
-1: position before terminal \n; for .insert(), .delete
|
| 176 |
+
0: position after terminal \n; for .get, .delete index 1
|
| 177 |
+
1: same viewed as beginning of non-existent next line (for .index)
|
| 178 |
+
'''
|
| 179 |
+
n = len(self.data)
|
| 180 |
+
if endflag == 1:
|
| 181 |
+
return n, 0
|
| 182 |
+
else:
|
| 183 |
+
n -= 1
|
| 184 |
+
return n, len(self.data[n]) + endflag
|
| 185 |
+
|
| 186 |
+
def insert(self, index, chars):
|
| 187 |
+
"Insert chars before the character at index."
|
| 188 |
+
|
| 189 |
+
if not chars: # ''.splitlines() is [], not ['']
|
| 190 |
+
return
|
| 191 |
+
chars = chars.splitlines(True)
|
| 192 |
+
if chars[-1][-1] == '\n':
|
| 193 |
+
chars.append('')
|
| 194 |
+
line, char = self._decode(index, -1)
|
| 195 |
+
before = self.data[line][:char]
|
| 196 |
+
after = self.data[line][char:]
|
| 197 |
+
self.data[line] = before + chars[0]
|
| 198 |
+
self.data[line+1:line+1] = chars[1:]
|
| 199 |
+
self.data[line+len(chars)-1] += after
|
| 200 |
+
|
| 201 |
+
def get(self, index1, index2=None):
|
| 202 |
+
"Return slice from index1 to index2 (default is 'index1+1')."
|
| 203 |
+
|
| 204 |
+
startline, startchar = self._decode(index1)
|
| 205 |
+
if index2 is None:
|
| 206 |
+
endline, endchar = startline, startchar+1
|
| 207 |
+
else:
|
| 208 |
+
endline, endchar = self._decode(index2)
|
| 209 |
+
|
| 210 |
+
if startline == endline:
|
| 211 |
+
return self.data[startline][startchar:endchar]
|
| 212 |
+
else:
|
| 213 |
+
lines = [self.data[startline][startchar:]]
|
| 214 |
+
for i in range(startline+1, endline):
|
| 215 |
+
lines.append(self.data[i])
|
| 216 |
+
lines.append(self.data[endline][:endchar])
|
| 217 |
+
return ''.join(lines)
|
| 218 |
+
|
| 219 |
+
def delete(self, index1, index2=None):
|
| 220 |
+
'''Delete slice from index1 to index2 (default is 'index1+1').
|
| 221 |
+
|
| 222 |
+
Adjust default index2 ('index+1) for line ends.
|
| 223 |
+
Do not delete the terminal \n at the very end of self.data ([-1][-1]).
|
| 224 |
+
'''
|
| 225 |
+
startline, startchar = self._decode(index1, -1)
|
| 226 |
+
if index2 is None:
|
| 227 |
+
if startchar < len(self.data[startline])-1:
|
| 228 |
+
# not deleting \n
|
| 229 |
+
endline, endchar = startline, startchar+1
|
| 230 |
+
elif startline < len(self.data) - 1:
|
| 231 |
+
# deleting non-terminal \n, convert 'index1+1 to start of next line
|
| 232 |
+
endline, endchar = startline+1, 0
|
| 233 |
+
else:
|
| 234 |
+
# do not delete terminal \n if index1 == 'insert'
|
| 235 |
+
return
|
| 236 |
+
else:
|
| 237 |
+
endline, endchar = self._decode(index2, -1)
|
| 238 |
+
# restricting end position to insert position excludes terminal \n
|
| 239 |
+
|
| 240 |
+
if startline == endline and startchar < endchar:
|
| 241 |
+
self.data[startline] = self.data[startline][:startchar] + \
|
| 242 |
+
self.data[startline][endchar:]
|
| 243 |
+
elif startline < endline:
|
| 244 |
+
self.data[startline] = self.data[startline][:startchar] + \
|
| 245 |
+
self.data[endline][endchar:]
|
| 246 |
+
startline += 1
|
| 247 |
+
for i in range(startline, endline+1):
|
| 248 |
+
del self.data[startline]
|
| 249 |
+
|
| 250 |
+
def compare(self, index1, op, index2):
|
| 251 |
+
line1, char1 = self._decode(index1)
|
| 252 |
+
line2, char2 = self._decode(index2)
|
| 253 |
+
if op == '<':
|
| 254 |
+
return line1 < line2 or line1 == line2 and char1 < char2
|
| 255 |
+
elif op == '<=':
|
| 256 |
+
return line1 < line2 or line1 == line2 and char1 <= char2
|
| 257 |
+
elif op == '>':
|
| 258 |
+
return line1 > line2 or line1 == line2 and char1 > char2
|
| 259 |
+
elif op == '>=':
|
| 260 |
+
return line1 > line2 or line1 == line2 and char1 >= char2
|
| 261 |
+
elif op == '==':
|
| 262 |
+
return line1 == line2 and char1 == char2
|
| 263 |
+
elif op == '!=':
|
| 264 |
+
return line1 != line2 or char1 != char2
|
| 265 |
+
else:
|
| 266 |
+
raise TclError('''bad comparison operator "%s": '''
|
| 267 |
+
'''must be <, <=, ==, >=, >, or !=''' % op)
|
| 268 |
+
|
| 269 |
+
# The following Text methods normally do something and return None.
|
| 270 |
+
# Whether doing nothing is sufficient for a test will depend on the test.
|
| 271 |
+
|
| 272 |
+
def mark_set(self, name, index):
|
| 273 |
+
"Set mark *name* before the character at index."
|
| 274 |
+
pass
|
| 275 |
+
|
| 276 |
+
def mark_unset(self, *markNames):
|
| 277 |
+
"Delete all marks in markNames."
|
| 278 |
+
|
| 279 |
+
def tag_remove(self, tagName, index1, index2=None):
|
| 280 |
+
"Remove tag tagName from all characters between index1 and index2."
|
| 281 |
+
pass
|
| 282 |
+
|
| 283 |
+
# The following Text methods affect the graphics screen and return None.
|
| 284 |
+
# Doing nothing should always be sufficient for tests.
|
| 285 |
+
|
| 286 |
+
def scan_dragto(self, x, y):
|
| 287 |
+
"Adjust the view of the text according to scan_mark"
|
| 288 |
+
|
| 289 |
+
def scan_mark(self, x, y):
|
| 290 |
+
"Remember the current X, Y coordinates."
|
| 291 |
+
|
| 292 |
+
def see(self, index):
|
| 293 |
+
"Scroll screen to make the character at INDEX is visible."
|
| 294 |
+
pass
|
| 295 |
+
|
| 296 |
+
# The following is a Misc method inherited by Text.
|
| 297 |
+
# It should properly go in a Misc mock, but is included here for now.
|
| 298 |
+
|
| 299 |
+
def bind(sequence=None, func=None, add=None):
|
| 300 |
+
"Bind to this widget at event sequence a call to function func."
|
| 301 |
+
pass
|
| 302 |
+
|
| 303 |
+
|
| 304 |
+
class Entry:
|
| 305 |
+
"Mock for tkinter.Entry."
|
| 306 |
+
def focus_set(self):
|
| 307 |
+
pass
|
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/template.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"Test , coverage %."
|
| 2 |
+
|
| 3 |
+
from idlelib import zzdummy
|
| 4 |
+
import unittest
|
| 5 |
+
from test.support import requires
|
| 6 |
+
from tkinter import Tk
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class Test(unittest.TestCase):
|
| 10 |
+
|
| 11 |
+
@classmethod
|
| 12 |
+
def setUpClass(cls):
|
| 13 |
+
requires('gui')
|
| 14 |
+
cls.root = Tk()
|
| 15 |
+
cls.root.withdraw()
|
| 16 |
+
|
| 17 |
+
@classmethod
|
| 18 |
+
def tearDownClass(cls):
|
| 19 |
+
cls.root.update_idletasks()
|
| 20 |
+
## for id in cls.root.tk.call('after', 'info'):
|
| 21 |
+
## cls.root.after_cancel(id) # Need for EditorWindow.
|
| 22 |
+
cls.root.destroy()
|
| 23 |
+
del cls.root
|
| 24 |
+
|
| 25 |
+
def test_init(self):
|
| 26 |
+
self.assertTrue(True)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
if __name__ == '__main__':
|
| 30 |
+
unittest.main(verbosity=2)
|
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/test_autocomplete.py
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"Test autocomplete, coverage 93%."
|
| 2 |
+
|
| 3 |
+
import unittest
|
| 4 |
+
from unittest.mock import Mock, patch
|
| 5 |
+
from test.support import requires
|
| 6 |
+
from tkinter import Tk, Text
|
| 7 |
+
import os
|
| 8 |
+
import __main__
|
| 9 |
+
|
| 10 |
+
import idlelib.autocomplete as ac
|
| 11 |
+
import idlelib.autocomplete_w as acw
|
| 12 |
+
from idlelib.idle_test.mock_idle import Func
|
| 13 |
+
from idlelib.idle_test.mock_tk import Event
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class DummyEditwin:
|
| 17 |
+
def __init__(self, root, text):
|
| 18 |
+
self.root = root
|
| 19 |
+
self.text = text
|
| 20 |
+
self.indentwidth = 8
|
| 21 |
+
self.tabwidth = 8
|
| 22 |
+
self.prompt_last_line = '>>>' # Currently not used by autocomplete.
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
class AutoCompleteTest(unittest.TestCase):
|
| 26 |
+
|
| 27 |
+
@classmethod
|
| 28 |
+
def setUpClass(cls):
|
| 29 |
+
requires('gui')
|
| 30 |
+
cls.root = Tk()
|
| 31 |
+
cls.root.withdraw()
|
| 32 |
+
cls.text = Text(cls.root)
|
| 33 |
+
cls.editor = DummyEditwin(cls.root, cls.text)
|
| 34 |
+
|
| 35 |
+
@classmethod
|
| 36 |
+
def tearDownClass(cls):
|
| 37 |
+
del cls.editor, cls.text
|
| 38 |
+
cls.root.update_idletasks()
|
| 39 |
+
cls.root.destroy()
|
| 40 |
+
del cls.root
|
| 41 |
+
|
| 42 |
+
def setUp(self):
|
| 43 |
+
self.text.delete('1.0', 'end')
|
| 44 |
+
self.autocomplete = ac.AutoComplete(self.editor)
|
| 45 |
+
|
| 46 |
+
def test_init(self):
|
| 47 |
+
self.assertEqual(self.autocomplete.editwin, self.editor)
|
| 48 |
+
self.assertEqual(self.autocomplete.text, self.text)
|
| 49 |
+
|
| 50 |
+
def test_make_autocomplete_window(self):
|
| 51 |
+
testwin = self.autocomplete._make_autocomplete_window()
|
| 52 |
+
self.assertIsInstance(testwin, acw.AutoCompleteWindow)
|
| 53 |
+
|
| 54 |
+
def test_remove_autocomplete_window(self):
|
| 55 |
+
acp = self.autocomplete
|
| 56 |
+
acp.autocompletewindow = m = Mock()
|
| 57 |
+
acp._remove_autocomplete_window()
|
| 58 |
+
m.hide_window.assert_called_once()
|
| 59 |
+
self.assertIsNone(acp.autocompletewindow)
|
| 60 |
+
|
| 61 |
+
def test_force_open_completions_event(self):
|
| 62 |
+
# Call _open_completions and break.
|
| 63 |
+
acp = self.autocomplete
|
| 64 |
+
open_c = Func()
|
| 65 |
+
acp.open_completions = open_c
|
| 66 |
+
self.assertEqual(acp.force_open_completions_event('event'), 'break')
|
| 67 |
+
self.assertEqual(open_c.args[0], ac.FORCE)
|
| 68 |
+
|
| 69 |
+
def test_autocomplete_event(self):
|
| 70 |
+
Equal = self.assertEqual
|
| 71 |
+
acp = self.autocomplete
|
| 72 |
+
|
| 73 |
+
# Result of autocomplete event: If modified tab, None.
|
| 74 |
+
ev = Event(mc_state=True)
|
| 75 |
+
self.assertIsNone(acp.autocomplete_event(ev))
|
| 76 |
+
del ev.mc_state
|
| 77 |
+
|
| 78 |
+
# If tab after whitespace, None.
|
| 79 |
+
self.text.insert('1.0', ' """Docstring.\n ')
|
| 80 |
+
self.assertIsNone(acp.autocomplete_event(ev))
|
| 81 |
+
self.text.delete('1.0', 'end')
|
| 82 |
+
|
| 83 |
+
# If active autocomplete window, complete() and 'break'.
|
| 84 |
+
self.text.insert('1.0', 're.')
|
| 85 |
+
acp.autocompletewindow = mock = Mock()
|
| 86 |
+
mock.is_active = Mock(return_value=True)
|
| 87 |
+
Equal(acp.autocomplete_event(ev), 'break')
|
| 88 |
+
mock.complete.assert_called_once()
|
| 89 |
+
acp.autocompletewindow = None
|
| 90 |
+
|
| 91 |
+
# If no active autocomplete window, open_completions(), None/break.
|
| 92 |
+
open_c = Func(result=False)
|
| 93 |
+
acp.open_completions = open_c
|
| 94 |
+
Equal(acp.autocomplete_event(ev), None)
|
| 95 |
+
Equal(open_c.args[0], ac.TAB)
|
| 96 |
+
open_c.result = True
|
| 97 |
+
Equal(acp.autocomplete_event(ev), 'break')
|
| 98 |
+
Equal(open_c.args[0], ac.TAB)
|
| 99 |
+
|
| 100 |
+
def test_try_open_completions_event(self):
|
| 101 |
+
Equal = self.assertEqual
|
| 102 |
+
text = self.text
|
| 103 |
+
acp = self.autocomplete
|
| 104 |
+
trycompletions = acp.try_open_completions_event
|
| 105 |
+
after = Func(result='after1')
|
| 106 |
+
acp.text.after = after
|
| 107 |
+
|
| 108 |
+
# If no text or trigger, after not called.
|
| 109 |
+
trycompletions()
|
| 110 |
+
Equal(after.called, 0)
|
| 111 |
+
text.insert('1.0', 're')
|
| 112 |
+
trycompletions()
|
| 113 |
+
Equal(after.called, 0)
|
| 114 |
+
|
| 115 |
+
# Attribute needed, no existing callback.
|
| 116 |
+
text.insert('insert', ' re.')
|
| 117 |
+
acp._delayed_completion_id = None
|
| 118 |
+
trycompletions()
|
| 119 |
+
Equal(acp._delayed_completion_index, text.index('insert'))
|
| 120 |
+
Equal(after.args,
|
| 121 |
+
(acp.popupwait, acp._delayed_open_completions, ac.TRY_A))
|
| 122 |
+
cb1 = acp._delayed_completion_id
|
| 123 |
+
Equal(cb1, 'after1')
|
| 124 |
+
|
| 125 |
+
# File needed, existing callback cancelled.
|
| 126 |
+
text.insert('insert', ' "./Lib/')
|
| 127 |
+
after.result = 'after2'
|
| 128 |
+
cancel = Func()
|
| 129 |
+
acp.text.after_cancel = cancel
|
| 130 |
+
trycompletions()
|
| 131 |
+
Equal(acp._delayed_completion_index, text.index('insert'))
|
| 132 |
+
Equal(cancel.args, (cb1,))
|
| 133 |
+
Equal(after.args,
|
| 134 |
+
(acp.popupwait, acp._delayed_open_completions, ac.TRY_F))
|
| 135 |
+
Equal(acp._delayed_completion_id, 'after2')
|
| 136 |
+
|
| 137 |
+
def test_delayed_open_completions(self):
|
| 138 |
+
Equal = self.assertEqual
|
| 139 |
+
acp = self.autocomplete
|
| 140 |
+
open_c = Func()
|
| 141 |
+
acp.open_completions = open_c
|
| 142 |
+
self.text.insert('1.0', '"dict.')
|
| 143 |
+
|
| 144 |
+
# Set autocomplete._delayed_completion_id to None.
|
| 145 |
+
# Text index changed, don't call open_completions.
|
| 146 |
+
acp._delayed_completion_id = 'after'
|
| 147 |
+
acp._delayed_completion_index = self.text.index('insert+1c')
|
| 148 |
+
acp._delayed_open_completions('dummy')
|
| 149 |
+
self.assertIsNone(acp._delayed_completion_id)
|
| 150 |
+
Equal(open_c.called, 0)
|
| 151 |
+
|
| 152 |
+
# Text index unchanged, call open_completions.
|
| 153 |
+
acp._delayed_completion_index = self.text.index('insert')
|
| 154 |
+
acp._delayed_open_completions((1, 2, 3, ac.FILES))
|
| 155 |
+
self.assertEqual(open_c.args[0], (1, 2, 3, ac.FILES))
|
| 156 |
+
|
| 157 |
+
def test_oc_cancel_comment(self):
|
| 158 |
+
none = self.assertIsNone
|
| 159 |
+
acp = self.autocomplete
|
| 160 |
+
|
| 161 |
+
# Comment is in neither code or string.
|
| 162 |
+
acp._delayed_completion_id = 'after'
|
| 163 |
+
after = Func(result='after')
|
| 164 |
+
acp.text.after_cancel = after
|
| 165 |
+
self.text.insert(1.0, '# comment')
|
| 166 |
+
none(acp.open_completions(ac.TAB)) # From 'else' after 'elif'.
|
| 167 |
+
none(acp._delayed_completion_id)
|
| 168 |
+
|
| 169 |
+
def test_oc_no_list(self):
|
| 170 |
+
acp = self.autocomplete
|
| 171 |
+
fetch = Func(result=([],[]))
|
| 172 |
+
acp.fetch_completions = fetch
|
| 173 |
+
self.text.insert('1.0', 'object')
|
| 174 |
+
self.assertIsNone(acp.open_completions(ac.TAB))
|
| 175 |
+
self.text.insert('insert', '.')
|
| 176 |
+
self.assertIsNone(acp.open_completions(ac.TAB))
|
| 177 |
+
self.assertEqual(fetch.called, 2)
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
def test_open_completions_none(self):
|
| 181 |
+
# Test other two None returns.
|
| 182 |
+
none = self.assertIsNone
|
| 183 |
+
acp = self.autocomplete
|
| 184 |
+
|
| 185 |
+
# No object for attributes or need call not allowed.
|
| 186 |
+
self.text.insert(1.0, '.')
|
| 187 |
+
none(acp.open_completions(ac.TAB))
|
| 188 |
+
self.text.insert('insert', ' int().')
|
| 189 |
+
none(acp.open_completions(ac.TAB))
|
| 190 |
+
|
| 191 |
+
# Blank or quote trigger 'if complete ...'.
|
| 192 |
+
self.text.delete(1.0, 'end')
|
| 193 |
+
self.assertFalse(acp.open_completions(ac.TAB))
|
| 194 |
+
self.text.insert('1.0', '"')
|
| 195 |
+
self.assertFalse(acp.open_completions(ac.TAB))
|
| 196 |
+
self.text.delete('1.0', 'end')
|
| 197 |
+
|
| 198 |
+
class dummy_acw:
|
| 199 |
+
__init__ = Func()
|
| 200 |
+
show_window = Func(result=False)
|
| 201 |
+
hide_window = Func()
|
| 202 |
+
|
| 203 |
+
def test_open_completions(self):
|
| 204 |
+
# Test completions of files and attributes.
|
| 205 |
+
acp = self.autocomplete
|
| 206 |
+
fetch = Func(result=(['tem'],['tem', '_tem']))
|
| 207 |
+
acp.fetch_completions = fetch
|
| 208 |
+
def make_acw(): return self.dummy_acw()
|
| 209 |
+
acp._make_autocomplete_window = make_acw
|
| 210 |
+
|
| 211 |
+
self.text.insert('1.0', 'int.')
|
| 212 |
+
acp.open_completions(ac.TAB)
|
| 213 |
+
self.assertIsInstance(acp.autocompletewindow, self.dummy_acw)
|
| 214 |
+
self.text.delete('1.0', 'end')
|
| 215 |
+
|
| 216 |
+
# Test files.
|
| 217 |
+
self.text.insert('1.0', '"t')
|
| 218 |
+
self.assertTrue(acp.open_completions(ac.TAB))
|
| 219 |
+
self.text.delete('1.0', 'end')
|
| 220 |
+
|
| 221 |
+
def test_completion_kwds(self):
|
| 222 |
+
self.assertIn('and', ac.completion_kwds)
|
| 223 |
+
self.assertIn('case', ac.completion_kwds)
|
| 224 |
+
self.assertNotIn('None', ac.completion_kwds)
|
| 225 |
+
|
| 226 |
+
def test_fetch_completions(self):
|
| 227 |
+
# Test that fetch_completions returns 2 lists:
|
| 228 |
+
# For attribute completion, a large list containing all variables, and
|
| 229 |
+
# a small list containing non-private variables.
|
| 230 |
+
# For file completion, a large list containing all files in the path,
|
| 231 |
+
# and a small list containing files that do not start with '.'.
|
| 232 |
+
acp = self.autocomplete
|
| 233 |
+
small, large = acp.fetch_completions(
|
| 234 |
+
'', ac.ATTRS)
|
| 235 |
+
if hasattr(__main__, '__file__') and __main__.__file__ != ac.__file__:
|
| 236 |
+
self.assertNotIn('AutoComplete', small) # See issue 36405.
|
| 237 |
+
|
| 238 |
+
# Test attributes
|
| 239 |
+
s, b = acp.fetch_completions('', ac.ATTRS)
|
| 240 |
+
self.assertLess(len(small), len(large))
|
| 241 |
+
self.assertTrue(all(filter(lambda x: x.startswith('_'), s)))
|
| 242 |
+
self.assertTrue(any(filter(lambda x: x.startswith('_'), b)))
|
| 243 |
+
|
| 244 |
+
# Test smalll should respect to __all__.
|
| 245 |
+
with patch.dict('__main__.__dict__', {'__all__': ['a', 'b']}):
|
| 246 |
+
s, b = acp.fetch_completions('', ac.ATTRS)
|
| 247 |
+
self.assertEqual(s, ['a', 'b'])
|
| 248 |
+
self.assertIn('__name__', b) # From __main__.__dict__.
|
| 249 |
+
self.assertIn('sum', b) # From __main__.__builtins__.__dict__.
|
| 250 |
+
self.assertIn('nonlocal', b) # From keyword.kwlist.
|
| 251 |
+
pos = b.index('False') # Test False not included twice.
|
| 252 |
+
self.assertNotEqual(b[pos+1], 'False')
|
| 253 |
+
|
| 254 |
+
# Test attributes with name entity.
|
| 255 |
+
mock = Mock()
|
| 256 |
+
mock._private = Mock()
|
| 257 |
+
with patch.dict('__main__.__dict__', {'foo': mock}):
|
| 258 |
+
s, b = acp.fetch_completions('foo', ac.ATTRS)
|
| 259 |
+
self.assertNotIn('_private', s)
|
| 260 |
+
self.assertIn('_private', b)
|
| 261 |
+
self.assertEqual(s, [i for i in sorted(dir(mock)) if i[:1] != '_'])
|
| 262 |
+
self.assertEqual(b, sorted(dir(mock)))
|
| 263 |
+
|
| 264 |
+
# Test files
|
| 265 |
+
def _listdir(path):
|
| 266 |
+
# This will be patch and used in fetch_completions.
|
| 267 |
+
if path == '.':
|
| 268 |
+
return ['foo', 'bar', '.hidden']
|
| 269 |
+
return ['monty', 'python', '.hidden']
|
| 270 |
+
|
| 271 |
+
with patch.object(os, 'listdir', _listdir):
|
| 272 |
+
s, b = acp.fetch_completions('', ac.FILES)
|
| 273 |
+
self.assertEqual(s, ['bar', 'foo'])
|
| 274 |
+
self.assertEqual(b, ['.hidden', 'bar', 'foo'])
|
| 275 |
+
|
| 276 |
+
s, b = acp.fetch_completions('~', ac.FILES)
|
| 277 |
+
self.assertEqual(s, ['monty', 'python'])
|
| 278 |
+
self.assertEqual(b, ['.hidden', 'monty', 'python'])
|
| 279 |
+
|
| 280 |
+
def test_get_entity(self):
|
| 281 |
+
# Test that a name is in the namespace of sys.modules and
|
| 282 |
+
# __main__.__dict__.
|
| 283 |
+
acp = self.autocomplete
|
| 284 |
+
Equal = self.assertEqual
|
| 285 |
+
|
| 286 |
+
Equal(acp.get_entity('int'), int)
|
| 287 |
+
|
| 288 |
+
# Test name from sys.modules.
|
| 289 |
+
mock = Mock()
|
| 290 |
+
with patch.dict('sys.modules', {'tempfile': mock}):
|
| 291 |
+
Equal(acp.get_entity('tempfile'), mock)
|
| 292 |
+
|
| 293 |
+
# Test name from __main__.__dict__.
|
| 294 |
+
di = {'foo': 10, 'bar': 20}
|
| 295 |
+
with patch.dict('__main__.__dict__', {'d': di}):
|
| 296 |
+
Equal(acp.get_entity('d'), di)
|
| 297 |
+
|
| 298 |
+
# Test name not in namespace.
|
| 299 |
+
with patch.dict('__main__.__dict__', {}):
|
| 300 |
+
with self.assertRaises(NameError):
|
| 301 |
+
acp.get_entity('not_exist')
|
| 302 |
+
|
| 303 |
+
|
| 304 |
+
if __name__ == '__main__':
|
| 305 |
+
unittest.main(verbosity=2)
|
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/test_autocomplete_w.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"Test autocomplete_w, coverage 11%."
|
| 2 |
+
|
| 3 |
+
import unittest
|
| 4 |
+
from test.support import requires
|
| 5 |
+
from tkinter import Tk, Text
|
| 6 |
+
|
| 7 |
+
import idlelib.autocomplete_w as acw
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class AutoCompleteWindowTest(unittest.TestCase):
|
| 11 |
+
|
| 12 |
+
@classmethod
|
| 13 |
+
def setUpClass(cls):
|
| 14 |
+
requires('gui')
|
| 15 |
+
cls.root = Tk()
|
| 16 |
+
cls.root.withdraw()
|
| 17 |
+
cls.text = Text(cls.root)
|
| 18 |
+
cls.acw = acw.AutoCompleteWindow(cls.text, tags=None)
|
| 19 |
+
|
| 20 |
+
@classmethod
|
| 21 |
+
def tearDownClass(cls):
|
| 22 |
+
del cls.text, cls.acw
|
| 23 |
+
cls.root.update_idletasks()
|
| 24 |
+
cls.root.destroy()
|
| 25 |
+
del cls.root
|
| 26 |
+
|
| 27 |
+
def test_init(self):
|
| 28 |
+
self.assertEqual(self.acw.widget, self.text)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
if __name__ == '__main__':
|
| 32 |
+
unittest.main(verbosity=2)
|
miniconda3/pkgs/python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and, coverage 100%."
|
| 2 |
+
|
| 3 |
+
from idlelib.autoexpand import AutoExpand
|
| 4 |
+
import unittest
|
| 5 |
+
from test.support import requires
|
| 6 |
+
from tkinter import Text, Tk
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class DummyEditwin:
|
| 10 |
+
# AutoExpand.__init__ only needs .text
|
| 11 |
+
def __init__(self, text):
|
| 12 |
+
self.text = text
|
| 13 |
+
|
| 14 |
+
class AutoExpandTest(unittest.TestCase):
|
| 15 |
+
|
| 16 |
+
@classmethod
|
| 17 |
+
def setUpClass(cls):
|
| 18 |
+
requires('gui')
|
| 19 |
+
cls.tk = Tk()
|
| 20 |
+
cls.text = Text(cls.tk)
|
| 21 |
+
cls.auto_expand = AutoExpand(DummyEditwin(cls.text))
|
| 22 |
+
cls.auto_expand.bell = lambda: None
|
| 23 |
+
|
| 24 |
+
# If mock_tk.Text._decode understood indexes 'insert' with suffixed 'linestart',
|
| 25 |
+
# 'wordstart', and 'lineend', used by autoexpand, we could use the following
|
| 26 |
+
# to run these test on non-gui machines (but check bell).
|
| 27 |
+
## try:
|
| 28 |
+
## requires('gui')
|
| 29 |
+
## #raise ResourceDenied() # Uncomment to test mock.
|
| 30 |
+
## except ResourceDenied:
|
| 31 |
+
## from idlelib.idle_test.mock_tk import Text
|
| 32 |
+
## cls.text = Text()
|
| 33 |
+
## cls.text.bell = lambda: None
|
| 34 |
+
## else:
|
| 35 |
+
## from tkinter import Tk, Text
|
| 36 |
+
## cls.tk = Tk()
|
| 37 |
+
## cls.text = Text(cls.tk)
|
| 38 |
+
|
| 39 |
+
@classmethod
|
| 40 |
+
def tearDownClass(cls):
|
| 41 |
+
del cls.text, cls.auto_expand
|
| 42 |
+
if hasattr(cls, 'tk'):
|
| 43 |
+
cls.tk.destroy()
|
| 44 |
+
del cls.tk
|
| 45 |
+
|
| 46 |
+
def tearDown(self):
|
| 47 |
+
self.text.delete('1.0', 'end')
|
| 48 |
+
|
| 49 |
+
def test_get_prevword(self):
|
| 50 |
+
text = self.text
|
| 51 |
+
previous = self.auto_expand.getprevword
|
| 52 |
+
equal = self.assertEqual
|
| 53 |
+
|
| 54 |
+
equal(previous(), '')
|
| 55 |
+
|
| 56 |
+
text.insert('insert', 't')
|
| 57 |
+
equal(previous(), 't')
|
| 58 |
+
|
| 59 |
+
text.insert('insert', 'his')
|
| 60 |
+
equal(previous(), 'this')
|
| 61 |
+
|
| 62 |
+
text.insert('insert', ' ')
|
| 63 |
+
equal(previous(), '')
|
| 64 |
+
|
| 65 |
+
text.insert('insert', 'is')
|
| 66 |
+
equal(previous(), 'is')
|
| 67 |
+
|
| 68 |
+
text.insert('insert', '\nsample\nstring')
|
| 69 |
+
equal(previous(), 'string')
|
| 70 |
+
|
| 71 |
+
text.delete('3.0', 'insert')
|
| 72 |
+
equal(previous(), '')
|
| 73 |
+
|
| 74 |
+
text.delete('1.0', 'end')
|
| 75 |
+
equal(previous(), '')
|
| 76 |
+
|
| 77 |
+
def test_before_only(self):
|
| 78 |
+
previous = self.auto_expand.getprevword
|
| 79 |
+
expand = self.auto_expand.expand_word_event
|
| 80 |
+
equal = self.assertEqual
|
| 81 |
+
|
| 82 |
+
self.text.insert('insert', 'ab ac bx ad ab a')
|
| 83 |
+
equal(self.auto_expand.getwords(), ['ab', 'ad', 'ac', 'a'])
|
| 84 |
+
expand('event')
|
| 85 |
+
equal(previous(), 'ab')
|
| 86 |
+
expand('event')
|
| 87 |
+
equal(previous(), 'ad')
|
| 88 |
+
expand('event')
|
| 89 |
+
equal(previous(), 'ac')
|
| 90 |
+
expand('event')
|
| 91 |
+
equal(previous(), 'a')
|
| 92 |
+
|
| 93 |
+
def test_after_only(self):
|
| 94 |
+
# Also add punctuation 'noise' that should be ignored.
|
| 95 |
+
text = self.text
|
| 96 |
+
previous = self.auto_expand.getprevword
|
| 97 |
+
expand = self.auto_expand.expand_word_event
|
| 98 |
+
equal = self.assertEqual
|
| 99 |
+
|
| 100 |
+
text.insert('insert', 'a, [ab] ac: () bx"" cd ac= ad ya')
|
| 101 |
+
text.mark_set('insert', '1.1')
|
| 102 |
+
equal(self.auto_expand.getwords(), ['ab', 'ac', 'ad', 'a'])
|
| 103 |
+
expand('event')
|
| 104 |
+
equal(previous(), 'ab')
|
| 105 |
+
expand('event')
|
| 106 |
+
equal(previous(), 'ac')
|
| 107 |
+
expand('event')
|
| 108 |
+
equal(previous(), 'ad')
|
| 109 |
+
expand('event')
|
| 110 |
+
equal(previous(), 'a')
|
| 111 |
+
|
| 112 |
+
def test_both_before_after(self):
|
| 113 |
+
text = self.text
|
| 114 |
+
previous = self.auto_expand.getprevword
|
| 115 |
+
expand = self.auto_expand.expand_word_event
|
| 116 |
+
equal = self.assertEqual
|
| 117 |
+
|
| 118 |
+
text.insert('insert', 'ab xy yz\n')
|
| 119 |
+
text.insert('insert', 'a ac by ac')
|
| 120 |
+
|
| 121 |
+
text.mark_set('insert', '2.1')
|
| 122 |
+
equal(self.auto_expand.getwords(), ['ab', 'ac', 'a'])
|
| 123 |
+
expand('event')
|
| 124 |
+
equal(previous(), 'ab')
|
| 125 |
+
expand('event')
|
| 126 |
+
equal(previous(), 'ac')
|
| 127 |
+
expand('event')
|
| 128 |
+
equal(previous(), 'a')
|
| 129 |
+
|
| 130 |
+
def test_other_expand_cases(self):
|
| 131 |
+
text = self.text
|
| 132 |
+
expand = self.auto_expand.expand_word_event
|
| 133 |
+
equal = self.assertEqual
|
| 134 |
+
|
| 135 |
+
# no expansion candidate found
|
| 136 |
+
equal(self.auto_expand.getwords(), [])
|
| 137 |
+
equal(expand('event'), 'break')
|
| 138 |
+
|
| 139 |
+
text.insert('insert', 'bx cy dz a')
|
| 140 |
+
equal(self.auto_expand.getwords(), [])
|
| 141 |
+
|
| 142 |
+
# reset state by successfully expanding once
|
| 143 |
+
# move cursor to another position and expand again
|
| 144 |
+
text.insert('insert', 'ac xy a ac ad a')
|
| 145 |
+
text.mark_set('insert', '1.7')
|
| 146 |
+
expand('event')
|
| 147 |
+
initial_state = self.auto_expand.state
|
| 148 |
+
text.mark_set('insert', '1.end')
|
| 149 |
+
expand('event')
|
| 150 |
+
new_state = self.auto_expand.state
|
| 151 |
+
self.assertNotEqual(initial_state, new_state)
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
if __name__ == '__main__':
|
| 155 |
+
unittest.main(verbosity=2)
|
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/test_browser.py
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"Test browser, coverage 90%."
|
| 2 |
+
|
| 3 |
+
from idlelib import browser
|
| 4 |
+
from test.support import requires
|
| 5 |
+
import unittest
|
| 6 |
+
from unittest import mock
|
| 7 |
+
from idlelib.idle_test.mock_idle import Func
|
| 8 |
+
from idlelib.util import py_extensions
|
| 9 |
+
|
| 10 |
+
from collections import deque
|
| 11 |
+
import os.path
|
| 12 |
+
import pyclbr
|
| 13 |
+
from tkinter import Tk
|
| 14 |
+
|
| 15 |
+
from idlelib.tree import TreeNode
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class ModuleBrowserTest(unittest.TestCase):
|
| 19 |
+
|
| 20 |
+
@classmethod
|
| 21 |
+
def setUpClass(cls):
|
| 22 |
+
requires('gui')
|
| 23 |
+
cls.root = Tk()
|
| 24 |
+
cls.root.withdraw()
|
| 25 |
+
cls.mb = browser.ModuleBrowser(cls.root, __file__, _utest=True)
|
| 26 |
+
|
| 27 |
+
@classmethod
|
| 28 |
+
def tearDownClass(cls):
|
| 29 |
+
cls.mb.close()
|
| 30 |
+
cls.root.update_idletasks()
|
| 31 |
+
cls.root.destroy()
|
| 32 |
+
del cls.root, cls.mb
|
| 33 |
+
|
| 34 |
+
def test_init(self):
|
| 35 |
+
mb = self.mb
|
| 36 |
+
eq = self.assertEqual
|
| 37 |
+
eq(mb.path, __file__)
|
| 38 |
+
eq(pyclbr._modules, {})
|
| 39 |
+
self.assertIsInstance(mb.node, TreeNode)
|
| 40 |
+
self.assertIsNotNone(browser.file_open)
|
| 41 |
+
|
| 42 |
+
def test_settitle(self):
|
| 43 |
+
mb = self.mb
|
| 44 |
+
self.assertIn(os.path.basename(__file__), mb.top.title())
|
| 45 |
+
self.assertEqual(mb.top.iconname(), 'Module Browser')
|
| 46 |
+
|
| 47 |
+
def test_rootnode(self):
|
| 48 |
+
mb = self.mb
|
| 49 |
+
rn = mb.rootnode()
|
| 50 |
+
self.assertIsInstance(rn, browser.ModuleBrowserTreeItem)
|
| 51 |
+
|
| 52 |
+
def test_close(self):
|
| 53 |
+
mb = self.mb
|
| 54 |
+
mb.top.destroy = Func()
|
| 55 |
+
mb.node.destroy = Func()
|
| 56 |
+
mb.close()
|
| 57 |
+
self.assertTrue(mb.top.destroy.called)
|
| 58 |
+
self.assertTrue(mb.node.destroy.called)
|
| 59 |
+
del mb.top.destroy, mb.node.destroy
|
| 60 |
+
|
| 61 |
+
def test_is_browseable_extension(self):
|
| 62 |
+
path = "/path/to/file"
|
| 63 |
+
for ext in py_extensions:
|
| 64 |
+
with self.subTest(ext=ext):
|
| 65 |
+
filename = f'{path}{ext}'
|
| 66 |
+
actual = browser.is_browseable_extension(filename)
|
| 67 |
+
expected = ext not in browser.browseable_extension_blocklist
|
| 68 |
+
self.assertEqual(actual, expected)
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
# Nested tree same as in test_pyclbr.py except for supers on C0. C1.
|
| 72 |
+
mb = pyclbr
|
| 73 |
+
module, fname = 'test', 'test.py'
|
| 74 |
+
C0 = mb.Class(module, 'C0', ['base'], fname, 1, end_lineno=9)
|
| 75 |
+
F1 = mb._nest_function(C0, 'F1', 3, 5)
|
| 76 |
+
C1 = mb._nest_class(C0, 'C1', 6, 9, [''])
|
| 77 |
+
C2 = mb._nest_class(C1, 'C2', 7, 9)
|
| 78 |
+
F3 = mb._nest_function(C2, 'F3', 9, 9)
|
| 79 |
+
f0 = mb.Function(module, 'f0', fname, 11, end_lineno=15)
|
| 80 |
+
f1 = mb._nest_function(f0, 'f1', 12, 14)
|
| 81 |
+
f2 = mb._nest_function(f1, 'f2', 13, 13)
|
| 82 |
+
c1 = mb._nest_class(f0, 'c1', 15, 15)
|
| 83 |
+
mock_pyclbr_tree = {'C0': C0, 'f0': f0}
|
| 84 |
+
|
| 85 |
+
# Adjust C0.name, C1.name so tests do not depend on order.
|
| 86 |
+
browser.transform_children(mock_pyclbr_tree, 'test') # C0(base)
|
| 87 |
+
browser.transform_children(C0.children) # C1()
|
| 88 |
+
|
| 89 |
+
# The class below checks that the calls above are correct
|
| 90 |
+
# and that duplicate calls have no effect.
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
class TransformChildrenTest(unittest.TestCase):
|
| 94 |
+
|
| 95 |
+
def test_transform_module_children(self):
|
| 96 |
+
eq = self.assertEqual
|
| 97 |
+
transform = browser.transform_children
|
| 98 |
+
# Parameter matches tree module.
|
| 99 |
+
tcl = list(transform(mock_pyclbr_tree, 'test'))
|
| 100 |
+
eq(tcl, [C0, f0])
|
| 101 |
+
eq(tcl[0].name, 'C0(base)')
|
| 102 |
+
eq(tcl[1].name, 'f0')
|
| 103 |
+
# Check that second call does not change suffix.
|
| 104 |
+
tcl = list(transform(mock_pyclbr_tree, 'test'))
|
| 105 |
+
eq(tcl[0].name, 'C0(base)')
|
| 106 |
+
# Nothing to traverse if parameter name isn't same as tree module.
|
| 107 |
+
tcl = list(transform(mock_pyclbr_tree, 'different name'))
|
| 108 |
+
eq(tcl, [])
|
| 109 |
+
|
| 110 |
+
def test_transform_node_children(self):
|
| 111 |
+
eq = self.assertEqual
|
| 112 |
+
transform = browser.transform_children
|
| 113 |
+
# Class with two children, one name altered.
|
| 114 |
+
tcl = list(transform(C0.children))
|
| 115 |
+
eq(tcl, [F1, C1])
|
| 116 |
+
eq(tcl[0].name, 'F1')
|
| 117 |
+
eq(tcl[1].name, 'C1()')
|
| 118 |
+
tcl = list(transform(C0.children))
|
| 119 |
+
eq(tcl[1].name, 'C1()')
|
| 120 |
+
# Function with two children.
|
| 121 |
+
eq(list(transform(f0.children)), [f1, c1])
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
class ModuleBrowserTreeItemTest(unittest.TestCase):
|
| 125 |
+
|
| 126 |
+
@classmethod
|
| 127 |
+
def setUpClass(cls):
|
| 128 |
+
cls.mbt = browser.ModuleBrowserTreeItem(fname)
|
| 129 |
+
|
| 130 |
+
def test_init(self):
|
| 131 |
+
self.assertEqual(self.mbt.file, fname)
|
| 132 |
+
|
| 133 |
+
def test_gettext(self):
|
| 134 |
+
self.assertEqual(self.mbt.GetText(), fname)
|
| 135 |
+
|
| 136 |
+
def test_geticonname(self):
|
| 137 |
+
self.assertEqual(self.mbt.GetIconName(), 'python')
|
| 138 |
+
|
| 139 |
+
def test_isexpandable(self):
|
| 140 |
+
self.assertTrue(self.mbt.IsExpandable())
|
| 141 |
+
|
| 142 |
+
def test_listchildren(self):
|
| 143 |
+
save_rex = browser.pyclbr.readmodule_ex
|
| 144 |
+
save_tc = browser.transform_children
|
| 145 |
+
browser.pyclbr.readmodule_ex = Func(result=mock_pyclbr_tree)
|
| 146 |
+
browser.transform_children = Func(result=[f0, C0])
|
| 147 |
+
try:
|
| 148 |
+
self.assertEqual(self.mbt.listchildren(), [f0, C0])
|
| 149 |
+
finally:
|
| 150 |
+
browser.pyclbr.readmodule_ex = save_rex
|
| 151 |
+
browser.transform_children = save_tc
|
| 152 |
+
|
| 153 |
+
def test_getsublist(self):
|
| 154 |
+
mbt = self.mbt
|
| 155 |
+
mbt.listchildren = Func(result=[f0, C0])
|
| 156 |
+
sub0, sub1 = mbt.GetSubList()
|
| 157 |
+
del mbt.listchildren
|
| 158 |
+
self.assertIsInstance(sub0, browser.ChildBrowserTreeItem)
|
| 159 |
+
self.assertIsInstance(sub1, browser.ChildBrowserTreeItem)
|
| 160 |
+
self.assertEqual(sub0.name, 'f0')
|
| 161 |
+
self.assertEqual(sub1.name, 'C0(base)')
|
| 162 |
+
|
| 163 |
+
@mock.patch('idlelib.browser.file_open')
|
| 164 |
+
def test_ondoubleclick(self, fopen):
|
| 165 |
+
mbt = self.mbt
|
| 166 |
+
|
| 167 |
+
with mock.patch('os.path.exists', return_value=False):
|
| 168 |
+
mbt.OnDoubleClick()
|
| 169 |
+
fopen.assert_not_called()
|
| 170 |
+
|
| 171 |
+
with mock.patch('os.path.exists', return_value=True):
|
| 172 |
+
mbt.OnDoubleClick()
|
| 173 |
+
fopen.assert_called_once_with(fname)
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
class ChildBrowserTreeItemTest(unittest.TestCase):
|
| 177 |
+
|
| 178 |
+
@classmethod
|
| 179 |
+
def setUpClass(cls):
|
| 180 |
+
CBT = browser.ChildBrowserTreeItem
|
| 181 |
+
cls.cbt_f1 = CBT(f1)
|
| 182 |
+
cls.cbt_C1 = CBT(C1)
|
| 183 |
+
cls.cbt_F1 = CBT(F1)
|
| 184 |
+
|
| 185 |
+
@classmethod
|
| 186 |
+
def tearDownClass(cls):
|
| 187 |
+
del cls.cbt_C1, cls.cbt_f1, cls.cbt_F1
|
| 188 |
+
|
| 189 |
+
def test_init(self):
|
| 190 |
+
eq = self.assertEqual
|
| 191 |
+
eq(self.cbt_C1.name, 'C1()')
|
| 192 |
+
self.assertFalse(self.cbt_C1.isfunction)
|
| 193 |
+
eq(self.cbt_f1.name, 'f1')
|
| 194 |
+
self.assertTrue(self.cbt_f1.isfunction)
|
| 195 |
+
|
| 196 |
+
def test_gettext(self):
|
| 197 |
+
self.assertEqual(self.cbt_C1.GetText(), 'class C1()')
|
| 198 |
+
self.assertEqual(self.cbt_f1.GetText(), 'def f1(...)')
|
| 199 |
+
|
| 200 |
+
def test_geticonname(self):
|
| 201 |
+
self.assertEqual(self.cbt_C1.GetIconName(), 'folder')
|
| 202 |
+
self.assertEqual(self.cbt_f1.GetIconName(), 'python')
|
| 203 |
+
|
| 204 |
+
def test_isexpandable(self):
|
| 205 |
+
self.assertTrue(self.cbt_C1.IsExpandable())
|
| 206 |
+
self.assertTrue(self.cbt_f1.IsExpandable())
|
| 207 |
+
self.assertFalse(self.cbt_F1.IsExpandable())
|
| 208 |
+
|
| 209 |
+
def test_getsublist(self):
|
| 210 |
+
eq = self.assertEqual
|
| 211 |
+
CBT = browser.ChildBrowserTreeItem
|
| 212 |
+
|
| 213 |
+
f1sublist = self.cbt_f1.GetSubList()
|
| 214 |
+
self.assertIsInstance(f1sublist[0], CBT)
|
| 215 |
+
eq(len(f1sublist), 1)
|
| 216 |
+
eq(f1sublist[0].name, 'f2')
|
| 217 |
+
|
| 218 |
+
eq(self.cbt_F1.GetSubList(), [])
|
| 219 |
+
|
| 220 |
+
@mock.patch('idlelib.browser.file_open')
|
| 221 |
+
def test_ondoubleclick(self, fopen):
|
| 222 |
+
goto = fopen.return_value.gotoline = mock.Mock()
|
| 223 |
+
self.cbt_F1.OnDoubleClick()
|
| 224 |
+
fopen.assert_called()
|
| 225 |
+
goto.assert_called()
|
| 226 |
+
goto.assert_called_with(self.cbt_F1.obj.lineno)
|
| 227 |
+
# Failure test would have to raise OSError or AttributeError.
|
| 228 |
+
|
| 229 |
+
|
| 230 |
+
class NestedChildrenTest(unittest.TestCase):
|
| 231 |
+
"Test that all the nodes in a nested tree are added to the BrowserTree."
|
| 232 |
+
|
| 233 |
+
def test_nested(self):
|
| 234 |
+
queue = deque()
|
| 235 |
+
actual_names = []
|
| 236 |
+
# The tree items are processed in breadth first order.
|
| 237 |
+
# Verify that processing each sublist hits every node and
|
| 238 |
+
# in the right order.
|
| 239 |
+
expected_names = ['f0', 'C0(base)',
|
| 240 |
+
'f1', 'c1', 'F1', 'C1()',
|
| 241 |
+
'f2', 'C2',
|
| 242 |
+
'F3']
|
| 243 |
+
CBT = browser.ChildBrowserTreeItem
|
| 244 |
+
queue.extend((CBT(f0), CBT(C0)))
|
| 245 |
+
while queue:
|
| 246 |
+
cb = queue.popleft()
|
| 247 |
+
sublist = cb.GetSubList()
|
| 248 |
+
queue.extend(sublist)
|
| 249 |
+
self.assertIn(cb.name, cb.GetText())
|
| 250 |
+
self.assertIn(cb.GetIconName(), ('python', 'folder'))
|
| 251 |
+
self.assertIs(cb.IsExpandable(), sublist != [])
|
| 252 |
+
actual_names.append(cb.name)
|
| 253 |
+
self.assertEqual(actual_names, expected_names)
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
if __name__ == '__main__':
|
| 257 |
+
unittest.main(verbosity=2)
|
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/test_calltip.py
ADDED
|
@@ -0,0 +1,372 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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| 3 |
+
from idlelib import calltip
|
| 4 |
+
import unittest
|
| 5 |
+
from unittest.mock import Mock
|
| 6 |
+
import textwrap
|
| 7 |
+
import types
|
| 8 |
+
import re
|
| 9 |
+
from idlelib.idle_test.mock_tk import Text
|
| 10 |
+
from test.support import MISSING_C_DOCSTRINGS
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
# Test Class TC is used in multiple get_argspec test methods
|
| 14 |
+
class TC:
|
| 15 |
+
'doc'
|
| 16 |
+
tip = "(ai=None, *b)"
|
| 17 |
+
def __init__(self, ai=None, *b): 'doc'
|
| 18 |
+
__init__.tip = "(self, ai=None, *b)"
|
| 19 |
+
def t1(self): 'doc'
|
| 20 |
+
t1.tip = "(self)"
|
| 21 |
+
def t2(self, ai, b=None): 'doc'
|
| 22 |
+
t2.tip = "(self, ai, b=None)"
|
| 23 |
+
def t3(self, ai, *args): 'doc'
|
| 24 |
+
t3.tip = "(self, ai, *args)"
|
| 25 |
+
def t4(self, *args): 'doc'
|
| 26 |
+
t4.tip = "(self, *args)"
|
| 27 |
+
def t5(self, ai, b=None, *args, **kw): 'doc'
|
| 28 |
+
t5.tip = "(self, ai, b=None, *args, **kw)"
|
| 29 |
+
def t6(no, self): 'doc'
|
| 30 |
+
t6.tip = "(no, self)"
|
| 31 |
+
def __call__(self, ci): 'doc'
|
| 32 |
+
__call__.tip = "(self, ci)"
|
| 33 |
+
def nd(self): pass # No doc.
|
| 34 |
+
# attaching .tip to wrapped methods does not work
|
| 35 |
+
@classmethod
|
| 36 |
+
def cm(cls, a): 'doc'
|
| 37 |
+
@staticmethod
|
| 38 |
+
def sm(b): 'doc'
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
tc = TC()
|
| 42 |
+
default_tip = calltip._default_callable_argspec
|
| 43 |
+
get_spec = calltip.get_argspec
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
class Get_argspecTest(unittest.TestCase):
|
| 47 |
+
# The get_spec function must return a string, even if blank.
|
| 48 |
+
# Test a variety of objects to be sure that none cause it to raise
|
| 49 |
+
# (quite aside from getting as correct an answer as possible).
|
| 50 |
+
# The tests of builtins may break if inspect or the docstrings change,
|
| 51 |
+
# but a red buildbot is better than a user crash (as has happened).
|
| 52 |
+
# For a simple mismatch, change the expected output to the actual.
|
| 53 |
+
|
| 54 |
+
@unittest.skipIf(MISSING_C_DOCSTRINGS,
|
| 55 |
+
"Signature information for builtins requires docstrings")
|
| 56 |
+
def test_builtins(self):
|
| 57 |
+
|
| 58 |
+
def tiptest(obj, out):
|
| 59 |
+
self.assertEqual(get_spec(obj), out)
|
| 60 |
+
|
| 61 |
+
# Python class that inherits builtin methods
|
| 62 |
+
class List(list): "List() doc"
|
| 63 |
+
|
| 64 |
+
# Simulate builtin with no docstring for default tip test
|
| 65 |
+
class SB: __call__ = None
|
| 66 |
+
|
| 67 |
+
if List.__doc__ is not None:
|
| 68 |
+
tiptest(List,
|
| 69 |
+
f'(iterable=(), /)'
|
| 70 |
+
f'\n{List.__doc__}')
|
| 71 |
+
tiptest(list.__new__,
|
| 72 |
+
'(*args, **kwargs)\n'
|
| 73 |
+
'Create and return a new object. '
|
| 74 |
+
'See help(type) for accurate signature.')
|
| 75 |
+
tiptest(list.__init__,
|
| 76 |
+
'(self, /, *args, **kwargs)\n'
|
| 77 |
+
'Initialize self. See help(type(self)) for accurate signature.')
|
| 78 |
+
append_doc = "\nAppend object to the end of the list."
|
| 79 |
+
tiptest(list.append, '(self, object, /)' + append_doc)
|
| 80 |
+
tiptest(List.append, '(self, object, /)' + append_doc)
|
| 81 |
+
tiptest([].append, '(object, /)' + append_doc)
|
| 82 |
+
# The use of 'object' above matches the signature text.
|
| 83 |
+
|
| 84 |
+
tiptest(types.MethodType,
|
| 85 |
+
'(function, instance, /)\n'
|
| 86 |
+
'Create a bound instance method object.')
|
| 87 |
+
tiptest(SB(), default_tip)
|
| 88 |
+
|
| 89 |
+
p = re.compile('')
|
| 90 |
+
tiptest(re.sub, '''\
|
| 91 |
+
(pattern, repl, string, count=0, flags=0)
|
| 92 |
+
Return the string obtained by replacing the leftmost
|
| 93 |
+
non-overlapping occurrences of the pattern in string by the
|
| 94 |
+
replacement repl. repl can be either a string or a callable;
|
| 95 |
+
if a string, backslash escapes in it are processed. If it is
|
| 96 |
+
a callable, it's passed the Match object and must return''')
|
| 97 |
+
tiptest(p.sub, '''\
|
| 98 |
+
(repl, string, count=0)
|
| 99 |
+
Return the string obtained by replacing the leftmost \
|
| 100 |
+
non-overlapping occurrences o...''')
|
| 101 |
+
|
| 102 |
+
def test_signature_wrap(self):
|
| 103 |
+
if textwrap.TextWrapper.__doc__ is not None:
|
| 104 |
+
self.assertEqual(get_spec(textwrap.TextWrapper), '''\
|
| 105 |
+
(width=70, initial_indent='', subsequent_indent='', expand_tabs=True,
|
| 106 |
+
replace_whitespace=True, fix_sentence_endings=False, break_long_words=True,
|
| 107 |
+
drop_whitespace=True, break_on_hyphens=True, tabsize=8, *, max_lines=None,
|
| 108 |
+
placeholder=' [...]')
|
| 109 |
+
Object for wrapping/filling text. The public interface consists of
|
| 110 |
+
the wrap() and fill() methods; the other methods are just there for
|
| 111 |
+
subclasses to override in order to tweak the default behaviour.
|
| 112 |
+
If you want to completely replace the main wrapping algorithm,
|
| 113 |
+
you\'ll probably have to override _wrap_chunks().''')
|
| 114 |
+
|
| 115 |
+
def test_properly_formatted(self):
|
| 116 |
+
|
| 117 |
+
def foo(s='a'*100):
|
| 118 |
+
pass
|
| 119 |
+
|
| 120 |
+
def bar(s='a'*100):
|
| 121 |
+
"""Hello Guido"""
|
| 122 |
+
pass
|
| 123 |
+
|
| 124 |
+
def baz(s='a'*100, z='b'*100):
|
| 125 |
+
pass
|
| 126 |
+
|
| 127 |
+
indent = calltip._INDENT
|
| 128 |
+
|
| 129 |
+
sfoo = "(s='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"\
|
| 130 |
+
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" + indent + "aaaaaaaaa"\
|
| 131 |
+
"aaaaaaaaaa')"
|
| 132 |
+
sbar = "(s='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"\
|
| 133 |
+
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" + indent + "aaaaaaaaa"\
|
| 134 |
+
"aaaaaaaaaa')\nHello Guido"
|
| 135 |
+
sbaz = "(s='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"\
|
| 136 |
+
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" + indent + "aaaaaaaaa"\
|
| 137 |
+
"aaaaaaaaaa', z='bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"\
|
| 138 |
+
"bbbbbbbbbbbbbbbbb\n" + indent + "bbbbbbbbbbbbbbbbbbbbbb"\
|
| 139 |
+
"bbbbbbbbbbbbbbbbbbbbbb')"
|
| 140 |
+
|
| 141 |
+
for func,doc in [(foo, sfoo), (bar, sbar), (baz, sbaz)]:
|
| 142 |
+
with self.subTest(func=func, doc=doc):
|
| 143 |
+
self.assertEqual(get_spec(func), doc)
|
| 144 |
+
|
| 145 |
+
def test_docline_truncation(self):
|
| 146 |
+
def f(): pass
|
| 147 |
+
f.__doc__ = 'a'*300
|
| 148 |
+
self.assertEqual(get_spec(f), f"()\n{'a'*(calltip._MAX_COLS-3) + '...'}")
|
| 149 |
+
|
| 150 |
+
@unittest.skipIf(MISSING_C_DOCSTRINGS,
|
| 151 |
+
"Signature information for builtins requires docstrings")
|
| 152 |
+
def test_multiline_docstring(self):
|
| 153 |
+
# Test fewer lines than max.
|
| 154 |
+
self.assertEqual(get_spec(range),
|
| 155 |
+
"range(stop) -> range object\n"
|
| 156 |
+
"range(start, stop[, step]) -> range object")
|
| 157 |
+
|
| 158 |
+
# Test max lines
|
| 159 |
+
self.assertEqual(get_spec(bytes), '''\
|
| 160 |
+
bytes(iterable_of_ints) -> bytes
|
| 161 |
+
bytes(string, encoding[, errors]) -> bytes
|
| 162 |
+
bytes(bytes_or_buffer) -> immutable copy of bytes_or_buffer
|
| 163 |
+
bytes(int) -> bytes object of size given by the parameter initialized with null bytes
|
| 164 |
+
bytes() -> empty bytes object''')
|
| 165 |
+
|
| 166 |
+
def test_multiline_docstring_2(self):
|
| 167 |
+
# Test more than max lines
|
| 168 |
+
def f(): pass
|
| 169 |
+
f.__doc__ = 'a\n' * 15
|
| 170 |
+
self.assertEqual(get_spec(f), '()' + '\na' * calltip._MAX_LINES)
|
| 171 |
+
|
| 172 |
+
def test_functions(self):
|
| 173 |
+
def t1(): 'doc'
|
| 174 |
+
t1.tip = "()"
|
| 175 |
+
def t2(a, b=None): 'doc'
|
| 176 |
+
t2.tip = "(a, b=None)"
|
| 177 |
+
def t3(a, *args): 'doc'
|
| 178 |
+
t3.tip = "(a, *args)"
|
| 179 |
+
def t4(*args): 'doc'
|
| 180 |
+
t4.tip = "(*args)"
|
| 181 |
+
def t5(a, b=None, *args, **kw): 'doc'
|
| 182 |
+
t5.tip = "(a, b=None, *args, **kw)"
|
| 183 |
+
|
| 184 |
+
doc = '\ndoc' if t1.__doc__ is not None else ''
|
| 185 |
+
for func in (t1, t2, t3, t4, t5, TC):
|
| 186 |
+
with self.subTest(func=func):
|
| 187 |
+
self.assertEqual(get_spec(func), func.tip + doc)
|
| 188 |
+
|
| 189 |
+
def test_methods(self):
|
| 190 |
+
doc = '\ndoc' if TC.__doc__ is not None else ''
|
| 191 |
+
for meth in (TC.t1, TC.t2, TC.t3, TC.t4, TC.t5, TC.t6, TC.__call__):
|
| 192 |
+
with self.subTest(meth=meth):
|
| 193 |
+
self.assertEqual(get_spec(meth), meth.tip + doc)
|
| 194 |
+
self.assertEqual(get_spec(TC.cm), "(a)" + doc)
|
| 195 |
+
self.assertEqual(get_spec(TC.sm), "(b)" + doc)
|
| 196 |
+
|
| 197 |
+
def test_bound_methods(self):
|
| 198 |
+
# test that first parameter is correctly removed from argspec
|
| 199 |
+
doc = '\ndoc' if TC.__doc__ is not None else ''
|
| 200 |
+
for meth, mtip in ((tc.t1, "()"), (tc.t4, "(*args)"),
|
| 201 |
+
(tc.t6, "(self)"), (tc.__call__, '(ci)'),
|
| 202 |
+
(tc, '(ci)'), (TC.cm, "(a)"),):
|
| 203 |
+
with self.subTest(meth=meth, mtip=mtip):
|
| 204 |
+
self.assertEqual(get_spec(meth), mtip + doc)
|
| 205 |
+
|
| 206 |
+
def test_starred_parameter(self):
|
| 207 |
+
# test that starred first parameter is *not* removed from argspec
|
| 208 |
+
class C:
|
| 209 |
+
def m1(*args): pass
|
| 210 |
+
c = C()
|
| 211 |
+
for meth, mtip in ((C.m1, '(*args)'), (c.m1, "(*args)"),):
|
| 212 |
+
with self.subTest(meth=meth, mtip=mtip):
|
| 213 |
+
self.assertEqual(get_spec(meth), mtip)
|
| 214 |
+
|
| 215 |
+
def test_invalid_method_get_spec(self):
|
| 216 |
+
class C:
|
| 217 |
+
def m2(**kwargs): pass
|
| 218 |
+
class Test:
|
| 219 |
+
def __call__(*, a): pass
|
| 220 |
+
|
| 221 |
+
mtip = calltip._invalid_method
|
| 222 |
+
self.assertEqual(get_spec(C().m2), mtip)
|
| 223 |
+
self.assertEqual(get_spec(Test()), mtip)
|
| 224 |
+
|
| 225 |
+
def test_non_ascii_name(self):
|
| 226 |
+
# test that re works to delete a first parameter name that
|
| 227 |
+
# includes non-ascii chars, such as various forms of A.
|
| 228 |
+
uni = "(A\u0391\u0410\u05d0\u0627\u0905\u1e00\u3042, a)"
|
| 229 |
+
assert calltip._first_param.sub('', uni) == '(a)'
|
| 230 |
+
|
| 231 |
+
def test_no_docstring(self):
|
| 232 |
+
for meth, mtip in ((TC.nd, "(self)"), (tc.nd, "()")):
|
| 233 |
+
with self.subTest(meth=meth, mtip=mtip):
|
| 234 |
+
self.assertEqual(get_spec(meth), mtip)
|
| 235 |
+
|
| 236 |
+
def test_buggy_getattr_class(self):
|
| 237 |
+
class NoCall:
|
| 238 |
+
def __getattr__(self, name): # Not invoked for class attribute.
|
| 239 |
+
raise IndexError # Bug.
|
| 240 |
+
class CallA(NoCall):
|
| 241 |
+
def __call__(self, ci): # Bug does not matter.
|
| 242 |
+
pass
|
| 243 |
+
class CallB(NoCall):
|
| 244 |
+
def __call__(oui, a, b, c): # Non-standard 'self'.
|
| 245 |
+
pass
|
| 246 |
+
|
| 247 |
+
for meth, mtip in ((NoCall, default_tip), (CallA, default_tip),
|
| 248 |
+
(NoCall(), ''), (CallA(), '(ci)'),
|
| 249 |
+
(CallB(), '(a, b, c)')):
|
| 250 |
+
with self.subTest(meth=meth, mtip=mtip):
|
| 251 |
+
self.assertEqual(get_spec(meth), mtip)
|
| 252 |
+
|
| 253 |
+
def test_metaclass_class(self): # Failure case for issue 38689.
|
| 254 |
+
class Type(type): # Type() requires 3 type args, returns class.
|
| 255 |
+
__class__ = property({}.__getitem__, {}.__setitem__)
|
| 256 |
+
class Object(metaclass=Type):
|
| 257 |
+
__slots__ = '__class__'
|
| 258 |
+
for meth, mtip in ((Type, get_spec(type)), (Object, default_tip),
|
| 259 |
+
(Object(), '')):
|
| 260 |
+
with self.subTest(meth=meth, mtip=mtip):
|
| 261 |
+
self.assertEqual(get_spec(meth), mtip)
|
| 262 |
+
|
| 263 |
+
def test_non_callables(self):
|
| 264 |
+
for obj in (0, 0.0, '0', b'0', [], {}):
|
| 265 |
+
with self.subTest(obj=obj):
|
| 266 |
+
self.assertEqual(get_spec(obj), '')
|
| 267 |
+
|
| 268 |
+
|
| 269 |
+
class Get_entityTest(unittest.TestCase):
|
| 270 |
+
def test_bad_entity(self):
|
| 271 |
+
self.assertIsNone(calltip.get_entity('1/0'))
|
| 272 |
+
def test_good_entity(self):
|
| 273 |
+
self.assertIs(calltip.get_entity('int'), int)
|
| 274 |
+
|
| 275 |
+
|
| 276 |
+
# Test the 9 Calltip methods.
|
| 277 |
+
# open_calltip is about half the code; the others are fairly trivial.
|
| 278 |
+
# The default mocks are what are needed for open_calltip.
|
| 279 |
+
|
| 280 |
+
class mock_Shell:
|
| 281 |
+
"Return mock sufficient to pass to hyperparser."
|
| 282 |
+
def __init__(self, text):
|
| 283 |
+
text.tag_prevrange = Mock(return_value=None)
|
| 284 |
+
self.text = text
|
| 285 |
+
self.prompt_last_line = ">>> "
|
| 286 |
+
self.indentwidth = 4
|
| 287 |
+
self.tabwidth = 8
|
| 288 |
+
|
| 289 |
+
|
| 290 |
+
class mock_TipWindow:
|
| 291 |
+
def __init__(self):
|
| 292 |
+
pass
|
| 293 |
+
|
| 294 |
+
def showtip(self, text, parenleft, parenright):
|
| 295 |
+
self.args = parenleft, parenright
|
| 296 |
+
self.parenline, self.parencol = map(int, parenleft.split('.'))
|
| 297 |
+
|
| 298 |
+
|
| 299 |
+
class WrappedCalltip(calltip.Calltip):
|
| 300 |
+
def _make_tk_calltip_window(self):
|
| 301 |
+
return mock_TipWindow()
|
| 302 |
+
|
| 303 |
+
def remove_calltip_window(self, event=None):
|
| 304 |
+
if self.active_calltip: # Setup to None.
|
| 305 |
+
self.active_calltip = None
|
| 306 |
+
self.tips_removed += 1 # Setup to 0.
|
| 307 |
+
|
| 308 |
+
def fetch_tip(self, expression):
|
| 309 |
+
return 'tip'
|
| 310 |
+
|
| 311 |
+
|
| 312 |
+
class CalltipTest(unittest.TestCase):
|
| 313 |
+
|
| 314 |
+
@classmethod
|
| 315 |
+
def setUpClass(cls):
|
| 316 |
+
cls.text = Text()
|
| 317 |
+
cls.ct = WrappedCalltip(mock_Shell(cls.text))
|
| 318 |
+
|
| 319 |
+
def setUp(self):
|
| 320 |
+
self.text.delete('1.0', 'end') # Insert and call
|
| 321 |
+
self.ct.active_calltip = None
|
| 322 |
+
# Test .active_calltip, +args
|
| 323 |
+
self.ct.tips_removed = 0
|
| 324 |
+
|
| 325 |
+
def open_close(self, testfunc):
|
| 326 |
+
# Open-close template with testfunc called in between.
|
| 327 |
+
opentip = self.ct.open_calltip
|
| 328 |
+
self.text.insert(1.0, 'f(')
|
| 329 |
+
opentip(False)
|
| 330 |
+
self.tip = self.ct.active_calltip
|
| 331 |
+
testfunc(self) ###
|
| 332 |
+
self.text.insert('insert', ')')
|
| 333 |
+
opentip(False)
|
| 334 |
+
self.assertIsNone(self.ct.active_calltip, None)
|
| 335 |
+
|
| 336 |
+
def test_open_close(self):
|
| 337 |
+
def args(self):
|
| 338 |
+
self.assertEqual(self.tip.args, ('1.1', '1.end'))
|
| 339 |
+
self.open_close(args)
|
| 340 |
+
|
| 341 |
+
def test_repeated_force(self):
|
| 342 |
+
def force(self):
|
| 343 |
+
for char in 'abc':
|
| 344 |
+
self.text.insert('insert', 'a')
|
| 345 |
+
self.ct.open_calltip(True)
|
| 346 |
+
self.ct.open_calltip(True)
|
| 347 |
+
self.assertIs(self.ct.active_calltip, self.tip)
|
| 348 |
+
self.open_close(force)
|
| 349 |
+
|
| 350 |
+
def test_repeated_parens(self):
|
| 351 |
+
def parens(self):
|
| 352 |
+
for context in "a", "'":
|
| 353 |
+
with self.subTest(context=context):
|
| 354 |
+
self.text.insert('insert', context)
|
| 355 |
+
for char in '(()())':
|
| 356 |
+
self.text.insert('insert', char)
|
| 357 |
+
self.assertIs(self.ct.active_calltip, self.tip)
|
| 358 |
+
self.text.insert('insert', "'")
|
| 359 |
+
self.open_close(parens)
|
| 360 |
+
|
| 361 |
+
def test_comment_parens(self):
|
| 362 |
+
def comment(self):
|
| 363 |
+
self.text.insert('insert', "# ")
|
| 364 |
+
for char in '(()())':
|
| 365 |
+
self.text.insert('insert', char)
|
| 366 |
+
self.assertIs(self.ct.active_calltip, self.tip)
|
| 367 |
+
self.text.insert('insert', "\n")
|
| 368 |
+
self.open_close(comment)
|
| 369 |
+
|
| 370 |
+
|
| 371 |
+
if __name__ == '__main__':
|
| 372 |
+
unittest.main(verbosity=2)
|
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/test_calltip_w.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"Test calltip_w, coverage 18%."
|
| 2 |
+
|
| 3 |
+
from idlelib import calltip_w
|
| 4 |
+
import unittest
|
| 5 |
+
from test.support import requires
|
| 6 |
+
from tkinter import Tk, Text
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class CallTipWindowTest(unittest.TestCase):
|
| 10 |
+
|
| 11 |
+
@classmethod
|
| 12 |
+
def setUpClass(cls):
|
| 13 |
+
requires('gui')
|
| 14 |
+
cls.root = Tk()
|
| 15 |
+
cls.root.withdraw()
|
| 16 |
+
cls.text = Text(cls.root)
|
| 17 |
+
cls.calltip = calltip_w.CalltipWindow(cls.text)
|
| 18 |
+
|
| 19 |
+
@classmethod
|
| 20 |
+
def tearDownClass(cls):
|
| 21 |
+
cls.root.update_idletasks()
|
| 22 |
+
cls.root.destroy()
|
| 23 |
+
del cls.text, cls.root
|
| 24 |
+
|
| 25 |
+
def test_init(self):
|
| 26 |
+
self.assertEqual(self.calltip.anchor_widget, self.text)
|
| 27 |
+
|
| 28 |
+
if __name__ == '__main__':
|
| 29 |
+
unittest.main(verbosity=2)
|
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/test_codecontext.py
ADDED
|
@@ -0,0 +1,455 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"Test codecontext, coverage 100%"
|
| 2 |
+
|
| 3 |
+
from idlelib import codecontext
|
| 4 |
+
import unittest
|
| 5 |
+
import unittest.mock
|
| 6 |
+
from test.support import requires
|
| 7 |
+
from tkinter import NSEW, Tk, Frame, Text, TclError
|
| 8 |
+
|
| 9 |
+
from unittest import mock
|
| 10 |
+
import re
|
| 11 |
+
from idlelib import config
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
usercfg = codecontext.idleConf.userCfg
|
| 15 |
+
testcfg = {
|
| 16 |
+
'main': config.IdleUserConfParser(''),
|
| 17 |
+
'highlight': config.IdleUserConfParser(''),
|
| 18 |
+
'keys': config.IdleUserConfParser(''),
|
| 19 |
+
'extensions': config.IdleUserConfParser(''),
|
| 20 |
+
}
|
| 21 |
+
code_sample = """\
|
| 22 |
+
|
| 23 |
+
class C1:
|
| 24 |
+
# Class comment.
|
| 25 |
+
def __init__(self, a, b):
|
| 26 |
+
self.a = a
|
| 27 |
+
self.b = b
|
| 28 |
+
def compare(self):
|
| 29 |
+
if a > b:
|
| 30 |
+
return a
|
| 31 |
+
elif a < b:
|
| 32 |
+
return b
|
| 33 |
+
else:
|
| 34 |
+
return None
|
| 35 |
+
"""
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
class DummyEditwin:
|
| 39 |
+
def __init__(self, root, frame, text):
|
| 40 |
+
self.root = root
|
| 41 |
+
self.top = root
|
| 42 |
+
self.text_frame = frame
|
| 43 |
+
self.text = text
|
| 44 |
+
self.label = ''
|
| 45 |
+
|
| 46 |
+
def getlineno(self, index):
|
| 47 |
+
return int(float(self.text.index(index)))
|
| 48 |
+
|
| 49 |
+
def update_menu_label(self, **kwargs):
|
| 50 |
+
self.label = kwargs['label']
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
class CodeContextTest(unittest.TestCase):
|
| 54 |
+
|
| 55 |
+
@classmethod
|
| 56 |
+
def setUpClass(cls):
|
| 57 |
+
requires('gui')
|
| 58 |
+
root = cls.root = Tk()
|
| 59 |
+
root.withdraw()
|
| 60 |
+
frame = cls.frame = Frame(root)
|
| 61 |
+
text = cls.text = Text(frame)
|
| 62 |
+
text.insert('1.0', code_sample)
|
| 63 |
+
# Need to pack for creation of code context text widget.
|
| 64 |
+
frame.pack(side='left', fill='both', expand=1)
|
| 65 |
+
text.grid(row=1, column=1, sticky=NSEW)
|
| 66 |
+
cls.editor = DummyEditwin(root, frame, text)
|
| 67 |
+
codecontext.idleConf.userCfg = testcfg
|
| 68 |
+
|
| 69 |
+
@classmethod
|
| 70 |
+
def tearDownClass(cls):
|
| 71 |
+
codecontext.idleConf.userCfg = usercfg
|
| 72 |
+
cls.editor.text.delete('1.0', 'end')
|
| 73 |
+
del cls.editor, cls.frame, cls.text
|
| 74 |
+
cls.root.update_idletasks()
|
| 75 |
+
cls.root.destroy()
|
| 76 |
+
del cls.root
|
| 77 |
+
|
| 78 |
+
def setUp(self):
|
| 79 |
+
self.text.yview(0)
|
| 80 |
+
self.text['font'] = 'TkFixedFont'
|
| 81 |
+
self.cc = codecontext.CodeContext(self.editor)
|
| 82 |
+
|
| 83 |
+
self.highlight_cfg = {"background": '#abcdef',
|
| 84 |
+
"foreground": '#123456'}
|
| 85 |
+
orig_idleConf_GetHighlight = codecontext.idleConf.GetHighlight
|
| 86 |
+
def mock_idleconf_GetHighlight(theme, element):
|
| 87 |
+
if element == 'context':
|
| 88 |
+
return self.highlight_cfg
|
| 89 |
+
return orig_idleConf_GetHighlight(theme, element)
|
| 90 |
+
GetHighlight_patcher = unittest.mock.patch.object(
|
| 91 |
+
codecontext.idleConf, 'GetHighlight', mock_idleconf_GetHighlight)
|
| 92 |
+
GetHighlight_patcher.start()
|
| 93 |
+
self.addCleanup(GetHighlight_patcher.stop)
|
| 94 |
+
|
| 95 |
+
self.font_override = 'TkFixedFont'
|
| 96 |
+
def mock_idleconf_GetFont(root, configType, section):
|
| 97 |
+
return self.font_override
|
| 98 |
+
GetFont_patcher = unittest.mock.patch.object(
|
| 99 |
+
codecontext.idleConf, 'GetFont', mock_idleconf_GetFont)
|
| 100 |
+
GetFont_patcher.start()
|
| 101 |
+
self.addCleanup(GetFont_patcher.stop)
|
| 102 |
+
|
| 103 |
+
def tearDown(self):
|
| 104 |
+
if self.cc.context:
|
| 105 |
+
self.cc.context.destroy()
|
| 106 |
+
# Explicitly call __del__ to remove scheduled scripts.
|
| 107 |
+
self.cc.__del__()
|
| 108 |
+
del self.cc.context, self.cc
|
| 109 |
+
|
| 110 |
+
def test_init(self):
|
| 111 |
+
eq = self.assertEqual
|
| 112 |
+
ed = self.editor
|
| 113 |
+
cc = self.cc
|
| 114 |
+
|
| 115 |
+
eq(cc.editwin, ed)
|
| 116 |
+
eq(cc.text, ed.text)
|
| 117 |
+
eq(cc.text['font'], ed.text['font'])
|
| 118 |
+
self.assertIsNone(cc.context)
|
| 119 |
+
eq(cc.info, [(0, -1, '', False)])
|
| 120 |
+
eq(cc.topvisible, 1)
|
| 121 |
+
self.assertIsNone(self.cc.t1)
|
| 122 |
+
|
| 123 |
+
def test_del(self):
|
| 124 |
+
self.cc.__del__()
|
| 125 |
+
|
| 126 |
+
def test_del_with_timer(self):
|
| 127 |
+
timer = self.cc.t1 = self.text.after(10000, lambda: None)
|
| 128 |
+
self.cc.__del__()
|
| 129 |
+
with self.assertRaises(TclError) as cm:
|
| 130 |
+
self.root.tk.call('after', 'info', timer)
|
| 131 |
+
self.assertIn("doesn't exist", str(cm.exception))
|
| 132 |
+
|
| 133 |
+
def test_reload(self):
|
| 134 |
+
codecontext.CodeContext.reload()
|
| 135 |
+
self.assertEqual(self.cc.context_depth, 15)
|
| 136 |
+
|
| 137 |
+
def test_toggle_code_context_event(self):
|
| 138 |
+
eq = self.assertEqual
|
| 139 |
+
cc = self.cc
|
| 140 |
+
toggle = cc.toggle_code_context_event
|
| 141 |
+
|
| 142 |
+
# Make sure code context is off.
|
| 143 |
+
if cc.context:
|
| 144 |
+
toggle()
|
| 145 |
+
|
| 146 |
+
# Toggle on.
|
| 147 |
+
toggle()
|
| 148 |
+
self.assertIsNotNone(cc.context)
|
| 149 |
+
eq(cc.context['font'], self.text['font'])
|
| 150 |
+
eq(cc.context['fg'], self.highlight_cfg['foreground'])
|
| 151 |
+
eq(cc.context['bg'], self.highlight_cfg['background'])
|
| 152 |
+
eq(cc.context.get('1.0', 'end-1c'), '')
|
| 153 |
+
eq(cc.editwin.label, 'Hide Code Context')
|
| 154 |
+
eq(self.root.tk.call('after', 'info', self.cc.t1)[1], 'timer')
|
| 155 |
+
|
| 156 |
+
# Toggle off.
|
| 157 |
+
toggle()
|
| 158 |
+
self.assertIsNone(cc.context)
|
| 159 |
+
eq(cc.editwin.label, 'Show Code Context')
|
| 160 |
+
self.assertIsNone(self.cc.t1)
|
| 161 |
+
|
| 162 |
+
# Scroll down and toggle back on.
|
| 163 |
+
line11_context = '\n'.join(x[2] for x in cc.get_context(11)[0])
|
| 164 |
+
cc.text.yview(11)
|
| 165 |
+
toggle()
|
| 166 |
+
eq(cc.context.get('1.0', 'end-1c'), line11_context)
|
| 167 |
+
|
| 168 |
+
# Toggle off and on again.
|
| 169 |
+
toggle()
|
| 170 |
+
toggle()
|
| 171 |
+
eq(cc.context.get('1.0', 'end-1c'), line11_context)
|
| 172 |
+
|
| 173 |
+
def test_get_context(self):
|
| 174 |
+
eq = self.assertEqual
|
| 175 |
+
gc = self.cc.get_context
|
| 176 |
+
|
| 177 |
+
# stopline must be greater than 0.
|
| 178 |
+
with self.assertRaises(AssertionError):
|
| 179 |
+
gc(1, stopline=0)
|
| 180 |
+
|
| 181 |
+
eq(gc(3), ([(2, 0, 'class C1:', 'class')], 0))
|
| 182 |
+
|
| 183 |
+
# Don't return comment.
|
| 184 |
+
eq(gc(4), ([(2, 0, 'class C1:', 'class')], 0))
|
| 185 |
+
|
| 186 |
+
# Two indentation levels and no comment.
|
| 187 |
+
eq(gc(5), ([(2, 0, 'class C1:', 'class'),
|
| 188 |
+
(4, 4, ' def __init__(self, a, b):', 'def')], 0))
|
| 189 |
+
|
| 190 |
+
# Only one 'def' is returned, not both at the same indent level.
|
| 191 |
+
eq(gc(10), ([(2, 0, 'class C1:', 'class'),
|
| 192 |
+
(7, 4, ' def compare(self):', 'def'),
|
| 193 |
+
(8, 8, ' if a > b:', 'if')], 0))
|
| 194 |
+
|
| 195 |
+
# With 'elif', also show the 'if' even though it's at the same level.
|
| 196 |
+
eq(gc(11), ([(2, 0, 'class C1:', 'class'),
|
| 197 |
+
(7, 4, ' def compare(self):', 'def'),
|
| 198 |
+
(8, 8, ' if a > b:', 'if'),
|
| 199 |
+
(10, 8, ' elif a < b:', 'elif')], 0))
|
| 200 |
+
|
| 201 |
+
# Set stop_line to not go back to first line in source code.
|
| 202 |
+
# Return includes stop_line.
|
| 203 |
+
eq(gc(11, stopline=2), ([(2, 0, 'class C1:', 'class'),
|
| 204 |
+
(7, 4, ' def compare(self):', 'def'),
|
| 205 |
+
(8, 8, ' if a > b:', 'if'),
|
| 206 |
+
(10, 8, ' elif a < b:', 'elif')], 0))
|
| 207 |
+
eq(gc(11, stopline=3), ([(7, 4, ' def compare(self):', 'def'),
|
| 208 |
+
(8, 8, ' if a > b:', 'if'),
|
| 209 |
+
(10, 8, ' elif a < b:', 'elif')], 4))
|
| 210 |
+
eq(gc(11, stopline=8), ([(8, 8, ' if a > b:', 'if'),
|
| 211 |
+
(10, 8, ' elif a < b:', 'elif')], 8))
|
| 212 |
+
|
| 213 |
+
# Set stop_indent to test indent level to stop at.
|
| 214 |
+
eq(gc(11, stopindent=4), ([(7, 4, ' def compare(self):', 'def'),
|
| 215 |
+
(8, 8, ' if a > b:', 'if'),
|
| 216 |
+
(10, 8, ' elif a < b:', 'elif')], 4))
|
| 217 |
+
# Check that the 'if' is included.
|
| 218 |
+
eq(gc(11, stopindent=8), ([(8, 8, ' if a > b:', 'if'),
|
| 219 |
+
(10, 8, ' elif a < b:', 'elif')], 8))
|
| 220 |
+
|
| 221 |
+
def test_update_code_context(self):
|
| 222 |
+
eq = self.assertEqual
|
| 223 |
+
cc = self.cc
|
| 224 |
+
# Ensure code context is active.
|
| 225 |
+
if not cc.context:
|
| 226 |
+
cc.toggle_code_context_event()
|
| 227 |
+
|
| 228 |
+
# Invoke update_code_context without scrolling - nothing happens.
|
| 229 |
+
self.assertIsNone(cc.update_code_context())
|
| 230 |
+
eq(cc.info, [(0, -1, '', False)])
|
| 231 |
+
eq(cc.topvisible, 1)
|
| 232 |
+
|
| 233 |
+
# Scroll down to line 1.
|
| 234 |
+
cc.text.yview(1)
|
| 235 |
+
cc.update_code_context()
|
| 236 |
+
eq(cc.info, [(0, -1, '', False)])
|
| 237 |
+
eq(cc.topvisible, 2)
|
| 238 |
+
eq(cc.context.get('1.0', 'end-1c'), '')
|
| 239 |
+
|
| 240 |
+
# Scroll down to line 2.
|
| 241 |
+
cc.text.yview(2)
|
| 242 |
+
cc.update_code_context()
|
| 243 |
+
eq(cc.info, [(0, -1, '', False), (2, 0, 'class C1:', 'class')])
|
| 244 |
+
eq(cc.topvisible, 3)
|
| 245 |
+
eq(cc.context.get('1.0', 'end-1c'), 'class C1:')
|
| 246 |
+
|
| 247 |
+
# Scroll down to line 3. Since it's a comment, nothing changes.
|
| 248 |
+
cc.text.yview(3)
|
| 249 |
+
cc.update_code_context()
|
| 250 |
+
eq(cc.info, [(0, -1, '', False), (2, 0, 'class C1:', 'class')])
|
| 251 |
+
eq(cc.topvisible, 4)
|
| 252 |
+
eq(cc.context.get('1.0', 'end-1c'), 'class C1:')
|
| 253 |
+
|
| 254 |
+
# Scroll down to line 4.
|
| 255 |
+
cc.text.yview(4)
|
| 256 |
+
cc.update_code_context()
|
| 257 |
+
eq(cc.info, [(0, -1, '', False),
|
| 258 |
+
(2, 0, 'class C1:', 'class'),
|
| 259 |
+
(4, 4, ' def __init__(self, a, b):', 'def')])
|
| 260 |
+
eq(cc.topvisible, 5)
|
| 261 |
+
eq(cc.context.get('1.0', 'end-1c'), 'class C1:\n'
|
| 262 |
+
' def __init__(self, a, b):')
|
| 263 |
+
|
| 264 |
+
# Scroll down to line 11. Last 'def' is removed.
|
| 265 |
+
cc.text.yview(11)
|
| 266 |
+
cc.update_code_context()
|
| 267 |
+
eq(cc.info, [(0, -1, '', False),
|
| 268 |
+
(2, 0, 'class C1:', 'class'),
|
| 269 |
+
(7, 4, ' def compare(self):', 'def'),
|
| 270 |
+
(8, 8, ' if a > b:', 'if'),
|
| 271 |
+
(10, 8, ' elif a < b:', 'elif')])
|
| 272 |
+
eq(cc.topvisible, 12)
|
| 273 |
+
eq(cc.context.get('1.0', 'end-1c'), 'class C1:\n'
|
| 274 |
+
' def compare(self):\n'
|
| 275 |
+
' if a > b:\n'
|
| 276 |
+
' elif a < b:')
|
| 277 |
+
|
| 278 |
+
# No scroll. No update, even though context_depth changed.
|
| 279 |
+
cc.update_code_context()
|
| 280 |
+
cc.context_depth = 1
|
| 281 |
+
eq(cc.info, [(0, -1, '', False),
|
| 282 |
+
(2, 0, 'class C1:', 'class'),
|
| 283 |
+
(7, 4, ' def compare(self):', 'def'),
|
| 284 |
+
(8, 8, ' if a > b:', 'if'),
|
| 285 |
+
(10, 8, ' elif a < b:', 'elif')])
|
| 286 |
+
eq(cc.topvisible, 12)
|
| 287 |
+
eq(cc.context.get('1.0', 'end-1c'), 'class C1:\n'
|
| 288 |
+
' def compare(self):\n'
|
| 289 |
+
' if a > b:\n'
|
| 290 |
+
' elif a < b:')
|
| 291 |
+
|
| 292 |
+
# Scroll up.
|
| 293 |
+
cc.text.yview(5)
|
| 294 |
+
cc.update_code_context()
|
| 295 |
+
eq(cc.info, [(0, -1, '', False),
|
| 296 |
+
(2, 0, 'class C1:', 'class'),
|
| 297 |
+
(4, 4, ' def __init__(self, a, b):', 'def')])
|
| 298 |
+
eq(cc.topvisible, 6)
|
| 299 |
+
# context_depth is 1.
|
| 300 |
+
eq(cc.context.get('1.0', 'end-1c'), ' def __init__(self, a, b):')
|
| 301 |
+
|
| 302 |
+
def test_jumptoline(self):
|
| 303 |
+
eq = self.assertEqual
|
| 304 |
+
cc = self.cc
|
| 305 |
+
jump = cc.jumptoline
|
| 306 |
+
|
| 307 |
+
if not cc.context:
|
| 308 |
+
cc.toggle_code_context_event()
|
| 309 |
+
|
| 310 |
+
# Empty context.
|
| 311 |
+
cc.text.yview('2.0')
|
| 312 |
+
cc.update_code_context()
|
| 313 |
+
eq(cc.topvisible, 2)
|
| 314 |
+
cc.context.mark_set('insert', '1.5')
|
| 315 |
+
jump()
|
| 316 |
+
eq(cc.topvisible, 1)
|
| 317 |
+
|
| 318 |
+
# 4 lines of context showing.
|
| 319 |
+
cc.text.yview('12.0')
|
| 320 |
+
cc.update_code_context()
|
| 321 |
+
eq(cc.topvisible, 12)
|
| 322 |
+
cc.context.mark_set('insert', '3.0')
|
| 323 |
+
jump()
|
| 324 |
+
eq(cc.topvisible, 8)
|
| 325 |
+
|
| 326 |
+
# More context lines than limit.
|
| 327 |
+
cc.context_depth = 2
|
| 328 |
+
cc.text.yview('12.0')
|
| 329 |
+
cc.update_code_context()
|
| 330 |
+
eq(cc.topvisible, 12)
|
| 331 |
+
cc.context.mark_set('insert', '1.0')
|
| 332 |
+
jump()
|
| 333 |
+
eq(cc.topvisible, 8)
|
| 334 |
+
|
| 335 |
+
# Context selection stops jump.
|
| 336 |
+
cc.text.yview('5.0')
|
| 337 |
+
cc.update_code_context()
|
| 338 |
+
cc.context.tag_add('sel', '1.0', '2.0')
|
| 339 |
+
cc.context.mark_set('insert', '1.0')
|
| 340 |
+
jump() # Without selection, to line 2.
|
| 341 |
+
eq(cc.topvisible, 5)
|
| 342 |
+
|
| 343 |
+
@mock.patch.object(codecontext.CodeContext, 'update_code_context')
|
| 344 |
+
def test_timer_event(self, mock_update):
|
| 345 |
+
# Ensure code context is not active.
|
| 346 |
+
if self.cc.context:
|
| 347 |
+
self.cc.toggle_code_context_event()
|
| 348 |
+
self.cc.timer_event()
|
| 349 |
+
mock_update.assert_not_called()
|
| 350 |
+
|
| 351 |
+
# Activate code context.
|
| 352 |
+
self.cc.toggle_code_context_event()
|
| 353 |
+
self.cc.timer_event()
|
| 354 |
+
mock_update.assert_called()
|
| 355 |
+
|
| 356 |
+
def test_font(self):
|
| 357 |
+
eq = self.assertEqual
|
| 358 |
+
cc = self.cc
|
| 359 |
+
|
| 360 |
+
orig_font = cc.text['font']
|
| 361 |
+
test_font = 'TkTextFont'
|
| 362 |
+
self.assertNotEqual(orig_font, test_font)
|
| 363 |
+
|
| 364 |
+
# Ensure code context is not active.
|
| 365 |
+
if cc.context is not None:
|
| 366 |
+
cc.toggle_code_context_event()
|
| 367 |
+
|
| 368 |
+
self.font_override = test_font
|
| 369 |
+
# Nothing breaks or changes with inactive code context.
|
| 370 |
+
cc.update_font()
|
| 371 |
+
|
| 372 |
+
# Activate code context, previous font change is immediately effective.
|
| 373 |
+
cc.toggle_code_context_event()
|
| 374 |
+
eq(cc.context['font'], test_font)
|
| 375 |
+
|
| 376 |
+
# Call the font update, change is picked up.
|
| 377 |
+
self.font_override = orig_font
|
| 378 |
+
cc.update_font()
|
| 379 |
+
eq(cc.context['font'], orig_font)
|
| 380 |
+
|
| 381 |
+
def test_highlight_colors(self):
|
| 382 |
+
eq = self.assertEqual
|
| 383 |
+
cc = self.cc
|
| 384 |
+
|
| 385 |
+
orig_colors = dict(self.highlight_cfg)
|
| 386 |
+
test_colors = {'background': '#222222', 'foreground': '#ffff00'}
|
| 387 |
+
|
| 388 |
+
def assert_colors_are_equal(colors):
|
| 389 |
+
eq(cc.context['background'], colors['background'])
|
| 390 |
+
eq(cc.context['foreground'], colors['foreground'])
|
| 391 |
+
|
| 392 |
+
# Ensure code context is not active.
|
| 393 |
+
if cc.context:
|
| 394 |
+
cc.toggle_code_context_event()
|
| 395 |
+
|
| 396 |
+
self.highlight_cfg = test_colors
|
| 397 |
+
# Nothing breaks with inactive code context.
|
| 398 |
+
cc.update_highlight_colors()
|
| 399 |
+
|
| 400 |
+
# Activate code context, previous colors change is immediately effective.
|
| 401 |
+
cc.toggle_code_context_event()
|
| 402 |
+
assert_colors_are_equal(test_colors)
|
| 403 |
+
|
| 404 |
+
# Call colors update with no change to the configured colors.
|
| 405 |
+
cc.update_highlight_colors()
|
| 406 |
+
assert_colors_are_equal(test_colors)
|
| 407 |
+
|
| 408 |
+
# Call the colors update with code context active, change is picked up.
|
| 409 |
+
self.highlight_cfg = orig_colors
|
| 410 |
+
cc.update_highlight_colors()
|
| 411 |
+
assert_colors_are_equal(orig_colors)
|
| 412 |
+
|
| 413 |
+
|
| 414 |
+
class HelperFunctionText(unittest.TestCase):
|
| 415 |
+
|
| 416 |
+
def test_get_spaces_firstword(self):
|
| 417 |
+
get = codecontext.get_spaces_firstword
|
| 418 |
+
test_lines = (
|
| 419 |
+
(' first word', (' ', 'first')),
|
| 420 |
+
('\tfirst word', ('\t', 'first')),
|
| 421 |
+
(' \u19D4\u19D2: ', (' ', '\u19D4\u19D2')),
|
| 422 |
+
('no spaces', ('', 'no')),
|
| 423 |
+
('', ('', '')),
|
| 424 |
+
('# TEST COMMENT', ('', '')),
|
| 425 |
+
(' (continuation)', (' ', ''))
|
| 426 |
+
)
|
| 427 |
+
for line, expected_output in test_lines:
|
| 428 |
+
self.assertEqual(get(line), expected_output)
|
| 429 |
+
|
| 430 |
+
# Send the pattern in the call.
|
| 431 |
+
self.assertEqual(get(' (continuation)',
|
| 432 |
+
c=re.compile(r'^(\s*)([^\s]*)')),
|
| 433 |
+
(' ', '(continuation)'))
|
| 434 |
+
|
| 435 |
+
def test_get_line_info(self):
|
| 436 |
+
eq = self.assertEqual
|
| 437 |
+
gli = codecontext.get_line_info
|
| 438 |
+
lines = code_sample.splitlines()
|
| 439 |
+
|
| 440 |
+
# Line 1 is not a BLOCKOPENER.
|
| 441 |
+
eq(gli(lines[0]), (codecontext.INFINITY, '', False))
|
| 442 |
+
# Line 2 is a BLOCKOPENER without an indent.
|
| 443 |
+
eq(gli(lines[1]), (0, 'class C1:', 'class'))
|
| 444 |
+
# Line 3 is not a BLOCKOPENER and does not return the indent level.
|
| 445 |
+
eq(gli(lines[2]), (codecontext.INFINITY, ' # Class comment.', False))
|
| 446 |
+
# Line 4 is a BLOCKOPENER and is indented.
|
| 447 |
+
eq(gli(lines[3]), (4, ' def __init__(self, a, b):', 'def'))
|
| 448 |
+
# Line 8 is a different BLOCKOPENER and is indented.
|
| 449 |
+
eq(gli(lines[7]), (8, ' if a > b:', 'if'))
|
| 450 |
+
# Test tab.
|
| 451 |
+
eq(gli('\tif a == b:'), (1, '\tif a == b:', 'if'))
|
| 452 |
+
|
| 453 |
+
|
| 454 |
+
if __name__ == '__main__':
|
| 455 |
+
unittest.main(verbosity=2)
|
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/test_colorizer.py
ADDED
|
@@ -0,0 +1,622 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"Test colorizer, coverage 99%."
|
| 2 |
+
from idlelib import colorizer
|
| 3 |
+
from test.support import requires
|
| 4 |
+
import unittest
|
| 5 |
+
from unittest import mock
|
| 6 |
+
from idlelib.idle_test.tkinter_testing_utils import run_in_tk_mainloop
|
| 7 |
+
|
| 8 |
+
from functools import partial
|
| 9 |
+
import textwrap
|
| 10 |
+
from tkinter import Tk, Text
|
| 11 |
+
from idlelib import config
|
| 12 |
+
from idlelib.percolator import Percolator
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
usercfg = colorizer.idleConf.userCfg
|
| 16 |
+
testcfg = {
|
| 17 |
+
'main': config.IdleUserConfParser(''),
|
| 18 |
+
'highlight': config.IdleUserConfParser(''),
|
| 19 |
+
'keys': config.IdleUserConfParser(''),
|
| 20 |
+
'extensions': config.IdleUserConfParser(''),
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
source = textwrap.dedent("""\
|
| 24 |
+
if True: int ('1') # keyword, builtin, string, comment
|
| 25 |
+
elif False: print(0) # 'string' in comment
|
| 26 |
+
else: float(None) # if in comment
|
| 27 |
+
if iF + If + IF: 'keyword matching must respect case'
|
| 28 |
+
if'': x or'' # valid keyword-string no-space combinations
|
| 29 |
+
async def f(): await g()
|
| 30 |
+
# Strings should be entirely colored, including quotes.
|
| 31 |
+
'x', '''x''', "x", \"""x\"""
|
| 32 |
+
'abc\\
|
| 33 |
+
def'
|
| 34 |
+
'''abc\\
|
| 35 |
+
def'''
|
| 36 |
+
# All valid prefixes for unicode and byte strings should be colored.
|
| 37 |
+
r'x', u'x', R'x', U'x', f'x', F'x'
|
| 38 |
+
fr'x', Fr'x', fR'x', FR'x', rf'x', rF'x', Rf'x', RF'x'
|
| 39 |
+
b'x',B'x', br'x',Br'x',bR'x',BR'x', rb'x', rB'x',Rb'x',RB'x'
|
| 40 |
+
# Invalid combinations of legal characters should be half colored.
|
| 41 |
+
ur'x', ru'x', uf'x', fu'x', UR'x', ufr'x', rfu'x', xf'x', fx'x'
|
| 42 |
+
match point:
|
| 43 |
+
case (x, 0) as _:
|
| 44 |
+
print(f"X={x}")
|
| 45 |
+
case [_, [_], "_",
|
| 46 |
+
_]:
|
| 47 |
+
pass
|
| 48 |
+
case _ if ("a" if _ else set()): pass
|
| 49 |
+
case _:
|
| 50 |
+
raise ValueError("Not a point _")
|
| 51 |
+
'''
|
| 52 |
+
case _:'''
|
| 53 |
+
"match x:"
|
| 54 |
+
""")
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def setUpModule():
|
| 58 |
+
colorizer.idleConf.userCfg = testcfg
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def tearDownModule():
|
| 62 |
+
colorizer.idleConf.userCfg = usercfg
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
class FunctionTest(unittest.TestCase):
|
| 66 |
+
|
| 67 |
+
def test_any(self):
|
| 68 |
+
self.assertEqual(colorizer.any('test', ('a', 'b', 'cd')),
|
| 69 |
+
'(?P<test>a|b|cd)')
|
| 70 |
+
|
| 71 |
+
def test_make_pat(self):
|
| 72 |
+
# Tested in more detail by testing prog.
|
| 73 |
+
self.assertTrue(colorizer.make_pat())
|
| 74 |
+
|
| 75 |
+
def test_prog(self):
|
| 76 |
+
prog = colorizer.prog
|
| 77 |
+
eq = self.assertEqual
|
| 78 |
+
line = 'def f():\n print("hello")\n'
|
| 79 |
+
m = prog.search(line)
|
| 80 |
+
eq(m.groupdict()['KEYWORD'], 'def')
|
| 81 |
+
m = prog.search(line, m.end())
|
| 82 |
+
eq(m.groupdict()['SYNC'], '\n')
|
| 83 |
+
m = prog.search(line, m.end())
|
| 84 |
+
eq(m.groupdict()['BUILTIN'], 'print')
|
| 85 |
+
m = prog.search(line, m.end())
|
| 86 |
+
eq(m.groupdict()['STRING'], '"hello"')
|
| 87 |
+
m = prog.search(line, m.end())
|
| 88 |
+
eq(m.groupdict()['SYNC'], '\n')
|
| 89 |
+
|
| 90 |
+
def test_idprog(self):
|
| 91 |
+
idprog = colorizer.idprog
|
| 92 |
+
m = idprog.match('nospace')
|
| 93 |
+
self.assertIsNone(m)
|
| 94 |
+
m = idprog.match(' space')
|
| 95 |
+
self.assertEqual(m.group(0), ' space')
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
class ColorConfigTest(unittest.TestCase):
|
| 99 |
+
|
| 100 |
+
@classmethod
|
| 101 |
+
def setUpClass(cls):
|
| 102 |
+
requires('gui')
|
| 103 |
+
root = cls.root = Tk()
|
| 104 |
+
root.withdraw()
|
| 105 |
+
cls.text = Text(root)
|
| 106 |
+
|
| 107 |
+
@classmethod
|
| 108 |
+
def tearDownClass(cls):
|
| 109 |
+
del cls.text
|
| 110 |
+
cls.root.update_idletasks()
|
| 111 |
+
cls.root.destroy()
|
| 112 |
+
del cls.root
|
| 113 |
+
|
| 114 |
+
def test_color_config(self):
|
| 115 |
+
text = self.text
|
| 116 |
+
eq = self.assertEqual
|
| 117 |
+
colorizer.color_config(text)
|
| 118 |
+
# Uses IDLE Classic theme as default.
|
| 119 |
+
eq(text['background'], '#ffffff')
|
| 120 |
+
eq(text['foreground'], '#000000')
|
| 121 |
+
eq(text['selectbackground'], 'gray')
|
| 122 |
+
eq(text['selectforeground'], '#000000')
|
| 123 |
+
eq(text['insertbackground'], 'black')
|
| 124 |
+
eq(text['inactiveselectbackground'], 'gray')
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
class ColorDelegatorInstantiationTest(unittest.TestCase):
|
| 128 |
+
|
| 129 |
+
@classmethod
|
| 130 |
+
def setUpClass(cls):
|
| 131 |
+
requires('gui')
|
| 132 |
+
root = cls.root = Tk()
|
| 133 |
+
root.withdraw()
|
| 134 |
+
cls.text = Text(root)
|
| 135 |
+
|
| 136 |
+
@classmethod
|
| 137 |
+
def tearDownClass(cls):
|
| 138 |
+
del cls.text
|
| 139 |
+
cls.root.update_idletasks()
|
| 140 |
+
cls.root.destroy()
|
| 141 |
+
del cls.root
|
| 142 |
+
|
| 143 |
+
def setUp(self):
|
| 144 |
+
self.color = colorizer.ColorDelegator()
|
| 145 |
+
|
| 146 |
+
def tearDown(self):
|
| 147 |
+
self.color.close()
|
| 148 |
+
self.text.delete('1.0', 'end')
|
| 149 |
+
self.color.resetcache()
|
| 150 |
+
del self.color
|
| 151 |
+
|
| 152 |
+
def test_init(self):
|
| 153 |
+
color = self.color
|
| 154 |
+
self.assertIsInstance(color, colorizer.ColorDelegator)
|
| 155 |
+
|
| 156 |
+
def test_init_state(self):
|
| 157 |
+
# init_state() is called during the instantiation of
|
| 158 |
+
# ColorDelegator in setUp().
|
| 159 |
+
color = self.color
|
| 160 |
+
self.assertIsNone(color.after_id)
|
| 161 |
+
self.assertTrue(color.allow_colorizing)
|
| 162 |
+
self.assertFalse(color.colorizing)
|
| 163 |
+
self.assertFalse(color.stop_colorizing)
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
class ColorDelegatorTest(unittest.TestCase):
|
| 167 |
+
|
| 168 |
+
@classmethod
|
| 169 |
+
def setUpClass(cls):
|
| 170 |
+
requires('gui')
|
| 171 |
+
root = cls.root = Tk()
|
| 172 |
+
root.withdraw()
|
| 173 |
+
text = cls.text = Text(root)
|
| 174 |
+
cls.percolator = Percolator(text)
|
| 175 |
+
# Delegator stack = [Delegator(text)]
|
| 176 |
+
|
| 177 |
+
@classmethod
|
| 178 |
+
def tearDownClass(cls):
|
| 179 |
+
cls.percolator.close()
|
| 180 |
+
del cls.percolator, cls.text
|
| 181 |
+
cls.root.update_idletasks()
|
| 182 |
+
cls.root.destroy()
|
| 183 |
+
del cls.root
|
| 184 |
+
|
| 185 |
+
def setUp(self):
|
| 186 |
+
self.color = colorizer.ColorDelegator()
|
| 187 |
+
self.percolator.insertfilter(self.color)
|
| 188 |
+
# Calls color.setdelegate(Delegator(text)).
|
| 189 |
+
|
| 190 |
+
def tearDown(self):
|
| 191 |
+
self.color.close()
|
| 192 |
+
self.percolator.removefilter(self.color)
|
| 193 |
+
self.text.delete('1.0', 'end')
|
| 194 |
+
self.color.resetcache()
|
| 195 |
+
del self.color
|
| 196 |
+
|
| 197 |
+
def test_setdelegate(self):
|
| 198 |
+
# Called in setUp when filter is attached to percolator.
|
| 199 |
+
color = self.color
|
| 200 |
+
self.assertIsInstance(color.delegate, colorizer.Delegator)
|
| 201 |
+
# It is too late to mock notify_range, so test side effect.
|
| 202 |
+
self.assertEqual(self.root.tk.call(
|
| 203 |
+
'after', 'info', color.after_id)[1], 'timer')
|
| 204 |
+
|
| 205 |
+
def test_LoadTagDefs(self):
|
| 206 |
+
highlight = partial(config.idleConf.GetHighlight, theme='IDLE Classic')
|
| 207 |
+
for tag, colors in self.color.tagdefs.items():
|
| 208 |
+
with self.subTest(tag=tag):
|
| 209 |
+
self.assertIn('background', colors)
|
| 210 |
+
self.assertIn('foreground', colors)
|
| 211 |
+
if tag not in ('SYNC', 'TODO'):
|
| 212 |
+
self.assertEqual(colors, highlight(element=tag.lower()))
|
| 213 |
+
|
| 214 |
+
def test_config_colors(self):
|
| 215 |
+
text = self.text
|
| 216 |
+
highlight = partial(config.idleConf.GetHighlight, theme='IDLE Classic')
|
| 217 |
+
for tag in self.color.tagdefs:
|
| 218 |
+
for plane in ('background', 'foreground'):
|
| 219 |
+
with self.subTest(tag=tag, plane=plane):
|
| 220 |
+
if tag in ('SYNC', 'TODO'):
|
| 221 |
+
self.assertEqual(text.tag_cget(tag, plane), '')
|
| 222 |
+
else:
|
| 223 |
+
self.assertEqual(text.tag_cget(tag, plane),
|
| 224 |
+
highlight(element=tag.lower())[plane])
|
| 225 |
+
# 'sel' is marked as the highest priority.
|
| 226 |
+
self.assertEqual(text.tag_names()[-1], 'sel')
|
| 227 |
+
|
| 228 |
+
@mock.patch.object(colorizer.ColorDelegator, 'notify_range')
|
| 229 |
+
def test_insert(self, mock_notify):
|
| 230 |
+
text = self.text
|
| 231 |
+
# Initial text.
|
| 232 |
+
text.insert('insert', 'foo')
|
| 233 |
+
self.assertEqual(text.get('1.0', 'end'), 'foo\n')
|
| 234 |
+
mock_notify.assert_called_with('1.0', '1.0+3c')
|
| 235 |
+
# Additional text.
|
| 236 |
+
text.insert('insert', 'barbaz')
|
| 237 |
+
self.assertEqual(text.get('1.0', 'end'), 'foobarbaz\n')
|
| 238 |
+
mock_notify.assert_called_with('1.3', '1.3+6c')
|
| 239 |
+
|
| 240 |
+
@mock.patch.object(colorizer.ColorDelegator, 'notify_range')
|
| 241 |
+
def test_delete(self, mock_notify):
|
| 242 |
+
text = self.text
|
| 243 |
+
# Initialize text.
|
| 244 |
+
text.insert('insert', 'abcdefghi')
|
| 245 |
+
self.assertEqual(text.get('1.0', 'end'), 'abcdefghi\n')
|
| 246 |
+
# Delete single character.
|
| 247 |
+
text.delete('1.7')
|
| 248 |
+
self.assertEqual(text.get('1.0', 'end'), 'abcdefgi\n')
|
| 249 |
+
mock_notify.assert_called_with('1.7')
|
| 250 |
+
# Delete multiple characters.
|
| 251 |
+
text.delete('1.3', '1.6')
|
| 252 |
+
self.assertEqual(text.get('1.0', 'end'), 'abcgi\n')
|
| 253 |
+
mock_notify.assert_called_with('1.3')
|
| 254 |
+
|
| 255 |
+
def test_notify_range(self):
|
| 256 |
+
text = self.text
|
| 257 |
+
color = self.color
|
| 258 |
+
eq = self.assertEqual
|
| 259 |
+
|
| 260 |
+
# Colorizing already scheduled.
|
| 261 |
+
save_id = color.after_id
|
| 262 |
+
eq(self.root.tk.call('after', 'info', save_id)[1], 'timer')
|
| 263 |
+
self.assertFalse(color.colorizing)
|
| 264 |
+
self.assertFalse(color.stop_colorizing)
|
| 265 |
+
self.assertTrue(color.allow_colorizing)
|
| 266 |
+
|
| 267 |
+
# Coloring scheduled and colorizing in progress.
|
| 268 |
+
color.colorizing = True
|
| 269 |
+
color.notify_range('1.0', 'end')
|
| 270 |
+
self.assertFalse(color.stop_colorizing)
|
| 271 |
+
eq(color.after_id, save_id)
|
| 272 |
+
|
| 273 |
+
# No colorizing scheduled and colorizing in progress.
|
| 274 |
+
text.after_cancel(save_id)
|
| 275 |
+
color.after_id = None
|
| 276 |
+
color.notify_range('1.0', '1.0+3c')
|
| 277 |
+
self.assertTrue(color.stop_colorizing)
|
| 278 |
+
self.assertIsNotNone(color.after_id)
|
| 279 |
+
eq(self.root.tk.call('after', 'info', color.after_id)[1], 'timer')
|
| 280 |
+
# New event scheduled.
|
| 281 |
+
self.assertNotEqual(color.after_id, save_id)
|
| 282 |
+
|
| 283 |
+
# No colorizing scheduled and colorizing off.
|
| 284 |
+
text.after_cancel(color.after_id)
|
| 285 |
+
color.after_id = None
|
| 286 |
+
color.allow_colorizing = False
|
| 287 |
+
color.notify_range('1.4', '1.4+10c')
|
| 288 |
+
# Nothing scheduled when colorizing is off.
|
| 289 |
+
self.assertIsNone(color.after_id)
|
| 290 |
+
|
| 291 |
+
def test_toggle_colorize_event(self):
|
| 292 |
+
color = self.color
|
| 293 |
+
eq = self.assertEqual
|
| 294 |
+
|
| 295 |
+
# Starts with colorizing allowed and scheduled.
|
| 296 |
+
self.assertFalse(color.colorizing)
|
| 297 |
+
self.assertFalse(color.stop_colorizing)
|
| 298 |
+
self.assertTrue(color.allow_colorizing)
|
| 299 |
+
eq(self.root.tk.call('after', 'info', color.after_id)[1], 'timer')
|
| 300 |
+
|
| 301 |
+
# Toggle colorizing off.
|
| 302 |
+
color.toggle_colorize_event()
|
| 303 |
+
self.assertIsNone(color.after_id)
|
| 304 |
+
self.assertFalse(color.colorizing)
|
| 305 |
+
self.assertFalse(color.stop_colorizing)
|
| 306 |
+
self.assertFalse(color.allow_colorizing)
|
| 307 |
+
|
| 308 |
+
# Toggle on while colorizing in progress (doesn't add timer).
|
| 309 |
+
color.colorizing = True
|
| 310 |
+
color.toggle_colorize_event()
|
| 311 |
+
self.assertIsNone(color.after_id)
|
| 312 |
+
self.assertTrue(color.colorizing)
|
| 313 |
+
self.assertFalse(color.stop_colorizing)
|
| 314 |
+
self.assertTrue(color.allow_colorizing)
|
| 315 |
+
|
| 316 |
+
# Toggle off while colorizing in progress.
|
| 317 |
+
color.toggle_colorize_event()
|
| 318 |
+
self.assertIsNone(color.after_id)
|
| 319 |
+
self.assertTrue(color.colorizing)
|
| 320 |
+
self.assertTrue(color.stop_colorizing)
|
| 321 |
+
self.assertFalse(color.allow_colorizing)
|
| 322 |
+
|
| 323 |
+
# Toggle on while colorizing not in progress.
|
| 324 |
+
color.colorizing = False
|
| 325 |
+
color.toggle_colorize_event()
|
| 326 |
+
eq(self.root.tk.call('after', 'info', color.after_id)[1], 'timer')
|
| 327 |
+
self.assertFalse(color.colorizing)
|
| 328 |
+
self.assertTrue(color.stop_colorizing)
|
| 329 |
+
self.assertTrue(color.allow_colorizing)
|
| 330 |
+
|
| 331 |
+
@mock.patch.object(colorizer.ColorDelegator, 'recolorize_main')
|
| 332 |
+
def test_recolorize(self, mock_recmain):
|
| 333 |
+
text = self.text
|
| 334 |
+
color = self.color
|
| 335 |
+
eq = self.assertEqual
|
| 336 |
+
# Call recolorize manually and not scheduled.
|
| 337 |
+
text.after_cancel(color.after_id)
|
| 338 |
+
|
| 339 |
+
# No delegate.
|
| 340 |
+
save_delegate = color.delegate
|
| 341 |
+
color.delegate = None
|
| 342 |
+
color.recolorize()
|
| 343 |
+
mock_recmain.assert_not_called()
|
| 344 |
+
color.delegate = save_delegate
|
| 345 |
+
|
| 346 |
+
# Toggle off colorizing.
|
| 347 |
+
color.allow_colorizing = False
|
| 348 |
+
color.recolorize()
|
| 349 |
+
mock_recmain.assert_not_called()
|
| 350 |
+
color.allow_colorizing = True
|
| 351 |
+
|
| 352 |
+
# Colorizing in progress.
|
| 353 |
+
color.colorizing = True
|
| 354 |
+
color.recolorize()
|
| 355 |
+
mock_recmain.assert_not_called()
|
| 356 |
+
color.colorizing = False
|
| 357 |
+
|
| 358 |
+
# Colorizing is done, but not completed, so rescheduled.
|
| 359 |
+
color.recolorize()
|
| 360 |
+
self.assertFalse(color.stop_colorizing)
|
| 361 |
+
self.assertFalse(color.colorizing)
|
| 362 |
+
mock_recmain.assert_called()
|
| 363 |
+
eq(mock_recmain.call_count, 1)
|
| 364 |
+
# Rescheduled when TODO tag still exists.
|
| 365 |
+
eq(self.root.tk.call('after', 'info', color.after_id)[1], 'timer')
|
| 366 |
+
|
| 367 |
+
# No changes to text, so no scheduling added.
|
| 368 |
+
text.tag_remove('TODO', '1.0', 'end')
|
| 369 |
+
color.recolorize()
|
| 370 |
+
self.assertFalse(color.stop_colorizing)
|
| 371 |
+
self.assertFalse(color.colorizing)
|
| 372 |
+
mock_recmain.assert_called()
|
| 373 |
+
eq(mock_recmain.call_count, 2)
|
| 374 |
+
self.assertIsNone(color.after_id)
|
| 375 |
+
|
| 376 |
+
@mock.patch.object(colorizer.ColorDelegator, 'notify_range')
|
| 377 |
+
def test_recolorize_main(self, mock_notify):
|
| 378 |
+
text = self.text
|
| 379 |
+
color = self.color
|
| 380 |
+
eq = self.assertEqual
|
| 381 |
+
|
| 382 |
+
text.insert('insert', source)
|
| 383 |
+
expected = (('1.0', ('KEYWORD',)), ('1.2', ()), ('1.3', ('KEYWORD',)),
|
| 384 |
+
('1.7', ()), ('1.9', ('BUILTIN',)), ('1.14', ('STRING',)),
|
| 385 |
+
('1.19', ('COMMENT',)),
|
| 386 |
+
('2.1', ('KEYWORD',)), ('2.18', ()), ('2.25', ('COMMENT',)),
|
| 387 |
+
('3.6', ('BUILTIN',)), ('3.12', ('KEYWORD',)), ('3.21', ('COMMENT',)),
|
| 388 |
+
('4.0', ('KEYWORD',)), ('4.3', ()), ('4.6', ()),
|
| 389 |
+
('5.2', ('STRING',)), ('5.8', ('KEYWORD',)), ('5.10', ('STRING',)),
|
| 390 |
+
('6.0', ('KEYWORD',)), ('6.10', ('DEFINITION',)), ('6.11', ()),
|
| 391 |
+
('8.0', ('STRING',)), ('8.4', ()), ('8.5', ('STRING',)),
|
| 392 |
+
('8.12', ()), ('8.14', ('STRING',)),
|
| 393 |
+
('19.0', ('KEYWORD',)),
|
| 394 |
+
('20.4', ('KEYWORD',)), ('20.16', ('KEYWORD',)),# ('20.19', ('KEYWORD',)),
|
| 395 |
+
#('22.4', ('KEYWORD',)), ('22.10', ('KEYWORD',)), ('22.14', ('KEYWORD',)), ('22.19', ('STRING',)),
|
| 396 |
+
#('23.12', ('KEYWORD',)),
|
| 397 |
+
('24.8', ('KEYWORD',)),
|
| 398 |
+
('25.4', ('KEYWORD',)), ('25.9', ('KEYWORD',)),
|
| 399 |
+
('25.11', ('KEYWORD',)), ('25.15', ('STRING',)),
|
| 400 |
+
('25.19', ('KEYWORD',)), ('25.22', ()),
|
| 401 |
+
('25.24', ('KEYWORD',)), ('25.29', ('BUILTIN',)), ('25.37', ('KEYWORD',)),
|
| 402 |
+
('26.4', ('KEYWORD',)), ('26.9', ('KEYWORD',)),# ('26.11', ('KEYWORD',)), ('26.14', (),),
|
| 403 |
+
('27.25', ('STRING',)), ('27.38', ('STRING',)),
|
| 404 |
+
('29.0', ('STRING',)),
|
| 405 |
+
('30.1', ('STRING',)),
|
| 406 |
+
# SYNC at the end of every line.
|
| 407 |
+
('1.55', ('SYNC',)), ('2.50', ('SYNC',)), ('3.34', ('SYNC',)),
|
| 408 |
+
)
|
| 409 |
+
|
| 410 |
+
# Nothing marked to do therefore no tags in text.
|
| 411 |
+
text.tag_remove('TODO', '1.0', 'end')
|
| 412 |
+
color.recolorize_main()
|
| 413 |
+
for tag in text.tag_names():
|
| 414 |
+
with self.subTest(tag=tag):
|
| 415 |
+
eq(text.tag_ranges(tag), ())
|
| 416 |
+
|
| 417 |
+
# Source marked for processing.
|
| 418 |
+
text.tag_add('TODO', '1.0', 'end')
|
| 419 |
+
# Check some indexes.
|
| 420 |
+
color.recolorize_main()
|
| 421 |
+
for index, expected_tags in expected:
|
| 422 |
+
with self.subTest(index=index):
|
| 423 |
+
eq(text.tag_names(index), expected_tags)
|
| 424 |
+
|
| 425 |
+
# Check for some tags for ranges.
|
| 426 |
+
eq(text.tag_nextrange('TODO', '1.0'), ())
|
| 427 |
+
eq(text.tag_nextrange('KEYWORD', '1.0'), ('1.0', '1.2'))
|
| 428 |
+
eq(text.tag_nextrange('COMMENT', '2.0'), ('2.22', '2.43'))
|
| 429 |
+
eq(text.tag_nextrange('SYNC', '2.0'), ('2.43', '3.0'))
|
| 430 |
+
eq(text.tag_nextrange('STRING', '2.0'), ('4.17', '4.53'))
|
| 431 |
+
eq(text.tag_nextrange('STRING', '8.0'), ('8.0', '8.3'))
|
| 432 |
+
eq(text.tag_nextrange('STRING', '8.3'), ('8.5', '8.12'))
|
| 433 |
+
eq(text.tag_nextrange('STRING', '8.12'), ('8.14', '8.17'))
|
| 434 |
+
eq(text.tag_nextrange('STRING', '8.17'), ('8.19', '8.26'))
|
| 435 |
+
eq(text.tag_nextrange('SYNC', '8.0'), ('8.26', '9.0'))
|
| 436 |
+
eq(text.tag_nextrange('SYNC', '30.0'), ('30.10', '32.0'))
|
| 437 |
+
|
| 438 |
+
def _assert_highlighting(self, source, tag_ranges):
|
| 439 |
+
"""Check highlighting of a given piece of code.
|
| 440 |
+
|
| 441 |
+
This inserts just this code into the Text widget. It will then
|
| 442 |
+
check that the resulting highlighting tag ranges exactly match
|
| 443 |
+
those described in the given `tag_ranges` dict.
|
| 444 |
+
|
| 445 |
+
Note that the irrelevant tags 'sel', 'TODO' and 'SYNC' are
|
| 446 |
+
ignored.
|
| 447 |
+
"""
|
| 448 |
+
text = self.text
|
| 449 |
+
|
| 450 |
+
with mock.patch.object(colorizer.ColorDelegator, 'notify_range'):
|
| 451 |
+
text.delete('1.0', 'end-1c')
|
| 452 |
+
text.insert('insert', source)
|
| 453 |
+
text.tag_add('TODO', '1.0', 'end-1c')
|
| 454 |
+
self.color.recolorize_main()
|
| 455 |
+
|
| 456 |
+
# Make a dict with highlighting tag ranges in the Text widget.
|
| 457 |
+
text_tag_ranges = {}
|
| 458 |
+
for tag in set(text.tag_names()) - {'sel', 'TODO', 'SYNC'}:
|
| 459 |
+
indexes = [rng.string for rng in text.tag_ranges(tag)]
|
| 460 |
+
for index_pair in zip(indexes[::2], indexes[1::2]):
|
| 461 |
+
text_tag_ranges.setdefault(tag, []).append(index_pair)
|
| 462 |
+
|
| 463 |
+
self.assertEqual(text_tag_ranges, tag_ranges)
|
| 464 |
+
|
| 465 |
+
with mock.patch.object(colorizer.ColorDelegator, 'notify_range'):
|
| 466 |
+
text.delete('1.0', 'end-1c')
|
| 467 |
+
|
| 468 |
+
def test_def_statement(self):
|
| 469 |
+
# empty def
|
| 470 |
+
self._assert_highlighting('def', {'KEYWORD': [('1.0', '1.3')]})
|
| 471 |
+
|
| 472 |
+
# def followed by identifier
|
| 473 |
+
self._assert_highlighting('def foo:', {'KEYWORD': [('1.0', '1.3')],
|
| 474 |
+
'DEFINITION': [('1.4', '1.7')]})
|
| 475 |
+
|
| 476 |
+
# def followed by partial identifier
|
| 477 |
+
self._assert_highlighting('def fo', {'KEYWORD': [('1.0', '1.3')],
|
| 478 |
+
'DEFINITION': [('1.4', '1.6')]})
|
| 479 |
+
|
| 480 |
+
# def followed by non-keyword
|
| 481 |
+
self._assert_highlighting('def ++', {'KEYWORD': [('1.0', '1.3')]})
|
| 482 |
+
|
| 483 |
+
def test_match_soft_keyword(self):
|
| 484 |
+
# empty match
|
| 485 |
+
self._assert_highlighting('match', {'KEYWORD': [('1.0', '1.5')]})
|
| 486 |
+
|
| 487 |
+
# match followed by partial identifier
|
| 488 |
+
self._assert_highlighting('match fo', {'KEYWORD': [('1.0', '1.5')]})
|
| 489 |
+
|
| 490 |
+
# match followed by identifier and colon
|
| 491 |
+
self._assert_highlighting('match foo:', {'KEYWORD': [('1.0', '1.5')]})
|
| 492 |
+
|
| 493 |
+
# match followed by keyword
|
| 494 |
+
self._assert_highlighting('match and', {'KEYWORD': [('1.6', '1.9')]})
|
| 495 |
+
|
| 496 |
+
# match followed by builtin with keyword prefix
|
| 497 |
+
self._assert_highlighting('match int:', {'KEYWORD': [('1.0', '1.5')],
|
| 498 |
+
'BUILTIN': [('1.6', '1.9')]})
|
| 499 |
+
|
| 500 |
+
# match followed by non-text operator
|
| 501 |
+
self._assert_highlighting('match^', {})
|
| 502 |
+
self._assert_highlighting('match @', {})
|
| 503 |
+
|
| 504 |
+
# match followed by colon
|
| 505 |
+
self._assert_highlighting('match :', {})
|
| 506 |
+
|
| 507 |
+
# match followed by comma
|
| 508 |
+
self._assert_highlighting('match\t,', {})
|
| 509 |
+
|
| 510 |
+
# match followed by a lone underscore
|
| 511 |
+
self._assert_highlighting('match _:', {'KEYWORD': [('1.0', '1.5')]})
|
| 512 |
+
|
| 513 |
+
def test_case_soft_keyword(self):
|
| 514 |
+
# empty case
|
| 515 |
+
self._assert_highlighting('case', {'KEYWORD': [('1.0', '1.4')]})
|
| 516 |
+
|
| 517 |
+
# case followed by partial identifier
|
| 518 |
+
self._assert_highlighting('case fo', {'KEYWORD': [('1.0', '1.4')]})
|
| 519 |
+
|
| 520 |
+
# case followed by identifier and colon
|
| 521 |
+
self._assert_highlighting('case foo:', {'KEYWORD': [('1.0', '1.4')]})
|
| 522 |
+
|
| 523 |
+
# case followed by keyword
|
| 524 |
+
self._assert_highlighting('case and', {'KEYWORD': [('1.5', '1.8')]})
|
| 525 |
+
|
| 526 |
+
# case followed by builtin with keyword prefix
|
| 527 |
+
self._assert_highlighting('case int:', {'KEYWORD': [('1.0', '1.4')],
|
| 528 |
+
'BUILTIN': [('1.5', '1.8')]})
|
| 529 |
+
|
| 530 |
+
# case followed by non-text operator
|
| 531 |
+
self._assert_highlighting('case^', {})
|
| 532 |
+
self._assert_highlighting('case @', {})
|
| 533 |
+
|
| 534 |
+
# case followed by colon
|
| 535 |
+
self._assert_highlighting('case :', {})
|
| 536 |
+
|
| 537 |
+
# case followed by comma
|
| 538 |
+
self._assert_highlighting('case\t,', {})
|
| 539 |
+
|
| 540 |
+
# case followed by a lone underscore
|
| 541 |
+
self._assert_highlighting('case _:', {'KEYWORD': [('1.0', '1.4'),
|
| 542 |
+
('1.5', '1.6')]})
|
| 543 |
+
|
| 544 |
+
def test_long_multiline_string(self):
|
| 545 |
+
source = textwrap.dedent('''\
|
| 546 |
+
"""a
|
| 547 |
+
b
|
| 548 |
+
c
|
| 549 |
+
d
|
| 550 |
+
e"""
|
| 551 |
+
''')
|
| 552 |
+
self._assert_highlighting(source, {'STRING': [('1.0', '5.4')]})
|
| 553 |
+
|
| 554 |
+
@run_in_tk_mainloop(delay=50)
|
| 555 |
+
def test_incremental_editing(self):
|
| 556 |
+
text = self.text
|
| 557 |
+
eq = self.assertEqual
|
| 558 |
+
|
| 559 |
+
# Simulate typing 'inte'. During this, the highlighting should
|
| 560 |
+
# change from normal to keyword to builtin to normal.
|
| 561 |
+
text.insert('insert', 'i')
|
| 562 |
+
yield
|
| 563 |
+
eq(text.tag_nextrange('BUILTIN', '1.0'), ())
|
| 564 |
+
eq(text.tag_nextrange('KEYWORD', '1.0'), ())
|
| 565 |
+
|
| 566 |
+
text.insert('insert', 'n')
|
| 567 |
+
yield
|
| 568 |
+
eq(text.tag_nextrange('BUILTIN', '1.0'), ())
|
| 569 |
+
eq(text.tag_nextrange('KEYWORD', '1.0'), ('1.0', '1.2'))
|
| 570 |
+
|
| 571 |
+
text.insert('insert', 't')
|
| 572 |
+
yield
|
| 573 |
+
eq(text.tag_nextrange('BUILTIN', '1.0'), ('1.0', '1.3'))
|
| 574 |
+
eq(text.tag_nextrange('KEYWORD', '1.0'), ())
|
| 575 |
+
|
| 576 |
+
text.insert('insert', 'e')
|
| 577 |
+
yield
|
| 578 |
+
eq(text.tag_nextrange('BUILTIN', '1.0'), ())
|
| 579 |
+
eq(text.tag_nextrange('KEYWORD', '1.0'), ())
|
| 580 |
+
|
| 581 |
+
# Simulate deleting three characters from the end of 'inte'.
|
| 582 |
+
# During this, the highlighting should change from normal to
|
| 583 |
+
# builtin to keyword to normal.
|
| 584 |
+
text.delete('insert-1c', 'insert')
|
| 585 |
+
yield
|
| 586 |
+
eq(text.tag_nextrange('BUILTIN', '1.0'), ('1.0', '1.3'))
|
| 587 |
+
eq(text.tag_nextrange('KEYWORD', '1.0'), ())
|
| 588 |
+
|
| 589 |
+
text.delete('insert-1c', 'insert')
|
| 590 |
+
yield
|
| 591 |
+
eq(text.tag_nextrange('BUILTIN', '1.0'), ())
|
| 592 |
+
eq(text.tag_nextrange('KEYWORD', '1.0'), ('1.0', '1.2'))
|
| 593 |
+
|
| 594 |
+
text.delete('insert-1c', 'insert')
|
| 595 |
+
yield
|
| 596 |
+
eq(text.tag_nextrange('BUILTIN', '1.0'), ())
|
| 597 |
+
eq(text.tag_nextrange('KEYWORD', '1.0'), ())
|
| 598 |
+
|
| 599 |
+
@mock.patch.object(colorizer.ColorDelegator, 'recolorize')
|
| 600 |
+
@mock.patch.object(colorizer.ColorDelegator, 'notify_range')
|
| 601 |
+
def test_removecolors(self, mock_notify, mock_recolorize):
|
| 602 |
+
text = self.text
|
| 603 |
+
color = self.color
|
| 604 |
+
text.insert('insert', source)
|
| 605 |
+
|
| 606 |
+
color.recolorize_main()
|
| 607 |
+
# recolorize_main doesn't add these tags.
|
| 608 |
+
text.tag_add("ERROR", "1.0")
|
| 609 |
+
text.tag_add("TODO", "1.0")
|
| 610 |
+
text.tag_add("hit", "1.0")
|
| 611 |
+
for tag in color.tagdefs:
|
| 612 |
+
with self.subTest(tag=tag):
|
| 613 |
+
self.assertNotEqual(text.tag_ranges(tag), ())
|
| 614 |
+
|
| 615 |
+
color.removecolors()
|
| 616 |
+
for tag in color.tagdefs:
|
| 617 |
+
with self.subTest(tag=tag):
|
| 618 |
+
self.assertEqual(text.tag_ranges(tag), ())
|
| 619 |
+
|
| 620 |
+
|
| 621 |
+
if __name__ == '__main__':
|
| 622 |
+
unittest.main(verbosity=2)
|
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/test_config.py
ADDED
|
@@ -0,0 +1,805 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Test config, coverage 93%.
|
| 2 |
+
(100% for IdleConfParser, IdleUserConfParser*, ConfigChanges).
|
| 3 |
+
* Exception is OSError clause in Save method.
|
| 4 |
+
Much of IdleConf is also exercised by ConfigDialog and test_configdialog.
|
| 5 |
+
"""
|
| 6 |
+
from idlelib import config
|
| 7 |
+
import sys
|
| 8 |
+
import os
|
| 9 |
+
import tempfile
|
| 10 |
+
from test.support import captured_stderr, findfile
|
| 11 |
+
import unittest
|
| 12 |
+
from unittest import mock
|
| 13 |
+
import idlelib
|
| 14 |
+
from idlelib.idle_test.mock_idle import Func
|
| 15 |
+
|
| 16 |
+
# Tests should not depend on fortuitous user configurations.
|
| 17 |
+
# They must not affect actual user .cfg files.
|
| 18 |
+
# Replace user parsers with empty parsers that cannot be saved
|
| 19 |
+
# due to getting '' as the filename when created.
|
| 20 |
+
|
| 21 |
+
idleConf = config.idleConf
|
| 22 |
+
usercfg = idleConf.userCfg
|
| 23 |
+
testcfg = {}
|
| 24 |
+
usermain = testcfg['main'] = config.IdleUserConfParser('')
|
| 25 |
+
userhigh = testcfg['highlight'] = config.IdleUserConfParser('')
|
| 26 |
+
userkeys = testcfg['keys'] = config.IdleUserConfParser('')
|
| 27 |
+
userextn = testcfg['extensions'] = config.IdleUserConfParser('')
|
| 28 |
+
|
| 29 |
+
def setUpModule():
|
| 30 |
+
idleConf.userCfg = testcfg
|
| 31 |
+
idlelib.testing = True
|
| 32 |
+
|
| 33 |
+
def tearDownModule():
|
| 34 |
+
idleConf.userCfg = usercfg
|
| 35 |
+
idlelib.testing = False
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
class IdleConfParserTest(unittest.TestCase):
|
| 39 |
+
"""Test that IdleConfParser works"""
|
| 40 |
+
|
| 41 |
+
config = """
|
| 42 |
+
[one]
|
| 43 |
+
one = false
|
| 44 |
+
two = true
|
| 45 |
+
three = 10
|
| 46 |
+
|
| 47 |
+
[two]
|
| 48 |
+
one = a string
|
| 49 |
+
two = true
|
| 50 |
+
three = false
|
| 51 |
+
"""
|
| 52 |
+
|
| 53 |
+
def test_get(self):
|
| 54 |
+
parser = config.IdleConfParser('')
|
| 55 |
+
parser.read_string(self.config)
|
| 56 |
+
eq = self.assertEqual
|
| 57 |
+
|
| 58 |
+
# Test with type argument.
|
| 59 |
+
self.assertIs(parser.Get('one', 'one', type='bool'), False)
|
| 60 |
+
self.assertIs(parser.Get('one', 'two', type='bool'), True)
|
| 61 |
+
eq(parser.Get('one', 'three', type='int'), 10)
|
| 62 |
+
eq(parser.Get('two', 'one'), 'a string')
|
| 63 |
+
self.assertIs(parser.Get('two', 'two', type='bool'), True)
|
| 64 |
+
self.assertIs(parser.Get('two', 'three', type='bool'), False)
|
| 65 |
+
|
| 66 |
+
# Test without type should fallback to string.
|
| 67 |
+
eq(parser.Get('two', 'two'), 'true')
|
| 68 |
+
eq(parser.Get('two', 'three'), 'false')
|
| 69 |
+
|
| 70 |
+
# If option not exist, should return None, or default.
|
| 71 |
+
self.assertIsNone(parser.Get('not', 'exist'))
|
| 72 |
+
eq(parser.Get('not', 'exist', default='DEFAULT'), 'DEFAULT')
|
| 73 |
+
|
| 74 |
+
def test_get_option_list(self):
|
| 75 |
+
parser = config.IdleConfParser('')
|
| 76 |
+
parser.read_string(self.config)
|
| 77 |
+
get_list = parser.GetOptionList
|
| 78 |
+
self.assertCountEqual(get_list('one'), ['one', 'two', 'three'])
|
| 79 |
+
self.assertCountEqual(get_list('two'), ['one', 'two', 'three'])
|
| 80 |
+
self.assertEqual(get_list('not exist'), [])
|
| 81 |
+
|
| 82 |
+
def test_load_nothing(self):
|
| 83 |
+
parser = config.IdleConfParser('')
|
| 84 |
+
parser.Load()
|
| 85 |
+
self.assertEqual(parser.sections(), [])
|
| 86 |
+
|
| 87 |
+
def test_load_file(self):
|
| 88 |
+
# Borrow test/configdata/cfgparser.1 from test_configparser.
|
| 89 |
+
config_path = findfile('cfgparser.1', subdir='configdata')
|
| 90 |
+
parser = config.IdleConfParser(config_path)
|
| 91 |
+
parser.Load()
|
| 92 |
+
|
| 93 |
+
self.assertEqual(parser.Get('Foo Bar', 'foo'), 'newbar')
|
| 94 |
+
self.assertEqual(parser.GetOptionList('Foo Bar'), ['foo'])
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
class IdleUserConfParserTest(unittest.TestCase):
|
| 98 |
+
"""Test that IdleUserConfParser works"""
|
| 99 |
+
|
| 100 |
+
def new_parser(self, path=''):
|
| 101 |
+
return config.IdleUserConfParser(path)
|
| 102 |
+
|
| 103 |
+
def test_set_option(self):
|
| 104 |
+
parser = self.new_parser()
|
| 105 |
+
parser.add_section('Foo')
|
| 106 |
+
# Setting new option in existing section should return True.
|
| 107 |
+
self.assertTrue(parser.SetOption('Foo', 'bar', 'true'))
|
| 108 |
+
# Setting existing option with same value should return False.
|
| 109 |
+
self.assertFalse(parser.SetOption('Foo', 'bar', 'true'))
|
| 110 |
+
# Setting exiting option with new value should return True.
|
| 111 |
+
self.assertTrue(parser.SetOption('Foo', 'bar', 'false'))
|
| 112 |
+
self.assertEqual(parser.Get('Foo', 'bar'), 'false')
|
| 113 |
+
|
| 114 |
+
# Setting option in new section should create section and return True.
|
| 115 |
+
self.assertTrue(parser.SetOption('Bar', 'bar', 'true'))
|
| 116 |
+
self.assertCountEqual(parser.sections(), ['Bar', 'Foo'])
|
| 117 |
+
self.assertEqual(parser.Get('Bar', 'bar'), 'true')
|
| 118 |
+
|
| 119 |
+
def test_remove_option(self):
|
| 120 |
+
parser = self.new_parser()
|
| 121 |
+
parser.AddSection('Foo')
|
| 122 |
+
parser.SetOption('Foo', 'bar', 'true')
|
| 123 |
+
|
| 124 |
+
self.assertTrue(parser.RemoveOption('Foo', 'bar'))
|
| 125 |
+
self.assertFalse(parser.RemoveOption('Foo', 'bar'))
|
| 126 |
+
self.assertFalse(parser.RemoveOption('Not', 'Exist'))
|
| 127 |
+
|
| 128 |
+
def test_add_section(self):
|
| 129 |
+
parser = self.new_parser()
|
| 130 |
+
self.assertEqual(parser.sections(), [])
|
| 131 |
+
|
| 132 |
+
# Should not add duplicate section.
|
| 133 |
+
# Configparser raises DuplicateError, IdleParser not.
|
| 134 |
+
parser.AddSection('Foo')
|
| 135 |
+
parser.AddSection('Foo')
|
| 136 |
+
parser.AddSection('Bar')
|
| 137 |
+
self.assertCountEqual(parser.sections(), ['Bar', 'Foo'])
|
| 138 |
+
|
| 139 |
+
def test_remove_empty_sections(self):
|
| 140 |
+
parser = self.new_parser()
|
| 141 |
+
|
| 142 |
+
parser.AddSection('Foo')
|
| 143 |
+
parser.AddSection('Bar')
|
| 144 |
+
parser.SetOption('Idle', 'name', 'val')
|
| 145 |
+
self.assertCountEqual(parser.sections(), ['Bar', 'Foo', 'Idle'])
|
| 146 |
+
parser.RemoveEmptySections()
|
| 147 |
+
self.assertEqual(parser.sections(), ['Idle'])
|
| 148 |
+
|
| 149 |
+
def test_is_empty(self):
|
| 150 |
+
parser = self.new_parser()
|
| 151 |
+
|
| 152 |
+
parser.AddSection('Foo')
|
| 153 |
+
parser.AddSection('Bar')
|
| 154 |
+
self.assertTrue(parser.IsEmpty())
|
| 155 |
+
self.assertEqual(parser.sections(), [])
|
| 156 |
+
|
| 157 |
+
parser.SetOption('Foo', 'bar', 'false')
|
| 158 |
+
parser.AddSection('Bar')
|
| 159 |
+
self.assertFalse(parser.IsEmpty())
|
| 160 |
+
self.assertCountEqual(parser.sections(), ['Foo'])
|
| 161 |
+
|
| 162 |
+
def test_save(self):
|
| 163 |
+
with tempfile.TemporaryDirectory() as tdir:
|
| 164 |
+
path = os.path.join(tdir, 'test.cfg')
|
| 165 |
+
parser = self.new_parser(path)
|
| 166 |
+
parser.AddSection('Foo')
|
| 167 |
+
parser.SetOption('Foo', 'bar', 'true')
|
| 168 |
+
|
| 169 |
+
# Should save to path when config is not empty.
|
| 170 |
+
self.assertFalse(os.path.exists(path))
|
| 171 |
+
parser.Save()
|
| 172 |
+
self.assertTrue(os.path.exists(path))
|
| 173 |
+
|
| 174 |
+
# Should remove the file from disk when config is empty.
|
| 175 |
+
parser.remove_section('Foo')
|
| 176 |
+
parser.Save()
|
| 177 |
+
self.assertFalse(os.path.exists(path))
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
class IdleConfTest(unittest.TestCase):
|
| 181 |
+
"""Test for idleConf"""
|
| 182 |
+
|
| 183 |
+
@classmethod
|
| 184 |
+
def setUpClass(cls):
|
| 185 |
+
cls.config_string = {}
|
| 186 |
+
|
| 187 |
+
conf = config.IdleConf(_utest=True)
|
| 188 |
+
if __name__ != '__main__':
|
| 189 |
+
idle_dir = os.path.dirname(__file__)
|
| 190 |
+
else:
|
| 191 |
+
idle_dir = os.path.abspath(sys.path[0])
|
| 192 |
+
for ctype in conf.config_types:
|
| 193 |
+
config_path = os.path.join(idle_dir, '../config-%s.def' % ctype)
|
| 194 |
+
with open(config_path) as f:
|
| 195 |
+
cls.config_string[ctype] = f.read()
|
| 196 |
+
|
| 197 |
+
cls.orig_warn = config._warn
|
| 198 |
+
config._warn = Func()
|
| 199 |
+
|
| 200 |
+
@classmethod
|
| 201 |
+
def tearDownClass(cls):
|
| 202 |
+
config._warn = cls.orig_warn
|
| 203 |
+
|
| 204 |
+
def new_config(self, _utest=False):
|
| 205 |
+
return config.IdleConf(_utest=_utest)
|
| 206 |
+
|
| 207 |
+
def mock_config(self):
|
| 208 |
+
"""Return a mocked idleConf
|
| 209 |
+
|
| 210 |
+
Both default and user config used the same config-*.def
|
| 211 |
+
"""
|
| 212 |
+
conf = config.IdleConf(_utest=True)
|
| 213 |
+
for ctype in conf.config_types:
|
| 214 |
+
conf.defaultCfg[ctype] = config.IdleConfParser('')
|
| 215 |
+
conf.defaultCfg[ctype].read_string(self.config_string[ctype])
|
| 216 |
+
conf.userCfg[ctype] = config.IdleUserConfParser('')
|
| 217 |
+
conf.userCfg[ctype].read_string(self.config_string[ctype])
|
| 218 |
+
|
| 219 |
+
return conf
|
| 220 |
+
|
| 221 |
+
@unittest.skipIf(sys.platform.startswith('win'), 'this is test for unix system')
|
| 222 |
+
def test_get_user_cfg_dir_unix(self):
|
| 223 |
+
# Test to get user config directory under unix.
|
| 224 |
+
conf = self.new_config(_utest=True)
|
| 225 |
+
|
| 226 |
+
# Check normal way should success
|
| 227 |
+
with mock.patch('os.path.expanduser', return_value='/home/foo'):
|
| 228 |
+
with mock.patch('os.path.exists', return_value=True):
|
| 229 |
+
self.assertEqual(conf.GetUserCfgDir(), '/home/foo/.idlerc')
|
| 230 |
+
|
| 231 |
+
# Check os.getcwd should success
|
| 232 |
+
with mock.patch('os.path.expanduser', return_value='~'):
|
| 233 |
+
with mock.patch('os.getcwd', return_value='/home/foo/cpython'):
|
| 234 |
+
with mock.patch('os.mkdir'):
|
| 235 |
+
self.assertEqual(conf.GetUserCfgDir(),
|
| 236 |
+
'/home/foo/cpython/.idlerc')
|
| 237 |
+
|
| 238 |
+
# Check user dir not exists and created failed should raise SystemExit
|
| 239 |
+
with mock.patch('os.path.join', return_value='/path/not/exists'):
|
| 240 |
+
with self.assertRaises(SystemExit):
|
| 241 |
+
with self.assertRaises(FileNotFoundError):
|
| 242 |
+
conf.GetUserCfgDir()
|
| 243 |
+
|
| 244 |
+
@unittest.skipIf(not sys.platform.startswith('win'), 'this is test for Windows system')
|
| 245 |
+
def test_get_user_cfg_dir_windows(self):
|
| 246 |
+
# Test to get user config directory under Windows.
|
| 247 |
+
conf = self.new_config(_utest=True)
|
| 248 |
+
|
| 249 |
+
# Check normal way should success
|
| 250 |
+
with mock.patch('os.path.expanduser', return_value='C:\\foo'):
|
| 251 |
+
with mock.patch('os.path.exists', return_value=True):
|
| 252 |
+
self.assertEqual(conf.GetUserCfgDir(), 'C:\\foo\\.idlerc')
|
| 253 |
+
|
| 254 |
+
# Check os.getcwd should success
|
| 255 |
+
with mock.patch('os.path.expanduser', return_value='~'):
|
| 256 |
+
with mock.patch('os.getcwd', return_value='C:\\foo\\cpython'):
|
| 257 |
+
with mock.patch('os.mkdir'):
|
| 258 |
+
self.assertEqual(conf.GetUserCfgDir(),
|
| 259 |
+
'C:\\foo\\cpython\\.idlerc')
|
| 260 |
+
|
| 261 |
+
# Check user dir not exists and created failed should raise SystemExit
|
| 262 |
+
with mock.patch('os.path.join', return_value='/path/not/exists'):
|
| 263 |
+
with self.assertRaises(SystemExit):
|
| 264 |
+
with self.assertRaises(FileNotFoundError):
|
| 265 |
+
conf.GetUserCfgDir()
|
| 266 |
+
|
| 267 |
+
def test_create_config_handlers(self):
|
| 268 |
+
conf = self.new_config(_utest=True)
|
| 269 |
+
|
| 270 |
+
# Mock out idle_dir
|
| 271 |
+
idle_dir = '/home/foo'
|
| 272 |
+
with mock.patch.dict({'__name__': '__foo__'}):
|
| 273 |
+
with mock.patch('os.path.dirname', return_value=idle_dir):
|
| 274 |
+
conf.CreateConfigHandlers()
|
| 275 |
+
|
| 276 |
+
# Check keys are equal
|
| 277 |
+
self.assertCountEqual(conf.defaultCfg, conf.config_types)
|
| 278 |
+
self.assertCountEqual(conf.userCfg, conf.config_types)
|
| 279 |
+
|
| 280 |
+
# Check conf parser are correct type
|
| 281 |
+
for default_parser in conf.defaultCfg.values():
|
| 282 |
+
self.assertIsInstance(default_parser, config.IdleConfParser)
|
| 283 |
+
for user_parser in conf.userCfg.values():
|
| 284 |
+
self.assertIsInstance(user_parser, config.IdleUserConfParser)
|
| 285 |
+
|
| 286 |
+
# Check config path are correct
|
| 287 |
+
for cfg_type, parser in conf.defaultCfg.items():
|
| 288 |
+
self.assertEqual(parser.file,
|
| 289 |
+
os.path.join(idle_dir, f'config-{cfg_type}.def'))
|
| 290 |
+
for cfg_type, parser in conf.userCfg.items():
|
| 291 |
+
self.assertEqual(parser.file,
|
| 292 |
+
os.path.join(conf.userdir or '#', f'config-{cfg_type}.cfg'))
|
| 293 |
+
|
| 294 |
+
def test_load_cfg_files(self):
|
| 295 |
+
conf = self.new_config(_utest=True)
|
| 296 |
+
|
| 297 |
+
# Borrow test/configdata/cfgparser.1 from test_configparser.
|
| 298 |
+
config_path = findfile('cfgparser.1', subdir='configdata')
|
| 299 |
+
conf.defaultCfg['foo'] = config.IdleConfParser(config_path)
|
| 300 |
+
conf.userCfg['foo'] = config.IdleUserConfParser(config_path)
|
| 301 |
+
|
| 302 |
+
# Load all config from path
|
| 303 |
+
conf.LoadCfgFiles()
|
| 304 |
+
|
| 305 |
+
eq = self.assertEqual
|
| 306 |
+
|
| 307 |
+
# Check defaultCfg is loaded
|
| 308 |
+
eq(conf.defaultCfg['foo'].Get('Foo Bar', 'foo'), 'newbar')
|
| 309 |
+
eq(conf.defaultCfg['foo'].GetOptionList('Foo Bar'), ['foo'])
|
| 310 |
+
|
| 311 |
+
# Check userCfg is loaded
|
| 312 |
+
eq(conf.userCfg['foo'].Get('Foo Bar', 'foo'), 'newbar')
|
| 313 |
+
eq(conf.userCfg['foo'].GetOptionList('Foo Bar'), ['foo'])
|
| 314 |
+
|
| 315 |
+
def test_save_user_cfg_files(self):
|
| 316 |
+
conf = self.mock_config()
|
| 317 |
+
|
| 318 |
+
with mock.patch('idlelib.config.IdleUserConfParser.Save') as m:
|
| 319 |
+
conf.SaveUserCfgFiles()
|
| 320 |
+
self.assertEqual(m.call_count, len(conf.userCfg))
|
| 321 |
+
|
| 322 |
+
def test_get_option(self):
|
| 323 |
+
conf = self.mock_config()
|
| 324 |
+
|
| 325 |
+
eq = self.assertEqual
|
| 326 |
+
eq(conf.GetOption('main', 'EditorWindow', 'width'), '80')
|
| 327 |
+
eq(conf.GetOption('main', 'EditorWindow', 'width', type='int'), 80)
|
| 328 |
+
with mock.patch('idlelib.config._warn') as _warn:
|
| 329 |
+
eq(conf.GetOption('main', 'EditorWindow', 'font', type='int'), None)
|
| 330 |
+
eq(conf.GetOption('main', 'EditorWindow', 'NotExists'), None)
|
| 331 |
+
eq(conf.GetOption('main', 'EditorWindow', 'NotExists', default='NE'), 'NE')
|
| 332 |
+
eq(_warn.call_count, 4)
|
| 333 |
+
|
| 334 |
+
def test_set_option(self):
|
| 335 |
+
conf = self.mock_config()
|
| 336 |
+
|
| 337 |
+
conf.SetOption('main', 'Foo', 'bar', 'newbar')
|
| 338 |
+
self.assertEqual(conf.GetOption('main', 'Foo', 'bar'), 'newbar')
|
| 339 |
+
|
| 340 |
+
def test_get_section_list(self):
|
| 341 |
+
conf = self.mock_config()
|
| 342 |
+
|
| 343 |
+
self.assertCountEqual(
|
| 344 |
+
conf.GetSectionList('default', 'main'),
|
| 345 |
+
['General', 'EditorWindow', 'PyShell', 'Indent', 'Theme',
|
| 346 |
+
'Keys', 'History', 'HelpFiles'])
|
| 347 |
+
self.assertCountEqual(
|
| 348 |
+
conf.GetSectionList('user', 'main'),
|
| 349 |
+
['General', 'EditorWindow', 'PyShell', 'Indent', 'Theme',
|
| 350 |
+
'Keys', 'History', 'HelpFiles'])
|
| 351 |
+
|
| 352 |
+
with self.assertRaises(config.InvalidConfigSet):
|
| 353 |
+
conf.GetSectionList('foobar', 'main')
|
| 354 |
+
with self.assertRaises(config.InvalidConfigType):
|
| 355 |
+
conf.GetSectionList('default', 'notexists')
|
| 356 |
+
|
| 357 |
+
def test_get_highlight(self):
|
| 358 |
+
conf = self.mock_config()
|
| 359 |
+
|
| 360 |
+
eq = self.assertEqual
|
| 361 |
+
eq(conf.GetHighlight('IDLE Classic', 'normal'), {'foreground': '#000000',
|
| 362 |
+
'background': '#ffffff'})
|
| 363 |
+
|
| 364 |
+
# Test cursor (this background should be normal-background)
|
| 365 |
+
eq(conf.GetHighlight('IDLE Classic', 'cursor'), {'foreground': 'black',
|
| 366 |
+
'background': '#ffffff'})
|
| 367 |
+
|
| 368 |
+
# Test get user themes
|
| 369 |
+
conf.SetOption('highlight', 'Foobar', 'normal-foreground', '#747474')
|
| 370 |
+
conf.SetOption('highlight', 'Foobar', 'normal-background', '#171717')
|
| 371 |
+
with mock.patch('idlelib.config._warn'):
|
| 372 |
+
eq(conf.GetHighlight('Foobar', 'normal'), {'foreground': '#747474',
|
| 373 |
+
'background': '#171717'})
|
| 374 |
+
|
| 375 |
+
def test_get_theme_dict(self):
|
| 376 |
+
# TODO: finish.
|
| 377 |
+
conf = self.mock_config()
|
| 378 |
+
|
| 379 |
+
# These two should be the same
|
| 380 |
+
self.assertEqual(
|
| 381 |
+
conf.GetThemeDict('default', 'IDLE Classic'),
|
| 382 |
+
conf.GetThemeDict('user', 'IDLE Classic'))
|
| 383 |
+
|
| 384 |
+
with self.assertRaises(config.InvalidTheme):
|
| 385 |
+
conf.GetThemeDict('bad', 'IDLE Classic')
|
| 386 |
+
|
| 387 |
+
def test_get_current_theme_and_keys(self):
|
| 388 |
+
conf = self.mock_config()
|
| 389 |
+
|
| 390 |
+
self.assertEqual(conf.CurrentTheme(), conf.current_colors_and_keys('Theme'))
|
| 391 |
+
self.assertEqual(conf.CurrentKeys(), conf.current_colors_and_keys('Keys'))
|
| 392 |
+
|
| 393 |
+
def test_current_colors_and_keys(self):
|
| 394 |
+
conf = self.mock_config()
|
| 395 |
+
|
| 396 |
+
self.assertEqual(conf.current_colors_and_keys('Theme'), 'IDLE Classic')
|
| 397 |
+
|
| 398 |
+
def test_default_keys(self):
|
| 399 |
+
current_platform = sys.platform
|
| 400 |
+
conf = self.new_config(_utest=True)
|
| 401 |
+
|
| 402 |
+
sys.platform = 'win32'
|
| 403 |
+
self.assertEqual(conf.default_keys(), 'IDLE Classic Windows')
|
| 404 |
+
|
| 405 |
+
sys.platform = 'darwin'
|
| 406 |
+
self.assertEqual(conf.default_keys(), 'IDLE Classic OSX')
|
| 407 |
+
|
| 408 |
+
sys.platform = 'some-linux'
|
| 409 |
+
self.assertEqual(conf.default_keys(), 'IDLE Modern Unix')
|
| 410 |
+
|
| 411 |
+
# Restore platform
|
| 412 |
+
sys.platform = current_platform
|
| 413 |
+
|
| 414 |
+
def test_get_extensions(self):
|
| 415 |
+
userextn.read_string('''
|
| 416 |
+
[ZzDummy]
|
| 417 |
+
enable = True
|
| 418 |
+
[DISABLE]
|
| 419 |
+
enable = False
|
| 420 |
+
''')
|
| 421 |
+
eq = self.assertEqual
|
| 422 |
+
iGE = idleConf.GetExtensions
|
| 423 |
+
eq(iGE(shell_only=True), [])
|
| 424 |
+
eq(iGE(), ['ZzDummy'])
|
| 425 |
+
eq(iGE(editor_only=True), ['ZzDummy'])
|
| 426 |
+
eq(iGE(active_only=False), ['ZzDummy', 'DISABLE'])
|
| 427 |
+
eq(iGE(active_only=False, editor_only=True), ['ZzDummy', 'DISABLE'])
|
| 428 |
+
userextn.remove_section('ZzDummy')
|
| 429 |
+
userextn.remove_section('DISABLE')
|
| 430 |
+
|
| 431 |
+
|
| 432 |
+
def test_remove_key_bind_names(self):
|
| 433 |
+
conf = self.mock_config()
|
| 434 |
+
|
| 435 |
+
self.assertCountEqual(
|
| 436 |
+
conf.RemoveKeyBindNames(conf.GetSectionList('default', 'extensions')),
|
| 437 |
+
['AutoComplete', 'CodeContext', 'FormatParagraph', 'ParenMatch', 'ZzDummy'])
|
| 438 |
+
|
| 439 |
+
def test_get_extn_name_for_event(self):
|
| 440 |
+
userextn.read_string('''
|
| 441 |
+
[ZzDummy]
|
| 442 |
+
enable = True
|
| 443 |
+
''')
|
| 444 |
+
eq = self.assertEqual
|
| 445 |
+
eq(idleConf.GetExtnNameForEvent('z-in'), 'ZzDummy')
|
| 446 |
+
eq(idleConf.GetExtnNameForEvent('z-out'), None)
|
| 447 |
+
userextn.remove_section('ZzDummy')
|
| 448 |
+
|
| 449 |
+
def test_get_extension_keys(self):
|
| 450 |
+
userextn.read_string('''
|
| 451 |
+
[ZzDummy]
|
| 452 |
+
enable = True
|
| 453 |
+
''')
|
| 454 |
+
self.assertEqual(idleConf.GetExtensionKeys('ZzDummy'),
|
| 455 |
+
{'<<z-in>>': ['<Control-Shift-KeyRelease-Insert>']})
|
| 456 |
+
userextn.remove_section('ZzDummy')
|
| 457 |
+
# need option key test
|
| 458 |
+
## key = ['<Option-Key-2>'] if sys.platform == 'darwin' else ['<Alt-Key-2>']
|
| 459 |
+
## eq(conf.GetExtensionKeys('ZoomHeight'), {'<<zoom-height>>': key})
|
| 460 |
+
|
| 461 |
+
def test_get_extension_bindings(self):
|
| 462 |
+
userextn.read_string('''
|
| 463 |
+
[ZzDummy]
|
| 464 |
+
enable = True
|
| 465 |
+
''')
|
| 466 |
+
eq = self.assertEqual
|
| 467 |
+
iGEB = idleConf.GetExtensionBindings
|
| 468 |
+
eq(iGEB('NotExists'), {})
|
| 469 |
+
expect = {'<<z-in>>': ['<Control-Shift-KeyRelease-Insert>'],
|
| 470 |
+
'<<z-out>>': ['<Control-Shift-KeyRelease-Delete>']}
|
| 471 |
+
eq(iGEB('ZzDummy'), expect)
|
| 472 |
+
userextn.remove_section('ZzDummy')
|
| 473 |
+
|
| 474 |
+
def test_get_keybinding(self):
|
| 475 |
+
conf = self.mock_config()
|
| 476 |
+
|
| 477 |
+
eq = self.assertEqual
|
| 478 |
+
eq(conf.GetKeyBinding('IDLE Modern Unix', '<<copy>>'),
|
| 479 |
+
['<Control-Shift-Key-C>', '<Control-Key-Insert>'])
|
| 480 |
+
eq(conf.GetKeyBinding('IDLE Classic Unix', '<<copy>>'),
|
| 481 |
+
['<Alt-Key-w>', '<Meta-Key-w>'])
|
| 482 |
+
eq(conf.GetKeyBinding('IDLE Classic Windows', '<<copy>>'),
|
| 483 |
+
['<Control-Key-c>', '<Control-Key-C>'])
|
| 484 |
+
eq(conf.GetKeyBinding('IDLE Classic Mac', '<<copy>>'), ['<Command-Key-c>'])
|
| 485 |
+
eq(conf.GetKeyBinding('IDLE Classic OSX', '<<copy>>'), ['<Command-Key-c>'])
|
| 486 |
+
|
| 487 |
+
# Test keybinding not exists
|
| 488 |
+
eq(conf.GetKeyBinding('NOT EXISTS', '<<copy>>'), [])
|
| 489 |
+
eq(conf.GetKeyBinding('IDLE Modern Unix', 'NOT EXISTS'), [])
|
| 490 |
+
|
| 491 |
+
def test_get_current_keyset(self):
|
| 492 |
+
current_platform = sys.platform
|
| 493 |
+
conf = self.mock_config()
|
| 494 |
+
|
| 495 |
+
# Ensure that platform isn't darwin
|
| 496 |
+
sys.platform = 'some-linux'
|
| 497 |
+
self.assertEqual(conf.GetCurrentKeySet(), conf.GetKeySet(conf.CurrentKeys()))
|
| 498 |
+
|
| 499 |
+
# This should not be the same, since replace <Alt- to <Option-.
|
| 500 |
+
# Above depended on config-extensions.def having Alt keys,
|
| 501 |
+
# which is no longer true.
|
| 502 |
+
# sys.platform = 'darwin'
|
| 503 |
+
# self.assertNotEqual(conf.GetCurrentKeySet(), conf.GetKeySet(conf.CurrentKeys()))
|
| 504 |
+
|
| 505 |
+
# Restore platform
|
| 506 |
+
sys.platform = current_platform
|
| 507 |
+
|
| 508 |
+
def test_get_keyset(self):
|
| 509 |
+
conf = self.mock_config()
|
| 510 |
+
|
| 511 |
+
# Conflict with key set, should be disable to ''
|
| 512 |
+
conf.defaultCfg['extensions'].add_section('Foobar')
|
| 513 |
+
conf.defaultCfg['extensions'].add_section('Foobar_cfgBindings')
|
| 514 |
+
conf.defaultCfg['extensions'].set('Foobar', 'enable', 'True')
|
| 515 |
+
conf.defaultCfg['extensions'].set('Foobar_cfgBindings', 'newfoo', '<Key-F3>')
|
| 516 |
+
self.assertEqual(conf.GetKeySet('IDLE Modern Unix')['<<newfoo>>'], '')
|
| 517 |
+
|
| 518 |
+
def test_is_core_binding(self):
|
| 519 |
+
# XXX: Should move out the core keys to config file or other place
|
| 520 |
+
conf = self.mock_config()
|
| 521 |
+
|
| 522 |
+
self.assertTrue(conf.IsCoreBinding('copy'))
|
| 523 |
+
self.assertTrue(conf.IsCoreBinding('cut'))
|
| 524 |
+
self.assertTrue(conf.IsCoreBinding('del-word-right'))
|
| 525 |
+
self.assertFalse(conf.IsCoreBinding('not-exists'))
|
| 526 |
+
|
| 527 |
+
def test_extra_help_source_list(self):
|
| 528 |
+
# Test GetExtraHelpSourceList and GetAllExtraHelpSourcesList in same
|
| 529 |
+
# place to prevent prepare input data twice.
|
| 530 |
+
conf = self.mock_config()
|
| 531 |
+
|
| 532 |
+
# Test default with no extra help source
|
| 533 |
+
self.assertEqual(conf.GetExtraHelpSourceList('default'), [])
|
| 534 |
+
self.assertEqual(conf.GetExtraHelpSourceList('user'), [])
|
| 535 |
+
with self.assertRaises(config.InvalidConfigSet):
|
| 536 |
+
self.assertEqual(conf.GetExtraHelpSourceList('bad'), [])
|
| 537 |
+
self.assertCountEqual(
|
| 538 |
+
conf.GetAllExtraHelpSourcesList(),
|
| 539 |
+
conf.GetExtraHelpSourceList('default') + conf.GetExtraHelpSourceList('user'))
|
| 540 |
+
|
| 541 |
+
# Add help source to user config
|
| 542 |
+
conf.userCfg['main'].SetOption('HelpFiles', '4', 'Python;https://python.org') # This is bad input
|
| 543 |
+
conf.userCfg['main'].SetOption('HelpFiles', '3', 'Python:https://python.org') # This is bad input
|
| 544 |
+
conf.userCfg['main'].SetOption('HelpFiles', '2', 'Pillow;https://pillow.readthedocs.io/en/latest/')
|
| 545 |
+
conf.userCfg['main'].SetOption('HelpFiles', '1', 'IDLE;C:/Programs/Python36/Lib/idlelib/help.html')
|
| 546 |
+
self.assertEqual(conf.GetExtraHelpSourceList('user'),
|
| 547 |
+
[('IDLE', 'C:/Programs/Python36/Lib/idlelib/help.html', '1'),
|
| 548 |
+
('Pillow', 'https://pillow.readthedocs.io/en/latest/', '2'),
|
| 549 |
+
('Python', 'https://python.org', '4')])
|
| 550 |
+
self.assertCountEqual(
|
| 551 |
+
conf.GetAllExtraHelpSourcesList(),
|
| 552 |
+
conf.GetExtraHelpSourceList('default') + conf.GetExtraHelpSourceList('user'))
|
| 553 |
+
|
| 554 |
+
def test_get_font(self):
|
| 555 |
+
from test.support import requires
|
| 556 |
+
from tkinter import Tk
|
| 557 |
+
from tkinter.font import Font
|
| 558 |
+
conf = self.mock_config()
|
| 559 |
+
|
| 560 |
+
requires('gui')
|
| 561 |
+
root = Tk()
|
| 562 |
+
root.withdraw()
|
| 563 |
+
|
| 564 |
+
f = Font.actual(Font(name='TkFixedFont', exists=True, root=root))
|
| 565 |
+
self.assertEqual(
|
| 566 |
+
conf.GetFont(root, 'main', 'EditorWindow'),
|
| 567 |
+
(f['family'], 10 if f['size'] <= 0 else f['size'], f['weight']))
|
| 568 |
+
|
| 569 |
+
# Cleanup root
|
| 570 |
+
root.destroy()
|
| 571 |
+
del root
|
| 572 |
+
|
| 573 |
+
def test_get_core_keys(self):
|
| 574 |
+
conf = self.mock_config()
|
| 575 |
+
|
| 576 |
+
eq = self.assertEqual
|
| 577 |
+
eq(conf.GetCoreKeys()['<<center-insert>>'], ['<Control-l>'])
|
| 578 |
+
eq(conf.GetCoreKeys()['<<copy>>'], ['<Control-c>', '<Control-C>'])
|
| 579 |
+
eq(conf.GetCoreKeys()['<<history-next>>'], ['<Alt-n>'])
|
| 580 |
+
eq(conf.GetCoreKeys('IDLE Classic Windows')['<<center-insert>>'],
|
| 581 |
+
['<Control-Key-l>', '<Control-Key-L>'])
|
| 582 |
+
eq(conf.GetCoreKeys('IDLE Classic OSX')['<<copy>>'], ['<Command-Key-c>'])
|
| 583 |
+
eq(conf.GetCoreKeys('IDLE Classic Unix')['<<history-next>>'],
|
| 584 |
+
['<Alt-Key-n>', '<Meta-Key-n>'])
|
| 585 |
+
eq(conf.GetCoreKeys('IDLE Modern Unix')['<<history-next>>'],
|
| 586 |
+
['<Alt-Key-n>', '<Meta-Key-n>'])
|
| 587 |
+
|
| 588 |
+
|
| 589 |
+
class CurrentColorKeysTest(unittest.TestCase):
|
| 590 |
+
""" Test colorkeys function with user config [Theme] and [Keys] patterns.
|
| 591 |
+
|
| 592 |
+
colorkeys = config.IdleConf.current_colors_and_keys
|
| 593 |
+
Test all patterns written by IDLE and some errors
|
| 594 |
+
Item 'default' should really be 'builtin' (versus 'custom).
|
| 595 |
+
"""
|
| 596 |
+
colorkeys = idleConf.current_colors_and_keys
|
| 597 |
+
default_theme = 'IDLE Classic'
|
| 598 |
+
default_keys = idleConf.default_keys()
|
| 599 |
+
|
| 600 |
+
def test_old_builtin_theme(self):
|
| 601 |
+
# On initial installation, user main is blank.
|
| 602 |
+
self.assertEqual(self.colorkeys('Theme'), self.default_theme)
|
| 603 |
+
# For old default, name2 must be blank.
|
| 604 |
+
usermain.read_string('''
|
| 605 |
+
[Theme]
|
| 606 |
+
default = True
|
| 607 |
+
''')
|
| 608 |
+
# IDLE omits 'name' for default old builtin theme.
|
| 609 |
+
self.assertEqual(self.colorkeys('Theme'), self.default_theme)
|
| 610 |
+
# IDLE adds 'name' for non-default old builtin theme.
|
| 611 |
+
usermain['Theme']['name'] = 'IDLE New'
|
| 612 |
+
self.assertEqual(self.colorkeys('Theme'), 'IDLE New')
|
| 613 |
+
# Erroneous non-default old builtin reverts to default.
|
| 614 |
+
usermain['Theme']['name'] = 'non-existent'
|
| 615 |
+
self.assertEqual(self.colorkeys('Theme'), self.default_theme)
|
| 616 |
+
usermain.remove_section('Theme')
|
| 617 |
+
|
| 618 |
+
def test_new_builtin_theme(self):
|
| 619 |
+
# IDLE writes name2 for new builtins.
|
| 620 |
+
usermain.read_string('''
|
| 621 |
+
[Theme]
|
| 622 |
+
default = True
|
| 623 |
+
name2 = IDLE Dark
|
| 624 |
+
''')
|
| 625 |
+
self.assertEqual(self.colorkeys('Theme'), 'IDLE Dark')
|
| 626 |
+
# Leftover 'name', not removed, is ignored.
|
| 627 |
+
usermain['Theme']['name'] = 'IDLE New'
|
| 628 |
+
self.assertEqual(self.colorkeys('Theme'), 'IDLE Dark')
|
| 629 |
+
# Erroneous non-default new builtin reverts to default.
|
| 630 |
+
usermain['Theme']['name2'] = 'non-existent'
|
| 631 |
+
self.assertEqual(self.colorkeys('Theme'), self.default_theme)
|
| 632 |
+
usermain.remove_section('Theme')
|
| 633 |
+
|
| 634 |
+
def test_user_override_theme(self):
|
| 635 |
+
# Erroneous custom name (no definition) reverts to default.
|
| 636 |
+
usermain.read_string('''
|
| 637 |
+
[Theme]
|
| 638 |
+
default = False
|
| 639 |
+
name = Custom Dark
|
| 640 |
+
''')
|
| 641 |
+
self.assertEqual(self.colorkeys('Theme'), self.default_theme)
|
| 642 |
+
# Custom name is valid with matching Section name.
|
| 643 |
+
userhigh.read_string('[Custom Dark]\na=b')
|
| 644 |
+
self.assertEqual(self.colorkeys('Theme'), 'Custom Dark')
|
| 645 |
+
# Name2 is ignored.
|
| 646 |
+
usermain['Theme']['name2'] = 'non-existent'
|
| 647 |
+
self.assertEqual(self.colorkeys('Theme'), 'Custom Dark')
|
| 648 |
+
usermain.remove_section('Theme')
|
| 649 |
+
userhigh.remove_section('Custom Dark')
|
| 650 |
+
|
| 651 |
+
def test_old_builtin_keys(self):
|
| 652 |
+
# On initial installation, user main is blank.
|
| 653 |
+
self.assertEqual(self.colorkeys('Keys'), self.default_keys)
|
| 654 |
+
# For old default, name2 must be blank, name is always used.
|
| 655 |
+
usermain.read_string('''
|
| 656 |
+
[Keys]
|
| 657 |
+
default = True
|
| 658 |
+
name = IDLE Classic Unix
|
| 659 |
+
''')
|
| 660 |
+
self.assertEqual(self.colorkeys('Keys'), 'IDLE Classic Unix')
|
| 661 |
+
# Erroneous non-default old builtin reverts to default.
|
| 662 |
+
usermain['Keys']['name'] = 'non-existent'
|
| 663 |
+
self.assertEqual(self.colorkeys('Keys'), self.default_keys)
|
| 664 |
+
usermain.remove_section('Keys')
|
| 665 |
+
|
| 666 |
+
def test_new_builtin_keys(self):
|
| 667 |
+
# IDLE writes name2 for new builtins.
|
| 668 |
+
usermain.read_string('''
|
| 669 |
+
[Keys]
|
| 670 |
+
default = True
|
| 671 |
+
name2 = IDLE Modern Unix
|
| 672 |
+
''')
|
| 673 |
+
self.assertEqual(self.colorkeys('Keys'), 'IDLE Modern Unix')
|
| 674 |
+
# Leftover 'name', not removed, is ignored.
|
| 675 |
+
usermain['Keys']['name'] = 'IDLE Classic Unix'
|
| 676 |
+
self.assertEqual(self.colorkeys('Keys'), 'IDLE Modern Unix')
|
| 677 |
+
# Erroneous non-default new builtin reverts to default.
|
| 678 |
+
usermain['Keys']['name2'] = 'non-existent'
|
| 679 |
+
self.assertEqual(self.colorkeys('Keys'), self.default_keys)
|
| 680 |
+
usermain.remove_section('Keys')
|
| 681 |
+
|
| 682 |
+
def test_user_override_keys(self):
|
| 683 |
+
# Erroneous custom name (no definition) reverts to default.
|
| 684 |
+
usermain.read_string('''
|
| 685 |
+
[Keys]
|
| 686 |
+
default = False
|
| 687 |
+
name = Custom Keys
|
| 688 |
+
''')
|
| 689 |
+
self.assertEqual(self.colorkeys('Keys'), self.default_keys)
|
| 690 |
+
# Custom name is valid with matching Section name.
|
| 691 |
+
userkeys.read_string('[Custom Keys]\na=b')
|
| 692 |
+
self.assertEqual(self.colorkeys('Keys'), 'Custom Keys')
|
| 693 |
+
# Name2 is ignored.
|
| 694 |
+
usermain['Keys']['name2'] = 'non-existent'
|
| 695 |
+
self.assertEqual(self.colorkeys('Keys'), 'Custom Keys')
|
| 696 |
+
usermain.remove_section('Keys')
|
| 697 |
+
userkeys.remove_section('Custom Keys')
|
| 698 |
+
|
| 699 |
+
|
| 700 |
+
class ChangesTest(unittest.TestCase):
|
| 701 |
+
|
| 702 |
+
empty = {'main':{}, 'highlight':{}, 'keys':{}, 'extensions':{}}
|
| 703 |
+
|
| 704 |
+
def load(self): # Test_add_option verifies that this works.
|
| 705 |
+
changes = self.changes
|
| 706 |
+
changes.add_option('main', 'Msec', 'mitem', 'mval')
|
| 707 |
+
changes.add_option('highlight', 'Hsec', 'hitem', 'hval')
|
| 708 |
+
changes.add_option('keys', 'Ksec', 'kitem', 'kval')
|
| 709 |
+
return changes
|
| 710 |
+
|
| 711 |
+
loaded = {'main': {'Msec': {'mitem': 'mval'}},
|
| 712 |
+
'highlight': {'Hsec': {'hitem': 'hval'}},
|
| 713 |
+
'keys': {'Ksec': {'kitem':'kval'}},
|
| 714 |
+
'extensions': {}}
|
| 715 |
+
|
| 716 |
+
def setUp(self):
|
| 717 |
+
self.changes = config.ConfigChanges()
|
| 718 |
+
|
| 719 |
+
def test_init(self):
|
| 720 |
+
self.assertEqual(self.changes, self.empty)
|
| 721 |
+
|
| 722 |
+
def test_add_option(self):
|
| 723 |
+
changes = self.load()
|
| 724 |
+
self.assertEqual(changes, self.loaded)
|
| 725 |
+
changes.add_option('main', 'Msec', 'mitem', 'mval')
|
| 726 |
+
self.assertEqual(changes, self.loaded)
|
| 727 |
+
|
| 728 |
+
def test_save_option(self): # Static function does not touch changes.
|
| 729 |
+
save_option = self.changes.save_option
|
| 730 |
+
self.assertTrue(save_option('main', 'Indent', 'what', '0'))
|
| 731 |
+
self.assertFalse(save_option('main', 'Indent', 'what', '0'))
|
| 732 |
+
self.assertEqual(usermain['Indent']['what'], '0')
|
| 733 |
+
|
| 734 |
+
self.assertTrue(save_option('main', 'Indent', 'use-spaces', '0'))
|
| 735 |
+
self.assertEqual(usermain['Indent']['use-spaces'], '0')
|
| 736 |
+
self.assertTrue(save_option('main', 'Indent', 'use-spaces', '1'))
|
| 737 |
+
self.assertFalse(usermain.has_option('Indent', 'use-spaces'))
|
| 738 |
+
usermain.remove_section('Indent')
|
| 739 |
+
|
| 740 |
+
def test_save_added(self):
|
| 741 |
+
changes = self.load()
|
| 742 |
+
self.assertTrue(changes.save_all())
|
| 743 |
+
self.assertEqual(usermain['Msec']['mitem'], 'mval')
|
| 744 |
+
self.assertEqual(userhigh['Hsec']['hitem'], 'hval')
|
| 745 |
+
self.assertEqual(userkeys['Ksec']['kitem'], 'kval')
|
| 746 |
+
changes.add_option('main', 'Msec', 'mitem', 'mval')
|
| 747 |
+
self.assertFalse(changes.save_all())
|
| 748 |
+
usermain.remove_section('Msec')
|
| 749 |
+
userhigh.remove_section('Hsec')
|
| 750 |
+
userkeys.remove_section('Ksec')
|
| 751 |
+
|
| 752 |
+
def test_save_help(self):
|
| 753 |
+
# Any change to HelpFiles overwrites entire section.
|
| 754 |
+
changes = self.changes
|
| 755 |
+
changes.save_option('main', 'HelpFiles', 'IDLE', 'idledoc')
|
| 756 |
+
changes.add_option('main', 'HelpFiles', 'ELDI', 'codeldi')
|
| 757 |
+
changes.save_all()
|
| 758 |
+
self.assertFalse(usermain.has_option('HelpFiles', 'IDLE'))
|
| 759 |
+
self.assertTrue(usermain.has_option('HelpFiles', 'ELDI'))
|
| 760 |
+
|
| 761 |
+
def test_save_default(self): # Cover 2nd and 3rd false branches.
|
| 762 |
+
changes = self.changes
|
| 763 |
+
changes.add_option('main', 'Indent', 'use-spaces', '1')
|
| 764 |
+
# save_option returns False; cfg_type_changed remains False.
|
| 765 |
+
|
| 766 |
+
# TODO: test that save_all calls usercfg Saves.
|
| 767 |
+
|
| 768 |
+
def test_delete_section(self):
|
| 769 |
+
changes = self.load()
|
| 770 |
+
changes.delete_section('main', 'fake') # Test no exception.
|
| 771 |
+
self.assertEqual(changes, self.loaded) # Test nothing deleted.
|
| 772 |
+
for cfgtype, section in (('main', 'Msec'), ('keys', 'Ksec')):
|
| 773 |
+
testcfg[cfgtype].SetOption(section, 'name', 'value')
|
| 774 |
+
changes.delete_section(cfgtype, section)
|
| 775 |
+
with self.assertRaises(KeyError):
|
| 776 |
+
changes[cfgtype][section] # Test section gone from changes
|
| 777 |
+
testcfg[cfgtype][section] # and from mock userCfg.
|
| 778 |
+
# TODO test for save call.
|
| 779 |
+
|
| 780 |
+
def test_clear(self):
|
| 781 |
+
changes = self.load()
|
| 782 |
+
changes.clear()
|
| 783 |
+
self.assertEqual(changes, self.empty)
|
| 784 |
+
|
| 785 |
+
|
| 786 |
+
class WarningTest(unittest.TestCase):
|
| 787 |
+
|
| 788 |
+
def test_warn(self):
|
| 789 |
+
Equal = self.assertEqual
|
| 790 |
+
config._warned = set()
|
| 791 |
+
with captured_stderr() as stderr:
|
| 792 |
+
config._warn('warning', 'key')
|
| 793 |
+
Equal(config._warned, {('warning','key')})
|
| 794 |
+
Equal(stderr.getvalue(), 'warning'+'\n')
|
| 795 |
+
with captured_stderr() as stderr:
|
| 796 |
+
config._warn('warning', 'key')
|
| 797 |
+
Equal(stderr.getvalue(), '')
|
| 798 |
+
with captured_stderr() as stderr:
|
| 799 |
+
config._warn('warn2', 'yek')
|
| 800 |
+
Equal(config._warned, {('warning','key'), ('warn2','yek')})
|
| 801 |
+
Equal(stderr.getvalue(), 'warn2'+'\n')
|
| 802 |
+
|
| 803 |
+
|
| 804 |
+
if __name__ == '__main__':
|
| 805 |
+
unittest.main(verbosity=2)
|
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/test_config_key.py
ADDED
|
@@ -0,0 +1,356 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Test config_key, coverage 98%.
|
| 2 |
+
|
| 3 |
+
Coverage is effectively 100%. Tkinter dialog is mocked, Mac-only line
|
| 4 |
+
may be skipped, and dummy function in bind test should not be called.
|
| 5 |
+
Not tested: exit with 'self.advanced or self.keys_ok(keys) ...' False.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
from idlelib import config_key
|
| 9 |
+
from test.support import requires
|
| 10 |
+
import unittest
|
| 11 |
+
from unittest import mock
|
| 12 |
+
from tkinter import Tk, TclError
|
| 13 |
+
from idlelib.idle_test.mock_idle import Func
|
| 14 |
+
from idlelib.idle_test.mock_tk import Mbox_func
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
class ValidationTest(unittest.TestCase):
|
| 18 |
+
"Test validation methods: ok, keys_ok, bind_ok."
|
| 19 |
+
|
| 20 |
+
class Validator(config_key.GetKeysFrame):
|
| 21 |
+
def __init__(self, *args, **kwargs):
|
| 22 |
+
super().__init__(*args, **kwargs)
|
| 23 |
+
class list_keys_final:
|
| 24 |
+
get = Func()
|
| 25 |
+
self.list_keys_final = list_keys_final
|
| 26 |
+
get_modifiers = Func()
|
| 27 |
+
showerror = Mbox_func()
|
| 28 |
+
|
| 29 |
+
@classmethod
|
| 30 |
+
def setUpClass(cls):
|
| 31 |
+
requires('gui')
|
| 32 |
+
cls.root = Tk()
|
| 33 |
+
cls.root.withdraw()
|
| 34 |
+
keylist = [['<Key-F12>'], ['<Control-Key-x>', '<Control-Key-X>']]
|
| 35 |
+
cls.dialog = cls.Validator(cls.root, '<<Test>>', keylist)
|
| 36 |
+
|
| 37 |
+
@classmethod
|
| 38 |
+
def tearDownClass(cls):
|
| 39 |
+
del cls.dialog
|
| 40 |
+
cls.root.update_idletasks()
|
| 41 |
+
cls.root.destroy()
|
| 42 |
+
del cls.root
|
| 43 |
+
|
| 44 |
+
def setUp(self):
|
| 45 |
+
self.dialog.showerror.message = ''
|
| 46 |
+
# A test that needs a particular final key value should set it.
|
| 47 |
+
# A test that sets a non-blank modifier list should reset it to [].
|
| 48 |
+
|
| 49 |
+
def test_ok_empty(self):
|
| 50 |
+
self.dialog.key_string.set(' ')
|
| 51 |
+
self.dialog.ok()
|
| 52 |
+
self.assertEqual(self.dialog.result, '')
|
| 53 |
+
self.assertEqual(self.dialog.showerror.message, 'No key specified.')
|
| 54 |
+
|
| 55 |
+
def test_ok_good(self):
|
| 56 |
+
self.dialog.key_string.set('<Key-F11>')
|
| 57 |
+
self.dialog.list_keys_final.get.result = 'F11'
|
| 58 |
+
self.dialog.ok()
|
| 59 |
+
self.assertEqual(self.dialog.result, '<Key-F11>')
|
| 60 |
+
self.assertEqual(self.dialog.showerror.message, '')
|
| 61 |
+
|
| 62 |
+
def test_keys_no_ending(self):
|
| 63 |
+
self.assertFalse(self.dialog.keys_ok('<Control-Shift'))
|
| 64 |
+
self.assertIn('Missing the final', self.dialog.showerror.message)
|
| 65 |
+
|
| 66 |
+
def test_keys_no_modifier_bad(self):
|
| 67 |
+
self.dialog.list_keys_final.get.result = 'A'
|
| 68 |
+
self.assertFalse(self.dialog.keys_ok('<Key-A>'))
|
| 69 |
+
self.assertIn('No modifier', self.dialog.showerror.message)
|
| 70 |
+
|
| 71 |
+
def test_keys_no_modifier_ok(self):
|
| 72 |
+
self.dialog.list_keys_final.get.result = 'F11'
|
| 73 |
+
self.assertTrue(self.dialog.keys_ok('<Key-F11>'))
|
| 74 |
+
self.assertEqual(self.dialog.showerror.message, '')
|
| 75 |
+
|
| 76 |
+
def test_keys_shift_bad(self):
|
| 77 |
+
self.dialog.list_keys_final.get.result = 'a'
|
| 78 |
+
self.dialog.get_modifiers.result = ['Shift']
|
| 79 |
+
self.assertFalse(self.dialog.keys_ok('<a>'))
|
| 80 |
+
self.assertIn('shift modifier', self.dialog.showerror.message)
|
| 81 |
+
self.dialog.get_modifiers.result = []
|
| 82 |
+
|
| 83 |
+
def test_keys_dup(self):
|
| 84 |
+
for mods, final, seq in (([], 'F12', '<Key-F12>'),
|
| 85 |
+
(['Control'], 'x', '<Control-Key-x>'),
|
| 86 |
+
(['Control'], 'X', '<Control-Key-X>')):
|
| 87 |
+
with self.subTest(m=mods, f=final, s=seq):
|
| 88 |
+
self.dialog.list_keys_final.get.result = final
|
| 89 |
+
self.dialog.get_modifiers.result = mods
|
| 90 |
+
self.assertFalse(self.dialog.keys_ok(seq))
|
| 91 |
+
self.assertIn('already in use', self.dialog.showerror.message)
|
| 92 |
+
self.dialog.get_modifiers.result = []
|
| 93 |
+
|
| 94 |
+
def test_bind_ok(self):
|
| 95 |
+
self.assertTrue(self.dialog.bind_ok('<Control-Shift-Key-a>'))
|
| 96 |
+
self.assertEqual(self.dialog.showerror.message, '')
|
| 97 |
+
|
| 98 |
+
def test_bind_not_ok(self):
|
| 99 |
+
self.assertFalse(self.dialog.bind_ok('<Control-Shift>'))
|
| 100 |
+
self.assertIn('not accepted', self.dialog.showerror.message)
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
class ToggleLevelTest(unittest.TestCase):
|
| 104 |
+
"Test toggle between Basic and Advanced frames."
|
| 105 |
+
|
| 106 |
+
@classmethod
|
| 107 |
+
def setUpClass(cls):
|
| 108 |
+
requires('gui')
|
| 109 |
+
cls.root = Tk()
|
| 110 |
+
cls.root.withdraw()
|
| 111 |
+
cls.dialog = config_key.GetKeysFrame(cls.root, '<<Test>>', [])
|
| 112 |
+
|
| 113 |
+
@classmethod
|
| 114 |
+
def tearDownClass(cls):
|
| 115 |
+
del cls.dialog
|
| 116 |
+
cls.root.update_idletasks()
|
| 117 |
+
cls.root.destroy()
|
| 118 |
+
del cls.root
|
| 119 |
+
|
| 120 |
+
def test_toggle_level(self):
|
| 121 |
+
dialog = self.dialog
|
| 122 |
+
|
| 123 |
+
def stackorder():
|
| 124 |
+
"""Get the stack order of the children of the frame.
|
| 125 |
+
|
| 126 |
+
winfo_children() stores the children in stack order, so
|
| 127 |
+
this can be used to check whether a frame is above or
|
| 128 |
+
below another one.
|
| 129 |
+
"""
|
| 130 |
+
for index, child in enumerate(dialog.winfo_children()):
|
| 131 |
+
if child._name == 'keyseq_basic':
|
| 132 |
+
basic = index
|
| 133 |
+
if child._name == 'keyseq_advanced':
|
| 134 |
+
advanced = index
|
| 135 |
+
return basic, advanced
|
| 136 |
+
|
| 137 |
+
# New window starts at basic level.
|
| 138 |
+
self.assertFalse(dialog.advanced)
|
| 139 |
+
self.assertIn('Advanced', dialog.button_level['text'])
|
| 140 |
+
basic, advanced = stackorder()
|
| 141 |
+
self.assertGreater(basic, advanced)
|
| 142 |
+
|
| 143 |
+
# Toggle to advanced.
|
| 144 |
+
dialog.toggle_level()
|
| 145 |
+
self.assertTrue(dialog.advanced)
|
| 146 |
+
self.assertIn('Basic', dialog.button_level['text'])
|
| 147 |
+
basic, advanced = stackorder()
|
| 148 |
+
self.assertGreater(advanced, basic)
|
| 149 |
+
|
| 150 |
+
# Toggle to basic.
|
| 151 |
+
dialog.button_level.invoke()
|
| 152 |
+
self.assertFalse(dialog.advanced)
|
| 153 |
+
self.assertIn('Advanced', dialog.button_level['text'])
|
| 154 |
+
basic, advanced = stackorder()
|
| 155 |
+
self.assertGreater(basic, advanced)
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
class KeySelectionTest(unittest.TestCase):
|
| 159 |
+
"Test selecting key on Basic frames."
|
| 160 |
+
|
| 161 |
+
class Basic(config_key.GetKeysFrame):
|
| 162 |
+
def __init__(self, *args, **kwargs):
|
| 163 |
+
super().__init__(*args, **kwargs)
|
| 164 |
+
class list_keys_final:
|
| 165 |
+
get = Func()
|
| 166 |
+
select_clear = Func()
|
| 167 |
+
yview = Func()
|
| 168 |
+
self.list_keys_final = list_keys_final
|
| 169 |
+
def set_modifiers_for_platform(self):
|
| 170 |
+
self.modifiers = ['foo', 'bar', 'BAZ']
|
| 171 |
+
self.modifier_label = {'BAZ': 'ZZZ'}
|
| 172 |
+
showerror = Mbox_func()
|
| 173 |
+
|
| 174 |
+
@classmethod
|
| 175 |
+
def setUpClass(cls):
|
| 176 |
+
requires('gui')
|
| 177 |
+
cls.root = Tk()
|
| 178 |
+
cls.root.withdraw()
|
| 179 |
+
cls.dialog = cls.Basic(cls.root, '<<Test>>', [])
|
| 180 |
+
|
| 181 |
+
@classmethod
|
| 182 |
+
def tearDownClass(cls):
|
| 183 |
+
del cls.dialog
|
| 184 |
+
cls.root.update_idletasks()
|
| 185 |
+
cls.root.destroy()
|
| 186 |
+
del cls.root
|
| 187 |
+
|
| 188 |
+
def setUp(self):
|
| 189 |
+
self.dialog.clear_key_seq()
|
| 190 |
+
|
| 191 |
+
def test_get_modifiers(self):
|
| 192 |
+
dialog = self.dialog
|
| 193 |
+
gm = dialog.get_modifiers
|
| 194 |
+
eq = self.assertEqual
|
| 195 |
+
|
| 196 |
+
# Modifiers are set on/off by invoking the checkbutton.
|
| 197 |
+
dialog.modifier_checkbuttons['foo'].invoke()
|
| 198 |
+
eq(gm(), ['foo'])
|
| 199 |
+
|
| 200 |
+
dialog.modifier_checkbuttons['BAZ'].invoke()
|
| 201 |
+
eq(gm(), ['foo', 'BAZ'])
|
| 202 |
+
|
| 203 |
+
dialog.modifier_checkbuttons['foo'].invoke()
|
| 204 |
+
eq(gm(), ['BAZ'])
|
| 205 |
+
|
| 206 |
+
@mock.patch.object(config_key.GetKeysFrame, 'get_modifiers')
|
| 207 |
+
def test_build_key_string(self, mock_modifiers):
|
| 208 |
+
dialog = self.dialog
|
| 209 |
+
key = dialog.list_keys_final
|
| 210 |
+
string = dialog.key_string.get
|
| 211 |
+
eq = self.assertEqual
|
| 212 |
+
|
| 213 |
+
key.get.result = 'a'
|
| 214 |
+
mock_modifiers.return_value = []
|
| 215 |
+
dialog.build_key_string()
|
| 216 |
+
eq(string(), '<Key-a>')
|
| 217 |
+
|
| 218 |
+
mock_modifiers.return_value = ['mymod']
|
| 219 |
+
dialog.build_key_string()
|
| 220 |
+
eq(string(), '<mymod-Key-a>')
|
| 221 |
+
|
| 222 |
+
key.get.result = ''
|
| 223 |
+
mock_modifiers.return_value = ['mymod', 'test']
|
| 224 |
+
dialog.build_key_string()
|
| 225 |
+
eq(string(), '<mymod-test>')
|
| 226 |
+
|
| 227 |
+
@mock.patch.object(config_key.GetKeysFrame, 'get_modifiers')
|
| 228 |
+
def test_final_key_selected(self, mock_modifiers):
|
| 229 |
+
dialog = self.dialog
|
| 230 |
+
key = dialog.list_keys_final
|
| 231 |
+
string = dialog.key_string.get
|
| 232 |
+
eq = self.assertEqual
|
| 233 |
+
|
| 234 |
+
mock_modifiers.return_value = ['Shift']
|
| 235 |
+
key.get.result = '{'
|
| 236 |
+
dialog.final_key_selected()
|
| 237 |
+
eq(string(), '<Shift-Key-braceleft>')
|
| 238 |
+
|
| 239 |
+
|
| 240 |
+
class CancelWindowTest(unittest.TestCase):
|
| 241 |
+
"Simulate user clicking [Cancel] button."
|
| 242 |
+
|
| 243 |
+
@classmethod
|
| 244 |
+
def setUpClass(cls):
|
| 245 |
+
requires('gui')
|
| 246 |
+
cls.root = Tk()
|
| 247 |
+
cls.root.withdraw()
|
| 248 |
+
cls.dialog = config_key.GetKeysWindow(
|
| 249 |
+
cls.root, 'Title', '<<Test>>', [], _utest=True)
|
| 250 |
+
|
| 251 |
+
@classmethod
|
| 252 |
+
def tearDownClass(cls):
|
| 253 |
+
cls.dialog.cancel()
|
| 254 |
+
del cls.dialog
|
| 255 |
+
cls.root.update_idletasks()
|
| 256 |
+
cls.root.destroy()
|
| 257 |
+
del cls.root
|
| 258 |
+
|
| 259 |
+
@mock.patch.object(config_key.GetKeysFrame, 'ok')
|
| 260 |
+
def test_cancel(self, mock_frame_ok):
|
| 261 |
+
self.assertEqual(self.dialog.winfo_class(), 'Toplevel')
|
| 262 |
+
self.dialog.button_cancel.invoke()
|
| 263 |
+
with self.assertRaises(TclError):
|
| 264 |
+
self.dialog.winfo_class()
|
| 265 |
+
self.assertEqual(self.dialog.result, '')
|
| 266 |
+
mock_frame_ok.assert_not_called()
|
| 267 |
+
|
| 268 |
+
|
| 269 |
+
class OKWindowTest(unittest.TestCase):
|
| 270 |
+
"Simulate user clicking [OK] button."
|
| 271 |
+
|
| 272 |
+
@classmethod
|
| 273 |
+
def setUpClass(cls):
|
| 274 |
+
requires('gui')
|
| 275 |
+
cls.root = Tk()
|
| 276 |
+
cls.root.withdraw()
|
| 277 |
+
cls.dialog = config_key.GetKeysWindow(
|
| 278 |
+
cls.root, 'Title', '<<Test>>', [], _utest=True)
|
| 279 |
+
|
| 280 |
+
@classmethod
|
| 281 |
+
def tearDownClass(cls):
|
| 282 |
+
cls.dialog.cancel()
|
| 283 |
+
del cls.dialog
|
| 284 |
+
cls.root.update_idletasks()
|
| 285 |
+
cls.root.destroy()
|
| 286 |
+
del cls.root
|
| 287 |
+
|
| 288 |
+
@mock.patch.object(config_key.GetKeysFrame, 'ok')
|
| 289 |
+
def test_ok(self, mock_frame_ok):
|
| 290 |
+
self.assertEqual(self.dialog.winfo_class(), 'Toplevel')
|
| 291 |
+
self.dialog.button_ok.invoke()
|
| 292 |
+
with self.assertRaises(TclError):
|
| 293 |
+
self.dialog.winfo_class()
|
| 294 |
+
mock_frame_ok.assert_called()
|
| 295 |
+
|
| 296 |
+
|
| 297 |
+
class WindowResultTest(unittest.TestCase):
|
| 298 |
+
"Test window result get and set."
|
| 299 |
+
|
| 300 |
+
@classmethod
|
| 301 |
+
def setUpClass(cls):
|
| 302 |
+
requires('gui')
|
| 303 |
+
cls.root = Tk()
|
| 304 |
+
cls.root.withdraw()
|
| 305 |
+
cls.dialog = config_key.GetKeysWindow(
|
| 306 |
+
cls.root, 'Title', '<<Test>>', [], _utest=True)
|
| 307 |
+
|
| 308 |
+
@classmethod
|
| 309 |
+
def tearDownClass(cls):
|
| 310 |
+
cls.dialog.cancel()
|
| 311 |
+
del cls.dialog
|
| 312 |
+
cls.root.update_idletasks()
|
| 313 |
+
cls.root.destroy()
|
| 314 |
+
del cls.root
|
| 315 |
+
|
| 316 |
+
def test_result(self):
|
| 317 |
+
dialog = self.dialog
|
| 318 |
+
eq = self.assertEqual
|
| 319 |
+
|
| 320 |
+
dialog.result = ''
|
| 321 |
+
eq(dialog.result, '')
|
| 322 |
+
eq(dialog.frame.result,'')
|
| 323 |
+
|
| 324 |
+
dialog.result = 'bar'
|
| 325 |
+
eq(dialog.result,'bar')
|
| 326 |
+
eq(dialog.frame.result,'bar')
|
| 327 |
+
|
| 328 |
+
dialog.frame.result = 'foo'
|
| 329 |
+
eq(dialog.result, 'foo')
|
| 330 |
+
eq(dialog.frame.result,'foo')
|
| 331 |
+
|
| 332 |
+
|
| 333 |
+
class HelperTest(unittest.TestCase):
|
| 334 |
+
"Test module level helper functions."
|
| 335 |
+
|
| 336 |
+
def test_translate_key(self):
|
| 337 |
+
tr = config_key.translate_key
|
| 338 |
+
eq = self.assertEqual
|
| 339 |
+
|
| 340 |
+
# Letters return unchanged with no 'Shift'.
|
| 341 |
+
eq(tr('q', []), 'Key-q')
|
| 342 |
+
eq(tr('q', ['Control', 'Alt']), 'Key-q')
|
| 343 |
+
|
| 344 |
+
# 'Shift' uppercases single lowercase letters.
|
| 345 |
+
eq(tr('q', ['Shift']), 'Key-Q')
|
| 346 |
+
eq(tr('q', ['Control', 'Shift']), 'Key-Q')
|
| 347 |
+
eq(tr('q', ['Control', 'Alt', 'Shift']), 'Key-Q')
|
| 348 |
+
|
| 349 |
+
# Convert key name to keysym.
|
| 350 |
+
eq(tr('Page Up', []), 'Key-Prior')
|
| 351 |
+
# 'Shift' doesn't change case when it's not a single char.
|
| 352 |
+
eq(tr('*', ['Shift']), 'Key-asterisk')
|
| 353 |
+
|
| 354 |
+
|
| 355 |
+
if __name__ == '__main__':
|
| 356 |
+
unittest.main(verbosity=2)
|
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/test_configdialog.py
ADDED
|
@@ -0,0 +1,1581 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Test configdialog, coverage 94%.
|
| 2 |
+
|
| 3 |
+
Half the class creates dialog, half works with user customizations.
|
| 4 |
+
"""
|
| 5 |
+
from idlelib import configdialog
|
| 6 |
+
from test.support import requires
|
| 7 |
+
requires('gui')
|
| 8 |
+
from test.support.testcase import ExtraAssertions
|
| 9 |
+
import unittest
|
| 10 |
+
from unittest import mock
|
| 11 |
+
from idlelib.idle_test.mock_idle import Func
|
| 12 |
+
from tkinter import (Tk, StringVar, IntVar, BooleanVar, DISABLED, NORMAL)
|
| 13 |
+
from idlelib import config
|
| 14 |
+
from idlelib.configdialog import idleConf, changes, tracers
|
| 15 |
+
|
| 16 |
+
# Tests should not depend on fortuitous user configurations.
|
| 17 |
+
# They must not affect actual user .cfg files.
|
| 18 |
+
# Use solution from test_config: empty parsers with no filename.
|
| 19 |
+
usercfg = idleConf.userCfg
|
| 20 |
+
testcfg = {
|
| 21 |
+
'main': config.IdleUserConfParser(''),
|
| 22 |
+
'highlight': config.IdleUserConfParser(''),
|
| 23 |
+
'keys': config.IdleUserConfParser(''),
|
| 24 |
+
'extensions': config.IdleUserConfParser(''),
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
root = None
|
| 28 |
+
dialog = None
|
| 29 |
+
mainpage = changes['main']
|
| 30 |
+
highpage = changes['highlight']
|
| 31 |
+
keyspage = changes['keys']
|
| 32 |
+
extpage = changes['extensions']
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def setUpModule():
|
| 36 |
+
global root, dialog
|
| 37 |
+
idleConf.userCfg = testcfg
|
| 38 |
+
root = Tk()
|
| 39 |
+
# root.withdraw() # Comment out, see issue 30870
|
| 40 |
+
dialog = configdialog.ConfigDialog(root, 'Test', _utest=True)
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def tearDownModule():
|
| 44 |
+
global root, dialog
|
| 45 |
+
idleConf.userCfg = usercfg
|
| 46 |
+
tracers.detach()
|
| 47 |
+
tracers.clear()
|
| 48 |
+
changes.clear()
|
| 49 |
+
root.update_idletasks()
|
| 50 |
+
root.destroy()
|
| 51 |
+
root = dialog = None
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
class ConfigDialogTest(unittest.TestCase):
|
| 55 |
+
|
| 56 |
+
def test_deactivate_current_config(self):
|
| 57 |
+
pass
|
| 58 |
+
|
| 59 |
+
def activate_config_changes(self):
|
| 60 |
+
pass
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
class ButtonTest(unittest.TestCase, ExtraAssertions):
|
| 64 |
+
|
| 65 |
+
def test_click_ok(self):
|
| 66 |
+
d = dialog
|
| 67 |
+
apply = d.apply = mock.Mock()
|
| 68 |
+
destroy = d.destroy = mock.Mock()
|
| 69 |
+
d.buttons['Ok'].invoke()
|
| 70 |
+
apply.assert_called_once()
|
| 71 |
+
destroy.assert_called_once()
|
| 72 |
+
del d.destroy, d.apply
|
| 73 |
+
|
| 74 |
+
def test_click_apply(self):
|
| 75 |
+
d = dialog
|
| 76 |
+
deactivate = d.deactivate_current_config = mock.Mock()
|
| 77 |
+
save_ext = d.extpage.save_all_changed_extensions = mock.Mock()
|
| 78 |
+
activate = d.activate_config_changes = mock.Mock()
|
| 79 |
+
d.buttons['Apply'].invoke()
|
| 80 |
+
deactivate.assert_called_once()
|
| 81 |
+
save_ext.assert_called_once()
|
| 82 |
+
activate.assert_called_once()
|
| 83 |
+
del d.extpage.save_all_changed_extensions
|
| 84 |
+
del d.activate_config_changes, d.deactivate_current_config
|
| 85 |
+
|
| 86 |
+
def test_click_cancel(self):
|
| 87 |
+
d = dialog
|
| 88 |
+
d.destroy = Func()
|
| 89 |
+
changes['main']['something'] = 1
|
| 90 |
+
d.buttons['Cancel'].invoke()
|
| 91 |
+
self.assertEqual(changes['main'], {})
|
| 92 |
+
self.assertEqual(d.destroy.called, 1)
|
| 93 |
+
del d.destroy
|
| 94 |
+
|
| 95 |
+
def test_click_help(self):
|
| 96 |
+
dialog.note.select(dialog.keyspage)
|
| 97 |
+
with mock.patch.object(configdialog, 'view_text',
|
| 98 |
+
new_callable=Func) as view:
|
| 99 |
+
dialog.buttons['Help'].invoke()
|
| 100 |
+
title, contents = view.kwds['title'], view.kwds['contents']
|
| 101 |
+
self.assertEqual(title, 'Help for IDLE preferences')
|
| 102 |
+
self.assertStartsWith(contents, 'When you click')
|
| 103 |
+
self.assertEndsWith(contents,'a different name.\n')
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
class FontPageTest(unittest.TestCase):
|
| 107 |
+
"""Test that font widgets enable users to make font changes.
|
| 108 |
+
|
| 109 |
+
Test that widget actions set vars, that var changes add three
|
| 110 |
+
options to changes and call set_samples, and that set_samples
|
| 111 |
+
changes the font of both sample boxes.
|
| 112 |
+
"""
|
| 113 |
+
@classmethod
|
| 114 |
+
def setUpClass(cls):
|
| 115 |
+
page = cls.page = dialog.fontpage
|
| 116 |
+
dialog.note.select(page)
|
| 117 |
+
page.set_samples = Func() # Mask instance method.
|
| 118 |
+
page.update()
|
| 119 |
+
|
| 120 |
+
@classmethod
|
| 121 |
+
def tearDownClass(cls):
|
| 122 |
+
del cls.page.set_samples # Unmask instance method.
|
| 123 |
+
|
| 124 |
+
def setUp(self):
|
| 125 |
+
changes.clear()
|
| 126 |
+
|
| 127 |
+
def test_load_font_cfg(self):
|
| 128 |
+
# Leave widget load test to human visual check.
|
| 129 |
+
# TODO Improve checks when add IdleConf.get_font_values.
|
| 130 |
+
tracers.detach()
|
| 131 |
+
d = self.page
|
| 132 |
+
d.font_name.set('Fake')
|
| 133 |
+
d.font_size.set('1')
|
| 134 |
+
d.font_bold.set(True)
|
| 135 |
+
d.set_samples.called = 0
|
| 136 |
+
d.load_font_cfg()
|
| 137 |
+
self.assertNotEqual(d.font_name.get(), 'Fake')
|
| 138 |
+
self.assertNotEqual(d.font_size.get(), '1')
|
| 139 |
+
self.assertFalse(d.font_bold.get())
|
| 140 |
+
self.assertEqual(d.set_samples.called, 1)
|
| 141 |
+
tracers.attach()
|
| 142 |
+
|
| 143 |
+
def test_fontlist_key(self):
|
| 144 |
+
# Up and Down keys should select a new font.
|
| 145 |
+
d = self.page
|
| 146 |
+
if d.fontlist.size() < 2:
|
| 147 |
+
self.skipTest('need at least 2 fonts')
|
| 148 |
+
fontlist = d.fontlist
|
| 149 |
+
fontlist.activate(0)
|
| 150 |
+
font = d.fontlist.get('active')
|
| 151 |
+
|
| 152 |
+
# Test Down key.
|
| 153 |
+
fontlist.focus_force()
|
| 154 |
+
fontlist.update()
|
| 155 |
+
fontlist.event_generate('<Key-Down>')
|
| 156 |
+
fontlist.event_generate('<KeyRelease-Down>')
|
| 157 |
+
|
| 158 |
+
down_font = fontlist.get('active')
|
| 159 |
+
self.assertNotEqual(down_font, font)
|
| 160 |
+
self.assertIn(d.font_name.get(), down_font.lower())
|
| 161 |
+
|
| 162 |
+
# Test Up key.
|
| 163 |
+
fontlist.focus_force()
|
| 164 |
+
fontlist.update()
|
| 165 |
+
fontlist.event_generate('<Key-Up>')
|
| 166 |
+
fontlist.event_generate('<KeyRelease-Up>')
|
| 167 |
+
|
| 168 |
+
up_font = fontlist.get('active')
|
| 169 |
+
self.assertEqual(up_font, font)
|
| 170 |
+
self.assertIn(d.font_name.get(), up_font.lower())
|
| 171 |
+
|
| 172 |
+
def test_fontlist_mouse(self):
|
| 173 |
+
# Click on item should select that item.
|
| 174 |
+
d = self.page
|
| 175 |
+
if d.fontlist.size() < 2:
|
| 176 |
+
self.skipTest('need at least 2 fonts')
|
| 177 |
+
fontlist = d.fontlist
|
| 178 |
+
fontlist.activate(0)
|
| 179 |
+
|
| 180 |
+
# Select next item in listbox
|
| 181 |
+
fontlist.focus_force()
|
| 182 |
+
fontlist.see(1)
|
| 183 |
+
fontlist.update()
|
| 184 |
+
x, y, dx, dy = fontlist.bbox(1)
|
| 185 |
+
x += dx // 2
|
| 186 |
+
y += dy // 2
|
| 187 |
+
fontlist.event_generate('<Button-1>', x=x, y=y)
|
| 188 |
+
fontlist.event_generate('<ButtonRelease-1>', x=x, y=y)
|
| 189 |
+
|
| 190 |
+
font1 = fontlist.get(1)
|
| 191 |
+
select_font = fontlist.get('anchor')
|
| 192 |
+
self.assertEqual(select_font, font1)
|
| 193 |
+
self.assertIn(d.font_name.get(), font1.lower())
|
| 194 |
+
|
| 195 |
+
def test_sizelist(self):
|
| 196 |
+
# Click on number should select that number
|
| 197 |
+
d = self.page
|
| 198 |
+
d.sizelist.variable.set(40)
|
| 199 |
+
self.assertEqual(d.font_size.get(), '40')
|
| 200 |
+
|
| 201 |
+
def test_bold_toggle(self):
|
| 202 |
+
# Click on checkbutton should invert it.
|
| 203 |
+
d = self.page
|
| 204 |
+
d.font_bold.set(False)
|
| 205 |
+
d.bold_toggle.invoke()
|
| 206 |
+
self.assertTrue(d.font_bold.get())
|
| 207 |
+
d.bold_toggle.invoke()
|
| 208 |
+
self.assertFalse(d.font_bold.get())
|
| 209 |
+
|
| 210 |
+
def test_font_set(self):
|
| 211 |
+
# Test that setting a font Variable results in 3 provisional
|
| 212 |
+
# change entries and a call to set_samples. Use values sure to
|
| 213 |
+
# not be defaults.
|
| 214 |
+
|
| 215 |
+
default_font = idleConf.GetFont(root, 'main', 'EditorWindow')
|
| 216 |
+
default_size = str(default_font[1])
|
| 217 |
+
default_bold = default_font[2] == 'bold'
|
| 218 |
+
d = self.page
|
| 219 |
+
d.font_size.set(default_size)
|
| 220 |
+
d.font_bold.set(default_bold)
|
| 221 |
+
d.set_samples.called = 0
|
| 222 |
+
|
| 223 |
+
d.font_name.set('Test Font')
|
| 224 |
+
expected = {'EditorWindow': {'font': 'Test Font',
|
| 225 |
+
'font-size': default_size,
|
| 226 |
+
'font-bold': str(default_bold)}}
|
| 227 |
+
self.assertEqual(mainpage, expected)
|
| 228 |
+
self.assertEqual(d.set_samples.called, 1)
|
| 229 |
+
changes.clear()
|
| 230 |
+
|
| 231 |
+
d.font_size.set('20')
|
| 232 |
+
expected = {'EditorWindow': {'font': 'Test Font',
|
| 233 |
+
'font-size': '20',
|
| 234 |
+
'font-bold': str(default_bold)}}
|
| 235 |
+
self.assertEqual(mainpage, expected)
|
| 236 |
+
self.assertEqual(d.set_samples.called, 2)
|
| 237 |
+
changes.clear()
|
| 238 |
+
|
| 239 |
+
d.font_bold.set(not default_bold)
|
| 240 |
+
expected = {'EditorWindow': {'font': 'Test Font',
|
| 241 |
+
'font-size': '20',
|
| 242 |
+
'font-bold': str(not default_bold)}}
|
| 243 |
+
self.assertEqual(mainpage, expected)
|
| 244 |
+
self.assertEqual(d.set_samples.called, 3)
|
| 245 |
+
|
| 246 |
+
def test_set_samples(self):
|
| 247 |
+
d = self.page
|
| 248 |
+
del d.set_samples # Unmask method for test
|
| 249 |
+
orig_samples = d.font_sample, d.highlight_sample
|
| 250 |
+
d.font_sample, d.highlight_sample = {}, {}
|
| 251 |
+
d.font_name.set('test')
|
| 252 |
+
d.font_size.set('5')
|
| 253 |
+
d.font_bold.set(1)
|
| 254 |
+
expected = {'font': ('test', '5', 'bold')}
|
| 255 |
+
|
| 256 |
+
# Test set_samples.
|
| 257 |
+
d.set_samples()
|
| 258 |
+
self.assertTrue(d.font_sample == d.highlight_sample == expected)
|
| 259 |
+
|
| 260 |
+
d.font_sample, d.highlight_sample = orig_samples
|
| 261 |
+
d.set_samples = Func() # Re-mask for other tests.
|
| 262 |
+
|
| 263 |
+
|
| 264 |
+
class HighPageTest(unittest.TestCase):
|
| 265 |
+
"""Test that highlight tab widgets enable users to make changes.
|
| 266 |
+
|
| 267 |
+
Test that widget actions set vars, that var changes add
|
| 268 |
+
options to changes and that themes work correctly.
|
| 269 |
+
"""
|
| 270 |
+
|
| 271 |
+
@classmethod
|
| 272 |
+
def setUpClass(cls):
|
| 273 |
+
page = cls.page = dialog.highpage
|
| 274 |
+
dialog.note.select(page)
|
| 275 |
+
page.set_theme_type = Func()
|
| 276 |
+
page.paint_theme_sample = Func()
|
| 277 |
+
page.set_highlight_target = Func()
|
| 278 |
+
page.set_color_sample = Func()
|
| 279 |
+
page.update()
|
| 280 |
+
|
| 281 |
+
@classmethod
|
| 282 |
+
def tearDownClass(cls):
|
| 283 |
+
d = cls.page
|
| 284 |
+
del d.set_theme_type, d.paint_theme_sample
|
| 285 |
+
del d.set_highlight_target, d.set_color_sample
|
| 286 |
+
|
| 287 |
+
def setUp(self):
|
| 288 |
+
d = self.page
|
| 289 |
+
# The following is needed for test_load_key_cfg, _delete_custom_keys.
|
| 290 |
+
# This may indicate a defect in some test or function.
|
| 291 |
+
for section in idleConf.GetSectionList('user', 'highlight'):
|
| 292 |
+
idleConf.userCfg['highlight'].remove_section(section)
|
| 293 |
+
changes.clear()
|
| 294 |
+
d.set_theme_type.called = 0
|
| 295 |
+
d.paint_theme_sample.called = 0
|
| 296 |
+
d.set_highlight_target.called = 0
|
| 297 |
+
d.set_color_sample.called = 0
|
| 298 |
+
|
| 299 |
+
def test_load_theme_cfg(self):
|
| 300 |
+
tracers.detach()
|
| 301 |
+
d = self.page
|
| 302 |
+
eq = self.assertEqual
|
| 303 |
+
|
| 304 |
+
# Use builtin theme with no user themes created.
|
| 305 |
+
idleConf.CurrentTheme = mock.Mock(return_value='IDLE Classic')
|
| 306 |
+
d.load_theme_cfg()
|
| 307 |
+
self.assertTrue(d.theme_source.get())
|
| 308 |
+
# builtinlist sets variable builtin_name to the CurrentTheme default.
|
| 309 |
+
eq(d.builtin_name.get(), 'IDLE Classic')
|
| 310 |
+
eq(d.custom_name.get(), '- no custom themes -')
|
| 311 |
+
eq(d.custom_theme_on.state(), ('disabled',))
|
| 312 |
+
eq(d.set_theme_type.called, 1)
|
| 313 |
+
eq(d.paint_theme_sample.called, 1)
|
| 314 |
+
eq(d.set_highlight_target.called, 1)
|
| 315 |
+
|
| 316 |
+
# Builtin theme with non-empty user theme list.
|
| 317 |
+
idleConf.SetOption('highlight', 'test1', 'option', 'value')
|
| 318 |
+
idleConf.SetOption('highlight', 'test2', 'option2', 'value2')
|
| 319 |
+
d.load_theme_cfg()
|
| 320 |
+
eq(d.builtin_name.get(), 'IDLE Classic')
|
| 321 |
+
eq(d.custom_name.get(), 'test1')
|
| 322 |
+
eq(d.set_theme_type.called, 2)
|
| 323 |
+
eq(d.paint_theme_sample.called, 2)
|
| 324 |
+
eq(d.set_highlight_target.called, 2)
|
| 325 |
+
|
| 326 |
+
# Use custom theme.
|
| 327 |
+
idleConf.CurrentTheme = mock.Mock(return_value='test2')
|
| 328 |
+
idleConf.SetOption('main', 'Theme', 'default', '0')
|
| 329 |
+
d.load_theme_cfg()
|
| 330 |
+
self.assertFalse(d.theme_source.get())
|
| 331 |
+
eq(d.builtin_name.get(), 'IDLE Classic')
|
| 332 |
+
eq(d.custom_name.get(), 'test2')
|
| 333 |
+
eq(d.set_theme_type.called, 3)
|
| 334 |
+
eq(d.paint_theme_sample.called, 3)
|
| 335 |
+
eq(d.set_highlight_target.called, 3)
|
| 336 |
+
|
| 337 |
+
del idleConf.CurrentTheme
|
| 338 |
+
tracers.attach()
|
| 339 |
+
|
| 340 |
+
def test_theme_source(self):
|
| 341 |
+
eq = self.assertEqual
|
| 342 |
+
d = self.page
|
| 343 |
+
# Test these separately.
|
| 344 |
+
d.var_changed_builtin_name = Func()
|
| 345 |
+
d.var_changed_custom_name = Func()
|
| 346 |
+
# Builtin selected.
|
| 347 |
+
d.builtin_theme_on.invoke()
|
| 348 |
+
eq(mainpage, {'Theme': {'default': 'True'}})
|
| 349 |
+
eq(d.var_changed_builtin_name.called, 1)
|
| 350 |
+
eq(d.var_changed_custom_name.called, 0)
|
| 351 |
+
changes.clear()
|
| 352 |
+
|
| 353 |
+
# Custom selected.
|
| 354 |
+
d.custom_theme_on.state(('!disabled',))
|
| 355 |
+
d.custom_theme_on.invoke()
|
| 356 |
+
self.assertEqual(mainpage, {'Theme': {'default': 'False'}})
|
| 357 |
+
eq(d.var_changed_builtin_name.called, 1)
|
| 358 |
+
eq(d.var_changed_custom_name.called, 1)
|
| 359 |
+
del d.var_changed_builtin_name, d.var_changed_custom_name
|
| 360 |
+
|
| 361 |
+
def test_builtin_name(self):
|
| 362 |
+
eq = self.assertEqual
|
| 363 |
+
d = self.page
|
| 364 |
+
item_list = ['IDLE Classic', 'IDLE Dark', 'IDLE New']
|
| 365 |
+
|
| 366 |
+
# Not in old_themes, defaults name to first item.
|
| 367 |
+
idleConf.SetOption('main', 'Theme', 'name', 'spam')
|
| 368 |
+
d.builtinlist.SetMenu(item_list, 'IDLE Dark')
|
| 369 |
+
eq(mainpage, {'Theme': {'name': 'IDLE Classic',
|
| 370 |
+
'name2': 'IDLE Dark'}})
|
| 371 |
+
eq(d.theme_message['text'], 'New theme, see Help')
|
| 372 |
+
eq(d.paint_theme_sample.called, 1)
|
| 373 |
+
|
| 374 |
+
# Not in old themes - uses name2.
|
| 375 |
+
changes.clear()
|
| 376 |
+
idleConf.SetOption('main', 'Theme', 'name', 'IDLE New')
|
| 377 |
+
d.builtinlist.SetMenu(item_list, 'IDLE Dark')
|
| 378 |
+
eq(mainpage, {'Theme': {'name2': 'IDLE Dark'}})
|
| 379 |
+
eq(d.theme_message['text'], 'New theme, see Help')
|
| 380 |
+
eq(d.paint_theme_sample.called, 2)
|
| 381 |
+
|
| 382 |
+
# Builtin name in old_themes.
|
| 383 |
+
changes.clear()
|
| 384 |
+
d.builtinlist.SetMenu(item_list, 'IDLE Classic')
|
| 385 |
+
eq(mainpage, {'Theme': {'name': 'IDLE Classic', 'name2': ''}})
|
| 386 |
+
eq(d.theme_message['text'], '')
|
| 387 |
+
eq(d.paint_theme_sample.called, 3)
|
| 388 |
+
|
| 389 |
+
def test_custom_name(self):
|
| 390 |
+
d = self.page
|
| 391 |
+
|
| 392 |
+
# If no selections, doesn't get added.
|
| 393 |
+
d.customlist.SetMenu([], '- no custom themes -')
|
| 394 |
+
self.assertNotIn('Theme', mainpage)
|
| 395 |
+
self.assertEqual(d.paint_theme_sample.called, 0)
|
| 396 |
+
|
| 397 |
+
# Custom name selected.
|
| 398 |
+
changes.clear()
|
| 399 |
+
d.customlist.SetMenu(['a', 'b', 'c'], 'c')
|
| 400 |
+
self.assertEqual(mainpage, {'Theme': {'name': 'c'}})
|
| 401 |
+
self.assertEqual(d.paint_theme_sample.called, 1)
|
| 402 |
+
|
| 403 |
+
def test_color(self):
|
| 404 |
+
d = self.page
|
| 405 |
+
d.on_new_color_set = Func()
|
| 406 |
+
# self.color is only set in get_color through colorchooser.
|
| 407 |
+
d.color.set('green')
|
| 408 |
+
self.assertEqual(d.on_new_color_set.called, 1)
|
| 409 |
+
del d.on_new_color_set
|
| 410 |
+
|
| 411 |
+
def test_highlight_target_list_mouse(self):
|
| 412 |
+
# Set highlight_target through targetlist.
|
| 413 |
+
eq = self.assertEqual
|
| 414 |
+
d = self.page
|
| 415 |
+
|
| 416 |
+
d.targetlist.SetMenu(['a', 'b', 'c'], 'c')
|
| 417 |
+
eq(d.highlight_target.get(), 'c')
|
| 418 |
+
eq(d.set_highlight_target.called, 1)
|
| 419 |
+
|
| 420 |
+
def test_highlight_target_text_mouse(self):
|
| 421 |
+
# Set highlight_target through clicking highlight_sample.
|
| 422 |
+
eq = self.assertEqual
|
| 423 |
+
d = self.page
|
| 424 |
+
hs = d.highlight_sample
|
| 425 |
+
hs.focus_force()
|
| 426 |
+
|
| 427 |
+
def click_char(index):
|
| 428 |
+
"Simulate click on character at *index*."
|
| 429 |
+
hs.see(index)
|
| 430 |
+
hs.update_idletasks()
|
| 431 |
+
x, y, dx, dy = hs.bbox(index)
|
| 432 |
+
x += dx // 2
|
| 433 |
+
y += dy // 2
|
| 434 |
+
hs.event_generate('<Enter>', x=0, y=0)
|
| 435 |
+
hs.event_generate('<Motion>', x=x, y=y)
|
| 436 |
+
hs.event_generate('<ButtonPress-1>', x=x, y=y)
|
| 437 |
+
hs.event_generate('<ButtonRelease-1>', x=x, y=y)
|
| 438 |
+
|
| 439 |
+
# Reverse theme_elements to make the tag the key.
|
| 440 |
+
elem = {tag: element for element, tag in d.theme_elements.items()}
|
| 441 |
+
|
| 442 |
+
# If highlight_sample has a tag that isn't in theme_elements, there
|
| 443 |
+
# will be a KeyError in the test run.
|
| 444 |
+
count = 0
|
| 445 |
+
for tag in hs.tag_names():
|
| 446 |
+
try:
|
| 447 |
+
click_char(hs.tag_nextrange(tag, "1.0")[0])
|
| 448 |
+
eq(d.highlight_target.get(), elem[tag])
|
| 449 |
+
count += 1
|
| 450 |
+
eq(d.set_highlight_target.called, count)
|
| 451 |
+
except IndexError:
|
| 452 |
+
pass # Skip unused theme_elements tag, like 'sel'.
|
| 453 |
+
|
| 454 |
+
def test_highlight_sample_double_click(self):
|
| 455 |
+
# Test double click on highlight_sample.
|
| 456 |
+
eq = self.assertEqual
|
| 457 |
+
d = self.page
|
| 458 |
+
|
| 459 |
+
hs = d.highlight_sample
|
| 460 |
+
hs.focus_force()
|
| 461 |
+
hs.see(1.0)
|
| 462 |
+
hs.update_idletasks()
|
| 463 |
+
|
| 464 |
+
# Test binding from configdialog.
|
| 465 |
+
hs.event_generate('<Enter>', x=0, y=0)
|
| 466 |
+
hs.event_generate('<Motion>', x=0, y=0)
|
| 467 |
+
# Double click is a sequence of two clicks in a row.
|
| 468 |
+
for _ in range(2):
|
| 469 |
+
hs.event_generate('<ButtonPress-1>', x=0, y=0)
|
| 470 |
+
hs.event_generate('<ButtonRelease-1>', x=0, y=0)
|
| 471 |
+
|
| 472 |
+
eq(hs.tag_ranges('sel'), ())
|
| 473 |
+
|
| 474 |
+
def test_highlight_sample_b1_motion(self):
|
| 475 |
+
# Test button motion on highlight_sample.
|
| 476 |
+
eq = self.assertEqual
|
| 477 |
+
d = self.page
|
| 478 |
+
|
| 479 |
+
hs = d.highlight_sample
|
| 480 |
+
hs.focus_force()
|
| 481 |
+
hs.see(1.0)
|
| 482 |
+
hs.update_idletasks()
|
| 483 |
+
|
| 484 |
+
x, y, dx, dy, offset = hs.dlineinfo('1.0')
|
| 485 |
+
|
| 486 |
+
# Test binding from configdialog.
|
| 487 |
+
hs.event_generate('<Leave>')
|
| 488 |
+
hs.event_generate('<Enter>')
|
| 489 |
+
hs.event_generate('<Motion>', x=x, y=y)
|
| 490 |
+
hs.event_generate('<ButtonPress-1>', x=x, y=y)
|
| 491 |
+
hs.event_generate('<B1-Motion>', x=dx, y=dy)
|
| 492 |
+
hs.event_generate('<ButtonRelease-1>', x=dx, y=dy)
|
| 493 |
+
|
| 494 |
+
eq(hs.tag_ranges('sel'), ())
|
| 495 |
+
|
| 496 |
+
def test_set_theme_type(self):
|
| 497 |
+
eq = self.assertEqual
|
| 498 |
+
d = self.page
|
| 499 |
+
del d.set_theme_type
|
| 500 |
+
|
| 501 |
+
# Builtin theme selected.
|
| 502 |
+
d.theme_source.set(True)
|
| 503 |
+
d.set_theme_type()
|
| 504 |
+
eq(d.builtinlist['state'], NORMAL)
|
| 505 |
+
eq(d.customlist['state'], DISABLED)
|
| 506 |
+
eq(d.button_delete_custom.state(), ('disabled',))
|
| 507 |
+
|
| 508 |
+
# Custom theme selected.
|
| 509 |
+
d.theme_source.set(False)
|
| 510 |
+
d.set_theme_type()
|
| 511 |
+
eq(d.builtinlist['state'], DISABLED)
|
| 512 |
+
eq(d.custom_theme_on.state(), ('selected',))
|
| 513 |
+
eq(d.customlist['state'], NORMAL)
|
| 514 |
+
eq(d.button_delete_custom.state(), ())
|
| 515 |
+
d.set_theme_type = Func()
|
| 516 |
+
|
| 517 |
+
def test_get_color(self):
|
| 518 |
+
eq = self.assertEqual
|
| 519 |
+
d = self.page
|
| 520 |
+
orig_chooser = configdialog.colorchooser.askcolor
|
| 521 |
+
chooser = configdialog.colorchooser.askcolor = Func()
|
| 522 |
+
gntn = d.get_new_theme_name = Func()
|
| 523 |
+
|
| 524 |
+
d.highlight_target.set('Editor Breakpoint')
|
| 525 |
+
d.color.set('#ffffff')
|
| 526 |
+
|
| 527 |
+
# Nothing selected.
|
| 528 |
+
chooser.result = (None, None)
|
| 529 |
+
d.button_set_color.invoke()
|
| 530 |
+
eq(d.color.get(), '#ffffff')
|
| 531 |
+
|
| 532 |
+
# Selection same as previous color.
|
| 533 |
+
chooser.result = ('', d.style.lookup(d.frame_color_set['style'], 'background'))
|
| 534 |
+
d.button_set_color.invoke()
|
| 535 |
+
eq(d.color.get(), '#ffffff')
|
| 536 |
+
|
| 537 |
+
# Select different color.
|
| 538 |
+
chooser.result = ((222.8671875, 0.0, 0.0), '#de0000')
|
| 539 |
+
|
| 540 |
+
# Default theme.
|
| 541 |
+
d.color.set('#ffffff')
|
| 542 |
+
d.theme_source.set(True)
|
| 543 |
+
|
| 544 |
+
# No theme name selected therefore color not saved.
|
| 545 |
+
gntn.result = ''
|
| 546 |
+
d.button_set_color.invoke()
|
| 547 |
+
eq(gntn.called, 1)
|
| 548 |
+
eq(d.color.get(), '#ffffff')
|
| 549 |
+
# Theme name selected.
|
| 550 |
+
gntn.result = 'My New Theme'
|
| 551 |
+
d.button_set_color.invoke()
|
| 552 |
+
eq(d.custom_name.get(), gntn.result)
|
| 553 |
+
eq(d.color.get(), '#de0000')
|
| 554 |
+
|
| 555 |
+
# Custom theme.
|
| 556 |
+
d.color.set('#ffffff')
|
| 557 |
+
d.theme_source.set(False)
|
| 558 |
+
d.button_set_color.invoke()
|
| 559 |
+
eq(d.color.get(), '#de0000')
|
| 560 |
+
|
| 561 |
+
del d.get_new_theme_name
|
| 562 |
+
configdialog.colorchooser.askcolor = orig_chooser
|
| 563 |
+
|
| 564 |
+
def test_on_new_color_set(self):
|
| 565 |
+
d = self.page
|
| 566 |
+
color = '#3f7cae'
|
| 567 |
+
d.custom_name.set('Python')
|
| 568 |
+
d.highlight_target.set('Selected Text')
|
| 569 |
+
d.fg_bg_toggle.set(True)
|
| 570 |
+
|
| 571 |
+
d.color.set(color)
|
| 572 |
+
self.assertEqual(d.style.lookup(d.frame_color_set['style'], 'background'), color)
|
| 573 |
+
self.assertEqual(d.highlight_sample.tag_cget('hilite', 'foreground'), color)
|
| 574 |
+
self.assertEqual(highpage,
|
| 575 |
+
{'Python': {'hilite-foreground': color}})
|
| 576 |
+
|
| 577 |
+
def test_get_new_theme_name(self):
|
| 578 |
+
orig_sectionname = configdialog.SectionName
|
| 579 |
+
sn = configdialog.SectionName = Func(return_self=True)
|
| 580 |
+
d = self.page
|
| 581 |
+
|
| 582 |
+
sn.result = 'New Theme'
|
| 583 |
+
self.assertEqual(d.get_new_theme_name(''), 'New Theme')
|
| 584 |
+
|
| 585 |
+
configdialog.SectionName = orig_sectionname
|
| 586 |
+
|
| 587 |
+
def test_save_as_new_theme(self):
|
| 588 |
+
d = self.page
|
| 589 |
+
gntn = d.get_new_theme_name = Func()
|
| 590 |
+
d.theme_source.set(True)
|
| 591 |
+
|
| 592 |
+
# No name entered.
|
| 593 |
+
gntn.result = ''
|
| 594 |
+
d.button_save_custom.invoke()
|
| 595 |
+
self.assertNotIn(gntn.result, idleConf.userCfg['highlight'])
|
| 596 |
+
|
| 597 |
+
# Name entered.
|
| 598 |
+
gntn.result = 'my new theme'
|
| 599 |
+
gntn.called = 0
|
| 600 |
+
self.assertNotIn(gntn.result, idleConf.userCfg['highlight'])
|
| 601 |
+
d.button_save_custom.invoke()
|
| 602 |
+
self.assertIn(gntn.result, idleConf.userCfg['highlight'])
|
| 603 |
+
|
| 604 |
+
del d.get_new_theme_name
|
| 605 |
+
|
| 606 |
+
def test_create_new_and_save_new(self):
|
| 607 |
+
eq = self.assertEqual
|
| 608 |
+
d = self.page
|
| 609 |
+
|
| 610 |
+
# Use default as previously active theme.
|
| 611 |
+
d.theme_source.set(True)
|
| 612 |
+
d.builtin_name.set('IDLE Classic')
|
| 613 |
+
first_new = 'my new custom theme'
|
| 614 |
+
second_new = 'my second custom theme'
|
| 615 |
+
|
| 616 |
+
# No changes, so themes are an exact copy.
|
| 617 |
+
self.assertNotIn(first_new, idleConf.userCfg)
|
| 618 |
+
d.create_new(first_new)
|
| 619 |
+
eq(idleConf.GetSectionList('user', 'highlight'), [first_new])
|
| 620 |
+
eq(idleConf.GetThemeDict('default', 'IDLE Classic'),
|
| 621 |
+
idleConf.GetThemeDict('user', first_new))
|
| 622 |
+
eq(d.custom_name.get(), first_new)
|
| 623 |
+
self.assertFalse(d.theme_source.get()) # Use custom set.
|
| 624 |
+
eq(d.set_theme_type.called, 1)
|
| 625 |
+
|
| 626 |
+
# Test that changed targets are in new theme.
|
| 627 |
+
changes.add_option('highlight', first_new, 'hit-background', 'yellow')
|
| 628 |
+
self.assertNotIn(second_new, idleConf.userCfg)
|
| 629 |
+
d.create_new(second_new)
|
| 630 |
+
eq(idleConf.GetSectionList('user', 'highlight'), [first_new, second_new])
|
| 631 |
+
self.assertNotEqual(idleConf.GetThemeDict('user', first_new),
|
| 632 |
+
idleConf.GetThemeDict('user', second_new))
|
| 633 |
+
# Check that difference in themes was in `hit-background` from `changes`.
|
| 634 |
+
idleConf.SetOption('highlight', first_new, 'hit-background', 'yellow')
|
| 635 |
+
eq(idleConf.GetThemeDict('user', first_new),
|
| 636 |
+
idleConf.GetThemeDict('user', second_new))
|
| 637 |
+
|
| 638 |
+
def test_set_highlight_target(self):
|
| 639 |
+
eq = self.assertEqual
|
| 640 |
+
d = self.page
|
| 641 |
+
del d.set_highlight_target
|
| 642 |
+
|
| 643 |
+
# Target is cursor.
|
| 644 |
+
d.highlight_target.set('Cursor')
|
| 645 |
+
eq(d.fg_on.state(), ('disabled', 'selected'))
|
| 646 |
+
eq(d.bg_on.state(), ('disabled',))
|
| 647 |
+
self.assertTrue(d.fg_bg_toggle)
|
| 648 |
+
eq(d.set_color_sample.called, 1)
|
| 649 |
+
|
| 650 |
+
# Target is not cursor.
|
| 651 |
+
d.highlight_target.set('Comment')
|
| 652 |
+
eq(d.fg_on.state(), ('selected',))
|
| 653 |
+
eq(d.bg_on.state(), ())
|
| 654 |
+
self.assertTrue(d.fg_bg_toggle)
|
| 655 |
+
eq(d.set_color_sample.called, 2)
|
| 656 |
+
|
| 657 |
+
d.set_highlight_target = Func()
|
| 658 |
+
|
| 659 |
+
def test_set_color_sample_binding(self):
|
| 660 |
+
d = self.page
|
| 661 |
+
scs = d.set_color_sample
|
| 662 |
+
|
| 663 |
+
d.fg_on.invoke()
|
| 664 |
+
self.assertEqual(scs.called, 1)
|
| 665 |
+
|
| 666 |
+
d.bg_on.invoke()
|
| 667 |
+
self.assertEqual(scs.called, 2)
|
| 668 |
+
|
| 669 |
+
def test_set_color_sample(self):
|
| 670 |
+
d = self.page
|
| 671 |
+
del d.set_color_sample
|
| 672 |
+
d.highlight_target.set('Selected Text')
|
| 673 |
+
d.fg_bg_toggle.set(True)
|
| 674 |
+
d.set_color_sample()
|
| 675 |
+
self.assertEqual(
|
| 676 |
+
d.style.lookup(d.frame_color_set['style'], 'background'),
|
| 677 |
+
d.highlight_sample.tag_cget('hilite', 'foreground'))
|
| 678 |
+
d.set_color_sample = Func()
|
| 679 |
+
|
| 680 |
+
def test_paint_theme_sample(self):
|
| 681 |
+
eq = self.assertEqual
|
| 682 |
+
page = self.page
|
| 683 |
+
del page.paint_theme_sample # Delete masking mock.
|
| 684 |
+
hs_tag = page.highlight_sample.tag_cget
|
| 685 |
+
gh = idleConf.GetHighlight
|
| 686 |
+
|
| 687 |
+
# Create custom theme based on IDLE Dark.
|
| 688 |
+
page.theme_source.set(True)
|
| 689 |
+
page.builtin_name.set('IDLE Dark')
|
| 690 |
+
theme = 'IDLE Test'
|
| 691 |
+
page.create_new(theme)
|
| 692 |
+
page.set_color_sample.called = 0
|
| 693 |
+
|
| 694 |
+
# Base theme with nothing in `changes`.
|
| 695 |
+
page.paint_theme_sample()
|
| 696 |
+
new_console = {'foreground': 'blue',
|
| 697 |
+
'background': 'yellow',}
|
| 698 |
+
for key, value in new_console.items():
|
| 699 |
+
self.assertNotEqual(hs_tag('console', key), value)
|
| 700 |
+
eq(page.set_color_sample.called, 1)
|
| 701 |
+
|
| 702 |
+
# Apply changes.
|
| 703 |
+
for key, value in new_console.items():
|
| 704 |
+
changes.add_option('highlight', theme, 'console-'+key, value)
|
| 705 |
+
page.paint_theme_sample()
|
| 706 |
+
for key, value in new_console.items():
|
| 707 |
+
eq(hs_tag('console', key), value)
|
| 708 |
+
eq(page.set_color_sample.called, 2)
|
| 709 |
+
|
| 710 |
+
page.paint_theme_sample = Func()
|
| 711 |
+
|
| 712 |
+
def test_delete_custom(self):
|
| 713 |
+
eq = self.assertEqual
|
| 714 |
+
d = self.page
|
| 715 |
+
d.button_delete_custom.state(('!disabled',))
|
| 716 |
+
yesno = d.askyesno = Func()
|
| 717 |
+
dialog.deactivate_current_config = Func()
|
| 718 |
+
dialog.activate_config_changes = Func()
|
| 719 |
+
|
| 720 |
+
theme_name = 'spam theme'
|
| 721 |
+
idleConf.userCfg['highlight'].SetOption(theme_name, 'name', 'value')
|
| 722 |
+
highpage[theme_name] = {'option': 'True'}
|
| 723 |
+
|
| 724 |
+
theme_name2 = 'other theme'
|
| 725 |
+
idleConf.userCfg['highlight'].SetOption(theme_name2, 'name', 'value')
|
| 726 |
+
highpage[theme_name2] = {'option': 'False'}
|
| 727 |
+
|
| 728 |
+
# Force custom theme.
|
| 729 |
+
d.custom_theme_on.state(('!disabled',))
|
| 730 |
+
d.custom_theme_on.invoke()
|
| 731 |
+
d.custom_name.set(theme_name)
|
| 732 |
+
|
| 733 |
+
# Cancel deletion.
|
| 734 |
+
yesno.result = False
|
| 735 |
+
d.button_delete_custom.invoke()
|
| 736 |
+
eq(yesno.called, 1)
|
| 737 |
+
eq(highpage[theme_name], {'option': 'True'})
|
| 738 |
+
eq(idleConf.GetSectionList('user', 'highlight'), [theme_name, theme_name2])
|
| 739 |
+
eq(dialog.deactivate_current_config.called, 0)
|
| 740 |
+
eq(dialog.activate_config_changes.called, 0)
|
| 741 |
+
eq(d.set_theme_type.called, 0)
|
| 742 |
+
|
| 743 |
+
# Confirm deletion.
|
| 744 |
+
yesno.result = True
|
| 745 |
+
d.button_delete_custom.invoke()
|
| 746 |
+
eq(yesno.called, 2)
|
| 747 |
+
self.assertNotIn(theme_name, highpage)
|
| 748 |
+
eq(idleConf.GetSectionList('user', 'highlight'), [theme_name2])
|
| 749 |
+
eq(d.custom_theme_on.state(), ())
|
| 750 |
+
eq(d.custom_name.get(), theme_name2)
|
| 751 |
+
eq(dialog.deactivate_current_config.called, 1)
|
| 752 |
+
eq(dialog.activate_config_changes.called, 1)
|
| 753 |
+
eq(d.set_theme_type.called, 1)
|
| 754 |
+
|
| 755 |
+
# Confirm deletion of second theme - empties list.
|
| 756 |
+
d.custom_name.set(theme_name2)
|
| 757 |
+
yesno.result = True
|
| 758 |
+
d.button_delete_custom.invoke()
|
| 759 |
+
eq(yesno.called, 3)
|
| 760 |
+
self.assertNotIn(theme_name, highpage)
|
| 761 |
+
eq(idleConf.GetSectionList('user', 'highlight'), [])
|
| 762 |
+
eq(d.custom_theme_on.state(), ('disabled',))
|
| 763 |
+
eq(d.custom_name.get(), '- no custom themes -')
|
| 764 |
+
eq(dialog.deactivate_current_config.called, 2)
|
| 765 |
+
eq(dialog.activate_config_changes.called, 2)
|
| 766 |
+
eq(d.set_theme_type.called, 2)
|
| 767 |
+
|
| 768 |
+
del dialog.activate_config_changes, dialog.deactivate_current_config
|
| 769 |
+
del d.askyesno
|
| 770 |
+
|
| 771 |
+
|
| 772 |
+
class KeysPageTest(unittest.TestCase):
|
| 773 |
+
"""Test that keys tab widgets enable users to make changes.
|
| 774 |
+
|
| 775 |
+
Test that widget actions set vars, that var changes add
|
| 776 |
+
options to changes and that key sets works correctly.
|
| 777 |
+
"""
|
| 778 |
+
|
| 779 |
+
@classmethod
|
| 780 |
+
def setUpClass(cls):
|
| 781 |
+
page = cls.page = dialog.keyspage
|
| 782 |
+
dialog.note.select(page)
|
| 783 |
+
page.set_keys_type = Func()
|
| 784 |
+
page.load_keys_list = Func()
|
| 785 |
+
|
| 786 |
+
@classmethod
|
| 787 |
+
def tearDownClass(cls):
|
| 788 |
+
page = cls.page
|
| 789 |
+
del page.set_keys_type, page.load_keys_list
|
| 790 |
+
|
| 791 |
+
def setUp(self):
|
| 792 |
+
d = self.page
|
| 793 |
+
# The following is needed for test_load_key_cfg, _delete_custom_keys.
|
| 794 |
+
# This may indicate a defect in some test or function.
|
| 795 |
+
for section in idleConf.GetSectionList('user', 'keys'):
|
| 796 |
+
idleConf.userCfg['keys'].remove_section(section)
|
| 797 |
+
changes.clear()
|
| 798 |
+
d.set_keys_type.called = 0
|
| 799 |
+
d.load_keys_list.called = 0
|
| 800 |
+
|
| 801 |
+
def test_load_key_cfg(self):
|
| 802 |
+
tracers.detach()
|
| 803 |
+
d = self.page
|
| 804 |
+
eq = self.assertEqual
|
| 805 |
+
|
| 806 |
+
# Use builtin keyset with no user keysets created.
|
| 807 |
+
idleConf.CurrentKeys = mock.Mock(return_value='IDLE Classic OSX')
|
| 808 |
+
d.load_key_cfg()
|
| 809 |
+
self.assertTrue(d.keyset_source.get())
|
| 810 |
+
# builtinlist sets variable builtin_name to the CurrentKeys default.
|
| 811 |
+
eq(d.builtin_name.get(), 'IDLE Classic OSX')
|
| 812 |
+
eq(d.custom_name.get(), '- no custom keys -')
|
| 813 |
+
eq(d.custom_keyset_on.state(), ('disabled',))
|
| 814 |
+
eq(d.set_keys_type.called, 1)
|
| 815 |
+
eq(d.load_keys_list.called, 1)
|
| 816 |
+
eq(d.load_keys_list.args, ('IDLE Classic OSX', ))
|
| 817 |
+
|
| 818 |
+
# Builtin keyset with non-empty user keyset list.
|
| 819 |
+
idleConf.SetOption('keys', 'test1', 'option', 'value')
|
| 820 |
+
idleConf.SetOption('keys', 'test2', 'option2', 'value2')
|
| 821 |
+
d.load_key_cfg()
|
| 822 |
+
eq(d.builtin_name.get(), 'IDLE Classic OSX')
|
| 823 |
+
eq(d.custom_name.get(), 'test1')
|
| 824 |
+
eq(d.set_keys_type.called, 2)
|
| 825 |
+
eq(d.load_keys_list.called, 2)
|
| 826 |
+
eq(d.load_keys_list.args, ('IDLE Classic OSX', ))
|
| 827 |
+
|
| 828 |
+
# Use custom keyset.
|
| 829 |
+
idleConf.CurrentKeys = mock.Mock(return_value='test2')
|
| 830 |
+
idleConf.default_keys = mock.Mock(return_value='IDLE Modern Unix')
|
| 831 |
+
idleConf.SetOption('main', 'Keys', 'default', '0')
|
| 832 |
+
d.load_key_cfg()
|
| 833 |
+
self.assertFalse(d.keyset_source.get())
|
| 834 |
+
eq(d.builtin_name.get(), 'IDLE Modern Unix')
|
| 835 |
+
eq(d.custom_name.get(), 'test2')
|
| 836 |
+
eq(d.set_keys_type.called, 3)
|
| 837 |
+
eq(d.load_keys_list.called, 3)
|
| 838 |
+
eq(d.load_keys_list.args, ('test2', ))
|
| 839 |
+
|
| 840 |
+
del idleConf.CurrentKeys, idleConf.default_keys
|
| 841 |
+
tracers.attach()
|
| 842 |
+
|
| 843 |
+
def test_keyset_source(self):
|
| 844 |
+
eq = self.assertEqual
|
| 845 |
+
d = self.page
|
| 846 |
+
# Test these separately.
|
| 847 |
+
d.var_changed_builtin_name = Func()
|
| 848 |
+
d.var_changed_custom_name = Func()
|
| 849 |
+
# Builtin selected.
|
| 850 |
+
d.builtin_keyset_on.invoke()
|
| 851 |
+
eq(mainpage, {'Keys': {'default': 'True'}})
|
| 852 |
+
eq(d.var_changed_builtin_name.called, 1)
|
| 853 |
+
eq(d.var_changed_custom_name.called, 0)
|
| 854 |
+
changes.clear()
|
| 855 |
+
|
| 856 |
+
# Custom selected.
|
| 857 |
+
d.custom_keyset_on.state(('!disabled',))
|
| 858 |
+
d.custom_keyset_on.invoke()
|
| 859 |
+
self.assertEqual(mainpage, {'Keys': {'default': 'False'}})
|
| 860 |
+
eq(d.var_changed_builtin_name.called, 1)
|
| 861 |
+
eq(d.var_changed_custom_name.called, 1)
|
| 862 |
+
del d.var_changed_builtin_name, d.var_changed_custom_name
|
| 863 |
+
|
| 864 |
+
def test_builtin_name(self):
|
| 865 |
+
eq = self.assertEqual
|
| 866 |
+
d = self.page
|
| 867 |
+
idleConf.userCfg['main'].remove_section('Keys')
|
| 868 |
+
item_list = ['IDLE Classic Windows', 'IDLE Classic OSX',
|
| 869 |
+
'IDLE Modern UNIX']
|
| 870 |
+
|
| 871 |
+
# Not in old_keys, defaults name to first item.
|
| 872 |
+
d.builtinlist.SetMenu(item_list, 'IDLE Modern UNIX')
|
| 873 |
+
eq(mainpage, {'Keys': {'name': 'IDLE Classic Windows',
|
| 874 |
+
'name2': 'IDLE Modern UNIX'}})
|
| 875 |
+
eq(d.keys_message['text'], 'New key set, see Help')
|
| 876 |
+
eq(d.load_keys_list.called, 1)
|
| 877 |
+
eq(d.load_keys_list.args, ('IDLE Modern UNIX', ))
|
| 878 |
+
|
| 879 |
+
# Not in old keys - uses name2.
|
| 880 |
+
changes.clear()
|
| 881 |
+
idleConf.SetOption('main', 'Keys', 'name', 'IDLE Classic Unix')
|
| 882 |
+
d.builtinlist.SetMenu(item_list, 'IDLE Modern UNIX')
|
| 883 |
+
eq(mainpage, {'Keys': {'name2': 'IDLE Modern UNIX'}})
|
| 884 |
+
eq(d.keys_message['text'], 'New key set, see Help')
|
| 885 |
+
eq(d.load_keys_list.called, 2)
|
| 886 |
+
eq(d.load_keys_list.args, ('IDLE Modern UNIX', ))
|
| 887 |
+
|
| 888 |
+
# Builtin name in old_keys.
|
| 889 |
+
changes.clear()
|
| 890 |
+
d.builtinlist.SetMenu(item_list, 'IDLE Classic OSX')
|
| 891 |
+
eq(mainpage, {'Keys': {'name': 'IDLE Classic OSX', 'name2': ''}})
|
| 892 |
+
eq(d.keys_message['text'], '')
|
| 893 |
+
eq(d.load_keys_list.called, 3)
|
| 894 |
+
eq(d.load_keys_list.args, ('IDLE Classic OSX', ))
|
| 895 |
+
|
| 896 |
+
def test_custom_name(self):
|
| 897 |
+
d = self.page
|
| 898 |
+
|
| 899 |
+
# If no selections, doesn't get added.
|
| 900 |
+
d.customlist.SetMenu([], '- no custom keys -')
|
| 901 |
+
self.assertNotIn('Keys', mainpage)
|
| 902 |
+
self.assertEqual(d.load_keys_list.called, 0)
|
| 903 |
+
|
| 904 |
+
# Custom name selected.
|
| 905 |
+
changes.clear()
|
| 906 |
+
d.customlist.SetMenu(['a', 'b', 'c'], 'c')
|
| 907 |
+
self.assertEqual(mainpage, {'Keys': {'name': 'c'}})
|
| 908 |
+
self.assertEqual(d.load_keys_list.called, 1)
|
| 909 |
+
|
| 910 |
+
def test_keybinding(self):
|
| 911 |
+
idleConf.SetOption('extensions', 'ZzDummy', 'enable', 'True')
|
| 912 |
+
d = self.page
|
| 913 |
+
d.custom_name.set('my custom keys')
|
| 914 |
+
d.bindingslist.delete(0, 'end')
|
| 915 |
+
d.bindingslist.insert(0, 'copy')
|
| 916 |
+
d.bindingslist.insert(1, 'z-in')
|
| 917 |
+
d.bindingslist.selection_set(0)
|
| 918 |
+
d.bindingslist.selection_anchor(0)
|
| 919 |
+
# Core binding - adds to keys.
|
| 920 |
+
d.keybinding.set('<Key-F11>')
|
| 921 |
+
self.assertEqual(keyspage,
|
| 922 |
+
{'my custom keys': {'copy': '<Key-F11>'}})
|
| 923 |
+
|
| 924 |
+
# Not a core binding - adds to extensions.
|
| 925 |
+
d.bindingslist.selection_set(1)
|
| 926 |
+
d.bindingslist.selection_anchor(1)
|
| 927 |
+
d.keybinding.set('<Key-F11>')
|
| 928 |
+
self.assertEqual(extpage,
|
| 929 |
+
{'ZzDummy_cfgBindings': {'z-in': '<Key-F11>'}})
|
| 930 |
+
|
| 931 |
+
def test_set_keys_type(self):
|
| 932 |
+
eq = self.assertEqual
|
| 933 |
+
d = self.page
|
| 934 |
+
del d.set_keys_type
|
| 935 |
+
|
| 936 |
+
# Builtin keyset selected.
|
| 937 |
+
d.keyset_source.set(True)
|
| 938 |
+
d.set_keys_type()
|
| 939 |
+
eq(d.builtinlist['state'], NORMAL)
|
| 940 |
+
eq(d.customlist['state'], DISABLED)
|
| 941 |
+
eq(d.button_delete_custom_keys.state(), ('disabled',))
|
| 942 |
+
|
| 943 |
+
# Custom keyset selected.
|
| 944 |
+
d.keyset_source.set(False)
|
| 945 |
+
d.set_keys_type()
|
| 946 |
+
eq(d.builtinlist['state'], DISABLED)
|
| 947 |
+
eq(d.custom_keyset_on.state(), ('selected',))
|
| 948 |
+
eq(d.customlist['state'], NORMAL)
|
| 949 |
+
eq(d.button_delete_custom_keys.state(), ())
|
| 950 |
+
d.set_keys_type = Func()
|
| 951 |
+
|
| 952 |
+
def test_get_new_keys(self):
|
| 953 |
+
eq = self.assertEqual
|
| 954 |
+
d = self.page
|
| 955 |
+
orig_getkeysdialog = configdialog.GetKeysWindow
|
| 956 |
+
gkd = configdialog.GetKeysWindow = Func(return_self=True)
|
| 957 |
+
gnkn = d.get_new_keys_name = Func()
|
| 958 |
+
|
| 959 |
+
d.button_new_keys.state(('!disabled',))
|
| 960 |
+
d.bindingslist.delete(0, 'end')
|
| 961 |
+
d.bindingslist.insert(0, 'copy - <Control-Shift-Key-C>')
|
| 962 |
+
d.bindingslist.selection_set(0)
|
| 963 |
+
d.bindingslist.selection_anchor(0)
|
| 964 |
+
d.keybinding.set('Key-a')
|
| 965 |
+
d.keyset_source.set(True) # Default keyset.
|
| 966 |
+
|
| 967 |
+
# Default keyset; no change to binding.
|
| 968 |
+
gkd.result = ''
|
| 969 |
+
d.button_new_keys.invoke()
|
| 970 |
+
eq(d.bindingslist.get('anchor'), 'copy - <Control-Shift-Key-C>')
|
| 971 |
+
# Keybinding isn't changed when there isn't a change entered.
|
| 972 |
+
eq(d.keybinding.get(), 'Key-a')
|
| 973 |
+
|
| 974 |
+
# Default keyset; binding changed.
|
| 975 |
+
gkd.result = '<Key-F11>'
|
| 976 |
+
# No keyset name selected therefore binding not saved.
|
| 977 |
+
gnkn.result = ''
|
| 978 |
+
d.button_new_keys.invoke()
|
| 979 |
+
eq(gnkn.called, 1)
|
| 980 |
+
eq(d.bindingslist.get('anchor'), 'copy - <Control-Shift-Key-C>')
|
| 981 |
+
# Keyset name selected.
|
| 982 |
+
gnkn.result = 'My New Key Set'
|
| 983 |
+
d.button_new_keys.invoke()
|
| 984 |
+
eq(d.custom_name.get(), gnkn.result)
|
| 985 |
+
eq(d.bindingslist.get('anchor'), 'copy - <Key-F11>')
|
| 986 |
+
eq(d.keybinding.get(), '<Key-F11>')
|
| 987 |
+
|
| 988 |
+
# User keyset; binding changed.
|
| 989 |
+
d.keyset_source.set(False) # Custom keyset.
|
| 990 |
+
gnkn.called = 0
|
| 991 |
+
gkd.result = '<Key-p>'
|
| 992 |
+
d.button_new_keys.invoke()
|
| 993 |
+
eq(gnkn.called, 0)
|
| 994 |
+
eq(d.bindingslist.get('anchor'), 'copy - <Key-p>')
|
| 995 |
+
eq(d.keybinding.get(), '<Key-p>')
|
| 996 |
+
|
| 997 |
+
del d.get_new_keys_name
|
| 998 |
+
configdialog.GetKeysWindow = orig_getkeysdialog
|
| 999 |
+
|
| 1000 |
+
def test_get_new_keys_name(self):
|
| 1001 |
+
orig_sectionname = configdialog.SectionName
|
| 1002 |
+
sn = configdialog.SectionName = Func(return_self=True)
|
| 1003 |
+
d = self.page
|
| 1004 |
+
|
| 1005 |
+
sn.result = 'New Keys'
|
| 1006 |
+
self.assertEqual(d.get_new_keys_name(''), 'New Keys')
|
| 1007 |
+
|
| 1008 |
+
configdialog.SectionName = orig_sectionname
|
| 1009 |
+
|
| 1010 |
+
def test_save_as_new_key_set(self):
|
| 1011 |
+
d = self.page
|
| 1012 |
+
gnkn = d.get_new_keys_name = Func()
|
| 1013 |
+
d.keyset_source.set(True)
|
| 1014 |
+
|
| 1015 |
+
# No name entered.
|
| 1016 |
+
gnkn.result = ''
|
| 1017 |
+
d.button_save_custom_keys.invoke()
|
| 1018 |
+
|
| 1019 |
+
# Name entered.
|
| 1020 |
+
gnkn.result = 'my new key set'
|
| 1021 |
+
gnkn.called = 0
|
| 1022 |
+
self.assertNotIn(gnkn.result, idleConf.userCfg['keys'])
|
| 1023 |
+
d.button_save_custom_keys.invoke()
|
| 1024 |
+
self.assertIn(gnkn.result, idleConf.userCfg['keys'])
|
| 1025 |
+
|
| 1026 |
+
del d.get_new_keys_name
|
| 1027 |
+
|
| 1028 |
+
def test_on_bindingslist_select(self):
|
| 1029 |
+
d = self.page
|
| 1030 |
+
b = d.bindingslist
|
| 1031 |
+
b.delete(0, 'end')
|
| 1032 |
+
b.insert(0, 'copy')
|
| 1033 |
+
b.insert(1, 'find')
|
| 1034 |
+
b.activate(0)
|
| 1035 |
+
|
| 1036 |
+
b.focus_force()
|
| 1037 |
+
b.see(1)
|
| 1038 |
+
b.update()
|
| 1039 |
+
x, y, dx, dy = b.bbox(1)
|
| 1040 |
+
x += dx // 2
|
| 1041 |
+
y += dy // 2
|
| 1042 |
+
b.event_generate('<Enter>', x=0, y=0)
|
| 1043 |
+
b.event_generate('<Motion>', x=x, y=y)
|
| 1044 |
+
b.event_generate('<Button-1>', x=x, y=y)
|
| 1045 |
+
b.event_generate('<ButtonRelease-1>', x=x, y=y)
|
| 1046 |
+
self.assertEqual(b.get('anchor'), 'find')
|
| 1047 |
+
self.assertEqual(d.button_new_keys.state(), ())
|
| 1048 |
+
|
| 1049 |
+
def test_create_new_key_set_and_save_new_key_set(self):
|
| 1050 |
+
eq = self.assertEqual
|
| 1051 |
+
d = self.page
|
| 1052 |
+
|
| 1053 |
+
# Use default as previously active keyset.
|
| 1054 |
+
d.keyset_source.set(True)
|
| 1055 |
+
d.builtin_name.set('IDLE Classic Windows')
|
| 1056 |
+
first_new = 'my new custom key set'
|
| 1057 |
+
second_new = 'my second custom keyset'
|
| 1058 |
+
|
| 1059 |
+
# No changes, so keysets are an exact copy.
|
| 1060 |
+
self.assertNotIn(first_new, idleConf.userCfg)
|
| 1061 |
+
d.create_new_key_set(first_new)
|
| 1062 |
+
eq(idleConf.GetSectionList('user', 'keys'), [first_new])
|
| 1063 |
+
eq(idleConf.GetKeySet('IDLE Classic Windows'),
|
| 1064 |
+
idleConf.GetKeySet(first_new))
|
| 1065 |
+
eq(d.custom_name.get(), first_new)
|
| 1066 |
+
self.assertFalse(d.keyset_source.get()) # Use custom set.
|
| 1067 |
+
eq(d.set_keys_type.called, 1)
|
| 1068 |
+
|
| 1069 |
+
# Test that changed keybindings are in new keyset.
|
| 1070 |
+
changes.add_option('keys', first_new, 'copy', '<Key-F11>')
|
| 1071 |
+
self.assertNotIn(second_new, idleConf.userCfg)
|
| 1072 |
+
d.create_new_key_set(second_new)
|
| 1073 |
+
eq(idleConf.GetSectionList('user', 'keys'), [first_new, second_new])
|
| 1074 |
+
self.assertNotEqual(idleConf.GetKeySet(first_new),
|
| 1075 |
+
idleConf.GetKeySet(second_new))
|
| 1076 |
+
# Check that difference in keysets was in option `copy` from `changes`.
|
| 1077 |
+
idleConf.SetOption('keys', first_new, 'copy', '<Key-F11>')
|
| 1078 |
+
eq(idleConf.GetKeySet(first_new), idleConf.GetKeySet(second_new))
|
| 1079 |
+
|
| 1080 |
+
def test_load_keys_list(self):
|
| 1081 |
+
eq = self.assertEqual
|
| 1082 |
+
d = self.page
|
| 1083 |
+
gks = idleConf.GetKeySet = Func()
|
| 1084 |
+
del d.load_keys_list
|
| 1085 |
+
b = d.bindingslist
|
| 1086 |
+
|
| 1087 |
+
b.delete(0, 'end')
|
| 1088 |
+
b.insert(0, '<<find>>')
|
| 1089 |
+
b.insert(1, '<<help>>')
|
| 1090 |
+
gks.result = {'<<copy>>': ['<Control-Key-c>', '<Control-Key-C>'],
|
| 1091 |
+
'<<force-open-completions>>': ['<Control-Key-space>'],
|
| 1092 |
+
'<<spam>>': ['<Key-F11>']}
|
| 1093 |
+
changes.add_option('keys', 'my keys', 'spam', '<Shift-Key-a>')
|
| 1094 |
+
expected = ('copy - <Control-Key-c> <Control-Key-C>',
|
| 1095 |
+
'force-open-completions - <Control-Key-space>',
|
| 1096 |
+
'spam - <Shift-Key-a>')
|
| 1097 |
+
|
| 1098 |
+
# No current selection.
|
| 1099 |
+
d.load_keys_list('my keys')
|
| 1100 |
+
eq(b.get(0, 'end'), expected)
|
| 1101 |
+
eq(b.get('anchor'), '')
|
| 1102 |
+
eq(b.curselection(), ())
|
| 1103 |
+
|
| 1104 |
+
# Check selection.
|
| 1105 |
+
b.selection_set(1)
|
| 1106 |
+
b.selection_anchor(1)
|
| 1107 |
+
d.load_keys_list('my keys')
|
| 1108 |
+
eq(b.get(0, 'end'), expected)
|
| 1109 |
+
eq(b.get('anchor'), 'force-open-completions - <Control-Key-space>')
|
| 1110 |
+
eq(b.curselection(), (1, ))
|
| 1111 |
+
|
| 1112 |
+
# Change selection.
|
| 1113 |
+
b.selection_set(2)
|
| 1114 |
+
b.selection_anchor(2)
|
| 1115 |
+
d.load_keys_list('my keys')
|
| 1116 |
+
eq(b.get(0, 'end'), expected)
|
| 1117 |
+
eq(b.get('anchor'), 'spam - <Shift-Key-a>')
|
| 1118 |
+
eq(b.curselection(), (2, ))
|
| 1119 |
+
d.load_keys_list = Func()
|
| 1120 |
+
|
| 1121 |
+
del idleConf.GetKeySet
|
| 1122 |
+
|
| 1123 |
+
def test_delete_custom_keys(self):
|
| 1124 |
+
eq = self.assertEqual
|
| 1125 |
+
d = self.page
|
| 1126 |
+
d.button_delete_custom_keys.state(('!disabled',))
|
| 1127 |
+
yesno = d.askyesno = Func()
|
| 1128 |
+
dialog.deactivate_current_config = Func()
|
| 1129 |
+
dialog.activate_config_changes = Func()
|
| 1130 |
+
|
| 1131 |
+
keyset_name = 'spam key set'
|
| 1132 |
+
idleConf.userCfg['keys'].SetOption(keyset_name, 'name', 'value')
|
| 1133 |
+
keyspage[keyset_name] = {'option': 'True'}
|
| 1134 |
+
|
| 1135 |
+
keyset_name2 = 'other key set'
|
| 1136 |
+
idleConf.userCfg['keys'].SetOption(keyset_name2, 'name', 'value')
|
| 1137 |
+
keyspage[keyset_name2] = {'option': 'False'}
|
| 1138 |
+
|
| 1139 |
+
# Force custom keyset.
|
| 1140 |
+
d.custom_keyset_on.state(('!disabled',))
|
| 1141 |
+
d.custom_keyset_on.invoke()
|
| 1142 |
+
d.custom_name.set(keyset_name)
|
| 1143 |
+
|
| 1144 |
+
# Cancel deletion.
|
| 1145 |
+
yesno.result = False
|
| 1146 |
+
d.button_delete_custom_keys.invoke()
|
| 1147 |
+
eq(yesno.called, 1)
|
| 1148 |
+
eq(keyspage[keyset_name], {'option': 'True'})
|
| 1149 |
+
eq(idleConf.GetSectionList('user', 'keys'), [keyset_name, keyset_name2])
|
| 1150 |
+
eq(dialog.deactivate_current_config.called, 0)
|
| 1151 |
+
eq(dialog.activate_config_changes.called, 0)
|
| 1152 |
+
eq(d.set_keys_type.called, 0)
|
| 1153 |
+
|
| 1154 |
+
# Confirm deletion.
|
| 1155 |
+
yesno.result = True
|
| 1156 |
+
d.button_delete_custom_keys.invoke()
|
| 1157 |
+
eq(yesno.called, 2)
|
| 1158 |
+
self.assertNotIn(keyset_name, keyspage)
|
| 1159 |
+
eq(idleConf.GetSectionList('user', 'keys'), [keyset_name2])
|
| 1160 |
+
eq(d.custom_keyset_on.state(), ())
|
| 1161 |
+
eq(d.custom_name.get(), keyset_name2)
|
| 1162 |
+
eq(dialog.deactivate_current_config.called, 1)
|
| 1163 |
+
eq(dialog.activate_config_changes.called, 1)
|
| 1164 |
+
eq(d.set_keys_type.called, 1)
|
| 1165 |
+
|
| 1166 |
+
# Confirm deletion of second keyset - empties list.
|
| 1167 |
+
d.custom_name.set(keyset_name2)
|
| 1168 |
+
yesno.result = True
|
| 1169 |
+
d.button_delete_custom_keys.invoke()
|
| 1170 |
+
eq(yesno.called, 3)
|
| 1171 |
+
self.assertNotIn(keyset_name, keyspage)
|
| 1172 |
+
eq(idleConf.GetSectionList('user', 'keys'), [])
|
| 1173 |
+
eq(d.custom_keyset_on.state(), ('disabled',))
|
| 1174 |
+
eq(d.custom_name.get(), '- no custom keys -')
|
| 1175 |
+
eq(dialog.deactivate_current_config.called, 2)
|
| 1176 |
+
eq(dialog.activate_config_changes.called, 2)
|
| 1177 |
+
eq(d.set_keys_type.called, 2)
|
| 1178 |
+
|
| 1179 |
+
del dialog.activate_config_changes, dialog.deactivate_current_config
|
| 1180 |
+
del d.askyesno
|
| 1181 |
+
|
| 1182 |
+
|
| 1183 |
+
class WinPageTest(unittest.TestCase):
|
| 1184 |
+
"""Test that general tab widgets enable users to make changes.
|
| 1185 |
+
|
| 1186 |
+
Test that widget actions set vars, that var changes add
|
| 1187 |
+
options to changes.
|
| 1188 |
+
"""
|
| 1189 |
+
@classmethod
|
| 1190 |
+
def setUpClass(cls):
|
| 1191 |
+
page = cls.page = dialog.winpage
|
| 1192 |
+
dialog.note.select(page)
|
| 1193 |
+
page.update()
|
| 1194 |
+
|
| 1195 |
+
def setUp(self):
|
| 1196 |
+
changes.clear()
|
| 1197 |
+
|
| 1198 |
+
def test_load_windows_cfg(self):
|
| 1199 |
+
# Set to wrong values, load, check right values.
|
| 1200 |
+
eq = self.assertEqual
|
| 1201 |
+
d = self.page
|
| 1202 |
+
d.startup_edit.set(1)
|
| 1203 |
+
d.win_width.set(1)
|
| 1204 |
+
d.win_height.set(1)
|
| 1205 |
+
d.load_windows_cfg()
|
| 1206 |
+
eq(d.startup_edit.get(), 0)
|
| 1207 |
+
eq(d.win_width.get(), '80')
|
| 1208 |
+
eq(d.win_height.get(), '40')
|
| 1209 |
+
|
| 1210 |
+
def test_startup(self):
|
| 1211 |
+
d = self.page
|
| 1212 |
+
d.startup_editor_on.invoke()
|
| 1213 |
+
self.assertEqual(mainpage,
|
| 1214 |
+
{'General': {'editor-on-startup': '1'}})
|
| 1215 |
+
changes.clear()
|
| 1216 |
+
d.startup_shell_on.invoke()
|
| 1217 |
+
self.assertEqual(mainpage,
|
| 1218 |
+
{'General': {'editor-on-startup': '0'}})
|
| 1219 |
+
|
| 1220 |
+
def test_editor_size(self):
|
| 1221 |
+
d = self.page
|
| 1222 |
+
d.win_height_int.delete(0, 'end')
|
| 1223 |
+
d.win_height_int.insert(0, '11')
|
| 1224 |
+
self.assertEqual(mainpage, {'EditorWindow': {'height': '11'}})
|
| 1225 |
+
changes.clear()
|
| 1226 |
+
d.win_width_int.delete(0, 'end')
|
| 1227 |
+
d.win_width_int.insert(0, '11')
|
| 1228 |
+
self.assertEqual(mainpage, {'EditorWindow': {'width': '11'}})
|
| 1229 |
+
|
| 1230 |
+
def test_indent_spaces(self):
|
| 1231 |
+
d = self.page
|
| 1232 |
+
d.indent_chooser.set(6)
|
| 1233 |
+
self.assertEqual(d.indent_spaces.get(), '6')
|
| 1234 |
+
self.assertEqual(mainpage, {'Indent': {'num-spaces': '6'}})
|
| 1235 |
+
|
| 1236 |
+
def test_cursor_blink(self):
|
| 1237 |
+
self.page.cursor_blink_bool.invoke()
|
| 1238 |
+
self.assertEqual(mainpage, {'EditorWindow': {'cursor-blink': 'False'}})
|
| 1239 |
+
|
| 1240 |
+
def test_autocomplete_wait(self):
|
| 1241 |
+
self.page.auto_wait_int.delete(0, 'end')
|
| 1242 |
+
self.page.auto_wait_int.insert(0, '11')
|
| 1243 |
+
self.assertEqual(extpage, {'AutoComplete': {'popupwait': '11'}})
|
| 1244 |
+
|
| 1245 |
+
def test_parenmatch(self):
|
| 1246 |
+
d = self.page
|
| 1247 |
+
eq = self.assertEqual
|
| 1248 |
+
d.paren_style_type['menu'].invoke(0)
|
| 1249 |
+
eq(extpage, {'ParenMatch': {'style': 'opener'}})
|
| 1250 |
+
changes.clear()
|
| 1251 |
+
d.paren_flash_time.delete(0, 'end')
|
| 1252 |
+
d.paren_flash_time.insert(0, '11')
|
| 1253 |
+
eq(extpage, {'ParenMatch': {'flash-delay': '11'}})
|
| 1254 |
+
changes.clear()
|
| 1255 |
+
d.bell_on.invoke()
|
| 1256 |
+
eq(extpage, {'ParenMatch': {'bell': 'False'}})
|
| 1257 |
+
|
| 1258 |
+
def test_paragraph(self):
|
| 1259 |
+
self.page.format_width_int.delete(0, 'end')
|
| 1260 |
+
self.page.format_width_int.insert(0, '11')
|
| 1261 |
+
self.assertEqual(extpage, {'FormatParagraph': {'max-width': '11'}})
|
| 1262 |
+
|
| 1263 |
+
|
| 1264 |
+
class ShedPageTest(unittest.TestCase):
|
| 1265 |
+
"""Test that shed tab widgets enable users to make changes.
|
| 1266 |
+
|
| 1267 |
+
Test that widget actions set vars, that var changes add
|
| 1268 |
+
options to changes.
|
| 1269 |
+
"""
|
| 1270 |
+
@classmethod
|
| 1271 |
+
def setUpClass(cls):
|
| 1272 |
+
page = cls.page = dialog.shedpage
|
| 1273 |
+
dialog.note.select(page)
|
| 1274 |
+
page.update()
|
| 1275 |
+
|
| 1276 |
+
def setUp(self):
|
| 1277 |
+
changes.clear()
|
| 1278 |
+
|
| 1279 |
+
def test_load_shelled_cfg(self):
|
| 1280 |
+
# Set to wrong values, load, check right values.
|
| 1281 |
+
eq = self.assertEqual
|
| 1282 |
+
d = self.page
|
| 1283 |
+
d.autosave.set(1)
|
| 1284 |
+
d.load_shelled_cfg()
|
| 1285 |
+
eq(d.autosave.get(), 0)
|
| 1286 |
+
|
| 1287 |
+
def test_autosave(self):
|
| 1288 |
+
d = self.page
|
| 1289 |
+
d.save_auto_on.invoke()
|
| 1290 |
+
self.assertEqual(mainpage, {'General': {'autosave': '1'}})
|
| 1291 |
+
d.save_ask_on.invoke()
|
| 1292 |
+
self.assertEqual(mainpage, {'General': {'autosave': '0'}})
|
| 1293 |
+
|
| 1294 |
+
def test_context(self):
|
| 1295 |
+
self.page.context_int.delete(0, 'end')
|
| 1296 |
+
self.page.context_int.insert(0, '1')
|
| 1297 |
+
self.assertEqual(extpage, {'CodeContext': {'maxlines': '1'}})
|
| 1298 |
+
|
| 1299 |
+
|
| 1300 |
+
#unittest.skip("Nothing here yet TODO")
|
| 1301 |
+
class ExtPageTest(unittest.TestCase):
|
| 1302 |
+
"""Test that the help source list works correctly."""
|
| 1303 |
+
@classmethod
|
| 1304 |
+
def setUpClass(cls):
|
| 1305 |
+
page = dialog.extpage
|
| 1306 |
+
dialog.note.select(page)
|
| 1307 |
+
|
| 1308 |
+
|
| 1309 |
+
class HelpSourceTest(unittest.TestCase):
|
| 1310 |
+
"""Test that the help source list works correctly."""
|
| 1311 |
+
@classmethod
|
| 1312 |
+
def setUpClass(cls):
|
| 1313 |
+
page = dialog.extpage
|
| 1314 |
+
dialog.note.select(page)
|
| 1315 |
+
frame = cls.frame = page.frame_help
|
| 1316 |
+
frame.set = frame.set_add_delete_state = Func()
|
| 1317 |
+
frame.upc = frame.update_help_changes = Func()
|
| 1318 |
+
frame.update()
|
| 1319 |
+
|
| 1320 |
+
@classmethod
|
| 1321 |
+
def tearDownClass(cls):
|
| 1322 |
+
frame = cls.frame
|
| 1323 |
+
del frame.set, frame.set_add_delete_state
|
| 1324 |
+
del frame.upc, frame.update_help_changes
|
| 1325 |
+
frame.helplist.delete(0, 'end')
|
| 1326 |
+
frame.user_helplist.clear()
|
| 1327 |
+
|
| 1328 |
+
def setUp(self):
|
| 1329 |
+
changes.clear()
|
| 1330 |
+
|
| 1331 |
+
def test_load_helplist(self):
|
| 1332 |
+
eq = self.assertEqual
|
| 1333 |
+
fr = self.frame
|
| 1334 |
+
fr.helplist.insert('end', 'bad')
|
| 1335 |
+
fr.user_helplist = ['bad', 'worse']
|
| 1336 |
+
idleConf.SetOption('main', 'HelpFiles', '1', 'name;file')
|
| 1337 |
+
fr.load_helplist()
|
| 1338 |
+
eq(fr.helplist.get(0, 'end'), ('name',))
|
| 1339 |
+
eq(fr.user_helplist, [('name', 'file', '1')])
|
| 1340 |
+
|
| 1341 |
+
def test_source_selected(self):
|
| 1342 |
+
fr = self.frame
|
| 1343 |
+
fr.set = fr.set_add_delete_state
|
| 1344 |
+
fr.upc = fr.update_help_changes
|
| 1345 |
+
helplist = fr.helplist
|
| 1346 |
+
dex = 'end'
|
| 1347 |
+
helplist.insert(dex, 'source')
|
| 1348 |
+
helplist.activate(dex)
|
| 1349 |
+
|
| 1350 |
+
helplist.focus_force()
|
| 1351 |
+
helplist.see(dex)
|
| 1352 |
+
helplist.update()
|
| 1353 |
+
x, y, dx, dy = helplist.bbox(dex)
|
| 1354 |
+
x += dx // 2
|
| 1355 |
+
y += dy // 2
|
| 1356 |
+
fr.set.called = fr.upc.called = 0
|
| 1357 |
+
helplist.event_generate('<Enter>', x=0, y=0)
|
| 1358 |
+
helplist.event_generate('<Motion>', x=x, y=y)
|
| 1359 |
+
helplist.event_generate('<Button-1>', x=x, y=y)
|
| 1360 |
+
helplist.event_generate('<ButtonRelease-1>', x=x, y=y)
|
| 1361 |
+
self.assertEqual(helplist.get('anchor'), 'source')
|
| 1362 |
+
self.assertTrue(fr.set.called)
|
| 1363 |
+
self.assertFalse(fr.upc.called)
|
| 1364 |
+
|
| 1365 |
+
def test_set_add_delete_state(self):
|
| 1366 |
+
# Call with 0 items, 1 unselected item, 1 selected item.
|
| 1367 |
+
eq = self.assertEqual
|
| 1368 |
+
fr = self.frame
|
| 1369 |
+
del fr.set_add_delete_state # Unmask method.
|
| 1370 |
+
sad = fr.set_add_delete_state
|
| 1371 |
+
h = fr.helplist
|
| 1372 |
+
|
| 1373 |
+
h.delete(0, 'end')
|
| 1374 |
+
sad()
|
| 1375 |
+
eq(fr.button_helplist_edit.state(), ('disabled',))
|
| 1376 |
+
eq(fr.button_helplist_remove.state(), ('disabled',))
|
| 1377 |
+
|
| 1378 |
+
h.insert(0, 'source')
|
| 1379 |
+
sad()
|
| 1380 |
+
eq(fr.button_helplist_edit.state(), ('disabled',))
|
| 1381 |
+
eq(fr.button_helplist_remove.state(), ('disabled',))
|
| 1382 |
+
|
| 1383 |
+
h.selection_set(0)
|
| 1384 |
+
sad()
|
| 1385 |
+
eq(fr.button_helplist_edit.state(), ())
|
| 1386 |
+
eq(fr.button_helplist_remove.state(), ())
|
| 1387 |
+
fr.set_add_delete_state = Func() # Mask method.
|
| 1388 |
+
|
| 1389 |
+
def test_helplist_item_add(self):
|
| 1390 |
+
# Call without and twice with HelpSource result.
|
| 1391 |
+
# Double call enables check on order.
|
| 1392 |
+
eq = self.assertEqual
|
| 1393 |
+
orig_helpsource = configdialog.HelpSource
|
| 1394 |
+
hs = configdialog.HelpSource = Func(return_self=True)
|
| 1395 |
+
fr = self.frame
|
| 1396 |
+
fr.helplist.delete(0, 'end')
|
| 1397 |
+
fr.user_helplist.clear()
|
| 1398 |
+
fr.set.called = fr.upc.called = 0
|
| 1399 |
+
|
| 1400 |
+
hs.result = ''
|
| 1401 |
+
fr.helplist_item_add()
|
| 1402 |
+
self.assertTrue(list(fr.helplist.get(0, 'end')) ==
|
| 1403 |
+
fr.user_helplist == [])
|
| 1404 |
+
self.assertFalse(fr.upc.called)
|
| 1405 |
+
|
| 1406 |
+
hs.result = ('name1', 'file1')
|
| 1407 |
+
fr.helplist_item_add()
|
| 1408 |
+
hs.result = ('name2', 'file2')
|
| 1409 |
+
fr.helplist_item_add()
|
| 1410 |
+
eq(fr.helplist.get(0, 'end'), ('name1', 'name2'))
|
| 1411 |
+
eq(fr.user_helplist, [('name1', 'file1'), ('name2', 'file2')])
|
| 1412 |
+
eq(fr.upc.called, 2)
|
| 1413 |
+
self.assertFalse(fr.set.called)
|
| 1414 |
+
|
| 1415 |
+
configdialog.HelpSource = orig_helpsource
|
| 1416 |
+
|
| 1417 |
+
def test_helplist_item_edit(self):
|
| 1418 |
+
# Call without and with HelpSource change.
|
| 1419 |
+
eq = self.assertEqual
|
| 1420 |
+
orig_helpsource = configdialog.HelpSource
|
| 1421 |
+
hs = configdialog.HelpSource = Func(return_self=True)
|
| 1422 |
+
fr = self.frame
|
| 1423 |
+
fr.helplist.delete(0, 'end')
|
| 1424 |
+
fr.helplist.insert(0, 'name1')
|
| 1425 |
+
fr.helplist.selection_set(0)
|
| 1426 |
+
fr.helplist.selection_anchor(0)
|
| 1427 |
+
fr.user_helplist.clear()
|
| 1428 |
+
fr.user_helplist.append(('name1', 'file1'))
|
| 1429 |
+
fr.set.called = fr.upc.called = 0
|
| 1430 |
+
|
| 1431 |
+
hs.result = ''
|
| 1432 |
+
fr.helplist_item_edit()
|
| 1433 |
+
hs.result = ('name1', 'file1')
|
| 1434 |
+
fr.helplist_item_edit()
|
| 1435 |
+
eq(fr.helplist.get(0, 'end'), ('name1',))
|
| 1436 |
+
eq(fr.user_helplist, [('name1', 'file1')])
|
| 1437 |
+
self.assertFalse(fr.upc.called)
|
| 1438 |
+
|
| 1439 |
+
hs.result = ('name2', 'file2')
|
| 1440 |
+
fr.helplist_item_edit()
|
| 1441 |
+
eq(fr.helplist.get(0, 'end'), ('name2',))
|
| 1442 |
+
eq(fr.user_helplist, [('name2', 'file2')])
|
| 1443 |
+
self.assertTrue(fr.upc.called == fr.set.called == 1)
|
| 1444 |
+
|
| 1445 |
+
configdialog.HelpSource = orig_helpsource
|
| 1446 |
+
|
| 1447 |
+
def test_helplist_item_remove(self):
|
| 1448 |
+
eq = self.assertEqual
|
| 1449 |
+
fr = self.frame
|
| 1450 |
+
fr.helplist.delete(0, 'end')
|
| 1451 |
+
fr.helplist.insert(0, 'name1')
|
| 1452 |
+
fr.helplist.selection_set(0)
|
| 1453 |
+
fr.helplist.selection_anchor(0)
|
| 1454 |
+
fr.user_helplist.clear()
|
| 1455 |
+
fr.user_helplist.append(('name1', 'file1'))
|
| 1456 |
+
fr.set.called = fr.upc.called = 0
|
| 1457 |
+
|
| 1458 |
+
fr.helplist_item_remove()
|
| 1459 |
+
eq(fr.helplist.get(0, 'end'), ())
|
| 1460 |
+
eq(fr.user_helplist, [])
|
| 1461 |
+
self.assertTrue(fr.upc.called == fr.set.called == 1)
|
| 1462 |
+
|
| 1463 |
+
def test_update_help_changes(self):
|
| 1464 |
+
fr = self.frame
|
| 1465 |
+
del fr.update_help_changes
|
| 1466 |
+
fr.user_helplist.clear()
|
| 1467 |
+
fr.user_helplist.append(('name1', 'file1'))
|
| 1468 |
+
fr.user_helplist.append(('name2', 'file2'))
|
| 1469 |
+
|
| 1470 |
+
fr.update_help_changes()
|
| 1471 |
+
self.assertEqual(mainpage['HelpFiles'],
|
| 1472 |
+
{'1': 'name1;file1', '2': 'name2;file2'})
|
| 1473 |
+
fr.update_help_changes = Func()
|
| 1474 |
+
|
| 1475 |
+
|
| 1476 |
+
class VarTraceTest(unittest.TestCase):
|
| 1477 |
+
|
| 1478 |
+
@classmethod
|
| 1479 |
+
def setUpClass(cls):
|
| 1480 |
+
cls.tracers = configdialog.VarTrace()
|
| 1481 |
+
cls.iv = IntVar(root)
|
| 1482 |
+
cls.bv = BooleanVar(root)
|
| 1483 |
+
|
| 1484 |
+
@classmethod
|
| 1485 |
+
def tearDownClass(cls):
|
| 1486 |
+
del cls.tracers, cls.iv, cls.bv
|
| 1487 |
+
|
| 1488 |
+
def setUp(self):
|
| 1489 |
+
self.tracers.clear()
|
| 1490 |
+
self.called = 0
|
| 1491 |
+
|
| 1492 |
+
def var_changed_increment(self, *params):
|
| 1493 |
+
self.called += 13
|
| 1494 |
+
|
| 1495 |
+
def var_changed_boolean(self, *params):
|
| 1496 |
+
pass
|
| 1497 |
+
|
| 1498 |
+
def test_init(self):
|
| 1499 |
+
tr = self.tracers
|
| 1500 |
+
tr.__init__()
|
| 1501 |
+
self.assertEqual(tr.untraced, [])
|
| 1502 |
+
self.assertEqual(tr.traced, [])
|
| 1503 |
+
|
| 1504 |
+
def test_clear(self):
|
| 1505 |
+
tr = self.tracers
|
| 1506 |
+
tr.untraced.append(0)
|
| 1507 |
+
tr.traced.append(1)
|
| 1508 |
+
tr.clear()
|
| 1509 |
+
self.assertEqual(tr.untraced, [])
|
| 1510 |
+
self.assertEqual(tr.traced, [])
|
| 1511 |
+
|
| 1512 |
+
def test_add(self):
|
| 1513 |
+
tr = self.tracers
|
| 1514 |
+
func = Func()
|
| 1515 |
+
cb = tr.make_callback = mock.Mock(return_value=func)
|
| 1516 |
+
|
| 1517 |
+
iv = tr.add(self.iv, self.var_changed_increment)
|
| 1518 |
+
self.assertIs(iv, self.iv)
|
| 1519 |
+
bv = tr.add(self.bv, self.var_changed_boolean)
|
| 1520 |
+
self.assertIs(bv, self.bv)
|
| 1521 |
+
|
| 1522 |
+
sv = StringVar(root)
|
| 1523 |
+
sv2 = tr.add(sv, ('main', 'section', 'option'))
|
| 1524 |
+
self.assertIs(sv2, sv)
|
| 1525 |
+
cb.assert_called_once()
|
| 1526 |
+
cb.assert_called_with(sv, ('main', 'section', 'option'))
|
| 1527 |
+
|
| 1528 |
+
expected = [(iv, self.var_changed_increment),
|
| 1529 |
+
(bv, self.var_changed_boolean),
|
| 1530 |
+
(sv, func)]
|
| 1531 |
+
self.assertEqual(tr.traced, [])
|
| 1532 |
+
self.assertEqual(tr.untraced, expected)
|
| 1533 |
+
|
| 1534 |
+
del tr.make_callback
|
| 1535 |
+
|
| 1536 |
+
def test_make_callback(self):
|
| 1537 |
+
cb = self.tracers.make_callback(self.iv, ('main', 'section', 'option'))
|
| 1538 |
+
self.assertTrue(callable(cb))
|
| 1539 |
+
self.iv.set(42)
|
| 1540 |
+
# Not attached, so set didn't invoke the callback.
|
| 1541 |
+
self.assertNotIn('section', changes['main'])
|
| 1542 |
+
# Invoke callback manually.
|
| 1543 |
+
cb()
|
| 1544 |
+
self.assertIn('section', changes['main'])
|
| 1545 |
+
self.assertEqual(changes['main']['section']['option'], '42')
|
| 1546 |
+
changes.clear()
|
| 1547 |
+
|
| 1548 |
+
def test_attach_detach(self):
|
| 1549 |
+
tr = self.tracers
|
| 1550 |
+
iv = tr.add(self.iv, self.var_changed_increment)
|
| 1551 |
+
bv = tr.add(self.bv, self.var_changed_boolean)
|
| 1552 |
+
expected = [(iv, self.var_changed_increment),
|
| 1553 |
+
(bv, self.var_changed_boolean)]
|
| 1554 |
+
|
| 1555 |
+
# Attach callbacks and test call increment.
|
| 1556 |
+
tr.attach()
|
| 1557 |
+
self.assertEqual(tr.untraced, [])
|
| 1558 |
+
self.assertCountEqual(tr.traced, expected)
|
| 1559 |
+
iv.set(1)
|
| 1560 |
+
self.assertEqual(iv.get(), 1)
|
| 1561 |
+
self.assertEqual(self.called, 13)
|
| 1562 |
+
|
| 1563 |
+
# Check that only one callback is attached to a variable.
|
| 1564 |
+
# If more than one callback were attached, then var_changed_increment
|
| 1565 |
+
# would be called twice and the counter would be 2.
|
| 1566 |
+
self.called = 0
|
| 1567 |
+
tr.attach()
|
| 1568 |
+
iv.set(1)
|
| 1569 |
+
self.assertEqual(self.called, 13)
|
| 1570 |
+
|
| 1571 |
+
# Detach callbacks.
|
| 1572 |
+
self.called = 0
|
| 1573 |
+
tr.detach()
|
| 1574 |
+
self.assertEqual(tr.traced, [])
|
| 1575 |
+
self.assertCountEqual(tr.untraced, expected)
|
| 1576 |
+
iv.set(1)
|
| 1577 |
+
self.assertEqual(self.called, 0)
|
| 1578 |
+
|
| 1579 |
+
|
| 1580 |
+
if __name__ == '__main__':
|
| 1581 |
+
unittest.main(verbosity=2)
|
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/test_debugger.py
ADDED
|
@@ -0,0 +1,298 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Test debugger, coverage 66%
|
| 2 |
+
|
| 3 |
+
Try to make tests pass with draft bdbx, which may replace bdb in 3.13+.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
from idlelib import debugger
|
| 7 |
+
from collections import namedtuple
|
| 8 |
+
from textwrap import dedent
|
| 9 |
+
from tkinter import Tk
|
| 10 |
+
|
| 11 |
+
from test.support import requires
|
| 12 |
+
from test.support.testcase import ExtraAssertions
|
| 13 |
+
import unittest
|
| 14 |
+
from unittest import mock
|
| 15 |
+
from unittest.mock import Mock, patch
|
| 16 |
+
|
| 17 |
+
"""A test python script for the debug tests."""
|
| 18 |
+
TEST_CODE = dedent("""
|
| 19 |
+
i = 1
|
| 20 |
+
i += 2
|
| 21 |
+
if i == 3:
|
| 22 |
+
print(i)
|
| 23 |
+
""")
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
class MockFrame:
|
| 27 |
+
"Minimal mock frame."
|
| 28 |
+
|
| 29 |
+
def __init__(self, code, lineno):
|
| 30 |
+
self.f_code = code
|
| 31 |
+
self.f_lineno = lineno
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
class IdbTest(unittest.TestCase):
|
| 35 |
+
|
| 36 |
+
@classmethod
|
| 37 |
+
def setUpClass(cls):
|
| 38 |
+
cls.gui = Mock()
|
| 39 |
+
cls.idb = debugger.Idb(cls.gui)
|
| 40 |
+
|
| 41 |
+
# Create test and code objects to simulate a debug session.
|
| 42 |
+
code_obj = compile(TEST_CODE, 'idlelib/file.py', mode='exec')
|
| 43 |
+
frame1 = MockFrame(code_obj, 1)
|
| 44 |
+
frame1.f_back = None
|
| 45 |
+
frame2 = MockFrame(code_obj, 2)
|
| 46 |
+
frame2.f_back = frame1
|
| 47 |
+
cls.frame = frame2
|
| 48 |
+
cls.msg = 'file.py:2: <module>()'
|
| 49 |
+
|
| 50 |
+
def test_init(self):
|
| 51 |
+
self.assertIs(self.idb.gui, self.gui)
|
| 52 |
+
# Won't test super call since two Bdbs are very different.
|
| 53 |
+
|
| 54 |
+
def test_user_line(self):
|
| 55 |
+
# Test that .user_line() creates a string message for a frame.
|
| 56 |
+
self.gui.interaction = Mock()
|
| 57 |
+
self.idb.user_line(self.frame)
|
| 58 |
+
self.gui.interaction.assert_called_once_with(self.msg, self.frame)
|
| 59 |
+
|
| 60 |
+
def test_user_exception(self):
|
| 61 |
+
# Test that .user_exception() creates a string message for a frame.
|
| 62 |
+
exc_info = (type(ValueError), ValueError(), None)
|
| 63 |
+
self.gui.interaction = Mock()
|
| 64 |
+
self.idb.user_exception(self.frame, exc_info)
|
| 65 |
+
self.gui.interaction.assert_called_once_with(
|
| 66 |
+
self.msg, self.frame, exc_info)
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
class FunctionTest(unittest.TestCase):
|
| 70 |
+
# Test module functions together.
|
| 71 |
+
|
| 72 |
+
def test_functions(self):
|
| 73 |
+
rpc_obj = compile(TEST_CODE,'rpc.py', mode='exec')
|
| 74 |
+
rpc_frame = MockFrame(rpc_obj, 2)
|
| 75 |
+
rpc_frame.f_back = rpc_frame
|
| 76 |
+
self.assertTrue(debugger._in_rpc_code(rpc_frame))
|
| 77 |
+
self.assertEqual(debugger._frame2message(rpc_frame),
|
| 78 |
+
'rpc.py:2: <module>()')
|
| 79 |
+
|
| 80 |
+
code_obj = compile(TEST_CODE, 'idlelib/debugger.py', mode='exec')
|
| 81 |
+
code_frame = MockFrame(code_obj, 1)
|
| 82 |
+
code_frame.f_back = None
|
| 83 |
+
self.assertFalse(debugger._in_rpc_code(code_frame))
|
| 84 |
+
self.assertEqual(debugger._frame2message(code_frame),
|
| 85 |
+
'debugger.py:1: <module>()')
|
| 86 |
+
|
| 87 |
+
code_frame.f_back = code_frame
|
| 88 |
+
self.assertFalse(debugger._in_rpc_code(code_frame))
|
| 89 |
+
code_frame.f_back = rpc_frame
|
| 90 |
+
self.assertTrue(debugger._in_rpc_code(code_frame))
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
class DebuggerTest(unittest.TestCase):
|
| 94 |
+
"Tests for Debugger that do not need a real root."
|
| 95 |
+
|
| 96 |
+
@classmethod
|
| 97 |
+
def setUpClass(cls):
|
| 98 |
+
cls.pyshell = Mock()
|
| 99 |
+
cls.pyshell.root = Mock()
|
| 100 |
+
cls.idb = Mock()
|
| 101 |
+
with patch.object(debugger.Debugger, 'make_gui'):
|
| 102 |
+
cls.debugger = debugger.Debugger(cls.pyshell, cls.idb)
|
| 103 |
+
cls.debugger.root = Mock()
|
| 104 |
+
|
| 105 |
+
def test_cont(self):
|
| 106 |
+
self.debugger.cont()
|
| 107 |
+
self.idb.set_continue.assert_called_once()
|
| 108 |
+
|
| 109 |
+
def test_step(self):
|
| 110 |
+
self.debugger.step()
|
| 111 |
+
self.idb.set_step.assert_called_once()
|
| 112 |
+
|
| 113 |
+
def test_quit(self):
|
| 114 |
+
self.debugger.quit()
|
| 115 |
+
self.idb.set_quit.assert_called_once()
|
| 116 |
+
|
| 117 |
+
def test_next(self):
|
| 118 |
+
with patch.object(self.debugger, 'frame') as frame:
|
| 119 |
+
self.debugger.next()
|
| 120 |
+
self.idb.set_next.assert_called_once_with(frame)
|
| 121 |
+
|
| 122 |
+
def test_ret(self):
|
| 123 |
+
with patch.object(self.debugger, 'frame') as frame:
|
| 124 |
+
self.debugger.ret()
|
| 125 |
+
self.idb.set_return.assert_called_once_with(frame)
|
| 126 |
+
|
| 127 |
+
def test_clear_breakpoint(self):
|
| 128 |
+
self.debugger.clear_breakpoint('test.py', 4)
|
| 129 |
+
self.idb.clear_break.assert_called_once_with('test.py', 4)
|
| 130 |
+
|
| 131 |
+
def test_clear_file_breaks(self):
|
| 132 |
+
self.debugger.clear_file_breaks('test.py')
|
| 133 |
+
self.idb.clear_all_file_breaks.assert_called_once_with('test.py')
|
| 134 |
+
|
| 135 |
+
def test_set_load_breakpoints(self):
|
| 136 |
+
# Test the .load_breakpoints() method calls idb.
|
| 137 |
+
FileIO = namedtuple('FileIO', 'filename')
|
| 138 |
+
|
| 139 |
+
class MockEditWindow(object):
|
| 140 |
+
def __init__(self, fn, breakpoints):
|
| 141 |
+
self.io = FileIO(fn)
|
| 142 |
+
self.breakpoints = breakpoints
|
| 143 |
+
|
| 144 |
+
self.pyshell.flist = Mock()
|
| 145 |
+
self.pyshell.flist.inversedict = (
|
| 146 |
+
MockEditWindow('test1.py', [4, 4]),
|
| 147 |
+
MockEditWindow('test2.py', [13, 44, 45]),
|
| 148 |
+
)
|
| 149 |
+
self.debugger.set_breakpoint('test0.py', 1)
|
| 150 |
+
self.idb.set_break.assert_called_once_with('test0.py', 1)
|
| 151 |
+
self.debugger.load_breakpoints() # Call set_breakpoint 5 times.
|
| 152 |
+
self.idb.set_break.assert_has_calls(
|
| 153 |
+
[mock.call('test0.py', 1),
|
| 154 |
+
mock.call('test1.py', 4),
|
| 155 |
+
mock.call('test1.py', 4),
|
| 156 |
+
mock.call('test2.py', 13),
|
| 157 |
+
mock.call('test2.py', 44),
|
| 158 |
+
mock.call('test2.py', 45)])
|
| 159 |
+
|
| 160 |
+
def test_sync_source_line(self):
|
| 161 |
+
# Test that .sync_source_line() will set the flist.gotofileline with fixed frame.
|
| 162 |
+
test_code = compile(TEST_CODE, 'test_sync.py', 'exec')
|
| 163 |
+
test_frame = MockFrame(test_code, 1)
|
| 164 |
+
self.debugger.frame = test_frame
|
| 165 |
+
|
| 166 |
+
self.debugger.flist = Mock()
|
| 167 |
+
with patch('idlelib.debugger.os.path.exists', return_value=True):
|
| 168 |
+
self.debugger.sync_source_line()
|
| 169 |
+
self.debugger.flist.gotofileline.assert_called_once_with('test_sync.py', 1)
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
class DebuggerGuiTest(unittest.TestCase):
|
| 173 |
+
"""Tests for debugger.Debugger that need tk root.
|
| 174 |
+
|
| 175 |
+
close needs debugger.top set in make_gui.
|
| 176 |
+
"""
|
| 177 |
+
|
| 178 |
+
@classmethod
|
| 179 |
+
def setUpClass(cls):
|
| 180 |
+
requires('gui')
|
| 181 |
+
cls.root = root = Tk()
|
| 182 |
+
root.withdraw()
|
| 183 |
+
cls.pyshell = Mock()
|
| 184 |
+
cls.pyshell.root = root
|
| 185 |
+
cls.idb = Mock()
|
| 186 |
+
# stack tests fail with debugger here.
|
| 187 |
+
## cls.debugger = debugger.Debugger(cls.pyshell, cls.idb)
|
| 188 |
+
## cls.debugger.root = root
|
| 189 |
+
## # real root needed for real make_gui
|
| 190 |
+
## # run, interacting, abort_loop
|
| 191 |
+
|
| 192 |
+
@classmethod
|
| 193 |
+
def tearDownClass(cls):
|
| 194 |
+
cls.root.destroy()
|
| 195 |
+
del cls.root
|
| 196 |
+
|
| 197 |
+
def setUp(self):
|
| 198 |
+
self.debugger = debugger.Debugger(self.pyshell, self.idb)
|
| 199 |
+
self.debugger.root = self.root
|
| 200 |
+
# real root needed for real make_gui
|
| 201 |
+
# run, interacting, abort_loop
|
| 202 |
+
|
| 203 |
+
def test_run_debugger(self):
|
| 204 |
+
self.debugger.run(1, 'two')
|
| 205 |
+
self.idb.run.assert_called_once_with(1, 'two')
|
| 206 |
+
self.assertEqual(self.debugger.interacting, 0)
|
| 207 |
+
|
| 208 |
+
def test_close(self):
|
| 209 |
+
# Test closing the window in an idle state.
|
| 210 |
+
self.debugger.close()
|
| 211 |
+
self.pyshell.close_debugger.assert_called_once()
|
| 212 |
+
|
| 213 |
+
def test_show_stack(self):
|
| 214 |
+
self.debugger.show_stack()
|
| 215 |
+
self.assertEqual(self.debugger.stackviewer.gui, self.debugger)
|
| 216 |
+
|
| 217 |
+
def test_show_stack_with_frame(self):
|
| 218 |
+
test_frame = MockFrame(None, None)
|
| 219 |
+
self.debugger.frame = test_frame
|
| 220 |
+
|
| 221 |
+
# Reset the stackviewer to force it to be recreated.
|
| 222 |
+
self.debugger.stackviewer = None
|
| 223 |
+
self.idb.get_stack.return_value = ([], 0)
|
| 224 |
+
self.debugger.show_stack()
|
| 225 |
+
|
| 226 |
+
# Check that the newly created stackviewer has the test gui as a field.
|
| 227 |
+
self.assertEqual(self.debugger.stackviewer.gui, self.debugger)
|
| 228 |
+
self.idb.get_stack.assert_called_once_with(test_frame, None)
|
| 229 |
+
|
| 230 |
+
|
| 231 |
+
class StackViewerTest(unittest.TestCase, ExtraAssertions):
|
| 232 |
+
|
| 233 |
+
@classmethod
|
| 234 |
+
def setUpClass(cls):
|
| 235 |
+
requires('gui')
|
| 236 |
+
cls.root = Tk()
|
| 237 |
+
cls.root.withdraw()
|
| 238 |
+
|
| 239 |
+
@classmethod
|
| 240 |
+
def tearDownClass(cls):
|
| 241 |
+
cls.root.destroy()
|
| 242 |
+
del cls.root
|
| 243 |
+
|
| 244 |
+
def setUp(self):
|
| 245 |
+
self.code = compile(TEST_CODE, 'test_stackviewer.py', 'exec')
|
| 246 |
+
self.stack = [
|
| 247 |
+
(MockFrame(self.code, 1), 1),
|
| 248 |
+
(MockFrame(self.code, 2), 2)
|
| 249 |
+
]
|
| 250 |
+
# Create a stackviewer and load the test stack.
|
| 251 |
+
self.sv = debugger.StackViewer(self.root, None, None)
|
| 252 |
+
self.sv.load_stack(self.stack)
|
| 253 |
+
|
| 254 |
+
def test_init(self):
|
| 255 |
+
# Test creation of StackViewer.
|
| 256 |
+
gui = None
|
| 257 |
+
flist = None
|
| 258 |
+
master_window = self.root
|
| 259 |
+
sv = debugger.StackViewer(master_window, flist, gui)
|
| 260 |
+
self.assertHasAttr(sv, 'stack')
|
| 261 |
+
|
| 262 |
+
def test_load_stack(self):
|
| 263 |
+
# Test the .load_stack() method against a fixed test stack.
|
| 264 |
+
# Check the test stack is assigned and the list contains the repr of them.
|
| 265 |
+
self.assertEqual(self.sv.stack, self.stack)
|
| 266 |
+
self.assertTrue('?.<module>(), line 1:' in self.sv.get(0))
|
| 267 |
+
self.assertEqual(self.sv.get(1), '?.<module>(), line 2: ')
|
| 268 |
+
|
| 269 |
+
def test_show_source(self):
|
| 270 |
+
# Test the .show_source() method against a fixed test stack.
|
| 271 |
+
# Patch out the file list to monitor it
|
| 272 |
+
self.sv.flist = Mock()
|
| 273 |
+
# Patch out isfile to pretend file exists.
|
| 274 |
+
with patch('idlelib.debugger.os.path.isfile', return_value=True) as isfile:
|
| 275 |
+
self.sv.show_source(1)
|
| 276 |
+
isfile.assert_called_once_with('test_stackviewer.py')
|
| 277 |
+
self.sv.flist.open.assert_called_once_with('test_stackviewer.py')
|
| 278 |
+
|
| 279 |
+
|
| 280 |
+
class NameSpaceTest(unittest.TestCase):
|
| 281 |
+
|
| 282 |
+
@classmethod
|
| 283 |
+
def setUpClass(cls):
|
| 284 |
+
requires('gui')
|
| 285 |
+
cls.root = Tk()
|
| 286 |
+
cls.root.withdraw()
|
| 287 |
+
|
| 288 |
+
@classmethod
|
| 289 |
+
def tearDownClass(cls):
|
| 290 |
+
cls.root.destroy()
|
| 291 |
+
del cls.root
|
| 292 |
+
|
| 293 |
+
def test_init(self):
|
| 294 |
+
debugger.NamespaceViewer(self.root, 'Test')
|
| 295 |
+
|
| 296 |
+
|
| 297 |
+
if __name__ == '__main__':
|
| 298 |
+
unittest.main(verbosity=2)
|
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/test_debugger_r.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"Test debugger_r, coverage 30%."
|
| 2 |
+
|
| 3 |
+
from idlelib import debugger_r
|
| 4 |
+
import unittest
|
| 5 |
+
|
| 6 |
+
# Boilerplate likely to be needed for future test classes.
|
| 7 |
+
##from test.support import requires
|
| 8 |
+
##from tkinter import Tk
|
| 9 |
+
##class Test(unittest.TestCase):
|
| 10 |
+
## @classmethod
|
| 11 |
+
## def setUpClass(cls):
|
| 12 |
+
## requires('gui')
|
| 13 |
+
## cls.root = Tk()
|
| 14 |
+
## @classmethod
|
| 15 |
+
## def tearDownClass(cls):
|
| 16 |
+
## cls.root.destroy()
|
| 17 |
+
|
| 18 |
+
# GUIProxy, IdbAdapter, FrameProxy, CodeProxy, DictProxy,
|
| 19 |
+
# GUIAdapter, IdbProxy, and 7 functions still need tests.
|
| 20 |
+
|
| 21 |
+
class IdbAdapterTest(unittest.TestCase):
|
| 22 |
+
|
| 23 |
+
def test_dict_item_noattr(self): # Issue 33065.
|
| 24 |
+
|
| 25 |
+
class BinData:
|
| 26 |
+
def __repr__(self):
|
| 27 |
+
return self.length
|
| 28 |
+
|
| 29 |
+
debugger_r.dicttable[0] = {'BinData': BinData()}
|
| 30 |
+
idb = debugger_r.IdbAdapter(None)
|
| 31 |
+
self.assertTrue(idb.dict_item(0, 'BinData'))
|
| 32 |
+
debugger_r.dicttable.clear()
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
if __name__ == '__main__':
|
| 36 |
+
unittest.main(verbosity=2)
|
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/test_debugobj.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"Test debugobj, coverage 40%."
|
| 2 |
+
|
| 3 |
+
from idlelib import debugobj
|
| 4 |
+
import unittest
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class ObjectTreeItemTest(unittest.TestCase):
|
| 8 |
+
|
| 9 |
+
def test_init(self):
|
| 10 |
+
ti = debugobj.ObjectTreeItem('label', 22)
|
| 11 |
+
self.assertEqual(ti.labeltext, 'label')
|
| 12 |
+
self.assertEqual(ti.object, 22)
|
| 13 |
+
self.assertEqual(ti.setfunction, None)
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class ClassTreeItemTest(unittest.TestCase):
|
| 17 |
+
|
| 18 |
+
def test_isexpandable(self):
|
| 19 |
+
ti = debugobj.ClassTreeItem('label', 0)
|
| 20 |
+
self.assertTrue(ti.IsExpandable())
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
class AtomicObjectTreeItemTest(unittest.TestCase):
|
| 24 |
+
|
| 25 |
+
def test_isexpandable(self):
|
| 26 |
+
ti = debugobj.AtomicObjectTreeItem('label', 0)
|
| 27 |
+
self.assertFalse(ti.IsExpandable())
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
class SequenceTreeItemTest(unittest.TestCase):
|
| 31 |
+
|
| 32 |
+
def test_isexpandable(self):
|
| 33 |
+
ti = debugobj.SequenceTreeItem('label', ())
|
| 34 |
+
self.assertFalse(ti.IsExpandable())
|
| 35 |
+
ti = debugobj.SequenceTreeItem('label', (1,))
|
| 36 |
+
self.assertTrue(ti.IsExpandable())
|
| 37 |
+
|
| 38 |
+
def test_keys(self):
|
| 39 |
+
ti = debugobj.SequenceTreeItem('label', 'abc')
|
| 40 |
+
self.assertEqual(list(ti.keys()), [0, 1, 2]) # keys() is a range.
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
class DictTreeItemTest(unittest.TestCase):
|
| 44 |
+
|
| 45 |
+
def test_isexpandable(self):
|
| 46 |
+
ti = debugobj.DictTreeItem('label', {})
|
| 47 |
+
self.assertFalse(ti.IsExpandable())
|
| 48 |
+
ti = debugobj.DictTreeItem('label', {1:1})
|
| 49 |
+
self.assertTrue(ti.IsExpandable())
|
| 50 |
+
|
| 51 |
+
def test_keys(self):
|
| 52 |
+
ti = debugobj.DictTreeItem('label', {1:1, 0:0, 2:2})
|
| 53 |
+
self.assertEqual(ti.keys(), [0, 1, 2]) # keys() is a sorted list.
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
if __name__ == '__main__':
|
| 57 |
+
unittest.main(verbosity=2)
|
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/test_debugobj_r.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"Test debugobj_r, coverage 56%."
|
| 2 |
+
|
| 3 |
+
from idlelib import debugobj_r
|
| 4 |
+
import unittest
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class WrappedObjectTreeItemTest(unittest.TestCase):
|
| 8 |
+
|
| 9 |
+
def test_getattr(self):
|
| 10 |
+
ti = debugobj_r.WrappedObjectTreeItem(list)
|
| 11 |
+
self.assertEqual(ti.append, list.append)
|
| 12 |
+
|
| 13 |
+
class StubObjectTreeItemTest(unittest.TestCase):
|
| 14 |
+
|
| 15 |
+
def test_init(self):
|
| 16 |
+
ti = debugobj_r.StubObjectTreeItem('socket', 1111)
|
| 17 |
+
self.assertEqual(ti.sockio, 'socket')
|
| 18 |
+
self.assertEqual(ti.oid, 1111)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
if __name__ == '__main__':
|
| 22 |
+
unittest.main(verbosity=2)
|
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/test_delegator.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"Test delegator, coverage 100%."
|
| 2 |
+
|
| 3 |
+
from idlelib.delegator import Delegator
|
| 4 |
+
import unittest
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class DelegatorTest(unittest.TestCase):
|
| 8 |
+
|
| 9 |
+
def test_mydel(self):
|
| 10 |
+
# Test a simple use scenario.
|
| 11 |
+
|
| 12 |
+
# Initialize an int delegator.
|
| 13 |
+
mydel = Delegator(int)
|
| 14 |
+
self.assertIs(mydel.delegate, int)
|
| 15 |
+
self.assertEqual(mydel._Delegator__cache, set())
|
| 16 |
+
# Trying to access a non-attribute of int fails.
|
| 17 |
+
self.assertRaises(AttributeError, mydel.__getattr__, 'xyz')
|
| 18 |
+
|
| 19 |
+
# Add real int attribute 'bit_length' by accessing it.
|
| 20 |
+
bl = mydel.bit_length
|
| 21 |
+
self.assertIs(bl, int.bit_length)
|
| 22 |
+
self.assertIs(mydel.__dict__['bit_length'], int.bit_length)
|
| 23 |
+
self.assertEqual(mydel._Delegator__cache, {'bit_length'})
|
| 24 |
+
|
| 25 |
+
# Add attribute 'numerator'.
|
| 26 |
+
mydel.numerator
|
| 27 |
+
self.assertEqual(mydel._Delegator__cache, {'bit_length', 'numerator'})
|
| 28 |
+
|
| 29 |
+
# Delete 'numerator'.
|
| 30 |
+
del mydel.numerator
|
| 31 |
+
self.assertNotIn('numerator', mydel.__dict__)
|
| 32 |
+
# The current implementation leaves it in the name cache.
|
| 33 |
+
# self.assertIn('numerator', mydel._Delegator__cache)
|
| 34 |
+
# However, this is not required and not part of the specification
|
| 35 |
+
|
| 36 |
+
# Change delegate to float, first resetting the attributes.
|
| 37 |
+
mydel.setdelegate(float) # calls resetcache
|
| 38 |
+
self.assertNotIn('bit_length', mydel.__dict__)
|
| 39 |
+
self.assertEqual(mydel._Delegator__cache, set())
|
| 40 |
+
self.assertIs(mydel.delegate, float)
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
if __name__ == '__main__':
|
| 44 |
+
unittest.main(verbosity=2, exit=2)
|
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/test_editmenu.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''Test (selected) IDLE Edit menu items.
|
| 2 |
+
|
| 3 |
+
Edit modules have their own test files
|
| 4 |
+
'''
|
| 5 |
+
from test.support import requires
|
| 6 |
+
requires('gui')
|
| 7 |
+
import tkinter as tk
|
| 8 |
+
from tkinter import ttk
|
| 9 |
+
import unittest
|
| 10 |
+
from idlelib import pyshell
|
| 11 |
+
|
| 12 |
+
class PasteTest(unittest.TestCase):
|
| 13 |
+
'''Test pasting into widgets that allow pasting.
|
| 14 |
+
|
| 15 |
+
On X11, replacing selections requires tk fix.
|
| 16 |
+
'''
|
| 17 |
+
@classmethod
|
| 18 |
+
def setUpClass(cls):
|
| 19 |
+
cls.root = root = tk.Tk()
|
| 20 |
+
cls.root.withdraw()
|
| 21 |
+
pyshell.fix_x11_paste(root)
|
| 22 |
+
cls.text = tk.Text(root)
|
| 23 |
+
cls.entry = tk.Entry(root)
|
| 24 |
+
cls.tentry = ttk.Entry(root)
|
| 25 |
+
cls.spin = tk.Spinbox(root)
|
| 26 |
+
root.clipboard_clear()
|
| 27 |
+
root.clipboard_append('two')
|
| 28 |
+
|
| 29 |
+
@classmethod
|
| 30 |
+
def tearDownClass(cls):
|
| 31 |
+
del cls.text, cls.entry, cls.tentry
|
| 32 |
+
cls.root.clipboard_clear()
|
| 33 |
+
cls.root.update_idletasks()
|
| 34 |
+
cls.root.destroy()
|
| 35 |
+
del cls.root
|
| 36 |
+
|
| 37 |
+
def test_paste_text(self):
|
| 38 |
+
"Test pasting into text with and without a selection."
|
| 39 |
+
text = self.text
|
| 40 |
+
for tag, ans in ('', 'onetwo\n'), ('sel', 'two\n'):
|
| 41 |
+
with self.subTest(tag=tag, ans=ans):
|
| 42 |
+
text.delete('1.0', 'end')
|
| 43 |
+
text.insert('1.0', 'one', tag)
|
| 44 |
+
text.event_generate('<<Paste>>')
|
| 45 |
+
self.assertEqual(text.get('1.0', 'end'), ans)
|
| 46 |
+
|
| 47 |
+
def test_paste_entry(self):
|
| 48 |
+
"Test pasting into an entry with and without a selection."
|
| 49 |
+
# Generated <<Paste>> fails for tk entry without empty select
|
| 50 |
+
# range for 'no selection'. Live widget works fine.
|
| 51 |
+
for entry in self.entry, self.tentry:
|
| 52 |
+
for end, ans in (0, 'onetwo'), ('end', 'two'):
|
| 53 |
+
with self.subTest(entry=entry, end=end, ans=ans):
|
| 54 |
+
entry.delete(0, 'end')
|
| 55 |
+
entry.insert(0, 'one')
|
| 56 |
+
entry.select_range(0, end)
|
| 57 |
+
entry.event_generate('<<Paste>>')
|
| 58 |
+
self.assertEqual(entry.get(), ans)
|
| 59 |
+
|
| 60 |
+
def test_paste_spin(self):
|
| 61 |
+
"Test pasting into a spinbox with and without a selection."
|
| 62 |
+
# See note above for entry.
|
| 63 |
+
spin = self.spin
|
| 64 |
+
for end, ans in (0, 'onetwo'), ('end', 'two'):
|
| 65 |
+
with self.subTest(end=end, ans=ans):
|
| 66 |
+
spin.delete(0, 'end')
|
| 67 |
+
spin.insert(0, 'one')
|
| 68 |
+
spin.selection('range', 0, end) # see note
|
| 69 |
+
spin.event_generate('<<Paste>>')
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"Test editor, coverage 53%."
|
| 2 |
+
|
| 3 |
+
from idlelib import editor
|
| 4 |
+
import unittest
|
| 5 |
+
from collections import namedtuple
|
| 6 |
+
from test.support import requires
|
| 7 |
+
from tkinter import Tk, Text
|
| 8 |
+
|
| 9 |
+
Editor = editor.EditorWindow
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class EditorWindowTest(unittest.TestCase):
|
| 13 |
+
|
| 14 |
+
@classmethod
|
| 15 |
+
def setUpClass(cls):
|
| 16 |
+
requires('gui')
|
| 17 |
+
cls.root = Tk()
|
| 18 |
+
cls.root.withdraw()
|
| 19 |
+
|
| 20 |
+
@classmethod
|
| 21 |
+
def tearDownClass(cls):
|
| 22 |
+
cls.root.update_idletasks()
|
| 23 |
+
for id in cls.root.tk.call('after', 'info'):
|
| 24 |
+
cls.root.after_cancel(id)
|
| 25 |
+
cls.root.destroy()
|
| 26 |
+
del cls.root
|
| 27 |
+
|
| 28 |
+
def test_init(self):
|
| 29 |
+
e = Editor(root=self.root)
|
| 30 |
+
self.assertEqual(e.root, self.root)
|
| 31 |
+
e._close()
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
class GetLineIndentTest(unittest.TestCase):
|
| 35 |
+
def test_empty_lines(self):
|
| 36 |
+
for tabwidth in [1, 2, 4, 6, 8]:
|
| 37 |
+
for line in ['', '\n']:
|
| 38 |
+
with self.subTest(line=line, tabwidth=tabwidth):
|
| 39 |
+
self.assertEqual(
|
| 40 |
+
editor.get_line_indent(line, tabwidth=tabwidth),
|
| 41 |
+
(0, 0),
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
def test_tabwidth_4(self):
|
| 45 |
+
# (line, (raw, effective))
|
| 46 |
+
tests = (('no spaces', (0, 0)),
|
| 47 |
+
# Internal space isn't counted.
|
| 48 |
+
(' space test', (4, 4)),
|
| 49 |
+
('\ttab test', (1, 4)),
|
| 50 |
+
('\t\tdouble tabs test', (2, 8)),
|
| 51 |
+
# Different results when mixing tabs and spaces.
|
| 52 |
+
(' \tmixed test', (5, 8)),
|
| 53 |
+
(' \t mixed test', (5, 6)),
|
| 54 |
+
('\t mixed test', (5, 8)),
|
| 55 |
+
# Spaces not divisible by tabwidth.
|
| 56 |
+
(' \tmixed test', (3, 4)),
|
| 57 |
+
(' \t mixed test', (3, 5)),
|
| 58 |
+
('\t mixed test', (3, 6)),
|
| 59 |
+
# Only checks spaces and tabs.
|
| 60 |
+
('\nnewline test', (0, 0)))
|
| 61 |
+
|
| 62 |
+
for line, expected in tests:
|
| 63 |
+
with self.subTest(line=line):
|
| 64 |
+
self.assertEqual(
|
| 65 |
+
editor.get_line_indent(line, tabwidth=4),
|
| 66 |
+
expected,
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
+
def test_tabwidth_8(self):
|
| 70 |
+
# (line, (raw, effective))
|
| 71 |
+
tests = (('no spaces', (0, 0)),
|
| 72 |
+
# Internal space isn't counted.
|
| 73 |
+
(' space test', (8, 8)),
|
| 74 |
+
('\ttab test', (1, 8)),
|
| 75 |
+
('\t\tdouble tabs test', (2, 16)),
|
| 76 |
+
# Different results when mixing tabs and spaces.
|
| 77 |
+
(' \tmixed test', (9, 16)),
|
| 78 |
+
(' \t mixed test', (9, 10)),
|
| 79 |
+
('\t mixed test', (9, 16)),
|
| 80 |
+
# Spaces not divisible by tabwidth.
|
| 81 |
+
(' \tmixed test', (3, 8)),
|
| 82 |
+
(' \t mixed test', (3, 9)),
|
| 83 |
+
('\t mixed test', (3, 10)),
|
| 84 |
+
# Only checks spaces and tabs.
|
| 85 |
+
('\nnewline test', (0, 0)))
|
| 86 |
+
|
| 87 |
+
for line, expected in tests:
|
| 88 |
+
with self.subTest(line=line):
|
| 89 |
+
self.assertEqual(
|
| 90 |
+
editor.get_line_indent(line, tabwidth=8),
|
| 91 |
+
expected,
|
| 92 |
+
)
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
def insert(text, string):
|
| 96 |
+
text.delete('1.0', 'end')
|
| 97 |
+
text.insert('end', string)
|
| 98 |
+
text.update_idletasks() # Force update for colorizer to finish.
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
class IndentAndNewlineTest(unittest.TestCase):
|
| 102 |
+
|
| 103 |
+
@classmethod
|
| 104 |
+
def setUpClass(cls):
|
| 105 |
+
requires('gui')
|
| 106 |
+
cls.root = Tk()
|
| 107 |
+
cls.root.withdraw()
|
| 108 |
+
cls.window = Editor(root=cls.root)
|
| 109 |
+
cls.window.indentwidth = 2
|
| 110 |
+
cls.window.tabwidth = 2
|
| 111 |
+
|
| 112 |
+
@classmethod
|
| 113 |
+
def tearDownClass(cls):
|
| 114 |
+
cls.window._close()
|
| 115 |
+
del cls.window
|
| 116 |
+
cls.root.update_idletasks()
|
| 117 |
+
for id in cls.root.tk.call('after', 'info'):
|
| 118 |
+
cls.root.after_cancel(id)
|
| 119 |
+
cls.root.destroy()
|
| 120 |
+
del cls.root
|
| 121 |
+
|
| 122 |
+
def test_indent_and_newline_event(self):
|
| 123 |
+
eq = self.assertEqual
|
| 124 |
+
w = self.window
|
| 125 |
+
text = w.text
|
| 126 |
+
get = text.get
|
| 127 |
+
nl = w.newline_and_indent_event
|
| 128 |
+
|
| 129 |
+
TestInfo = namedtuple('Tests', ['label', 'text', 'expected', 'mark'])
|
| 130 |
+
|
| 131 |
+
tests = (TestInfo('Empty line inserts with no indent.',
|
| 132 |
+
' \n def __init__(self):',
|
| 133 |
+
'\n \n def __init__(self):\n',
|
| 134 |
+
'1.end'),
|
| 135 |
+
TestInfo('Inside bracket before space, deletes space.',
|
| 136 |
+
' def f1(self, a, b):',
|
| 137 |
+
' def f1(self,\n a, b):\n',
|
| 138 |
+
'1.14'),
|
| 139 |
+
TestInfo('Inside bracket after space, deletes space.',
|
| 140 |
+
' def f1(self, a, b):',
|
| 141 |
+
' def f1(self,\n a, b):\n',
|
| 142 |
+
'1.15'),
|
| 143 |
+
TestInfo('Inside string with one line - no indent.',
|
| 144 |
+
' """Docstring."""',
|
| 145 |
+
' """Docstring.\n"""\n',
|
| 146 |
+
'1.15'),
|
| 147 |
+
TestInfo('Inside string with more than one line.',
|
| 148 |
+
' """Docstring.\n Docstring Line 2"""',
|
| 149 |
+
' """Docstring.\n Docstring Line 2\n """\n',
|
| 150 |
+
'2.18'),
|
| 151 |
+
TestInfo('Backslash with one line.',
|
| 152 |
+
'a =\\',
|
| 153 |
+
'a =\\\n \n',
|
| 154 |
+
'1.end'),
|
| 155 |
+
TestInfo('Backslash with more than one line.',
|
| 156 |
+
'a =\\\n multiline\\',
|
| 157 |
+
'a =\\\n multiline\\\n \n',
|
| 158 |
+
'2.end'),
|
| 159 |
+
TestInfo('Block opener - indents +1 level.',
|
| 160 |
+
' def f1(self):\n pass',
|
| 161 |
+
' def f1(self):\n \n pass\n',
|
| 162 |
+
'1.end'),
|
| 163 |
+
TestInfo('Block closer - dedents -1 level.',
|
| 164 |
+
' def f1(self):\n pass',
|
| 165 |
+
' def f1(self):\n pass\n \n',
|
| 166 |
+
'2.end'),
|
| 167 |
+
)
|
| 168 |
+
|
| 169 |
+
for test in tests:
|
| 170 |
+
with self.subTest(label=test.label):
|
| 171 |
+
insert(text, test.text)
|
| 172 |
+
text.mark_set('insert', test.mark)
|
| 173 |
+
nl(event=None)
|
| 174 |
+
eq(get('1.0', 'end'), test.expected)
|
| 175 |
+
|
| 176 |
+
# Selected text.
|
| 177 |
+
insert(text, ' def f1(self, a, b):\n return a + b')
|
| 178 |
+
text.tag_add('sel', '1.17', '1.end')
|
| 179 |
+
nl(None)
|
| 180 |
+
# Deletes selected text before adding new line.
|
| 181 |
+
eq(get('1.0', 'end'), ' def f1(self, a,\n \n return a + b\n')
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
class IndentSearcherTest(unittest.TestCase):
|
| 185 |
+
|
| 186 |
+
@classmethod
|
| 187 |
+
def setUpClass(cls):
|
| 188 |
+
requires('gui')
|
| 189 |
+
cls.root = Tk()
|
| 190 |
+
cls.root.withdraw()
|
| 191 |
+
cls.text = Text(cls.root)
|
| 192 |
+
|
| 193 |
+
@classmethod
|
| 194 |
+
def tearDownClass(cls):
|
| 195 |
+
cls.root.destroy()
|
| 196 |
+
del cls.root
|
| 197 |
+
|
| 198 |
+
def test_searcher(self):
|
| 199 |
+
text = self.text
|
| 200 |
+
searcher = (self.text)
|
| 201 |
+
test_info = (# text, (block, indent))
|
| 202 |
+
("", (None, None)),
|
| 203 |
+
("[1,", (None, None)), # TokenError
|
| 204 |
+
("if 1:\n", ('if 1:\n', None)),
|
| 205 |
+
("if 1:\n 2\n 3\n", ('if 1:\n', ' 2\n')),
|
| 206 |
+
)
|
| 207 |
+
for code, expected_pair in test_info:
|
| 208 |
+
with self.subTest(code=code):
|
| 209 |
+
insert(text, code)
|
| 210 |
+
actual_pair = editor.IndentSearcher(text).run()
|
| 211 |
+
self.assertEqual(actual_pair, expected_pair)
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
class RMenuTest(unittest.TestCase):
|
| 215 |
+
|
| 216 |
+
@classmethod
|
| 217 |
+
def setUpClass(cls):
|
| 218 |
+
requires('gui')
|
| 219 |
+
cls.root = Tk()
|
| 220 |
+
cls.root.withdraw()
|
| 221 |
+
cls.window = Editor(root=cls.root)
|
| 222 |
+
|
| 223 |
+
@classmethod
|
| 224 |
+
def tearDownClass(cls):
|
| 225 |
+
cls.window._close()
|
| 226 |
+
del cls.window
|
| 227 |
+
cls.root.update_idletasks()
|
| 228 |
+
for id in cls.root.tk.call('after', 'info'):
|
| 229 |
+
cls.root.after_cancel(id)
|
| 230 |
+
cls.root.destroy()
|
| 231 |
+
del cls.root
|
| 232 |
+
|
| 233 |
+
class DummyRMenu:
|
| 234 |
+
def tk_popup(x, y): pass
|
| 235 |
+
|
| 236 |
+
def test_rclick(self):
|
| 237 |
+
pass
|
| 238 |
+
|
| 239 |
+
|
| 240 |
+
if __name__ == '__main__':
|
| 241 |
+
unittest.main(verbosity=2)
|
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/test_filelist.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"Test filelist, coverage 19%."
|
| 2 |
+
|
| 3 |
+
from idlelib import filelist
|
| 4 |
+
import unittest
|
| 5 |
+
from test.support import requires
|
| 6 |
+
from tkinter import Tk
|
| 7 |
+
|
| 8 |
+
class FileListTest(unittest.TestCase):
|
| 9 |
+
|
| 10 |
+
@classmethod
|
| 11 |
+
def setUpClass(cls):
|
| 12 |
+
requires('gui')
|
| 13 |
+
cls.root = Tk()
|
| 14 |
+
cls.root.withdraw()
|
| 15 |
+
|
| 16 |
+
@classmethod
|
| 17 |
+
def tearDownClass(cls):
|
| 18 |
+
cls.root.update_idletasks()
|
| 19 |
+
for id in cls.root.tk.call('after', 'info'):
|
| 20 |
+
cls.root.after_cancel(id)
|
| 21 |
+
cls.root.destroy()
|
| 22 |
+
del cls.root
|
| 23 |
+
|
| 24 |
+
def test_new_empty(self):
|
| 25 |
+
flist = filelist.FileList(self.root)
|
| 26 |
+
self.assertEqual(flist.root, self.root)
|
| 27 |
+
e = flist.new()
|
| 28 |
+
self.assertEqual(type(e), flist.EditorWindow)
|
| 29 |
+
e._close()
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
if __name__ == '__main__':
|
| 33 |
+
unittest.main(verbosity=2)
|
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/test_format.py
ADDED
|
@@ -0,0 +1,668 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"Test format, coverage 99%."
|
| 2 |
+
|
| 3 |
+
from idlelib import format as ft
|
| 4 |
+
import unittest
|
| 5 |
+
from unittest import mock
|
| 6 |
+
from test.support import requires
|
| 7 |
+
from tkinter import Tk, Text
|
| 8 |
+
from idlelib.editor import EditorWindow
|
| 9 |
+
from idlelib.idle_test.mock_idle import Editor as MockEditor
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class Is_Get_Test(unittest.TestCase):
|
| 13 |
+
"""Test the is_ and get_ functions"""
|
| 14 |
+
test_comment = '# This is a comment'
|
| 15 |
+
test_nocomment = 'This is not a comment'
|
| 16 |
+
trailingws_comment = '# This is a comment '
|
| 17 |
+
leadingws_comment = ' # This is a comment'
|
| 18 |
+
leadingws_nocomment = ' This is not a comment'
|
| 19 |
+
|
| 20 |
+
def test_is_all_white(self):
|
| 21 |
+
self.assertTrue(ft.is_all_white(''))
|
| 22 |
+
self.assertTrue(ft.is_all_white('\t\n\r\f\v'))
|
| 23 |
+
self.assertFalse(ft.is_all_white(self.test_comment))
|
| 24 |
+
|
| 25 |
+
def test_get_indent(self):
|
| 26 |
+
Equal = self.assertEqual
|
| 27 |
+
Equal(ft.get_indent(self.test_comment), '')
|
| 28 |
+
Equal(ft.get_indent(self.trailingws_comment), '')
|
| 29 |
+
Equal(ft.get_indent(self.leadingws_comment), ' ')
|
| 30 |
+
Equal(ft.get_indent(self.leadingws_nocomment), ' ')
|
| 31 |
+
|
| 32 |
+
def test_get_comment_header(self):
|
| 33 |
+
Equal = self.assertEqual
|
| 34 |
+
# Test comment strings
|
| 35 |
+
Equal(ft.get_comment_header(self.test_comment), '#')
|
| 36 |
+
Equal(ft.get_comment_header(self.trailingws_comment), '#')
|
| 37 |
+
Equal(ft.get_comment_header(self.leadingws_comment), ' #')
|
| 38 |
+
# Test non-comment strings
|
| 39 |
+
Equal(ft.get_comment_header(self.leadingws_nocomment), ' ')
|
| 40 |
+
Equal(ft.get_comment_header(self.test_nocomment), '')
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
class FindTest(unittest.TestCase):
|
| 44 |
+
"""Test the find_paragraph function in paragraph module.
|
| 45 |
+
|
| 46 |
+
Using the runcase() function, find_paragraph() is called with 'mark' set at
|
| 47 |
+
multiple indexes before and inside the test paragraph.
|
| 48 |
+
|
| 49 |
+
It appears that code with the same indentation as a quoted string is grouped
|
| 50 |
+
as part of the same paragraph, which is probably incorrect behavior.
|
| 51 |
+
"""
|
| 52 |
+
|
| 53 |
+
@classmethod
|
| 54 |
+
def setUpClass(cls):
|
| 55 |
+
from idlelib.idle_test.mock_tk import Text
|
| 56 |
+
cls.text = Text()
|
| 57 |
+
|
| 58 |
+
def runcase(self, inserttext, stopline, expected):
|
| 59 |
+
# Check that find_paragraph returns the expected paragraph when
|
| 60 |
+
# the mark index is set to beginning, middle, end of each line
|
| 61 |
+
# up to but not including the stop line
|
| 62 |
+
text = self.text
|
| 63 |
+
text.insert('1.0', inserttext)
|
| 64 |
+
for line in range(1, stopline):
|
| 65 |
+
linelength = int(text.index("%d.end" % line).split('.')[1])
|
| 66 |
+
for col in (0, linelength//2, linelength):
|
| 67 |
+
tempindex = "%d.%d" % (line, col)
|
| 68 |
+
self.assertEqual(ft.find_paragraph(text, tempindex), expected)
|
| 69 |
+
text.delete('1.0', 'end')
|
| 70 |
+
|
| 71 |
+
def test_find_comment(self):
|
| 72 |
+
comment = (
|
| 73 |
+
"# Comment block with no blank lines before\n"
|
| 74 |
+
"# Comment line\n"
|
| 75 |
+
"\n")
|
| 76 |
+
self.runcase(comment, 3, ('1.0', '3.0', '#', comment[0:58]))
|
| 77 |
+
|
| 78 |
+
comment = (
|
| 79 |
+
"\n"
|
| 80 |
+
"# Comment block with whitespace line before and after\n"
|
| 81 |
+
"# Comment line\n"
|
| 82 |
+
"\n")
|
| 83 |
+
self.runcase(comment, 4, ('2.0', '4.0', '#', comment[1:70]))
|
| 84 |
+
|
| 85 |
+
comment = (
|
| 86 |
+
"\n"
|
| 87 |
+
" # Indented comment block with whitespace before and after\n"
|
| 88 |
+
" # Comment line\n"
|
| 89 |
+
"\n")
|
| 90 |
+
self.runcase(comment, 4, ('2.0', '4.0', ' #', comment[1:82]))
|
| 91 |
+
|
| 92 |
+
comment = (
|
| 93 |
+
"\n"
|
| 94 |
+
"# Single line comment\n"
|
| 95 |
+
"\n")
|
| 96 |
+
self.runcase(comment, 3, ('2.0', '3.0', '#', comment[1:23]))
|
| 97 |
+
|
| 98 |
+
comment = (
|
| 99 |
+
"\n"
|
| 100 |
+
" # Single line comment with leading whitespace\n"
|
| 101 |
+
"\n")
|
| 102 |
+
self.runcase(comment, 3, ('2.0', '3.0', ' #', comment[1:51]))
|
| 103 |
+
|
| 104 |
+
comment = (
|
| 105 |
+
"\n"
|
| 106 |
+
"# Comment immediately followed by code\n"
|
| 107 |
+
"x = 42\n"
|
| 108 |
+
"\n")
|
| 109 |
+
self.runcase(comment, 3, ('2.0', '3.0', '#', comment[1:40]))
|
| 110 |
+
|
| 111 |
+
comment = (
|
| 112 |
+
"\n"
|
| 113 |
+
" # Indented comment immediately followed by code\n"
|
| 114 |
+
"x = 42\n"
|
| 115 |
+
"\n")
|
| 116 |
+
self.runcase(comment, 3, ('2.0', '3.0', ' #', comment[1:53]))
|
| 117 |
+
|
| 118 |
+
comment = (
|
| 119 |
+
"\n"
|
| 120 |
+
"# Comment immediately followed by indented code\n"
|
| 121 |
+
" x = 42\n"
|
| 122 |
+
"\n")
|
| 123 |
+
self.runcase(comment, 3, ('2.0', '3.0', '#', comment[1:49]))
|
| 124 |
+
|
| 125 |
+
def test_find_paragraph(self):
|
| 126 |
+
teststring = (
|
| 127 |
+
'"""String with no blank lines before\n'
|
| 128 |
+
'String line\n'
|
| 129 |
+
'"""\n'
|
| 130 |
+
'\n')
|
| 131 |
+
self.runcase(teststring, 4, ('1.0', '4.0', '', teststring[0:53]))
|
| 132 |
+
|
| 133 |
+
teststring = (
|
| 134 |
+
"\n"
|
| 135 |
+
'"""String with whitespace line before and after\n'
|
| 136 |
+
'String line.\n'
|
| 137 |
+
'"""\n'
|
| 138 |
+
'\n')
|
| 139 |
+
self.runcase(teststring, 5, ('2.0', '5.0', '', teststring[1:66]))
|
| 140 |
+
|
| 141 |
+
teststring = (
|
| 142 |
+
'\n'
|
| 143 |
+
' """Indented string with whitespace before and after\n'
|
| 144 |
+
' Comment string.\n'
|
| 145 |
+
' """\n'
|
| 146 |
+
'\n')
|
| 147 |
+
self.runcase(teststring, 5, ('2.0', '5.0', ' ', teststring[1:85]))
|
| 148 |
+
|
| 149 |
+
teststring = (
|
| 150 |
+
'\n'
|
| 151 |
+
'"""Single line string."""\n'
|
| 152 |
+
'\n')
|
| 153 |
+
self.runcase(teststring, 3, ('2.0', '3.0', '', teststring[1:27]))
|
| 154 |
+
|
| 155 |
+
teststring = (
|
| 156 |
+
'\n'
|
| 157 |
+
' """Single line string with leading whitespace."""\n'
|
| 158 |
+
'\n')
|
| 159 |
+
self.runcase(teststring, 3, ('2.0', '3.0', ' ', teststring[1:55]))
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
class ReformatFunctionTest(unittest.TestCase):
|
| 163 |
+
"""Test the reformat_paragraph function without the editor window."""
|
| 164 |
+
|
| 165 |
+
def test_reformat_paragraph(self):
|
| 166 |
+
Equal = self.assertEqual
|
| 167 |
+
reform = ft.reformat_paragraph
|
| 168 |
+
hw = "O hello world"
|
| 169 |
+
Equal(reform(' ', 1), ' ')
|
| 170 |
+
Equal(reform("Hello world", 20), "Hello world")
|
| 171 |
+
|
| 172 |
+
# Test without leading newline
|
| 173 |
+
Equal(reform(hw, 1), "O\nhello\nworld")
|
| 174 |
+
Equal(reform(hw, 6), "O\nhello\nworld")
|
| 175 |
+
Equal(reform(hw, 7), "O hello\nworld")
|
| 176 |
+
Equal(reform(hw, 12), "O hello\nworld")
|
| 177 |
+
Equal(reform(hw, 13), "O hello world")
|
| 178 |
+
|
| 179 |
+
# Test with leading newline
|
| 180 |
+
hw = "\nO hello world"
|
| 181 |
+
Equal(reform(hw, 1), "\nO\nhello\nworld")
|
| 182 |
+
Equal(reform(hw, 6), "\nO\nhello\nworld")
|
| 183 |
+
Equal(reform(hw, 7), "\nO hello\nworld")
|
| 184 |
+
Equal(reform(hw, 12), "\nO hello\nworld")
|
| 185 |
+
Equal(reform(hw, 13), "\nO hello world")
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
class ReformatCommentTest(unittest.TestCase):
|
| 189 |
+
"""Test the reformat_comment function without the editor window."""
|
| 190 |
+
|
| 191 |
+
def test_reformat_comment(self):
|
| 192 |
+
Equal = self.assertEqual
|
| 193 |
+
|
| 194 |
+
# reformat_comment formats to a minimum of 20 characters
|
| 195 |
+
test_string = (
|
| 196 |
+
" \"\"\"this is a test of a reformat for a triple quoted string"
|
| 197 |
+
" will it reformat to less than 70 characters for me?\"\"\"")
|
| 198 |
+
result = ft.reformat_comment(test_string, 70, " ")
|
| 199 |
+
expected = (
|
| 200 |
+
" \"\"\"this is a test of a reformat for a triple quoted string will it\n"
|
| 201 |
+
" reformat to less than 70 characters for me?\"\"\"")
|
| 202 |
+
Equal(result, expected)
|
| 203 |
+
|
| 204 |
+
test_comment = (
|
| 205 |
+
"# this is a test of a reformat for a triple quoted string will "
|
| 206 |
+
"it reformat to less than 70 characters for me?")
|
| 207 |
+
result = ft.reformat_comment(test_comment, 70, "#")
|
| 208 |
+
expected = (
|
| 209 |
+
"# this is a test of a reformat for a triple quoted string will it\n"
|
| 210 |
+
"# reformat to less than 70 characters for me?")
|
| 211 |
+
Equal(result, expected)
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
class FormatClassTest(unittest.TestCase):
|
| 215 |
+
def test_init_close(self):
|
| 216 |
+
instance = ft.FormatParagraph('editor')
|
| 217 |
+
self.assertEqual(instance.editwin, 'editor')
|
| 218 |
+
instance.close()
|
| 219 |
+
self.assertEqual(instance.editwin, None)
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
# For testing format_paragraph_event, Initialize FormatParagraph with
|
| 223 |
+
# a mock Editor with .text and .get_selection_indices. The text must
|
| 224 |
+
# be a Text wrapper that adds two methods
|
| 225 |
+
|
| 226 |
+
# A real EditorWindow creates unneeded, time-consuming baggage and
|
| 227 |
+
# sometimes emits shutdown warnings like this:
|
| 228 |
+
# "warning: callback failed in WindowList <class '_tkinter.TclError'>
|
| 229 |
+
# : invalid command name ".55131368.windows".
|
| 230 |
+
# Calling EditorWindow._close in tearDownClass prevents this but causes
|
| 231 |
+
# other problems (windows left open).
|
| 232 |
+
|
| 233 |
+
class TextWrapper:
|
| 234 |
+
def __init__(self, master):
|
| 235 |
+
self.text = Text(master=master)
|
| 236 |
+
def __getattr__(self, name):
|
| 237 |
+
return getattr(self.text, name)
|
| 238 |
+
def undo_block_start(self): pass
|
| 239 |
+
def undo_block_stop(self): pass
|
| 240 |
+
|
| 241 |
+
class Editor:
|
| 242 |
+
def __init__(self, root):
|
| 243 |
+
self.text = TextWrapper(root)
|
| 244 |
+
get_selection_indices = EditorWindow. get_selection_indices
|
| 245 |
+
|
| 246 |
+
class FormatEventTest(unittest.TestCase):
|
| 247 |
+
"""Test the formatting of text inside a Text widget.
|
| 248 |
+
|
| 249 |
+
This is done with FormatParagraph.format.paragraph_event,
|
| 250 |
+
which calls functions in the module as appropriate.
|
| 251 |
+
"""
|
| 252 |
+
test_string = (
|
| 253 |
+
" '''this is a test of a reformat for a triple "
|
| 254 |
+
"quoted string will it reformat to less than 70 "
|
| 255 |
+
"characters for me?'''\n")
|
| 256 |
+
multiline_test_string = (
|
| 257 |
+
" '''The first line is under the max width.\n"
|
| 258 |
+
" The second line's length is way over the max width. It goes "
|
| 259 |
+
"on and on until it is over 100 characters long.\n"
|
| 260 |
+
" Same thing with the third line. It is also way over the max "
|
| 261 |
+
"width, but FormatParagraph will fix it.\n"
|
| 262 |
+
" '''\n")
|
| 263 |
+
multiline_test_comment = (
|
| 264 |
+
"# The first line is under the max width.\n"
|
| 265 |
+
"# The second line's length is way over the max width. It goes on "
|
| 266 |
+
"and on until it is over 100 characters long.\n"
|
| 267 |
+
"# Same thing with the third line. It is also way over the max "
|
| 268 |
+
"width, but FormatParagraph will fix it.\n"
|
| 269 |
+
"# The fourth line is short like the first line.")
|
| 270 |
+
|
| 271 |
+
@classmethod
|
| 272 |
+
def setUpClass(cls):
|
| 273 |
+
requires('gui')
|
| 274 |
+
cls.root = Tk()
|
| 275 |
+
cls.root.withdraw()
|
| 276 |
+
editor = Editor(root=cls.root)
|
| 277 |
+
cls.text = editor.text.text # Test code does not need the wrapper.
|
| 278 |
+
cls.formatter = ft.FormatParagraph(editor).format_paragraph_event
|
| 279 |
+
# Sets the insert mark just after the re-wrapped and inserted text.
|
| 280 |
+
|
| 281 |
+
@classmethod
|
| 282 |
+
def tearDownClass(cls):
|
| 283 |
+
del cls.text, cls.formatter
|
| 284 |
+
cls.root.update_idletasks()
|
| 285 |
+
cls.root.destroy()
|
| 286 |
+
del cls.root
|
| 287 |
+
|
| 288 |
+
def test_short_line(self):
|
| 289 |
+
self.text.insert('1.0', "Short line\n")
|
| 290 |
+
self.formatter("Dummy")
|
| 291 |
+
self.assertEqual(self.text.get('1.0', 'insert'), "Short line\n" )
|
| 292 |
+
self.text.delete('1.0', 'end')
|
| 293 |
+
|
| 294 |
+
def test_long_line(self):
|
| 295 |
+
text = self.text
|
| 296 |
+
|
| 297 |
+
# Set cursor ('insert' mark) to '1.0', within text.
|
| 298 |
+
text.insert('1.0', self.test_string)
|
| 299 |
+
text.mark_set('insert', '1.0')
|
| 300 |
+
self.formatter('ParameterDoesNothing', limit=70)
|
| 301 |
+
result = text.get('1.0', 'insert')
|
| 302 |
+
# find function includes \n
|
| 303 |
+
expected = (
|
| 304 |
+
" '''this is a test of a reformat for a triple quoted string will it\n"
|
| 305 |
+
" reformat to less than 70 characters for me?'''\n") # yes
|
| 306 |
+
self.assertEqual(result, expected)
|
| 307 |
+
text.delete('1.0', 'end')
|
| 308 |
+
|
| 309 |
+
# Select from 1.11 to line end.
|
| 310 |
+
text.insert('1.0', self.test_string)
|
| 311 |
+
text.tag_add('sel', '1.11', '1.end')
|
| 312 |
+
self.formatter('ParameterDoesNothing', limit=70)
|
| 313 |
+
result = text.get('1.0', 'insert')
|
| 314 |
+
# selection excludes \n
|
| 315 |
+
expected = (
|
| 316 |
+
" '''this is a test of a reformat for a triple quoted string will it reformat\n"
|
| 317 |
+
" to less than 70 characters for me?'''") # no
|
| 318 |
+
self.assertEqual(result, expected)
|
| 319 |
+
text.delete('1.0', 'end')
|
| 320 |
+
|
| 321 |
+
def test_multiple_lines(self):
|
| 322 |
+
text = self.text
|
| 323 |
+
# Select 2 long lines.
|
| 324 |
+
text.insert('1.0', self.multiline_test_string)
|
| 325 |
+
text.tag_add('sel', '2.0', '4.0')
|
| 326 |
+
self.formatter('ParameterDoesNothing', limit=70)
|
| 327 |
+
result = text.get('2.0', 'insert')
|
| 328 |
+
expected = (
|
| 329 |
+
" The second line's length is way over the max width. It goes on and\n"
|
| 330 |
+
" on until it is over 100 characters long. Same thing with the third\n"
|
| 331 |
+
" line. It is also way over the max width, but FormatParagraph will\n"
|
| 332 |
+
" fix it.\n")
|
| 333 |
+
self.assertEqual(result, expected)
|
| 334 |
+
text.delete('1.0', 'end')
|
| 335 |
+
|
| 336 |
+
def test_comment_block(self):
|
| 337 |
+
text = self.text
|
| 338 |
+
|
| 339 |
+
# Set cursor ('insert') to '1.0', within block.
|
| 340 |
+
text.insert('1.0', self.multiline_test_comment)
|
| 341 |
+
self.formatter('ParameterDoesNothing', limit=70)
|
| 342 |
+
result = text.get('1.0', 'insert')
|
| 343 |
+
expected = (
|
| 344 |
+
"# The first line is under the max width. The second line's length is\n"
|
| 345 |
+
"# way over the max width. It goes on and on until it is over 100\n"
|
| 346 |
+
"# characters long. Same thing with the third line. It is also way over\n"
|
| 347 |
+
"# the max width, but FormatParagraph will fix it. The fourth line is\n"
|
| 348 |
+
"# short like the first line.\n")
|
| 349 |
+
self.assertEqual(result, expected)
|
| 350 |
+
text.delete('1.0', 'end')
|
| 351 |
+
|
| 352 |
+
# Select line 2, verify line 1 unaffected.
|
| 353 |
+
text.insert('1.0', self.multiline_test_comment)
|
| 354 |
+
text.tag_add('sel', '2.0', '3.0')
|
| 355 |
+
self.formatter('ParameterDoesNothing', limit=70)
|
| 356 |
+
result = text.get('1.0', 'insert')
|
| 357 |
+
expected = (
|
| 358 |
+
"# The first line is under the max width.\n"
|
| 359 |
+
"# The second line's length is way over the max width. It goes on and\n"
|
| 360 |
+
"# on until it is over 100 characters long.\n")
|
| 361 |
+
self.assertEqual(result, expected)
|
| 362 |
+
text.delete('1.0', 'end')
|
| 363 |
+
|
| 364 |
+
# The following block worked with EditorWindow but fails with the mock.
|
| 365 |
+
# Lines 2 and 3 get pasted together even though the previous block left
|
| 366 |
+
# the previous line alone. More investigation is needed.
|
| 367 |
+
## # Select lines 3 and 4
|
| 368 |
+
## text.insert('1.0', self.multiline_test_comment)
|
| 369 |
+
## text.tag_add('sel', '3.0', '5.0')
|
| 370 |
+
## self.formatter('ParameterDoesNothing')
|
| 371 |
+
## result = text.get('3.0', 'insert')
|
| 372 |
+
## expected = (
|
| 373 |
+
##"# Same thing with the third line. It is also way over the max width,\n"
|
| 374 |
+
##"# but FormatParagraph will fix it. The fourth line is short like the\n"
|
| 375 |
+
##"# first line.\n")
|
| 376 |
+
## self.assertEqual(result, expected)
|
| 377 |
+
## text.delete('1.0', 'end')
|
| 378 |
+
|
| 379 |
+
|
| 380 |
+
class DummyEditwin:
|
| 381 |
+
def __init__(self, root, text):
|
| 382 |
+
self.root = root
|
| 383 |
+
self.text = text
|
| 384 |
+
self.indentwidth = 4
|
| 385 |
+
self.tabwidth = 4
|
| 386 |
+
self.usetabs = False
|
| 387 |
+
self.context_use_ps1 = True
|
| 388 |
+
|
| 389 |
+
_make_blanks = EditorWindow._make_blanks
|
| 390 |
+
get_selection_indices = EditorWindow.get_selection_indices
|
| 391 |
+
|
| 392 |
+
|
| 393 |
+
class FormatRegionTest(unittest.TestCase):
|
| 394 |
+
|
| 395 |
+
@classmethod
|
| 396 |
+
def setUpClass(cls):
|
| 397 |
+
requires('gui')
|
| 398 |
+
cls.root = Tk()
|
| 399 |
+
cls.root.withdraw()
|
| 400 |
+
cls.text = Text(cls.root)
|
| 401 |
+
cls.text.undo_block_start = mock.Mock()
|
| 402 |
+
cls.text.undo_block_stop = mock.Mock()
|
| 403 |
+
cls.editor = DummyEditwin(cls.root, cls.text)
|
| 404 |
+
cls.formatter = ft.FormatRegion(cls.editor)
|
| 405 |
+
|
| 406 |
+
@classmethod
|
| 407 |
+
def tearDownClass(cls):
|
| 408 |
+
del cls.text, cls.formatter, cls.editor
|
| 409 |
+
cls.root.update_idletasks()
|
| 410 |
+
cls.root.destroy()
|
| 411 |
+
del cls.root
|
| 412 |
+
|
| 413 |
+
def setUp(self):
|
| 414 |
+
self.text.insert('1.0', self.code_sample)
|
| 415 |
+
|
| 416 |
+
def tearDown(self):
|
| 417 |
+
self.text.delete('1.0', 'end')
|
| 418 |
+
|
| 419 |
+
code_sample = """\
|
| 420 |
+
# WS line needed for test.
|
| 421 |
+
class C1:
|
| 422 |
+
# Class comment.
|
| 423 |
+
def __init__(self, a, b):
|
| 424 |
+
self.a = a
|
| 425 |
+
self.b = b
|
| 426 |
+
|
| 427 |
+
def compare(self):
|
| 428 |
+
if a > b:
|
| 429 |
+
return a
|
| 430 |
+
elif a < b:
|
| 431 |
+
return b
|
| 432 |
+
else:
|
| 433 |
+
return None
|
| 434 |
+
"""
|
| 435 |
+
|
| 436 |
+
def test_get_region(self):
|
| 437 |
+
get = self.formatter.get_region
|
| 438 |
+
text = self.text
|
| 439 |
+
eq = self.assertEqual
|
| 440 |
+
|
| 441 |
+
# Add selection.
|
| 442 |
+
text.tag_add('sel', '7.0', '10.0')
|
| 443 |
+
expected_lines = ['',
|
| 444 |
+
' def compare(self):',
|
| 445 |
+
' if a > b:',
|
| 446 |
+
'']
|
| 447 |
+
eq(get(), ('7.0', '10.0', '\n'.join(expected_lines), expected_lines))
|
| 448 |
+
|
| 449 |
+
# Remove selection.
|
| 450 |
+
text.tag_remove('sel', '1.0', 'end')
|
| 451 |
+
eq(get(), ('15.0', '16.0', '\n', ['', '']))
|
| 452 |
+
|
| 453 |
+
def test_set_region(self):
|
| 454 |
+
set_ = self.formatter.set_region
|
| 455 |
+
text = self.text
|
| 456 |
+
eq = self.assertEqual
|
| 457 |
+
|
| 458 |
+
save_bell = text.bell
|
| 459 |
+
text.bell = mock.Mock()
|
| 460 |
+
line6 = self.code_sample.splitlines()[5]
|
| 461 |
+
line10 = self.code_sample.splitlines()[9]
|
| 462 |
+
|
| 463 |
+
text.tag_add('sel', '6.0', '11.0')
|
| 464 |
+
head, tail, chars, lines = self.formatter.get_region()
|
| 465 |
+
|
| 466 |
+
# No changes.
|
| 467 |
+
set_(head, tail, chars, lines)
|
| 468 |
+
text.bell.assert_called_once()
|
| 469 |
+
eq(text.get('6.0', '11.0'), chars)
|
| 470 |
+
eq(text.get('sel.first', 'sel.last'), chars)
|
| 471 |
+
text.tag_remove('sel', '1.0', 'end')
|
| 472 |
+
|
| 473 |
+
# Alter selected lines by changing lines and adding a newline.
|
| 474 |
+
newstring = 'added line 1\n\n\n\n'
|
| 475 |
+
newlines = newstring.split('\n')
|
| 476 |
+
set_('7.0', '10.0', chars, newlines)
|
| 477 |
+
# Selection changed.
|
| 478 |
+
eq(text.get('sel.first', 'sel.last'), newstring)
|
| 479 |
+
# Additional line added, so last index is changed.
|
| 480 |
+
eq(text.get('7.0', '11.0'), newstring)
|
| 481 |
+
# Before and after lines unchanged.
|
| 482 |
+
eq(text.get('6.0', '7.0-1c'), line6)
|
| 483 |
+
eq(text.get('11.0', '12.0-1c'), line10)
|
| 484 |
+
text.tag_remove('sel', '1.0', 'end')
|
| 485 |
+
|
| 486 |
+
text.bell = save_bell
|
| 487 |
+
|
| 488 |
+
def test_indent_region_event(self):
|
| 489 |
+
indent = self.formatter.indent_region_event
|
| 490 |
+
text = self.text
|
| 491 |
+
eq = self.assertEqual
|
| 492 |
+
|
| 493 |
+
text.tag_add('sel', '7.0', '10.0')
|
| 494 |
+
indent()
|
| 495 |
+
# Blank lines aren't affected by indent.
|
| 496 |
+
eq(text.get('7.0', '10.0'), ('\n def compare(self):\n if a > b:\n'))
|
| 497 |
+
|
| 498 |
+
def test_dedent_region_event(self):
|
| 499 |
+
dedent = self.formatter.dedent_region_event
|
| 500 |
+
text = self.text
|
| 501 |
+
eq = self.assertEqual
|
| 502 |
+
|
| 503 |
+
text.tag_add('sel', '7.0', '10.0')
|
| 504 |
+
dedent()
|
| 505 |
+
# Blank lines aren't affected by dedent.
|
| 506 |
+
eq(text.get('7.0', '10.0'), ('\ndef compare(self):\n if a > b:\n'))
|
| 507 |
+
|
| 508 |
+
def test_comment_region_event(self):
|
| 509 |
+
comment = self.formatter.comment_region_event
|
| 510 |
+
text = self.text
|
| 511 |
+
eq = self.assertEqual
|
| 512 |
+
|
| 513 |
+
text.tag_add('sel', '7.0', '10.0')
|
| 514 |
+
comment()
|
| 515 |
+
eq(text.get('7.0', '10.0'), ('##\n## def compare(self):\n## if a > b:\n'))
|
| 516 |
+
|
| 517 |
+
def test_uncomment_region_event(self):
|
| 518 |
+
comment = self.formatter.comment_region_event
|
| 519 |
+
uncomment = self.formatter.uncomment_region_event
|
| 520 |
+
text = self.text
|
| 521 |
+
eq = self.assertEqual
|
| 522 |
+
|
| 523 |
+
text.tag_add('sel', '7.0', '10.0')
|
| 524 |
+
comment()
|
| 525 |
+
uncomment()
|
| 526 |
+
eq(text.get('7.0', '10.0'), ('\n def compare(self):\n if a > b:\n'))
|
| 527 |
+
|
| 528 |
+
# Only remove comments at the beginning of a line.
|
| 529 |
+
text.tag_remove('sel', '1.0', 'end')
|
| 530 |
+
text.tag_add('sel', '3.0', '4.0')
|
| 531 |
+
uncomment()
|
| 532 |
+
eq(text.get('3.0', '3.end'), (' # Class comment.'))
|
| 533 |
+
|
| 534 |
+
self.formatter.set_region('3.0', '4.0', '', ['# Class comment.', ''])
|
| 535 |
+
uncomment()
|
| 536 |
+
eq(text.get('3.0', '3.end'), (' Class comment.'))
|
| 537 |
+
|
| 538 |
+
@mock.patch.object(ft.FormatRegion, "_asktabwidth")
|
| 539 |
+
def test_tabify_region_event(self, _asktabwidth):
|
| 540 |
+
tabify = self.formatter.tabify_region_event
|
| 541 |
+
text = self.text
|
| 542 |
+
eq = self.assertEqual
|
| 543 |
+
|
| 544 |
+
text.tag_add('sel', '7.0', '10.0')
|
| 545 |
+
# No tabwidth selected.
|
| 546 |
+
_asktabwidth.return_value = None
|
| 547 |
+
self.assertIsNone(tabify())
|
| 548 |
+
|
| 549 |
+
_asktabwidth.return_value = 3
|
| 550 |
+
self.assertIsNotNone(tabify())
|
| 551 |
+
eq(text.get('7.0', '10.0'), ('\n\t def compare(self):\n\t\t if a > b:\n'))
|
| 552 |
+
|
| 553 |
+
@mock.patch.object(ft.FormatRegion, "_asktabwidth")
|
| 554 |
+
def test_untabify_region_event(self, _asktabwidth):
|
| 555 |
+
untabify = self.formatter.untabify_region_event
|
| 556 |
+
text = self.text
|
| 557 |
+
eq = self.assertEqual
|
| 558 |
+
|
| 559 |
+
text.tag_add('sel', '7.0', '10.0')
|
| 560 |
+
# No tabwidth selected.
|
| 561 |
+
_asktabwidth.return_value = None
|
| 562 |
+
self.assertIsNone(untabify())
|
| 563 |
+
|
| 564 |
+
_asktabwidth.return_value = 2
|
| 565 |
+
self.formatter.tabify_region_event()
|
| 566 |
+
_asktabwidth.return_value = 3
|
| 567 |
+
self.assertIsNotNone(untabify())
|
| 568 |
+
eq(text.get('7.0', '10.0'), ('\n def compare(self):\n if a > b:\n'))
|
| 569 |
+
|
| 570 |
+
@mock.patch.object(ft, "askinteger")
|
| 571 |
+
def test_ask_tabwidth(self, askinteger):
|
| 572 |
+
ask = self.formatter._asktabwidth
|
| 573 |
+
askinteger.return_value = 10
|
| 574 |
+
self.assertEqual(ask(), 10)
|
| 575 |
+
|
| 576 |
+
|
| 577 |
+
class IndentsTest(unittest.TestCase):
|
| 578 |
+
|
| 579 |
+
@mock.patch.object(ft, "askyesno")
|
| 580 |
+
def test_toggle_tabs(self, askyesno):
|
| 581 |
+
editor = DummyEditwin(None, None) # usetabs == False.
|
| 582 |
+
indents = ft.Indents(editor)
|
| 583 |
+
askyesno.return_value = True
|
| 584 |
+
|
| 585 |
+
indents.toggle_tabs_event(None)
|
| 586 |
+
self.assertEqual(editor.usetabs, True)
|
| 587 |
+
self.assertEqual(editor.indentwidth, 8)
|
| 588 |
+
|
| 589 |
+
indents.toggle_tabs_event(None)
|
| 590 |
+
self.assertEqual(editor.usetabs, False)
|
| 591 |
+
self.assertEqual(editor.indentwidth, 8)
|
| 592 |
+
|
| 593 |
+
@mock.patch.object(ft, "askinteger")
|
| 594 |
+
def test_change_indentwidth(self, askinteger):
|
| 595 |
+
editor = DummyEditwin(None, None) # indentwidth == 4.
|
| 596 |
+
indents = ft.Indents(editor)
|
| 597 |
+
|
| 598 |
+
askinteger.return_value = None
|
| 599 |
+
indents.change_indentwidth_event(None)
|
| 600 |
+
self.assertEqual(editor.indentwidth, 4)
|
| 601 |
+
|
| 602 |
+
askinteger.return_value = 3
|
| 603 |
+
indents.change_indentwidth_event(None)
|
| 604 |
+
self.assertEqual(editor.indentwidth, 3)
|
| 605 |
+
|
| 606 |
+
askinteger.return_value = 5
|
| 607 |
+
editor.usetabs = True
|
| 608 |
+
indents.change_indentwidth_event(None)
|
| 609 |
+
self.assertEqual(editor.indentwidth, 3)
|
| 610 |
+
|
| 611 |
+
|
| 612 |
+
class RstripTest(unittest.TestCase):
|
| 613 |
+
|
| 614 |
+
@classmethod
|
| 615 |
+
def setUpClass(cls):
|
| 616 |
+
requires('gui')
|
| 617 |
+
cls.root = Tk()
|
| 618 |
+
cls.root.withdraw()
|
| 619 |
+
cls.text = Text(cls.root)
|
| 620 |
+
cls.editor = MockEditor(text=cls.text)
|
| 621 |
+
cls.do_rstrip = ft.Rstrip(cls.editor).do_rstrip
|
| 622 |
+
|
| 623 |
+
@classmethod
|
| 624 |
+
def tearDownClass(cls):
|
| 625 |
+
del cls.text, cls.do_rstrip, cls.editor
|
| 626 |
+
cls.root.update_idletasks()
|
| 627 |
+
cls.root.destroy()
|
| 628 |
+
del cls.root
|
| 629 |
+
|
| 630 |
+
def tearDown(self):
|
| 631 |
+
self.text.delete('1.0', 'end-1c')
|
| 632 |
+
|
| 633 |
+
def test_rstrip_lines(self):
|
| 634 |
+
original = (
|
| 635 |
+
"Line with an ending tab \n"
|
| 636 |
+
"Line ending in 5 spaces \n"
|
| 637 |
+
"Linewithnospaces\n"
|
| 638 |
+
" indented line\n"
|
| 639 |
+
" indented line with trailing space \n"
|
| 640 |
+
" \n")
|
| 641 |
+
stripped = (
|
| 642 |
+
"Line with an ending tab\n"
|
| 643 |
+
"Line ending in 5 spaces\n"
|
| 644 |
+
"Linewithnospaces\n"
|
| 645 |
+
" indented line\n"
|
| 646 |
+
" indented line with trailing space\n")
|
| 647 |
+
|
| 648 |
+
self.text.insert('1.0', original)
|
| 649 |
+
self.do_rstrip()
|
| 650 |
+
self.assertEqual(self.text.get('1.0', 'insert'), stripped)
|
| 651 |
+
|
| 652 |
+
def test_rstrip_end(self):
|
| 653 |
+
text = self.text
|
| 654 |
+
for code in ('', '\n', '\n\n\n'):
|
| 655 |
+
with self.subTest(code=code):
|
| 656 |
+
text.insert('1.0', code)
|
| 657 |
+
self.do_rstrip()
|
| 658 |
+
self.assertEqual(text.get('1.0','end-1c'), '')
|
| 659 |
+
for code in ('a\n', 'a\n\n', 'a\n\n\n'):
|
| 660 |
+
with self.subTest(code=code):
|
| 661 |
+
text.delete('1.0', 'end-1c')
|
| 662 |
+
text.insert('1.0', code)
|
| 663 |
+
self.do_rstrip()
|
| 664 |
+
self.assertEqual(text.get('1.0','end-1c'), 'a\n')
|
| 665 |
+
|
| 666 |
+
|
| 667 |
+
if __name__ == '__main__':
|
| 668 |
+
unittest.main(verbosity=2, exit=2)
|
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/test_grep.py
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
""" !Changing this line will break Test_findfile.test_found!
|
| 2 |
+
Non-gui unit tests for grep.GrepDialog methods.
|
| 3 |
+
dummy_command calls grep_it calls findfiles.
|
| 4 |
+
An exception raised in one method will fail callers.
|
| 5 |
+
Otherwise, tests are mostly independent.
|
| 6 |
+
Currently only test grep_it, coverage 51%.
|
| 7 |
+
"""
|
| 8 |
+
from idlelib import grep
|
| 9 |
+
import unittest
|
| 10 |
+
from test.support import captured_stdout
|
| 11 |
+
from test.support.testcase import ExtraAssertions
|
| 12 |
+
from idlelib.idle_test.mock_tk import Var
|
| 13 |
+
import os
|
| 14 |
+
import re
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
class Dummy_searchengine:
|
| 18 |
+
'''GrepDialog.__init__ calls parent SearchDiabolBase which attaches the
|
| 19 |
+
passed in SearchEngine instance as attribute 'engine'. Only a few of the
|
| 20 |
+
many possible self.engine.x attributes are needed here.
|
| 21 |
+
'''
|
| 22 |
+
def getpat(self):
|
| 23 |
+
return self._pat
|
| 24 |
+
|
| 25 |
+
searchengine = Dummy_searchengine()
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
class Dummy_grep:
|
| 29 |
+
# Methods tested
|
| 30 |
+
#default_command = GrepDialog.default_command
|
| 31 |
+
grep_it = grep.GrepDialog.grep_it
|
| 32 |
+
# Other stuff needed
|
| 33 |
+
recvar = Var(False)
|
| 34 |
+
engine = searchengine
|
| 35 |
+
def close(self): # gui method
|
| 36 |
+
pass
|
| 37 |
+
|
| 38 |
+
_grep = Dummy_grep()
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
class FindfilesTest(unittest.TestCase):
|
| 42 |
+
|
| 43 |
+
@classmethod
|
| 44 |
+
def setUpClass(cls):
|
| 45 |
+
cls.realpath = os.path.realpath(__file__)
|
| 46 |
+
cls.path = os.path.dirname(cls.realpath)
|
| 47 |
+
|
| 48 |
+
@classmethod
|
| 49 |
+
def tearDownClass(cls):
|
| 50 |
+
del cls.realpath, cls.path
|
| 51 |
+
|
| 52 |
+
def test_invaliddir(self):
|
| 53 |
+
with captured_stdout() as s:
|
| 54 |
+
filelist = list(grep.findfiles('invaliddir', '*.*', False))
|
| 55 |
+
self.assertEqual(filelist, [])
|
| 56 |
+
self.assertIn('invalid', s.getvalue())
|
| 57 |
+
|
| 58 |
+
def test_curdir(self):
|
| 59 |
+
# Test os.curdir.
|
| 60 |
+
ff = grep.findfiles
|
| 61 |
+
save_cwd = os.getcwd()
|
| 62 |
+
os.chdir(self.path)
|
| 63 |
+
filename = 'test_grep.py'
|
| 64 |
+
filelist = list(ff(os.curdir, filename, False))
|
| 65 |
+
self.assertIn(os.path.join(os.curdir, filename), filelist)
|
| 66 |
+
os.chdir(save_cwd)
|
| 67 |
+
|
| 68 |
+
def test_base(self):
|
| 69 |
+
ff = grep.findfiles
|
| 70 |
+
readme = os.path.join(self.path, 'README.txt')
|
| 71 |
+
|
| 72 |
+
# Check for Python files in path where this file lives.
|
| 73 |
+
filelist = list(ff(self.path, '*.py', False))
|
| 74 |
+
# This directory has many Python files.
|
| 75 |
+
self.assertGreater(len(filelist), 10)
|
| 76 |
+
self.assertIn(self.realpath, filelist)
|
| 77 |
+
self.assertNotIn(readme, filelist)
|
| 78 |
+
|
| 79 |
+
# Look for .txt files in path where this file lives.
|
| 80 |
+
filelist = list(ff(self.path, '*.txt', False))
|
| 81 |
+
self.assertNotEqual(len(filelist), 0)
|
| 82 |
+
self.assertNotIn(self.realpath, filelist)
|
| 83 |
+
self.assertIn(readme, filelist)
|
| 84 |
+
|
| 85 |
+
# Look for non-matching pattern.
|
| 86 |
+
filelist = list(ff(self.path, 'grep.*', False))
|
| 87 |
+
self.assertEqual(len(filelist), 0)
|
| 88 |
+
self.assertNotIn(self.realpath, filelist)
|
| 89 |
+
|
| 90 |
+
def test_recurse(self):
|
| 91 |
+
ff = grep.findfiles
|
| 92 |
+
parent = os.path.dirname(self.path)
|
| 93 |
+
grepfile = os.path.join(parent, 'grep.py')
|
| 94 |
+
pat = '*.py'
|
| 95 |
+
|
| 96 |
+
# Get Python files only in parent directory.
|
| 97 |
+
filelist = list(ff(parent, pat, False))
|
| 98 |
+
parent_size = len(filelist)
|
| 99 |
+
# Lots of Python files in idlelib.
|
| 100 |
+
self.assertGreater(parent_size, 20)
|
| 101 |
+
self.assertIn(grepfile, filelist)
|
| 102 |
+
# Without subdirectories, this file isn't returned.
|
| 103 |
+
self.assertNotIn(self.realpath, filelist)
|
| 104 |
+
|
| 105 |
+
# Include subdirectories.
|
| 106 |
+
filelist = list(ff(parent, pat, True))
|
| 107 |
+
# More files found now.
|
| 108 |
+
self.assertGreater(len(filelist), parent_size)
|
| 109 |
+
self.assertIn(grepfile, filelist)
|
| 110 |
+
# This file exists in list now.
|
| 111 |
+
self.assertIn(self.realpath, filelist)
|
| 112 |
+
|
| 113 |
+
# Check another level up the tree.
|
| 114 |
+
parent = os.path.dirname(parent)
|
| 115 |
+
filelist = list(ff(parent, '*.py', True))
|
| 116 |
+
self.assertIn(self.realpath, filelist)
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
class Grep_itTest(unittest.TestCase, ExtraAssertions):
|
| 120 |
+
# Test captured reports with 0 and some hits.
|
| 121 |
+
# Should test file names, but Windows reports have mixed / and \ separators
|
| 122 |
+
# from incomplete replacement, so 'later'.
|
| 123 |
+
|
| 124 |
+
def report(self, pat):
|
| 125 |
+
_grep.engine._pat = pat
|
| 126 |
+
with captured_stdout() as s:
|
| 127 |
+
_grep.grep_it(re.compile(pat), __file__)
|
| 128 |
+
lines = s.getvalue().split('\n')
|
| 129 |
+
lines.pop() # remove bogus '' after last \n
|
| 130 |
+
return lines
|
| 131 |
+
|
| 132 |
+
def test_unfound(self):
|
| 133 |
+
pat = 'xyz*'*7
|
| 134 |
+
lines = self.report(pat)
|
| 135 |
+
self.assertEqual(len(lines), 2)
|
| 136 |
+
self.assertIn(pat, lines[0])
|
| 137 |
+
self.assertEqual(lines[1], 'No hits.')
|
| 138 |
+
|
| 139 |
+
def test_found(self):
|
| 140 |
+
|
| 141 |
+
pat = '""" !Changing this line will break Test_findfile.test_found!'
|
| 142 |
+
lines = self.report(pat)
|
| 143 |
+
self.assertEqual(len(lines), 5)
|
| 144 |
+
self.assertIn(pat, lines[0])
|
| 145 |
+
self.assertIn('py: 1:', lines[1]) # line number 1
|
| 146 |
+
self.assertIn('2', lines[3]) # hits found 2
|
| 147 |
+
self.assertStartsWith(lines[4], '(Hint:')
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
class Default_commandTest(unittest.TestCase):
|
| 151 |
+
# To write this, move outwin import to top of GrepDialog
|
| 152 |
+
# so it can be replaced by captured_stdout in class setup/teardown.
|
| 153 |
+
pass
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
if __name__ == '__main__':
|
| 157 |
+
unittest.main(verbosity=2)
|
miniconda3/pkgs/python-3.13.12-hb7b561f_100_cp313/lib/python3.13/idlelib/idle_test/test_help.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"Test help, coverage 94%."
|
| 2 |
+
|
| 3 |
+
from idlelib import help
|
| 4 |
+
import unittest
|
| 5 |
+
from test.support import requires
|
| 6 |
+
requires('gui')
|
| 7 |
+
from os.path import abspath, dirname, join
|
| 8 |
+
from tkinter import Tk
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class IdleDocTest(unittest.TestCase):
|
| 12 |
+
|
| 13 |
+
@classmethod
|
| 14 |
+
def setUpClass(cls):
|
| 15 |
+
"By itself, this tests that file parsed without exception."
|
| 16 |
+
cls.root = root = Tk()
|
| 17 |
+
root.withdraw()
|
| 18 |
+
cls.window = help.show_idlehelp(root)
|
| 19 |
+
|
| 20 |
+
@classmethod
|
| 21 |
+
def tearDownClass(cls):
|
| 22 |
+
del cls.window
|
| 23 |
+
cls.root.update_idletasks()
|
| 24 |
+
cls.root.destroy()
|
| 25 |
+
del cls.root
|
| 26 |
+
|
| 27 |
+
def test_1window(self):
|
| 28 |
+
self.assertIn('IDLE Doc', self.window.wm_title())
|
| 29 |
+
|
| 30 |
+
def test_4text(self):
|
| 31 |
+
text = self.window.frame.text
|
| 32 |
+
self.assertEqual(text.get('1.0', '1.end'), ' IDLE — Python editor and shell ')
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
if __name__ == '__main__':
|
| 36 |
+
unittest.main(verbosity=2)
|