Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- evalkit_cambrian/lib/python3.10/idlelib/Icons/README.txt +13 -0
- evalkit_cambrian/lib/python3.10/idlelib/Icons/folder.gif +3 -0
- evalkit_cambrian/lib/python3.10/idlelib/Icons/idle.ico +0 -0
- evalkit_cambrian/lib/python3.10/idlelib/Icons/idle_16.gif +3 -0
- evalkit_cambrian/lib/python3.10/idlelib/Icons/idle_16.png +3 -0
- evalkit_cambrian/lib/python3.10/idlelib/Icons/idle_256.png +3 -0
- evalkit_cambrian/lib/python3.10/idlelib/Icons/idle_48.gif +3 -0
- evalkit_cambrian/lib/python3.10/idlelib/Icons/idle_48.png +3 -0
- evalkit_cambrian/lib/python3.10/idlelib/Icons/openfolder.gif +3 -0
- evalkit_cambrian/lib/python3.10/idlelib/Icons/plusnode.gif +3 -0
- evalkit_cambrian/lib/python3.10/idlelib/NEWS.txt +1321 -0
- evalkit_cambrian/lib/python3.10/idlelib/TODO.txt +210 -0
- evalkit_cambrian/lib/python3.10/idlelib/autocomplete_w.py +502 -0
- evalkit_cambrian/lib/python3.10/idlelib/browser.py +258 -0
- evalkit_cambrian/lib/python3.10/idlelib/codecontext.py +270 -0
- evalkit_cambrian/lib/python3.10/idlelib/config.py +911 -0
- evalkit_cambrian/lib/python3.10/idlelib/debugobj.py +142 -0
- evalkit_cambrian/lib/python3.10/idlelib/debugobj_r.py +41 -0
- evalkit_cambrian/lib/python3.10/idlelib/extend.txt +83 -0
- evalkit_cambrian/lib/python3.10/idlelib/filelist.py +131 -0
- evalkit_cambrian/lib/python3.10/idlelib/grep.py +221 -0
- evalkit_cambrian/lib/python3.10/idlelib/history.py +106 -0
- evalkit_cambrian/lib/python3.10/idlelib/idle.bat +4 -0
- evalkit_cambrian/lib/python3.10/idlelib/idle.pyw +17 -0
- evalkit_cambrian/lib/python3.10/idlelib/idle_test/README.txt +238 -0
- evalkit_cambrian/lib/python3.10/idlelib/idle_test/__init__.py +17 -0
- evalkit_cambrian/lib/python3.10/idlelib/idle_test/example_noext +4 -0
- evalkit_cambrian/lib/python3.10/idlelib/idle_test/example_stub.pyi +2 -0
- evalkit_cambrian/lib/python3.10/idlelib/idle_test/mock_idle.py +61 -0
- evalkit_cambrian/lib/python3.10/idlelib/idle_test/mock_tk.py +307 -0
- evalkit_cambrian/lib/python3.10/idlelib/idle_test/template.py +30 -0
- evalkit_cambrian/lib/python3.10/idlelib/idle_test/test_autocomplete.py +305 -0
- evalkit_cambrian/lib/python3.10/idlelib/idle_test/test_autocomplete_w.py +32 -0
- evalkit_cambrian/lib/python3.10/idlelib/idle_test/test_autoexpand.py +155 -0
- evalkit_cambrian/lib/python3.10/idlelib/idle_test/test_browser.py +257 -0
- evalkit_cambrian/lib/python3.10/idlelib/idle_test/test_calltip_w.py +29 -0
- evalkit_cambrian/lib/python3.10/idlelib/idle_test/test_codecontext.py +455 -0
- evalkit_cambrian/lib/python3.10/idlelib/idle_test/test_colorizer.py +622 -0
- evalkit_cambrian/lib/python3.10/idlelib/idle_test/test_config.py +805 -0
- evalkit_cambrian/lib/python3.10/idlelib/idle_test/test_configdialog.py +1583 -0
- evalkit_cambrian/lib/python3.10/idlelib/idle_test/test_debugger_r.py +36 -0
- evalkit_cambrian/lib/python3.10/idlelib/idle_test/test_debugobj.py +57 -0
- evalkit_cambrian/lib/python3.10/idlelib/idle_test/test_editmenu.py +74 -0
- evalkit_cambrian/lib/python3.10/idlelib/idle_test/test_editor.py +211 -0
- evalkit_cambrian/lib/python3.10/idlelib/idle_test/test_filelist.py +33 -0
- evalkit_cambrian/lib/python3.10/idlelib/idle_test/test_format.py +668 -0
- evalkit_cambrian/lib/python3.10/idlelib/idle_test/test_grep.py +156 -0
- evalkit_cambrian/lib/python3.10/idlelib/idle_test/test_help.py +34 -0
- evalkit_cambrian/lib/python3.10/idlelib/idle_test/test_help_about.py +182 -0
- evalkit_cambrian/lib/python3.10/idlelib/idle_test/test_hyperparser.py +276 -0
evalkit_cambrian/lib/python3.10/idlelib/Icons/README.txt
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
The IDLE icons are from https://bugs.python.org/issue1490384
|
| 2 |
+
|
| 3 |
+
Created by Andrew Clover.
|
| 4 |
+
|
| 5 |
+
The original sources are available from Andrew's website:
|
| 6 |
+
https://www.doxdesk.com/software/py/pyicons.html
|
| 7 |
+
|
| 8 |
+
Various different formats and sizes are available at this GitHub Pull Request:
|
| 9 |
+
https://github.com/python/cpython/pull/17473
|
| 10 |
+
|
| 11 |
+
The idle.ico file was created with ImageMagick:
|
| 12 |
+
|
| 13 |
+
$ convert idle_16.png idle_32.png idle_48.png idle_256.png idle.ico
|
evalkit_cambrian/lib/python3.10/idlelib/Icons/folder.gif
ADDED
|
|
Git LFS Details
|
evalkit_cambrian/lib/python3.10/idlelib/Icons/idle.ico
ADDED
|
|
evalkit_cambrian/lib/python3.10/idlelib/Icons/idle_16.gif
ADDED
|
|
Git LFS Details
|
evalkit_cambrian/lib/python3.10/idlelib/Icons/idle_16.png
ADDED
|
|
Git LFS Details
|
evalkit_cambrian/lib/python3.10/idlelib/Icons/idle_256.png
ADDED
|
|
Git LFS Details
|
evalkit_cambrian/lib/python3.10/idlelib/Icons/idle_48.gif
ADDED
|
|
Git LFS Details
|
evalkit_cambrian/lib/python3.10/idlelib/Icons/idle_48.png
ADDED
|
|
Git LFS Details
|
evalkit_cambrian/lib/python3.10/idlelib/Icons/openfolder.gif
ADDED
|
|
Git LFS Details
|
evalkit_cambrian/lib/python3.10/idlelib/Icons/plusnode.gif
ADDED
|
|
Git LFS Details
|
evalkit_cambrian/lib/python3.10/idlelib/NEWS.txt
ADDED
|
@@ -0,0 +1,1321 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
What's New in IDLE 3.10.z
|
| 2 |
+
after 3.10.0 until 3.10.10?
|
| 3 |
+
Released 2023-04-03?
|
| 4 |
+
=========================
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
gh-97527: Fix a bug in the previous bugfix that caused IDLE to not
|
| 8 |
+
start when run with 3.10.8, 3.12.0a1, and at least Microsoft Python
|
| 9 |
+
3.10.2288.0 installed without the Lib/test package. 3.11.0 was never
|
| 10 |
+
affected.
|
| 11 |
+
|
| 12 |
+
gh-65802: Document handling of extensions in Save As dialogs.
|
| 13 |
+
|
| 14 |
+
gh-95191: Include prompts when saving Shell (interactive input/output).
|
| 15 |
+
|
| 16 |
+
gh-95511: Fix the Shell context menu copy-with-prompts bug of copying
|
| 17 |
+
an extra line when one selects whole lines.
|
| 18 |
+
|
| 19 |
+
gh-95471: Tweak Edit menu. Move 'Select All' above 'Cut' as it is used
|
| 20 |
+
with 'Cut' and 'Copy' but not 'Paste'. Add a separator between 'Replace'
|
| 21 |
+
and 'Go to Line' to help IDLE issue triagers.
|
| 22 |
+
|
| 23 |
+
gh-95411: Enable using IDLE's module browser with .pyw files.
|
| 24 |
+
|
| 25 |
+
gh-89610: Add .pyi as a recognized extension for IDLE on macOS. This allows
|
| 26 |
+
opening stub files by double clicking on them in the Finder.
|
| 27 |
+
|
| 28 |
+
bpo-28950: Apply IDLE syntax highlighting to `.pyi` files. Add util.py
|
| 29 |
+
for common components. Patch by Alex Waygood and Terry Jan Reedy.
|
| 30 |
+
|
| 31 |
+
bpo-46630: Make query dialogs on Windows start with a cursor in the
|
| 32 |
+
entry box.
|
| 33 |
+
|
| 34 |
+
bpo-46591: Make the IDLE doc URL on the About IDLE dialog clickable.
|
| 35 |
+
|
| 36 |
+
bpo-45296: Clarify close, quit, and exit in IDLE. In the File menu,
|
| 37 |
+
'Close' and 'Exit' are now 'Close Window' (the current one) and 'Exit'
|
| 38 |
+
is now 'Exit IDLE' (by closing all windows). In Shell, 'quit()' and
|
| 39 |
+
'exit()' mean 'close Shell'. If there are no other windows,
|
| 40 |
+
this also exits IDLE.
|
| 41 |
+
|
| 42 |
+
bpo-45495: Add context keywords 'case' and 'match' to completions list.
|
| 43 |
+
|
| 44 |
+
bpo-45296: On Windows, change exit/quit message to suggest Ctrl-D, which
|
| 45 |
+
works, instead of <Ctrl-Z Return>, which does not work in IDLE.
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
What's New in IDLE 3.10.0
|
| 49 |
+
(since 3.9.0)
|
| 50 |
+
Released on 2021-10-04
|
| 51 |
+
=========================
|
| 52 |
+
|
| 53 |
+
bpo-45193: Make completion boxes appear on Ubuntu again.
|
| 54 |
+
|
| 55 |
+
bpo-40128: Mostly fix completions on macOS when not using tcl/tk 8.6.11
|
| 56 |
+
(as with 3.9).
|
| 57 |
+
|
| 58 |
+
bpo-33962: Move the indent space setting from the Font tab to the new Windows
|
| 59 |
+
tab. Patch by Mark Roseman and Terry Jan Reedy.
|
| 60 |
+
|
| 61 |
+
bpo-40468: Split the settings dialog General tab into Windows and Shell/Ed
|
| 62 |
+
tabs. Move help sources, which extend the Help menu, to the Extensions tab.
|
| 63 |
+
Make space for new options and shorten the dialog. The latter makes the
|
| 64 |
+
dialog better fit small screens.
|
| 65 |
+
|
| 66 |
+
bpo-44010: Highlight the new match statement's soft keywords: match, case,
|
| 67 |
+
and _. This highlighting is not perfect and will be incorrect in some rare
|
| 68 |
+
cases, especially for some _s in case patterns.
|
| 69 |
+
|
| 70 |
+
bpo-44026: Include interpreter's typo fix suggestions in message line
|
| 71 |
+
for NameErrors and AttributeErrors. Patch by E. Paine.
|
| 72 |
+
|
| 73 |
+
bpo-41611: Avoid occasional uncaught exceptions and freezing when using
|
| 74 |
+
completions on macOS.
|
| 75 |
+
|
| 76 |
+
bpo-37903: Add mouse actions to the shell sidebar. Left click and
|
| 77 |
+
optional drag selects one or more lines of text, as with the
|
| 78 |
+
editor line number sidebar. Right click after selecting text lines
|
| 79 |
+
displays a context menu with 'copy with prompts'. This zips together
|
| 80 |
+
prompts from the sidebar with lines from the selected text. This option
|
| 81 |
+
also appears on the context menu for the text.
|
| 82 |
+
|
| 83 |
+
bpo-43981: Fix reference leaks in test_sidebar and test_squeezer.
|
| 84 |
+
Patches by Terry Jan Reedy and Pablo Galindo
|
| 85 |
+
|
| 86 |
+
bpo-37892: Change Shell input indents from tabs to spaces. Shell input
|
| 87 |
+
now 'looks right'. Making this feasible motivated the shell sidebar.
|
| 88 |
+
|
| 89 |
+
bpo-37903: Move the Shell input prompt to a side bar.
|
| 90 |
+
|
| 91 |
+
bpo-43655: Make window managers on macOS and X Window recognize
|
| 92 |
+
IDLE dialog windows as dialogs.
|
| 93 |
+
|
| 94 |
+
bpo-42225: Document that IDLE can fail on Unix either from misconfigured IP
|
| 95 |
+
masquerade rules or failure displaying complex colored (non-ascii) characters.
|
| 96 |
+
|
| 97 |
+
bpo-43283: Document why printing to IDLE's Shell is often slower than
|
| 98 |
+
printing to a system terminal and that it can be made faster by
|
| 99 |
+
pre-formatting a single string before printing.
|
| 100 |
+
|
| 101 |
+
bpo-23544: Disable Debug=>Stack Viewer when user code is running or
|
| 102 |
+
Debugger is active, to prevent hang or crash. Patch by Zackery Spytz.
|
| 103 |
+
|
| 104 |
+
bpo-43008: Make IDLE invoke :func:`sys.excepthook` in normal,
|
| 105 |
+
2-process mode. User hooks were previously ignored.
|
| 106 |
+
Patch by Ken Hilton.
|
| 107 |
+
|
| 108 |
+
bpo-33065: Fix problem debugging user classes with __repr__ method.
|
| 109 |
+
|
| 110 |
+
bpo-32631: Finish zzdummy example extension module: make menu entries
|
| 111 |
+
work; add docstrings and tests with 100% coverage.
|
| 112 |
+
|
| 113 |
+
bpo-42508: Keep IDLE running on macOS. Remove obsolete workaround
|
| 114 |
+
that prevented running files with shortcuts when using new universal2
|
| 115 |
+
installers built on macOS 11.
|
| 116 |
+
|
| 117 |
+
bpo-42426: Fix reporting offset of the RE error in searchengine.
|
| 118 |
+
|
| 119 |
+
bpo-42416: Display docstrings in IDLE calltips in more cases,
|
| 120 |
+
by using inspect.getdoc.
|
| 121 |
+
|
| 122 |
+
bpo-33987: Mostly finish using ttk widgets, mainly for editor,
|
| 123 |
+
settings, and searches. Some patches by Mark Roseman.
|
| 124 |
+
|
| 125 |
+
bpo-40511: Stop unnecessary "flashing" when typing opening and closing
|
| 126 |
+
parentheses inside the parentheses of a function call.
|
| 127 |
+
|
| 128 |
+
bpo-38439: Add a 256x256 pixel IDLE icon to the Windows .ico file. Created by
|
| 129 |
+
Andrew Clover. Remove the low-color gif variations from the .ico file.
|
| 130 |
+
|
| 131 |
+
bpo-41775: Make 'IDLE Shell' the shell title.
|
| 132 |
+
|
| 133 |
+
bpo-35764: Rewrite the Calltips doc section.
|
| 134 |
+
|
| 135 |
+
bpo-40181: In calltips, stop reminding that '/' marks the end of
|
| 136 |
+
positional-only arguments.
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
What's New in IDLE 3.9.0 (since 3.8.0)
|
| 140 |
+
Released on 2020-10-05?
|
| 141 |
+
======================================
|
| 142 |
+
|
| 143 |
+
bpo-41468: Improve IDLE run crash error message (which users should
|
| 144 |
+
never see).
|
| 145 |
+
|
| 146 |
+
bpo-41373: Save files loaded with no line ending, as when blank, or
|
| 147 |
+
different line endings, by setting its line ending to the system
|
| 148 |
+
default. Fix regression in 3.8.4 and 3.9.0b4.
|
| 149 |
+
|
| 150 |
+
bpo-41300: Save files with non-ascii chars. Fix regression in
|
| 151 |
+
3.9.0b4 and 3.8.4.
|
| 152 |
+
|
| 153 |
+
bpo-37765: Add keywords to module name completion list. Rewrite
|
| 154 |
+
Completions section of IDLE doc.
|
| 155 |
+
|
| 156 |
+
bpo-41152: The encoding of ``stdin``, ``stdout`` and ``stderr`` in IDLE
|
| 157 |
+
is now always UTF-8.
|
| 158 |
+
|
| 159 |
+
bpo-41144: Make Open Module open a special module such as os.path.
|
| 160 |
+
|
| 161 |
+
bpo-40723: Make test_idle pass when run after import.
|
| 162 |
+
Patch by Florian Dahlitz.
|
| 163 |
+
|
| 164 |
+
bpo-38689: IDLE will no longer freeze when inspect.signature fails
|
| 165 |
+
when fetching a calltip.
|
| 166 |
+
|
| 167 |
+
bpo-27115: For 'Go to Line', use a Query entry box subclass with
|
| 168 |
+
IDLE standard behavior and improved error checking.
|
| 169 |
+
|
| 170 |
+
bpo-39885: When a context menu is invoked by right-clicking outside
|
| 171 |
+
of a selection, clear the selection and move the cursor. Cut and
|
| 172 |
+
Copy require that the click be within the selection.
|
| 173 |
+
|
| 174 |
+
bpo-39852: Edit "Go to line" now clears any selection, preventing
|
| 175 |
+
accidental deletion. It also updates Ln and Col on the status bar.
|
| 176 |
+
|
| 177 |
+
bpo-39781: Selecting code context lines no longer causes a jump.
|
| 178 |
+
|
| 179 |
+
bpo-39663: Add tests for pyparse find_good_parse_start().
|
| 180 |
+
|
| 181 |
+
bpo-39600: Remove duplicate font names from configuration list.
|
| 182 |
+
|
| 183 |
+
bpo-38792: Close a shell calltip if a :exc:`KeyboardInterrupt`
|
| 184 |
+
or shell restart occurs. Patch by Zackery Spytz.
|
| 185 |
+
|
| 186 |
+
bpo-30780: Add remaining configdialog tests for buttons and
|
| 187 |
+
highlights and keys tabs.
|
| 188 |
+
|
| 189 |
+
bpo-39388: Settings dialog Cancel button cancels pending changes.
|
| 190 |
+
|
| 191 |
+
bpo-39050: Settings dialog Help button again displays help text.
|
| 192 |
+
|
| 193 |
+
bpo-32989: Add tests for editor newline_and_indent_event method.
|
| 194 |
+
Remove unneeded arguments and dead code from pyparse
|
| 195 |
+
find_good_parse_start method.
|
| 196 |
+
|
| 197 |
+
bpo-38943: Fix autocomplete windows not always appearing on some
|
| 198 |
+
systems. Patch by Johnny Najera.
|
| 199 |
+
|
| 200 |
+
bpo-38944: Escape key now closes IDLE completion windows. Patch by
|
| 201 |
+
Johnny Najera.
|
| 202 |
+
|
| 203 |
+
bpo-38862: 'Strip Trailing Whitespace' on the Format menu removes extra
|
| 204 |
+
newlines at the end of non-shell files.
|
| 205 |
+
|
| 206 |
+
bpo-38636: Fix IDLE Format menu tab toggle and file indent width. These
|
| 207 |
+
functions (default shortcuts Alt-T and Alt-U) were mistakenly disabled
|
| 208 |
+
in 3.7.5 and 3.8.0.
|
| 209 |
+
|
| 210 |
+
bpo-4630: Add an option to toggle IDLE's cursor blink for shell,
|
| 211 |
+
editor, and output windows. See Settings, General, Window Preferences,
|
| 212 |
+
Cursor Blink. Patch by Zackery Spytz.
|
| 213 |
+
|
| 214 |
+
bpo-26353: Stop adding newline when saving an IDLE shell window.
|
| 215 |
+
|
| 216 |
+
bpo-38598: Do not try to compile IDLE shell or output windows.
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
What's New in IDLE 3.8.0 (since 3.7.0)
|
| 220 |
+
Released on 2019-10-14
|
| 221 |
+
======================================
|
| 222 |
+
|
| 223 |
+
bpo-36698: IDLE no longer fails when writing non-encodable characters
|
| 224 |
+
to stderr. It now escapes them with a backslash, like the regular
|
| 225 |
+
Python interpreter. Add an errors field to the standard streams.
|
| 226 |
+
|
| 227 |
+
bpo-13153: Improve tkinter's handing of non-BMP (astral) unicode
|
| 228 |
+
characters, such as 'rocket \U0001f680'. Whether a proper glyph or
|
| 229 |
+
replacement char is displayed depends on the OS and font. For IDLE,
|
| 230 |
+
astral chars in code interfere with editing.
|
| 231 |
+
|
| 232 |
+
bpo-35379: When exiting IDLE, catch any AttributeError. One happens
|
| 233 |
+
when EditorWindow.close is called twice. Printing a traceback, when
|
| 234 |
+
IDLE is run from a terminal, is useless and annoying.
|
| 235 |
+
|
| 236 |
+
bpo-38183: To avoid test issues, test_idle ignores the user config
|
| 237 |
+
directory. It no longer tries to create or access .idlerc or any files
|
| 238 |
+
within. Users must run IDLE to discover problems with saving settings.
|
| 239 |
+
|
| 240 |
+
bpo-38077: IDLE no longer adds 'argv' to the user namespace when
|
| 241 |
+
initializing it. This bug only affected 3.7.4 and 3.8.0b2 to 3.8.0b4.
|
| 242 |
+
|
| 243 |
+
bpo-38401: Shell restart lines now fill the window width, always start
|
| 244 |
+
with '=', and avoid wrapping unnecessarily. The line will still wrap
|
| 245 |
+
if the included file name is long relative to the width.
|
| 246 |
+
|
| 247 |
+
bpo-37092: Add mousewheel scrolling for IDLE module, path, and stack
|
| 248 |
+
browsers. Patch by George Zhang.
|
| 249 |
+
|
| 250 |
+
bpo-35771: To avoid occasional spurious test_idle failures on slower
|
| 251 |
+
machines, increase the ``hover_delay`` in test_tooltip.
|
| 252 |
+
|
| 253 |
+
bpo-37824: Properly handle user input warnings in IDLE shell.
|
| 254 |
+
Cease turning SyntaxWarnings into SyntaxErrors.
|
| 255 |
+
|
| 256 |
+
bpo-37929: IDLE Settings dialog now closes properly when there is no
|
| 257 |
+
shell window.
|
| 258 |
+
|
| 259 |
+
bpo-37849: Fix completions list appearing too high or low when shown
|
| 260 |
+
above the current line.
|
| 261 |
+
|
| 262 |
+
bpo-36419: Refactor autocompete and improve testing.
|
| 263 |
+
|
| 264 |
+
bpo-37748: Reorder the Run menu. Put the most common choice,
|
| 265 |
+
Run Module, at the top.
|
| 266 |
+
|
| 267 |
+
bpo-37692: Improve highlight config sample with example shell
|
| 268 |
+
interaction and better labels for shell elements.
|
| 269 |
+
|
| 270 |
+
bpo-37628: Settings dialog no longer expands with font size.
|
| 271 |
+
The font and highlight sample boxes gain scrollbars instead.
|
| 272 |
+
|
| 273 |
+
bpo-17535: Add optional line numbers for IDLE editor windows.
|
| 274 |
+
|
| 275 |
+
bpo-37627: Initialize the Customize Run dialog with the command line
|
| 276 |
+
arguments most recently entered before. The user can optionally edit
|
| 277 |
+
before submitting them.
|
| 278 |
+
|
| 279 |
+
bpo-33610: Code context always shows the correct context when toggled on.
|
| 280 |
+
|
| 281 |
+
bpo-36390: Gather Format menu functions into format.py. Combine
|
| 282 |
+
paragraph.py, rstrip.py, and format methods from editor.py.
|
| 283 |
+
|
| 284 |
+
bpo-37530: Optimize code context to reduce unneeded background activity.
|
| 285 |
+
Font and highlight changes now occur along with text changes instead
|
| 286 |
+
of after a random delay.
|
| 287 |
+
|
| 288 |
+
bpo-27452: Cleanup config.py by inlining RemoveFile and simplifying
|
| 289 |
+
the handling of __file__ in CreateConfigHandlers/
|
| 290 |
+
|
| 291 |
+
bpo-26806: To compensate for stack frames added by IDLE and avoid
|
| 292 |
+
possible problems with low recursion limits, add 30 to limits in the
|
| 293 |
+
user code execution process. Subtract 30 when reporting recursion
|
| 294 |
+
limits to make this addition mostly transparent.
|
| 295 |
+
|
| 296 |
+
bpo-37325: Fix tab focus traversal order for help source and custom
|
| 297 |
+
run dialogs.
|
| 298 |
+
|
| 299 |
+
bpo-37321: Both subprocess connection error messages now refer to
|
| 300 |
+
the 'Startup failure' section of the IDLE doc.
|
| 301 |
+
|
| 302 |
+
bpo-37177: Properly attach search dialogs to their main window so
|
| 303 |
+
that they behave like other dialogs and do not get hidden behind
|
| 304 |
+
their main window.
|
| 305 |
+
|
| 306 |
+
bpo-37039: Adjust "Zoom Height" to individual screens by momentarily
|
| 307 |
+
maximizing the window on first use with a particular screen. Changing
|
| 308 |
+
screen settings may invalidate the saved height. While a window is
|
| 309 |
+
maximized, "Zoom Height" has no effect.
|
| 310 |
+
|
| 311 |
+
bpo-35763: Make calltip reminder about '/' meaning positional-only less
|
| 312 |
+
obtrusive by only adding it when there is room on the first line.
|
| 313 |
+
|
| 314 |
+
bpo-5680: Add 'Run Customized' to the Run menu to run a module with
|
| 315 |
+
customized settings. Any command line arguments entered are added
|
| 316 |
+
to sys.argv. One can suppress the normal Shell main module restart.
|
| 317 |
+
|
| 318 |
+
bpo-35610: Replace now redundant editor.context_use_ps1 with
|
| 319 |
+
.prompt_last_line. This finishes change started in bpo-31858.
|
| 320 |
+
|
| 321 |
+
bpo-32411: Stop sorting dict created with desired line order.
|
| 322 |
+
|
| 323 |
+
bpo-37038: Make idlelib.run runnable; add test clause.
|
| 324 |
+
|
| 325 |
+
bpo-36958: Print any argument other than None or int passed to
|
| 326 |
+
SystemExit or sys.exit().
|
| 327 |
+
|
| 328 |
+
bpo-36807: When saving a file, call file.flush() and os.fsync()
|
| 329 |
+
so bits are flushed to e.g. a USB drive.
|
| 330 |
+
|
| 331 |
+
bpo-36429: Fix starting IDLE with pyshell.
|
| 332 |
+
Add idlelib.pyshell alias at top; remove pyshell alias at bottom.
|
| 333 |
+
Remove obsolete __name__=='__main__' command.
|
| 334 |
+
|
| 335 |
+
bpo-30348: Increase test coverage of idlelib.autocomplete by 30%.
|
| 336 |
+
Patch by Louie Lu.
|
| 337 |
+
|
| 338 |
+
bpo-23205: Add tests and refactor grep's findfiles.
|
| 339 |
+
|
| 340 |
+
bpo-36405: Use dict unpacking in idlelib.
|
| 341 |
+
|
| 342 |
+
bpo-36396: Remove fgBg param of idlelib.config.GetHighlight().
|
| 343 |
+
This param was only used twice and changed the return type.
|
| 344 |
+
|
| 345 |
+
bpo-23216: IDLE: Add docstrings to search modules.
|
| 346 |
+
|
| 347 |
+
bpo-36176: Fix IDLE autocomplete & calltip popup colors.
|
| 348 |
+
Prevent conflicts with Linux dark themes
|
| 349 |
+
(and slightly darken calltip background).
|
| 350 |
+
|
| 351 |
+
bpo-36152: Remove colorizer.ColorDelegator.close_when_done and the
|
| 352 |
+
corresponding argument of .close(). In IDLE, both have always been
|
| 353 |
+
None or False since 2007.
|
| 354 |
+
|
| 355 |
+
bpo-36096: Make colorizer state variables instance-only.
|
| 356 |
+
|
| 357 |
+
bpo-32129: Avoid blurry IDLE application icon on macOS with Tk 8.6.
|
| 358 |
+
Patch by Kevin Walzer.
|
| 359 |
+
|
| 360 |
+
bpo-24310: Document settings dialog font tab sample.
|
| 361 |
+
|
| 362 |
+
bpo-35689: Add docstrings and tests for colorizer.
|
| 363 |
+
|
| 364 |
+
bpo-35833: Revise IDLE doc for control codes sent to Shell.
|
| 365 |
+
Add a code example block.
|
| 366 |
+
|
| 367 |
+
bpo-35770: IDLE macosx deletes Options => Configure IDLE.
|
| 368 |
+
It previously deleted Window => Zoom Height by mistake.
|
| 369 |
+
(Zoom Height is now on the Options menu). On Mac, the settings
|
| 370 |
+
dialog is accessed via Preferences on the IDLE menu.
|
| 371 |
+
|
| 372 |
+
bpo-35769: Change new file name from 'Untitled' to 'untitled'.
|
| 373 |
+
|
| 374 |
+
bpo-35660: Fix imports in window module.
|
| 375 |
+
|
| 376 |
+
bpo-35641: Properly format calltip for function without docstring.
|
| 377 |
+
|
| 378 |
+
bpo-33987: Use ttk Frame for ttk widgets.
|
| 379 |
+
|
| 380 |
+
bpo-34055: Fix erroneous 'smart' indents and newlines in IDLE Shell.
|
| 381 |
+
|
| 382 |
+
bpo-28097: Add Previous/Next History entries to Shell menu.
|
| 383 |
+
|
| 384 |
+
bpo-35591: Find Selection now works when selection not found.
|
| 385 |
+
|
| 386 |
+
bpo-35598: Update config_key: use PEP 8 names and ttk widgets,
|
| 387 |
+
make some objects global, and add tests.
|
| 388 |
+
|
| 389 |
+
bpo-35196: Speed up squeezer line counting.
|
| 390 |
+
|
| 391 |
+
bpo-35208: Squeezer now counts wrapped lines before newlines.
|
| 392 |
+
|
| 393 |
+
bpo-35555: Gray out Code Context menu entry when it's not applicable.
|
| 394 |
+
|
| 395 |
+
bpo-22703: Improve the Code Context and Zoom Height menu labels.
|
| 396 |
+
The Code Context menu label now toggles between Show/Hide Code Context.
|
| 397 |
+
The Zoom Height menu now toggles between Zoom/Restore Height.
|
| 398 |
+
Zoom Height has moved from the Window menu to the Options menu.
|
| 399 |
+
|
| 400 |
+
bpo-35521: Document the editor code context feature.
|
| 401 |
+
Add some internal references within the IDLE doc.
|
| 402 |
+
|
| 403 |
+
bpo-34864: When starting IDLE on MacOS, warn if the system setting
|
| 404 |
+
"Prefer tabs when opening documents" is "Always". As previous
|
| 405 |
+
documented for this issue, running IDLE with this setting causes
|
| 406 |
+
problems. If the setting is changed while IDLE is running,
|
| 407 |
+
there will be no warning until IDLE is restarted.
|
| 408 |
+
|
| 409 |
+
bpo-35213: Where appropriate, use 'macOS' in idlelib.
|
| 410 |
+
|
| 411 |
+
bpo-34864: Document two IDLE on MacOS issues. The System Preferences
|
| 412 |
+
Dock "prefer tabs always" setting disables some IDLE features.
|
| 413 |
+
Menus are a bit different than as described for Windows and Linux.
|
| 414 |
+
|
| 415 |
+
bpo-35202: Remove unused imports in idlelib.
|
| 416 |
+
|
| 417 |
+
bpo-33000: Document that IDLE's shell has no line limit.
|
| 418 |
+
A program that runs indefinitely can overfill memory.
|
| 419 |
+
|
| 420 |
+
bpo-23220: Explain how IDLE's Shell displays output.
|
| 421 |
+
Add new subsection "User output in Shell".
|
| 422 |
+
|
| 423 |
+
bpo-35099: Improve the doc about IDLE running user code.
|
| 424 |
+
"IDLE -- console differences" is renamed "Running user code".
|
| 425 |
+
It mostly covers the implications of using custom sys.stdxxx objects.
|
| 426 |
+
|
| 427 |
+
bpo-35097: Add IDLE doc subsection explaining editor windows.
|
| 428 |
+
Topics include opening, title and status bars, .py* extension, and running.
|
| 429 |
+
|
| 430 |
+
Issue 35093: Document the IDLE document viewer in the IDLE doc.
|
| 431 |
+
Add a paragraph in "Help and preferences", "Help sources" subsection.
|
| 432 |
+
|
| 433 |
+
bpo-1529353: Explain Shell text squeezing in the IDLE doc.
|
| 434 |
+
|
| 435 |
+
bpo-35088: Update idlelib.help.copy_string docstring.
|
| 436 |
+
We now use git and backporting instead of hg and forward merging.
|
| 437 |
+
|
| 438 |
+
bpo-35087: Update idlelib help files for the current doc build.
|
| 439 |
+
The main change is the elimination of chapter-section numbers.
|
| 440 |
+
|
| 441 |
+
bpo-1529353: Output over N lines (50 by default) is squeezed down to a button.
|
| 442 |
+
N can be changed in the PyShell section of the General page of the
|
| 443 |
+
Settings dialog. Fewer, but possibly extra long, lines can be squeezed by
|
| 444 |
+
right clicking on the output. Squeezed output can be expanded in place
|
| 445 |
+
by double-clicking the button or into the clipboard or a separate window
|
| 446 |
+
by right-clicking the button.
|
| 447 |
+
|
| 448 |
+
bpo-34548: Use configured color theme for read-only text views.
|
| 449 |
+
|
| 450 |
+
bpo-33839: Refactor ToolTip and CallTip classes; add documentation
|
| 451 |
+
and tests.
|
| 452 |
+
|
| 453 |
+
bpo-34047: Fix mouse wheel scrolling direction on macOS.
|
| 454 |
+
|
| 455 |
+
bpo-34275: Make calltips always visible on Mac.
|
| 456 |
+
Patch by Kevin Walzer.
|
| 457 |
+
|
| 458 |
+
bpo-34120: Fix freezing after closing some dialogs on Mac.
|
| 459 |
+
This is one of multiple regressions from using newer tcl/tk.
|
| 460 |
+
|
| 461 |
+
bpo-33975: Avoid small type when running htests.
|
| 462 |
+
Since part of the purpose of human-viewed tests is to determine that
|
| 463 |
+
widgets look right, it is important that they look the same for
|
| 464 |
+
testing as when running IDLE.
|
| 465 |
+
|
| 466 |
+
bpo-33905: Add test for idlelib.stackview.StackBrowser.
|
| 467 |
+
|
| 468 |
+
bpo-33924: Change mainmenu.menudefs key 'windows' to 'window'.
|
| 469 |
+
Every other menudef key is the lowercase version of the
|
| 470 |
+
corresponding main menu entry (in this case, 'Window').
|
| 471 |
+
|
| 472 |
+
bpo-33906: Rename idlelib.windows as window
|
| 473 |
+
Match Window on the main menu and remove last plural module name.
|
| 474 |
+
Change imports, test, and attribute references to match new name.
|
| 475 |
+
|
| 476 |
+
bpo-33917: Fix and document idlelib/idle_test/template.py.
|
| 477 |
+
The revised file compiles, runs, and tests OK. idle_test/README.txt
|
| 478 |
+
explains how to use it to create new IDLE test files.
|
| 479 |
+
|
| 480 |
+
bpo-33904: In rstrip module, rename class RstripExtension as Rstrip.
|
| 481 |
+
|
| 482 |
+
bpo-33907: For consistency and clarity, rename calltip objects.
|
| 483 |
+
Module calltips and its class CallTips are now calltip and Calltip.
|
| 484 |
+
In module calltip_w, class CallTip is now CalltipWindow.
|
| 485 |
+
|
| 486 |
+
bpo-33855: Minimally test all IDLE modules.
|
| 487 |
+
Standardize the test file format. Add missing test files that import
|
| 488 |
+
the tested module and perform at least one test. Check and record the
|
| 489 |
+
coverage of each test.
|
| 490 |
+
|
| 491 |
+
bpo-33856: Add 'help' to Shell's initial welcome message.
|
| 492 |
+
|
| 493 |
+
|
| 494 |
+
What's New in IDLE 3.7.0 (since 3.6.0)
|
| 495 |
+
Released on 2018-06-27
|
| 496 |
+
======================================
|
| 497 |
+
|
| 498 |
+
bpo-33656: On Windows, add API call saying that tk scales for DPI.
|
| 499 |
+
On Windows 8.1+ or 10, with DPI compatibility properties of the Python
|
| 500 |
+
binary unchanged, and a monitor resolution greater than 96 DPI, this
|
| 501 |
+
should make text and lines sharper and some colors brighter.
|
| 502 |
+
On other systems, it should have no effect. If you have a custom theme,
|
| 503 |
+
you may want to adjust a color or two. If perchance it make text worse
|
| 504 |
+
on your monitor, you can disable the ctypes.OleDLL call near the top of
|
| 505 |
+
pyshell.py and report the problem on python-list or [email protected].
|
| 506 |
+
|
| 507 |
+
bpo-33768: Clicking on a context line moves that line to the top
|
| 508 |
+
of the editor window.
|
| 509 |
+
|
| 510 |
+
bpo-33763: Replace the code context label widget with a text widget.
|
| 511 |
+
|
| 512 |
+
bpo-33664: Scroll IDLE editor text by lines.
|
| 513 |
+
(Previously, the mouse wheel and scrollbar slider moved text by a fixed
|
| 514 |
+
number of pixels, resulting in partial lines at the top of the editor
|
| 515 |
+
box.) This change also applies to the shell and grep output windows,
|
| 516 |
+
but currently not to read-only text views.
|
| 517 |
+
|
| 518 |
+
bpo-33679: Enable theme-specific color configuration for Code Context.
|
| 519 |
+
(Previously, there was one code context foreground and background font
|
| 520 |
+
color setting, default or custom, on the extensions tab, that applied
|
| 521 |
+
to all themes.) For built-in themes, the foreground is the same as
|
| 522 |
+
normal text and the background is a contrasting gray. Context colors for
|
| 523 |
+
custom themes are set on the Hightlights tab along with other colors.
|
| 524 |
+
When one starts IDLE from a console and loads a custom theme without
|
| 525 |
+
definitions for 'context', one will see a warning message on the
|
| 526 |
+
console.
|
| 527 |
+
|
| 528 |
+
bpo-33642: Display up to maxlines non-blank lines for Code Context.
|
| 529 |
+
If there is no current context, show a single blank line. (Previously,
|
| 530 |
+
the Code Contex had numlines lines, usually with some blank.) The use
|
| 531 |
+
of a new option, 'maxlines' (default 15), avoids possible interference
|
| 532 |
+
with user settings of the old option, 'numlines' (default 3).
|
| 533 |
+
|
| 534 |
+
bpo-33628: Cleanup codecontext.py and its test.
|
| 535 |
+
|
| 536 |
+
bpo-32831: Add docstrings and tests for codecontext.py.
|
| 537 |
+
Coverage is 100%. Patch by Cheryl Sabella.
|
| 538 |
+
|
| 539 |
+
bpo-33564: Code context now recognizes async as a block opener.
|
| 540 |
+
|
| 541 |
+
bpo-21474: Update word/identifier definition from ascii to unicode.
|
| 542 |
+
In text and entry boxes, this affects selection by double-click,
|
| 543 |
+
movement left/right by control-left/right, and deletion left/right
|
| 544 |
+
by control-BACKSPACE/DEL.
|
| 545 |
+
|
| 546 |
+
bpo-33204: Consistently color invalid string prefixes.
|
| 547 |
+
A 'u' string prefix cannot be paired with either 'r' or 'f'.
|
| 548 |
+
IDLE now consistently colors as much of the prefix, starting at the
|
| 549 |
+
right, as is valid. Revise and extend colorizer test.
|
| 550 |
+
|
| 551 |
+
bpo-32984: Set __file__ while running a startup file.
|
| 552 |
+
Like Python, IDLE optionally runs 1 startup file in the Shell window
|
| 553 |
+
before presenting the first interactive input prompt. For IDLE,
|
| 554 |
+
option -s runs a file named in environmental variable IDLESTARTUP or
|
| 555 |
+
PYTHONSTARTUP; -r file runs file. Python sets __file__ to the startup
|
| 556 |
+
file name before running the file and unsets it before the first
|
| 557 |
+
prompt. IDLE now does the same when run normally, without the -n
|
| 558 |
+
option.
|
| 559 |
+
|
| 560 |
+
bpo-32940: Replace StringTranslatePseudoMapping with faster code.
|
| 561 |
+
|
| 562 |
+
bpo-32916: Change 'str' to 'code' in idlelib.pyparse and users.
|
| 563 |
+
|
| 564 |
+
bpo-32905: Remove unused code in pyparse module.
|
| 565 |
+
|
| 566 |
+
bpo-32874: IDLE - add pyparse tests with 97% coverage.
|
| 567 |
+
|
| 568 |
+
bpo-32837: IDLE - require encoding argument for textview.view_file.
|
| 569 |
+
Using the system and place-dependent default encoding for open()
|
| 570 |
+
is a bad idea for IDLE's system and location-independent files.
|
| 571 |
+
|
| 572 |
+
bpo-32826: Add "encoding=utf-8" to open() in IDLE's test_help_about.
|
| 573 |
+
GUI test test_file_buttons() only looks at initial ascii-only lines,
|
| 574 |
+
but failed on systems where open() defaults to 'ascii' because
|
| 575 |
+
readline() internally reads and decodes far enough ahead to encounter
|
| 576 |
+
a non-ascii character in CREDITS.txt.
|
| 577 |
+
|
| 578 |
+
bpo-32765: Update configdialog General tab create page docstring.
|
| 579 |
+
Add new widgets to the widget list.
|
| 580 |
+
|
| 581 |
+
bpo-32207: Improve tk event exception tracebacks in IDLE.
|
| 582 |
+
When tk event handling is driven by IDLE's run loop, a confusing
|
| 583 |
+
and distracting queue.EMPTY traceback context is no longer added
|
| 584 |
+
to tk event exception tracebacks. The traceback is now the same
|
| 585 |
+
as when event handling is driven by user code. Patch based on
|
| 586 |
+
a suggestion by Serhiy Storchaka.
|
| 587 |
+
|
| 588 |
+
bpo-32164: Delete unused file idlelib/tabbedpages.py.
|
| 589 |
+
Use of TabbedPageSet in configdialog was replaced by ttk.Notebook.
|
| 590 |
+
|
| 591 |
+
bpo-32100: Fix old and new bugs in pathbrowser; improve tests.
|
| 592 |
+
Patch mostly by Cheryl Sabella.
|
| 593 |
+
|
| 594 |
+
bpo-31860: The font sample in the settings dialog is now editable.
|
| 595 |
+
Edits persist while IDLE remains open.
|
| 596 |
+
Patch by Serhiy Storchake and Terry Jan Reedy.
|
| 597 |
+
|
| 598 |
+
bpo-31858: Restrict shell prompt manipulation to the shell.
|
| 599 |
+
Editor and output windows only see an empty last prompt line. This
|
| 600 |
+
simplifies the code and fixes a minor bug when newline is inserted.
|
| 601 |
+
Sys.ps1, if present, is read on Shell start-up, but is not set or changed.
|
| 602 |
+
Patch by Terry Jan Reedy.
|
| 603 |
+
|
| 604 |
+
bpo-28603: Fix a TypeError that caused a shell restart when printing
|
| 605 |
+
a traceback that includes an exception that is unhashable.
|
| 606 |
+
Patch by Zane Bitter.
|
| 607 |
+
|
| 608 |
+
bpo-13802: Use non-Latin characters in the Font settings sample.
|
| 609 |
+
Even if one selects a font that defines a limited subset of the unicode
|
| 610 |
+
Basic Multilingual Plane, tcl/tk will use other fonts that define a
|
| 611 |
+
character. The expanded example give users of non-Latin characters
|
| 612 |
+
a better idea of what they might see in the shell and editors.
|
| 613 |
+
|
| 614 |
+
To make room for the expanded sample, frames on the Font tab are
|
| 615 |
+
re-arranged. The Font/Tabs help explains a bit about the additions.
|
| 616 |
+
Patch by Terry Jan Reedy
|
| 617 |
+
|
| 618 |
+
bpo-31460: Simplify the API of IDLE's Module Browser.
|
| 619 |
+
Passing a widget instead of an flist with a root widget opens the
|
| 620 |
+
option of creating a browser frame that is only part of a window.
|
| 621 |
+
Passing a full file name instead of pieces assumed to come from a
|
| 622 |
+
.py file opens the possibility of browsing python files that do not
|
| 623 |
+
end in .py.
|
| 624 |
+
|
| 625 |
+
bpo-31649: Make _htest and _utest parameters keyword-only.
|
| 626 |
+
These are used to adjust code for human and unit tests.
|
| 627 |
+
|
| 628 |
+
bpo-31459: Rename module browser from Class Browser to Module Browser.
|
| 629 |
+
The original module-level class and method browser became a module
|
| 630 |
+
browser, with the addition of module-level functions, years ago.
|
| 631 |
+
Nested classes and functions were added yesterday. For back-
|
| 632 |
+
compatibility, the virtual event <<open-class-browser>>, which
|
| 633 |
+
appears on the Keys tab of the Settings dialog, is not changed.
|
| 634 |
+
Patch by Cheryl Sabella.
|
| 635 |
+
|
| 636 |
+
bpo-1612262: Module browser now shows nested classes and functions.
|
| 637 |
+
Original patches for code and tests by Guilherme Polo and
|
| 638 |
+
Cheryl Sabella, respectively. Revisions by Terry Jan Reedy.
|
| 639 |
+
|
| 640 |
+
bpo-31500: Tk's default fonts now are scaled on HiDPI displays.
|
| 641 |
+
This affects all dialogs. Patch by Serhiy Storchaka.
|
| 642 |
+
|
| 643 |
+
bpo-31493: Fix code context update and font update timers.
|
| 644 |
+
Canceling timers prevents a warning message when test_idle completes.
|
| 645 |
+
|
| 646 |
+
bpo-31488: Update non-key options in former extension classes.
|
| 647 |
+
When applying configdialog changes, call .reload for each feature class.
|
| 648 |
+
Change ParenMatch so updated options affect existing instances attached
|
| 649 |
+
to existing editor windows.
|
| 650 |
+
|
| 651 |
+
bpo-31477: Improve rstrip entry in IDLE doc.
|
| 652 |
+
Strip Trailing Whitespace strips more than blank spaces.
|
| 653 |
+
Multiline string literals are not skipped.
|
| 654 |
+
|
| 655 |
+
bpo-31480: fix tests to pass with zzdummy extension disabled. (#3590)
|
| 656 |
+
To see the example in action, enable it on options extensions tab.
|
| 657 |
+
|
| 658 |
+
bpo-31421: Document how IDLE runs tkinter programs.
|
| 659 |
+
IDLE calls tcl/tk update in the background in order to make live
|
| 660 |
+
interaction and experimentation with tkinter applications much easier.
|
| 661 |
+
|
| 662 |
+
bpo-31414: Fix tk entry box tests by deleting first.
|
| 663 |
+
Adding to an int entry is not the same as deleting and inserting
|
| 664 |
+
because int('') will fail. Patch by Terry Jan Reedy.
|
| 665 |
+
|
| 666 |
+
bpo-27099: Convert IDLE's built-in 'extensions' to regular features.
|
| 667 |
+
About 10 IDLE features were implemented as supposedly optional
|
| 668 |
+
extensions. Their different behavior could be confusing or worse for
|
| 669 |
+
users and not good for maintenance. Hence the conversion.
|
| 670 |
+
The main difference for users is that user configurable key bindings
|
| 671 |
+
for builtin features are now handled uniformly. Now, editing a binding
|
| 672 |
+
in a keyset only affects its value in the keyset. All bindings are
|
| 673 |
+
defined together in the system-specific default keysets in config-
|
| 674 |
+
extensions.def. All custom keysets are saved as a whole in config-
|
| 675 |
+
extension.cfg. All take effect as soon as one clicks Apply or Ok.
|
| 676 |
+
The affected events are '<<force-open-completions>>',
|
| 677 |
+
'<<expand-word>>', '<<force-open-calltip>>', '<<flash-paren>>',
|
| 678 |
+
'<<format-paragraph>>', '<<run-module>>', '<<check-module>>', and
|
| 679 |
+
'<<zoom-height>>'. Any (global) customizations made before 3.6.3 will
|
| 680 |
+
not affect their keyset-specific customization after 3.6.3. and vice
|
| 681 |
+
versa.
|
| 682 |
+
Initial patch by Charles Wohlganger, revised by Terry Jan Reedy.
|
| 683 |
+
|
| 684 |
+
bpo-31051: Rearrange condigdialog General tab.
|
| 685 |
+
Sort non-Help options into Window (Shell+Editor) and Editor (only).
|
| 686 |
+
Leave room for the addition of new options.
|
| 687 |
+
Patch by Terry Jan Reedy.
|
| 688 |
+
|
| 689 |
+
bpo-30617: Add docstrings and tests for outwin subclass of editor.
|
| 690 |
+
Move some data and functions from the class to module level.
|
| 691 |
+
Patch by Cheryl Sabella.
|
| 692 |
+
|
| 693 |
+
bpo-31287: Do not modify tkinter.messagebox in test_configdialog.
|
| 694 |
+
Instead, mask it with an instance mock that can be deleted.
|
| 695 |
+
Patch by Terry Jan Reedy.
|
| 696 |
+
|
| 697 |
+
bpo-30781: Use ttk widgets in ConfigDialog pages.
|
| 698 |
+
These should especially look better on MacOSX.
|
| 699 |
+
Patches by Terry Jan Reedy and Cheryl Sabella.
|
| 700 |
+
|
| 701 |
+
bpo-31206: Factor HighPage(Frame) class from ConfigDialog.
|
| 702 |
+
Patch by Cheryl Sabella.
|
| 703 |
+
|
| 704 |
+
bp0-31001: Add tests for configdialog highlight tab.
|
| 705 |
+
Patch by Cheryl Sabella.
|
| 706 |
+
|
| 707 |
+
bpo-31205: Factor KeysPage(Frame) class from ConfigDialog.
|
| 708 |
+
The slightly modified tests continue to pass.
|
| 709 |
+
Patch by Cheryl Sabella.
|
| 710 |
+
|
| 711 |
+
bpo-31002: Add tests for configdialog keys tab.
|
| 712 |
+
Patch by Cheryl Sabella.
|
| 713 |
+
|
| 714 |
+
bpo-19903: Change calltipes to use inspect.signature.
|
| 715 |
+
Idlelib.calltips.get_argspec now uses inspect.signature instead of
|
| 716 |
+
inspect.getfullargspec, like help() does. This improves the signature
|
| 717 |
+
in the call tip in a few different cases, including builtins converted
|
| 718 |
+
to provide a signature. A message is added if the object is not
|
| 719 |
+
callable, has an invalid signature, or if it has positional-only
|
| 720 |
+
parameters. Patch by Louie Lu.
|
| 721 |
+
|
| 722 |
+
bop-31083: Add an outline of a TabPage class in configdialog.
|
| 723 |
+
Add template as comment. Update existing classes to match outline.
|
| 724 |
+
Initial patch by Cheryl Sabella.
|
| 725 |
+
|
| 726 |
+
bpo-31050: Factor GenPage(Frame) class from ConfigDialog.
|
| 727 |
+
The slightly modified tests for the General tab continue to pass.
|
| 728 |
+
Patch by Cheryl Sabella.
|
| 729 |
+
|
| 730 |
+
bpo-31004: Factor FontPage(Frame) class from ConfigDialog.
|
| 731 |
+
The slightly modified tests continue to pass. The General test
|
| 732 |
+
broken by the switch to ttk.Notebook is fixed.
|
| 733 |
+
Patch mostly by Cheryl Sabella.
|
| 734 |
+
|
| 735 |
+
bpo-30781: IDLE - Use ttk Notebook in ConfigDialog.
|
| 736 |
+
This improves navigation by tabbing.
|
| 737 |
+
Patch by Terry Jan Reedy.
|
| 738 |
+
|
| 739 |
+
bpo-31060: IDLE - Finish rearranging methods of ConfigDialog.
|
| 740 |
+
Grouping methods pertaining to each tab and the buttons will aid
|
| 741 |
+
writing tests and improving the tabs and will enable splitting the
|
| 742 |
+
groups into classes.
|
| 743 |
+
Patch by Terry Jan Reedy.
|
| 744 |
+
|
| 745 |
+
bpo-30853: IDLE -- Factor a VarTrace class out of ConfigDialog.
|
| 746 |
+
Instance tracers manages pairs consisting of a tk variable and a
|
| 747 |
+
callback function. When tracing is turned on, setting the variable
|
| 748 |
+
calls the function. Test coverage for the new class is 100%.
|
| 749 |
+
Patch by Terry Jan Reedy.
|
| 750 |
+
|
| 751 |
+
bpo-31003: IDLE: Add more tests for General tab.
|
| 752 |
+
Patch by Terry Jan Reedy.
|
| 753 |
+
|
| 754 |
+
bpo-30993: IDLE - Improve configdialog font page and tests.
|
| 755 |
+
*In configdialog: Document causal pathways in create_font_tab
|
| 756 |
+
docstring. Simplify some attribute names. Move set_samples calls to
|
| 757 |
+
var_changed_font (idea from Cheryl Sabella). Move related functions to
|
| 758 |
+
positions after the create widgets function.
|
| 759 |
+
* In test_configdialog: Fix test_font_set so not order dependent. Fix
|
| 760 |
+
renamed test_indent_scale so it tests the widget. Adjust tests for
|
| 761 |
+
movement of set_samples call. Add tests for load functions. Put all
|
| 762 |
+
font tests in one class and tab indent tests in another. Except for
|
| 763 |
+
two lines, these tests completely cover the related functions.
|
| 764 |
+
Patch by Terry Jan Reedy.
|
| 765 |
+
|
| 766 |
+
bpo-30981: IDLE -- Add more configdialog font page tests.
|
| 767 |
+
|
| 768 |
+
bpo-28523: IDLE: replace 'colour' with 'color' in configdialog.
|
| 769 |
+
|
| 770 |
+
bpo-30917: Add tests for idlelib.config.IdleConf.
|
| 771 |
+
Increase coverage from 46% to 96%.
|
| 772 |
+
Patch by Louie Lu.
|
| 773 |
+
|
| 774 |
+
bpo-30913: Document ConfigDialog tk Vars, methods, and widgets in docstrings
|
| 775 |
+
This will facilitate improving the dialog and splitting up the class.
|
| 776 |
+
Original patch by Cheryl Sabella.
|
| 777 |
+
|
| 778 |
+
bpo-30899: Add tests for ConfigParser subclasses in config.
|
| 779 |
+
Coverage is 100% for those classes and ConfigChanges.
|
| 780 |
+
Patch by Louie Lu.
|
| 781 |
+
|
| 782 |
+
bpo-30881: Add docstrings to browser.py.
|
| 783 |
+
Patch by Cheryl Sabella.
|
| 784 |
+
|
| 785 |
+
bpo-30851: Remove unused tk variables in configdialog.
|
| 786 |
+
One is a duplicate, one is set but cannot be altered by users.
|
| 787 |
+
Patch by Cheryl Sabella.
|
| 788 |
+
|
| 789 |
+
bpo-30870: Select font option with Up and Down keys, as well as with mouse.
|
| 790 |
+
Added test increases configdialog coverage to 60%
|
| 791 |
+
Patches mostly by Louie Lu.
|
| 792 |
+
|
| 793 |
+
bpo-8231: Call config.IdleConf.GetUserCfgDir only once per process.
|
| 794 |
+
|
| 795 |
+
bpo-30779: Factor ConfigChanges class from configdialog, put in config; test.
|
| 796 |
+
* In config, put dump test code in a function; run it and unittest in
|
| 797 |
+
'if __name__ == '__main__'.
|
| 798 |
+
* Add class config.ConfigChanges based on changes_class_v4.py on bpo issue.
|
| 799 |
+
* Add class test_config.ChangesTest, partly using configdialog_tests_v1.py.
|
| 800 |
+
* Revise configdialog to use ConfigChanges; see tracker msg297804.
|
| 801 |
+
* Revise test_configdialog to match configdialog changes.
|
| 802 |
+
* Remove configdialog functions unused or moved to ConfigChanges.
|
| 803 |
+
Cheryl Sabella contributed parts of the patch.
|
| 804 |
+
|
| 805 |
+
bpo-30777: Configdialog - add docstrings and improve comments.
|
| 806 |
+
Patch by Cheryl Sabella.
|
| 807 |
+
|
| 808 |
+
bpo-30495: Improve textview with docstrings, PEP8 names, and more tests.
|
| 809 |
+
Split TextViewer class into ViewWindow, ViewFrame, and TextFrame classes
|
| 810 |
+
so that instances of the latter two can be placed with other widgets
|
| 811 |
+
within a multiframe window.
|
| 812 |
+
Patches by Cheryl Sabella and Terry Jan Reedy.
|
| 813 |
+
|
| 814 |
+
bpo-30723: Make several improvements to parenmatch.
|
| 815 |
+
* Add 'parens' style to highlight both opener and closer.
|
| 816 |
+
* Make 'default' style, which is not default, a synonym for 'opener'.
|
| 817 |
+
* Make time-delay work the same with all styles.
|
| 818 |
+
* Add help for config dialog extensions tab, including parenmatch.
|
| 819 |
+
* Add new tests.
|
| 820 |
+
Original patch by Charles Wohlganger. Revisions by Terry Jan Reedy
|
| 821 |
+
|
| 822 |
+
bpo-30674: Grep -- Add docstrings. Patch by Cheryl Sabella.
|
| 823 |
+
|
| 824 |
+
bpo-21519: IDLE's basic custom key entry dialog now detects
|
| 825 |
+
duplicates properly. Original patch by Saimadhav Heblikar.
|
| 826 |
+
|
| 827 |
+
bpo-29910: IDLE no longer deletes a character after commenting out a
|
| 828 |
+
region by a key shortcut. Add "return 'break'" for this and other
|
| 829 |
+
potential conflicts between IDLE and default key bindings.
|
| 830 |
+
Patch by Serhiy Storchaka.
|
| 831 |
+
|
| 832 |
+
bpo-30728: Modernize idlelib.configdialog:
|
| 833 |
+
* replace import * with specific imports;
|
| 834 |
+
* lowercase method and attribute lines.
|
| 835 |
+
Patch by Cheryl Sabella.
|
| 836 |
+
|
| 837 |
+
bpo-6739: Verify user-entered key sequences by trying to bind them
|
| 838 |
+
with to a tk widget. Add tests for all 3 validation functions.
|
| 839 |
+
Original patch by G Polo. Tests added by Cheryl Sabella.
|
| 840 |
+
Code revised and more tests added by Terry Jan Reedy
|
| 841 |
+
|
| 842 |
+
bpo-24813: Add icon to help_about and make other changes.
|
| 843 |
+
|
| 844 |
+
bpo-15786: Fix several problems with IDLE's autocompletion box.
|
| 845 |
+
The following should now work: clicking on selection box items;
|
| 846 |
+
using the scrollbar; selecting an item by hitting Return.
|
| 847 |
+
Hangs on MacOSX should no longer happen. Patch by Louie Lu.
|
| 848 |
+
|
| 849 |
+
bpo-25514: Add doc subsubsection about IDLE failure to start.
|
| 850 |
+
Popup no-connection message directs users to this section.
|
| 851 |
+
|
| 852 |
+
bpo-30642: Fix reference leaks in IDLE tests.
|
| 853 |
+
Patches by Louie Lu and Terry Jan Reedy.
|
| 854 |
+
|
| 855 |
+
bpo-30495: Add docstrings for textview.py and use PEP8 names.
|
| 856 |
+
Patches by Cheryl Sabella and Terry Jan Reedy.
|
| 857 |
+
|
| 858 |
+
bpo-30290: Help-about: use pep8 names and add tests.
|
| 859 |
+
Increase coverage to 100%.
|
| 860 |
+
Patches by Louie Lu, Cheryl Sabella, and Terry Jan Reedy.
|
| 861 |
+
|
| 862 |
+
bpo-30303: Add _utest option to textview; add new tests.
|
| 863 |
+
Increase coverage to 100%.
|
| 864 |
+
Patches by Louie Lu and Terry Jan Reedy.
|
| 865 |
+
|
| 866 |
+
Issue #29071: IDLE colors f-string prefixes but not invalid ur prefixes.
|
| 867 |
+
|
| 868 |
+
Issue #28572: Add 10% to coverage of IDLE's test_configdialog.
|
| 869 |
+
Update and augment description of the configuration system.
|
| 870 |
+
|
| 871 |
+
|
| 872 |
+
What's New in IDLE 3.6.0 (since 3.5.0)
|
| 873 |
+
Released on 2016-12-23
|
| 874 |
+
======================================
|
| 875 |
+
|
| 876 |
+
- Issue #15308: Add 'interrupt execution' (^C) to Shell menu.
|
| 877 |
+
Patch by Roger Serwy, updated by Bayard Randel.
|
| 878 |
+
|
| 879 |
+
- Issue #27922: Stop IDLE tests from 'flashing' gui widgets on the screen.
|
| 880 |
+
|
| 881 |
+
- Issue #27891: Consistently group and sort imports within idlelib modules.
|
| 882 |
+
|
| 883 |
+
- Issue #17642: add larger font sizes for classroom projection.
|
| 884 |
+
|
| 885 |
+
- Add version to title of IDLE help window.
|
| 886 |
+
|
| 887 |
+
- Issue #25564: In section on IDLE -- console differences, mention that
|
| 888 |
+
using exec means that __builtins__ is defined for each statement.
|
| 889 |
+
|
| 890 |
+
- Issue #27821: Fix 3.6.0a3 regression that prevented custom key sets
|
| 891 |
+
from being selected when no custom theme was defined.
|
| 892 |
+
|
| 893 |
+
- Issue #27714: text_textview and test_autocomplete now pass when re-run
|
| 894 |
+
in the same process. This occurs when test_idle fails when run with the
|
| 895 |
+
-w option but without -jn. Fix warning from test_config.
|
| 896 |
+
|
| 897 |
+
- Issue #27621: Put query response validation error messages in the query
|
| 898 |
+
box itself instead of in a separate messagebox. Redo tests to match.
|
| 899 |
+
Add Mac OSX refinements. Original patch by Mark Roseman.
|
| 900 |
+
|
| 901 |
+
- Issue #27620: Escape key now closes Query box as cancelled.
|
| 902 |
+
|
| 903 |
+
- Issue #27609: IDLE: tab after initial whitespace should tab, not
|
| 904 |
+
autocomplete. This fixes problem with writing docstrings at least
|
| 905 |
+
twice indented.
|
| 906 |
+
|
| 907 |
+
- Issue #27609: Explicitly return None when there are also non-None
|
| 908 |
+
returns. In a few cases, reverse a condition and eliminate a return.
|
| 909 |
+
|
| 910 |
+
- Issue #25507: IDLE no longer runs buggy code because of its tkinter imports.
|
| 911 |
+
Users must include the same imports required to run directly in Python.
|
| 912 |
+
|
| 913 |
+
- Issue #27173: Add 'IDLE Modern Unix' to the built-in key sets.
|
| 914 |
+
Make the default key set depend on the platform.
|
| 915 |
+
Add tests for the changes to the config module.
|
| 916 |
+
|
| 917 |
+
- Issue #27452: add line counter and crc to IDLE configHandler test dump.
|
| 918 |
+
|
| 919 |
+
- Issue #27477: IDLE search dialogs now use ttk widgets.
|
| 920 |
+
|
| 921 |
+
- Issue #27173: Add 'IDLE Modern Unix' to the built-in key sets.
|
| 922 |
+
Make the default key set depend on the platform.
|
| 923 |
+
Add tests for the changes to the config module.
|
| 924 |
+
|
| 925 |
+
- Issue #27452: make command line "idle-test> python test_help.py" work.
|
| 926 |
+
__file__ is relative when python is started in the file's directory.
|
| 927 |
+
|
| 928 |
+
- Issue #27452: add line counter and crc to IDLE configHandler test dump.
|
| 929 |
+
|
| 930 |
+
- Issue #27380: IDLE: add query.py with base Query dialog and ttk widgets.
|
| 931 |
+
Module had subclasses SectionName, ModuleName, and HelpSource, which are
|
| 932 |
+
used to get information from users by configdialog and file =>Load Module.
|
| 933 |
+
Each subclass has itw own validity checks. Using ModuleName allows users
|
| 934 |
+
to edit bad module names instead of starting over.
|
| 935 |
+
Add tests and delete the two files combined into the new one.
|
| 936 |
+
|
| 937 |
+
- Issue #27372: Test_idle no longer changes the locale.
|
| 938 |
+
|
| 939 |
+
- Issue #27365: Allow non-ascii chars in IDLE NEWS.txt, for contributor names.
|
| 940 |
+
|
| 941 |
+
- Issue #27245: IDLE: Cleanly delete custom themes and key bindings.
|
| 942 |
+
Previously, when IDLE was started from a console or by import, a cascade
|
| 943 |
+
of warnings was emitted. Patch by Serhiy Storchaka.
|
| 944 |
+
|
| 945 |
+
- Issue #24137: Run IDLE, test_idle, and htest with tkinter default root disabled.
|
| 946 |
+
Fix code and tests that fail with this restriction.
|
| 947 |
+
Fix htests to not create a second and redundant root and mainloop.
|
| 948 |
+
|
| 949 |
+
- Issue #27310: Fix IDLE.app failure to launch on OS X due to vestigial import.
|
| 950 |
+
|
| 951 |
+
- Issue #5124: Paste with text selected now replaces the selection on X11.
|
| 952 |
+
This matches how paste works on Windows, Mac, most modern Linux apps,
|
| 953 |
+
and ttk widgets. Original patch by Serhiy Storchaka.
|
| 954 |
+
|
| 955 |
+
- Issue #24750: Switch all scrollbars in IDLE to ttk versions.
|
| 956 |
+
Where needed, minimal tests are added to cover changes.
|
| 957 |
+
|
| 958 |
+
- Issue #24759: IDLE requires tk 8.5 and availability ttk widgets.
|
| 959 |
+
Delete now unneeded tk version tests and code for older versions.
|
| 960 |
+
Add test for IDLE syntax colorizer.
|
| 961 |
+
|
| 962 |
+
- Issue #27239: idlelib.macosx.isXyzTk functions initialize as needed.
|
| 963 |
+
|
| 964 |
+
- Issue #27262: move Aqua unbinding code, which enable context menus, to macosx.
|
| 965 |
+
|
| 966 |
+
- Issue #24759: Make clear in idlelib.idle_test.__init__ that the directory
|
| 967 |
+
is a private implementation of test.test_idle and tool for maintainers.
|
| 968 |
+
|
| 969 |
+
- Issue #27196: Stop 'ThemeChanged' warnings when running IDLE tests.
|
| 970 |
+
These persisted after other warnings were suppressed in #20567.
|
| 971 |
+
Apply Serhiy Storchaka's update_idletasks solution to four test files.
|
| 972 |
+
Record this additional advice in idle_test/README.txt
|
| 973 |
+
|
| 974 |
+
- Issue #20567: Revise idle_test/README.txt with advice about avoiding
|
| 975 |
+
tk warning messages from tests. Apply advice to several IDLE tests.
|
| 976 |
+
|
| 977 |
+
- Issue # 24225: Update idlelib/README.txt with new file names
|
| 978 |
+
and event handlers.
|
| 979 |
+
|
| 980 |
+
- Issue #27156: Remove obsolete code not used by IDLE. Replacements:
|
| 981 |
+
1. help.txt, replaced by help.html, is out-of-date and should not be used.
|
| 982 |
+
Its dedicated viewer has be replaced by the html viewer in help.py.
|
| 983 |
+
2. 'import idlever; I = idlever.IDLE_VERSION' is the same as
|
| 984 |
+
'import sys; I = version[:version.index(' ')]'
|
| 985 |
+
3. After 'ob = stackviewer.VariablesTreeItem(*args)',
|
| 986 |
+
'ob.keys()' == 'list(ob.object.keys).
|
| 987 |
+
4. In macosc, runningAsOSXAPP == isAquaTk; idCarbonAquaTk == isCarbonTk
|
| 988 |
+
|
| 989 |
+
- Issue #27117: Make colorizer htest and turtledemo work with dark themes.
|
| 990 |
+
Move code for configuring text widget colors to a new function.
|
| 991 |
+
|
| 992 |
+
- Issue #24225: Rename many idlelib/*.py and idle_test/test_*.py files.
|
| 993 |
+
Edit files to replace old names with new names when the old name
|
| 994 |
+
referred to the module rather than the class it contained.
|
| 995 |
+
See the issue and IDLE section in What's New in 3.6 for more.
|
| 996 |
+
|
| 997 |
+
- Issue #26673: When tk reports font size as 0, change to size 10.
|
| 998 |
+
Such fonts on Linux prevented the configuration dialog from opening.
|
| 999 |
+
|
| 1000 |
+
- Issue #21939: Add test for IDLE's percolator.
|
| 1001 |
+
Original patch by Saimadhav Heblikar.
|
| 1002 |
+
|
| 1003 |
+
- Issue #21676: Add test for IDLE's replace dialog.
|
| 1004 |
+
Original patch by Saimadhav Heblikar.
|
| 1005 |
+
|
| 1006 |
+
- Issue #18410: Add test for IDLE's search dialog.
|
| 1007 |
+
Original patch by Westley Martínez.
|
| 1008 |
+
|
| 1009 |
+
- Issue #21703: Add test for undo delegator. Patch mostly by
|
| 1010 |
+
Saimadhav Heblikar .
|
| 1011 |
+
|
| 1012 |
+
- Issue #27044: Add ConfigDialog.remove_var_callbacks to stop memory leaks.
|
| 1013 |
+
|
| 1014 |
+
- Issue #23977: Add more asserts to test_delegator.
|
| 1015 |
+
|
| 1016 |
+
- Issue #20640: Add tests for idlelib.configHelpSourceEdit.
|
| 1017 |
+
Patch by Saimadhav Heblikar.
|
| 1018 |
+
|
| 1019 |
+
- In the 'IDLE-console differences' section of the IDLE doc, clarify
|
| 1020 |
+
how running with IDLE affects sys.modules and the standard streams.
|
| 1021 |
+
|
| 1022 |
+
- Issue #25507: fix incorrect change in IOBinding that prevented printing.
|
| 1023 |
+
Augment IOBinding htest to include all major IOBinding functions.
|
| 1024 |
+
|
| 1025 |
+
- Issue #25905: Revert unwanted conversion of ' to ’ RIGHT SINGLE QUOTATION
|
| 1026 |
+
MARK in README.txt and open this and NEWS.txt with 'ascii'.
|
| 1027 |
+
Re-encode CREDITS.txt to utf-8 and open it with 'utf-8'.
|
| 1028 |
+
|
| 1029 |
+
- Issue 15348: Stop the debugger engine (normally in a user process)
|
| 1030 |
+
before closing the debugger window (running in the IDLE process).
|
| 1031 |
+
This prevents the RuntimeErrors that were being caught and ignored.
|
| 1032 |
+
|
| 1033 |
+
- Issue #24455: Prevent IDLE from hanging when a) closing the shell while the
|
| 1034 |
+
debugger is active (15347); b) closing the debugger with the [X] button
|
| 1035 |
+
(15348); and c) activating the debugger when already active (24455).
|
| 1036 |
+
The patch by Mark Roseman does this by making two changes.
|
| 1037 |
+
1. Suspend and resume the gui.interaction method with the tcl vwait
|
| 1038 |
+
mechanism intended for this purpose (instead of root.mainloop & .quit).
|
| 1039 |
+
2. In gui.run, allow any existing interaction to terminate first.
|
| 1040 |
+
|
| 1041 |
+
- Change 'The program' to 'Your program' in an IDLE 'kill program?' message
|
| 1042 |
+
to make it clearer that the program referred to is the currently running
|
| 1043 |
+
user program, not IDLE itself.
|
| 1044 |
+
|
| 1045 |
+
- Issue #24750: Improve the appearance of the IDLE editor window status bar.
|
| 1046 |
+
Patch by Mark Roseman.
|
| 1047 |
+
|
| 1048 |
+
- Issue #25313: Change the handling of new built-in text color themes to better
|
| 1049 |
+
address the compatibility problem introduced by the addition of IDLE Dark.
|
| 1050 |
+
Consistently use the revised idleConf.CurrentTheme everywhere in idlelib.
|
| 1051 |
+
|
| 1052 |
+
- Issue #24782: Extension configuration is now a tab in the IDLE Preferences
|
| 1053 |
+
dialog rather than a separate dialog. The former tabs are now a sorted
|
| 1054 |
+
list. Patch by Mark Roseman.
|
| 1055 |
+
|
| 1056 |
+
- Issue #22726: Re-activate the config dialog help button with some content
|
| 1057 |
+
about the other buttons and the new IDLE Dark theme.
|
| 1058 |
+
|
| 1059 |
+
- Issue #24820: IDLE now has an 'IDLE Dark' built-in text color theme.
|
| 1060 |
+
It is more or less IDLE Classic inverted, with a cobalt blue background.
|
| 1061 |
+
Strings, comments, keywords, ... are still green, red, orange, ... .
|
| 1062 |
+
To use it with IDLEs released before November 2015, hit the
|
| 1063 |
+
'Save as New Custom Theme' button and enter a new name,
|
| 1064 |
+
such as 'Custom Dark'. The custom theme will work with any IDLE
|
| 1065 |
+
release, and can be modified.
|
| 1066 |
+
|
| 1067 |
+
- Issue #25224: README.txt is now an idlelib index for IDLE developers and
|
| 1068 |
+
curious users. The previous user content is now in the IDLE doc chapter.
|
| 1069 |
+
'IDLE' now means 'Integrated Development and Learning Environment'.
|
| 1070 |
+
|
| 1071 |
+
- Issue #24820: Users can now set breakpoint colors in
|
| 1072 |
+
Settings -> Custom Highlighting. Original patch by Mark Roseman.
|
| 1073 |
+
|
| 1074 |
+
- Issue #24972: Inactive selection background now matches active selection
|
| 1075 |
+
background, as configured by users, on all systems. Found items are now
|
| 1076 |
+
always highlighted on Windows. Initial patch by Mark Roseman.
|
| 1077 |
+
|
| 1078 |
+
- Issue #24570: Idle: make calltip and completion boxes appear on Macs
|
| 1079 |
+
affected by a tk regression. Initial patch by Mark Roseman.
|
| 1080 |
+
|
| 1081 |
+
- Issue #24988: Idle ScrolledList context menus (used in debugger)
|
| 1082 |
+
now work on Mac Aqua. Patch by Mark Roseman.
|
| 1083 |
+
|
| 1084 |
+
- Issue #24801: Make right-click for context menu work on Mac Aqua.
|
| 1085 |
+
Patch by Mark Roseman.
|
| 1086 |
+
|
| 1087 |
+
- Issue #25173: Associate tkinter messageboxes with a specific widget.
|
| 1088 |
+
For Mac OSX, make them a 'sheet'. Patch by Mark Roseman.
|
| 1089 |
+
|
| 1090 |
+
- Issue #25198: Enhance the initial html viewer now used for Idle Help.
|
| 1091 |
+
* Properly indent fixed-pitch text (patch by Mark Roseman).
|
| 1092 |
+
* Give code snippet a very Sphinx-like light blueish-gray background.
|
| 1093 |
+
* Re-use initial width and height set by users for shell and editor.
|
| 1094 |
+
* When the Table of Contents (TOC) menu is used, put the section header
|
| 1095 |
+
at the top of the screen.
|
| 1096 |
+
|
| 1097 |
+
- Issue #25225: Condense and rewrite Idle doc section on text colors.
|
| 1098 |
+
|
| 1099 |
+
- Issue #21995: Explain some differences between IDLE and console Python.
|
| 1100 |
+
|
| 1101 |
+
- Issue #22820: Explain need for *print* when running file from Idle editor.
|
| 1102 |
+
|
| 1103 |
+
- Issue #25224: Doc: augment Idle feature list and no-subprocess section.
|
| 1104 |
+
|
| 1105 |
+
- Issue #25219: Update doc for Idle command line options.
|
| 1106 |
+
Some were missing and notes were not correct.
|
| 1107 |
+
|
| 1108 |
+
- Issue #24861: Most of idlelib is private and subject to change.
|
| 1109 |
+
Use idleib.idle.* to start Idle. See idlelib.__init__.__doc__.
|
| 1110 |
+
|
| 1111 |
+
- Issue #25199: Idle: add synchronization comments for future maintainers.
|
| 1112 |
+
|
| 1113 |
+
- Issue #16893: Replace help.txt with help.html for Idle doc display.
|
| 1114 |
+
The new idlelib/help.html is rstripped Doc/build/html/library/idle.html.
|
| 1115 |
+
It looks better than help.txt and will better document Idle as released.
|
| 1116 |
+
The tkinter html viewer that works for this file was written by Mark Roseman.
|
| 1117 |
+
The now unused EditorWindow.HelpDialog class and helt.txt file are deprecated.
|
| 1118 |
+
|
| 1119 |
+
- Issue #24199: Deprecate unused idlelib.idlever with possible removal in 3.6.
|
| 1120 |
+
|
| 1121 |
+
- Issue #24790: Remove extraneous code (which also create 2 & 3 conflicts).
|
| 1122 |
+
|
| 1123 |
+
|
| 1124 |
+
What's New in IDLE 3.5.0?
|
| 1125 |
+
=========================
|
| 1126 |
+
*Release date: 2015-09-13*
|
| 1127 |
+
|
| 1128 |
+
- Issue #23672: Allow Idle to edit and run files with astral chars in name.
|
| 1129 |
+
Patch by Mohd Sanad Zaki Rizvi.
|
| 1130 |
+
|
| 1131 |
+
- Issue 24745: Idle editor default font. Switch from Courier to
|
| 1132 |
+
platform-sensitive TkFixedFont. This should not affect current customized
|
| 1133 |
+
font selections. If there is a problem, edit $HOME/.idlerc/config-main.cfg
|
| 1134 |
+
and remove 'fontxxx' entries from [Editor Window]. Patch by Mark Roseman.
|
| 1135 |
+
|
| 1136 |
+
- Issue #21192: Idle editor. When a file is run, put its name in the restart bar.
|
| 1137 |
+
Do not print false prompts. Original patch by Adnan Umer.
|
| 1138 |
+
|
| 1139 |
+
- Issue #13884: Idle menus. Remove tearoff lines. Patch by Roger Serwy.
|
| 1140 |
+
|
| 1141 |
+
- Issue #23184: remove unused names and imports in idlelib.
|
| 1142 |
+
Initial patch by Al Sweigart.
|
| 1143 |
+
|
| 1144 |
+
- Issue #20577: Configuration of the max line length for the FormatParagraph
|
| 1145 |
+
extension has been moved from the General tab of the Idle preferences dialog
|
| 1146 |
+
to the FormatParagraph tab of the Config Extensions dialog.
|
| 1147 |
+
Patch by Tal Einat.
|
| 1148 |
+
|
| 1149 |
+
- Issue #16893: Update Idle doc chapter to match current Idle and add new
|
| 1150 |
+
information.
|
| 1151 |
+
|
| 1152 |
+
- Issue #3068: Add Idle extension configuration dialog to Options menu.
|
| 1153 |
+
Changes are written to HOME/.idlerc/config-extensions.cfg.
|
| 1154 |
+
Original patch by Tal Einat.
|
| 1155 |
+
|
| 1156 |
+
- Issue #16233: A module browser (File : Class Browser, Alt+C) requires an
|
| 1157 |
+
editor window with a filename. When Class Browser is requested otherwise,
|
| 1158 |
+
from a shell, output window, or 'Untitled' editor, Idle no longer displays
|
| 1159 |
+
an error box. It now pops up an Open Module box (Alt+M). If a valid name
|
| 1160 |
+
is entered and a module is opened, a corresponding browser is also opened.
|
| 1161 |
+
|
| 1162 |
+
- Issue #4832: Save As to type Python files automatically adds .py to the
|
| 1163 |
+
name you enter (even if your system does not display it). Some systems
|
| 1164 |
+
automatically add .txt when type is Text files.
|
| 1165 |
+
|
| 1166 |
+
- Issue #21986: Code objects are not normally pickled by the pickle module.
|
| 1167 |
+
To match this, they are no longer pickled when running under Idle.
|
| 1168 |
+
|
| 1169 |
+
- Issue #23180: Rename IDLE "Windows" menu item to "Window".
|
| 1170 |
+
Patch by Al Sweigart.
|
| 1171 |
+
|
| 1172 |
+
- Issue #17390: Adjust Editor window title; remove 'Python',
|
| 1173 |
+
move version to end.
|
| 1174 |
+
|
| 1175 |
+
- Issue #14105: Idle debugger breakpoints no longer disappear
|
| 1176 |
+
when inserting or deleting lines.
|
| 1177 |
+
|
| 1178 |
+
- Issue #17172: Turtledemo can now be run from Idle.
|
| 1179 |
+
Currently, the entry is on the Help menu, but it may move to Run.
|
| 1180 |
+
Patch by Ramchandra Apt and Lita Cho.
|
| 1181 |
+
|
| 1182 |
+
- Issue #21765: Add support for non-ascii identifiers to HyperParser.
|
| 1183 |
+
|
| 1184 |
+
- Issue #21940: Add unittest for WidgetRedirector. Initial patch by Saimadhav
|
| 1185 |
+
Heblikar.
|
| 1186 |
+
|
| 1187 |
+
- Issue #18592: Add unittest for SearchDialogBase. Patch by Phil Webster.
|
| 1188 |
+
|
| 1189 |
+
- Issue #21694: Add unittest for ParenMatch. Patch by Saimadhav Heblikar.
|
| 1190 |
+
|
| 1191 |
+
- Issue #21686: add unittest for HyperParser. Original patch by Saimadhav
|
| 1192 |
+
Heblikar.
|
| 1193 |
+
|
| 1194 |
+
- Issue #12387: Add missing upper(lower)case versions of default Windows key
|
| 1195 |
+
bindings for Idle so Caps Lock does not disable them. Patch by Roger Serwy.
|
| 1196 |
+
|
| 1197 |
+
- Issue #21695: Closing a Find-in-files output window while the search is
|
| 1198 |
+
still in progress no longer closes Idle.
|
| 1199 |
+
|
| 1200 |
+
- Issue #18910: Add unittest for textView. Patch by Phil Webster.
|
| 1201 |
+
|
| 1202 |
+
- Issue #18292: Add unittest for AutoExpand. Patch by Saihadhav Heblikar.
|
| 1203 |
+
|
| 1204 |
+
- Issue #18409: Add unittest for AutoComplete. Patch by Phil Webster.
|
| 1205 |
+
|
| 1206 |
+
- Issue #21477: htest.py - Improve framework, complete set of tests.
|
| 1207 |
+
Patches by Saimadhav Heblikar
|
| 1208 |
+
|
| 1209 |
+
- Issue #18104: Add idlelib/idle_test/htest.py with a few sample tests to begin
|
| 1210 |
+
consolidating and improving human-validated tests of Idle. Change other files
|
| 1211 |
+
as needed to work with htest. Running the module as __main__ runs all tests.
|
| 1212 |
+
|
| 1213 |
+
- Issue #21139: Change default paragraph width to 72, the PEP 8 recommendation.
|
| 1214 |
+
|
| 1215 |
+
- Issue #21284: Paragraph reformat test passes after user changes reformat width.
|
| 1216 |
+
|
| 1217 |
+
- Issue #17654: Ensure IDLE menus are customized properly on OS X for
|
| 1218 |
+
non-framework builds and for all variants of Tk.
|
| 1219 |
+
|
| 1220 |
+
|
| 1221 |
+
What's New in IDLE 3.4.0?
|
| 1222 |
+
=========================
|
| 1223 |
+
*Release date: 2014-03-16*
|
| 1224 |
+
|
| 1225 |
+
- Issue #17390: Display Python version on Idle title bar.
|
| 1226 |
+
Initial patch by Edmond Burnett.
|
| 1227 |
+
|
| 1228 |
+
- Issue #5066: Update IDLE docs. Patch by Todd Rovito.
|
| 1229 |
+
|
| 1230 |
+
- Issue #17625: Close the replace dialog after it is used.
|
| 1231 |
+
|
| 1232 |
+
- Issue #16226: Fix IDLE Path Browser crash.
|
| 1233 |
+
(Patch by Roger Serwy)
|
| 1234 |
+
|
| 1235 |
+
- Issue #15853: Prevent IDLE crash on OS X when opening Preferences menu
|
| 1236 |
+
with certain versions of Tk 8.5. Initial patch by Kevin Walzer.
|
| 1237 |
+
|
| 1238 |
+
|
| 1239 |
+
What's New in IDLE 3.3.0?
|
| 1240 |
+
=========================
|
| 1241 |
+
*Release date: 2012-09-29*
|
| 1242 |
+
|
| 1243 |
+
- Issue #17625: Close the replace dialog after it is used.
|
| 1244 |
+
|
| 1245 |
+
- Issue #7163: Propagate return value of sys.stdout.write.
|
| 1246 |
+
|
| 1247 |
+
- Issue #15318: Prevent writing to sys.stdin.
|
| 1248 |
+
|
| 1249 |
+
- Issue #4832: Modify IDLE to save files with .py extension by
|
| 1250 |
+
default on Windows and OS X (Tk 8.5) as it already does with X11 Tk.
|
| 1251 |
+
|
| 1252 |
+
- Issue #13532, #15319: Check that arguments to sys.stdout.write are strings.
|
| 1253 |
+
|
| 1254 |
+
- Issue # 12510: Attempt to get certain tool tips no longer crashes IDLE.
|
| 1255 |
+
Erroneous tool tips have been corrected. Default added for callables.
|
| 1256 |
+
|
| 1257 |
+
- Issue #10365: File open dialog now works instead of crashing even when
|
| 1258 |
+
parent window is closed while dialog is open.
|
| 1259 |
+
|
| 1260 |
+
- Issue 14876: use user-selected font for highlight configuration.
|
| 1261 |
+
|
| 1262 |
+
- Issue #14937: Perform auto-completion of filenames in strings even for
|
| 1263 |
+
non-ASCII filenames. Likewise for identifiers.
|
| 1264 |
+
|
| 1265 |
+
- Issue #8515: Set __file__ when run file in IDLE.
|
| 1266 |
+
Initial patch by Bruce Frederiksen.
|
| 1267 |
+
|
| 1268 |
+
- IDLE can be launched as `python -m idlelib`
|
| 1269 |
+
|
| 1270 |
+
- Issue #14409: IDLE now properly executes commands in the Shell window
|
| 1271 |
+
when it cannot read the normal config files on startup and
|
| 1272 |
+
has to use the built-in default key bindings.
|
| 1273 |
+
There was previously a bug in one of the defaults.
|
| 1274 |
+
|
| 1275 |
+
- Issue #3573: IDLE hangs when passing invalid command line args
|
| 1276 |
+
(directory(ies) instead of file(s)).
|
| 1277 |
+
|
| 1278 |
+
- Issue #14018: Update checks for unstable system Tcl/Tk versions on OS X
|
| 1279 |
+
to include versions shipped with OS X 10.7 and 10.8 in addition to 10.6.
|
| 1280 |
+
|
| 1281 |
+
|
| 1282 |
+
What's New in IDLE 3.2.1?
|
| 1283 |
+
=========================
|
| 1284 |
+
*Release date: 15-May-11*
|
| 1285 |
+
|
| 1286 |
+
- Issue #6378: Further adjust idle.bat to start associated Python
|
| 1287 |
+
|
| 1288 |
+
- Issue #11896: Save on Close failed despite selecting "Yes" in dialog.
|
| 1289 |
+
|
| 1290 |
+
- Issue #1028: Ctrl-space binding to show completions was causing IDLE to exit.
|
| 1291 |
+
Tk < 8.5 was sending invalid Unicode null; replaced with valid null.
|
| 1292 |
+
|
| 1293 |
+
- Issue #4676: <Home> toggle failing on Tk 8.5, causing IDLE exits and strange selection
|
| 1294 |
+
behavior. Improve selection extension behaviour.
|
| 1295 |
+
|
| 1296 |
+
- Issue #3851: <Home> toggle non-functional when NumLock set on Windows.
|
| 1297 |
+
|
| 1298 |
+
|
| 1299 |
+
What's New in IDLE 3.1b1?
|
| 1300 |
+
=========================
|
| 1301 |
+
*Release date: 06-May-09*
|
| 1302 |
+
|
| 1303 |
+
- Issue #5707: Use of 'filter' in keybindingDialog.py was causing custom key assignment to
|
| 1304 |
+
fail. Patch by Amaury Forgeot d'Arc.
|
| 1305 |
+
|
| 1306 |
+
- Issue #4815: Offer conversion to UTF-8 if source files have
|
| 1307 |
+
no encoding declaration and are not encoded in UTF-8.
|
| 1308 |
+
|
| 1309 |
+
- Issue #4008: Fix problems with non-ASCII source files.
|
| 1310 |
+
|
| 1311 |
+
- Issue #4323: Always encode source as UTF-8 without asking
|
| 1312 |
+
the user (unless a different encoding is declared); remove
|
| 1313 |
+
user configuration of source encoding; all according to
|
| 1314 |
+
PEP 3120.
|
| 1315 |
+
|
| 1316 |
+
- Issue #2665: On Windows, an IDLE installation upgraded from an old version
|
| 1317 |
+
would not start if a custom theme was defined.
|
| 1318 |
+
|
| 1319 |
+
------------------------------------------------------------------------
|
| 1320 |
+
Refer to NEWS2x.txt and HISTORY.txt for information on earlier releases.
|
| 1321 |
+
------------------------------------------------------------------------
|
evalkit_cambrian/lib/python3.10/idlelib/TODO.txt
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Original IDLE todo, much of it now outdated:
|
| 2 |
+
============================================
|
| 3 |
+
TO DO:
|
| 4 |
+
|
| 5 |
+
- improve debugger:
|
| 6 |
+
- manage breakpoints globally, allow bp deletion, tbreak, cbreak etc.
|
| 7 |
+
- real object browser
|
| 8 |
+
- help on how to use it (a simple help button will do wonders)
|
| 9 |
+
- performance? (updates of large sets of locals are slow)
|
| 10 |
+
- better integration of "debug module"
|
| 11 |
+
- debugger should be global resource (attached to flist, not to shell)
|
| 12 |
+
- fix the stupid bug where you need to step twice
|
| 13 |
+
- display class name in stack viewer entries for methods
|
| 14 |
+
- suppress tracing through IDLE internals (e.g. print) DONE
|
| 15 |
+
- add a button to suppress through a specific module or class or method
|
| 16 |
+
- more object inspection to stack viewer, e.g. to view all array items
|
| 17 |
+
- insert the initial current directory into sys.path DONE
|
| 18 |
+
- default directory attribute for each window instead of only for windows
|
| 19 |
+
that have an associated filename
|
| 20 |
+
- command expansion from keywords, module contents, other buffers, etc.
|
| 21 |
+
- "Recent documents" menu item DONE
|
| 22 |
+
- Filter region command
|
| 23 |
+
- Optional horizontal scroll bar
|
| 24 |
+
- more Emacsisms:
|
| 25 |
+
- ^K should cut to buffer
|
| 26 |
+
- M-[, M-] to move by paragraphs
|
| 27 |
+
- incremental search?
|
| 28 |
+
- search should indicate wrap-around in some way
|
| 29 |
+
- restructure state sensitive code to avoid testing flags all the time
|
| 30 |
+
- persistent user state (e.g. window and cursor positions, bindings)
|
| 31 |
+
- make backups when saving
|
| 32 |
+
- check file mtimes at various points
|
| 33 |
+
- Pluggable interface with RCS/CVS/Perforce/Clearcase
|
| 34 |
+
- better help?
|
| 35 |
+
- don't open second class browser on same module (nor second path browser)
|
| 36 |
+
- unify class and path browsers
|
| 37 |
+
- Need to define a standard way whereby one can determine one is running
|
| 38 |
+
inside IDLE (needed for Tk mainloop, also handy for $PYTHONSTARTUP)
|
| 39 |
+
- Add more utility methods for use by extensions (a la get_selection)
|
| 40 |
+
- Way to run command in totally separate interpreter (fork+os.system?) DONE
|
| 41 |
+
- Way to find definition of fully-qualified name:
|
| 42 |
+
In other words, select "UserDict.UserDict", hit some magic key and
|
| 43 |
+
it loads up UserDict.py and finds the first def or class for UserDict.
|
| 44 |
+
- need a way to force colorization on/off
|
| 45 |
+
- need a way to force auto-indent on/off
|
| 46 |
+
|
| 47 |
+
Details:
|
| 48 |
+
|
| 49 |
+
- ^O (on Unix -- open-line) should honor autoindent
|
| 50 |
+
- after paste, show end of pasted text
|
| 51 |
+
- on Windows, should turn short filename to long filename (not only in argv!)
|
| 52 |
+
(shouldn't this be done -- or undone -- by ntpath.normpath?)
|
| 53 |
+
- new autoindent after colon even indents when the colon is in a comment!
|
| 54 |
+
- sometimes forward slashes in pathname remain
|
| 55 |
+
- sometimes star in window name remains in Windows menu
|
| 56 |
+
- With unix bindings, ESC by itself is ignored
|
| 57 |
+
- Sometimes for no apparent reason a selection from the cursor to the
|
| 58 |
+
end of the command buffer appears, which is hard to get rid of
|
| 59 |
+
because it stays when you are typing!
|
| 60 |
+
- The Line/Col in the status bar can be wrong initially in PyShell DONE
|
| 61 |
+
|
| 62 |
+
Structural problems:
|
| 63 |
+
|
| 64 |
+
- too much knowledge in FileList about EditorWindow (for example)
|
| 65 |
+
- should add some primitives for accessing the selection etc.
|
| 66 |
+
to repeat cumbersome code over and over
|
| 67 |
+
|
| 68 |
+
======================================================================
|
| 69 |
+
|
| 70 |
+
Jeff Bauer suggests:
|
| 71 |
+
|
| 72 |
+
- Open Module doesn't appear to handle hierarchical packages.
|
| 73 |
+
- Class browser should also allow hierarchical packages.
|
| 74 |
+
- Open and Open Module could benefit from a history, DONE
|
| 75 |
+
either command line style, or Microsoft recent-file
|
| 76 |
+
style.
|
| 77 |
+
- Add a Smalltalk-style inspector (i.e. Tkinspect)
|
| 78 |
+
|
| 79 |
+
The last suggestion is already a reality, but not yet
|
| 80 |
+
integrated into IDLE. I use a module called inspector.py,
|
| 81 |
+
that used to be available from python.org(?) It no longer
|
| 82 |
+
appears to be in the contributed section, and the source
|
| 83 |
+
has no author attribution.
|
| 84 |
+
|
| 85 |
+
In any case, the code is useful for visually navigating
|
| 86 |
+
an object's attributes, including its container hierarchy.
|
| 87 |
+
|
| 88 |
+
>>> from inspector import Tkinspect
|
| 89 |
+
>>> Tkinspect(None, myObject)
|
| 90 |
+
|
| 91 |
+
Tkinspect could probably be extended and refined to
|
| 92 |
+
integrate better into IDLE.
|
| 93 |
+
|
| 94 |
+
======================================================================
|
| 95 |
+
|
| 96 |
+
Comparison to PTUI
|
| 97 |
+
------------------
|
| 98 |
+
|
| 99 |
+
+ PTUI's help is better (HTML!)
|
| 100 |
+
|
| 101 |
+
+ PTUI can attach a shell to any module
|
| 102 |
+
|
| 103 |
+
+ PTUI has some more I/O commands:
|
| 104 |
+
open multiple
|
| 105 |
+
append
|
| 106 |
+
examine (what's that?)
|
| 107 |
+
|
| 108 |
+
======================================================================
|
| 109 |
+
|
| 110 |
+
Notes after trying to run Grail
|
| 111 |
+
-------------------------------
|
| 112 |
+
|
| 113 |
+
- Grail does stuff to sys.path based on sys.argv[0]; you must set
|
| 114 |
+
sys.argv[0] to something decent first (it is normally set to the path of
|
| 115 |
+
the idle script).
|
| 116 |
+
|
| 117 |
+
- Grail must be exec'ed in __main__ because that's imported by some
|
| 118 |
+
other parts of Grail.
|
| 119 |
+
|
| 120 |
+
- Grail uses a module called History and so does idle :-(
|
| 121 |
+
|
| 122 |
+
======================================================================
|
| 123 |
+
|
| 124 |
+
Robin Friedrich's items:
|
| 125 |
+
|
| 126 |
+
Things I'd like to see:
|
| 127 |
+
- I'd like support for shift-click extending the selection. There's a
|
| 128 |
+
bug now that it doesn't work the first time you try it.
|
| 129 |
+
- Printing is needed. How hard can that be on Windows? FIRST CUT DONE
|
| 130 |
+
- The python-mode trick of autoindenting a line with <tab> is neat and
|
| 131 |
+
very handy.
|
| 132 |
+
- (someday) a spellchecker for docstrings and comments.
|
| 133 |
+
- a pagedown/up command key which moves to next class/def statement (top
|
| 134 |
+
level)
|
| 135 |
+
- split window capability
|
| 136 |
+
- DnD text relocation/copying
|
| 137 |
+
|
| 138 |
+
Things I don't want to see.
|
| 139 |
+
- line numbers... will probably slow things down way too much.
|
| 140 |
+
- Please use another icon for the tree browser leaf. The small snake
|
| 141 |
+
isn't cutting it.
|
| 142 |
+
|
| 143 |
+
----------------------------------------------------------------------
|
| 144 |
+
|
| 145 |
+
- Customizable views (multi-window or multi-pane). (Markus Gritsch)
|
| 146 |
+
|
| 147 |
+
- Being able to double click (maybe double right click) on a callable
|
| 148 |
+
object in the editor which shows the source of the object, if
|
| 149 |
+
possible. (Gerrit Holl)
|
| 150 |
+
|
| 151 |
+
- Hooks into the guts, like in Emacs. (Mike Romberg)
|
| 152 |
+
|
| 153 |
+
- Sharing the editor with a remote tutor. (Martijn Faassen)
|
| 154 |
+
|
| 155 |
+
- Multiple views on the same file. (Tony J Ibbs)
|
| 156 |
+
|
| 157 |
+
- Store breakpoints in a global (per-project) database (GvR); Dirk
|
| 158 |
+
Heise adds: save some space-trimmed context and search around when
|
| 159 |
+
reopening a file that might have been edited by someone else.
|
| 160 |
+
|
| 161 |
+
- Capture menu events in extensions without changing the IDLE source.
|
| 162 |
+
(Matthias Barmeier)
|
| 163 |
+
|
| 164 |
+
- Use overlapping panels (a "notebook" in MFC terms I think) for info
|
| 165 |
+
that doesn't need to be accessible simultaneously (e.g. HTML source
|
| 166 |
+
and output). Use multi-pane windows for info that does need to be
|
| 167 |
+
shown together (e.g. class browser and source). (Albert Brandl)
|
| 168 |
+
|
| 169 |
+
- A project should invisibly track all symbols, for instant search,
|
| 170 |
+
replace and cross-ref. Projects should be allowed to span multiple
|
| 171 |
+
directories, hosts, etc. Project management files are placed in a
|
| 172 |
+
directory you specify. A global mapping between project names and
|
| 173 |
+
project directories should exist [not so sure --GvR]. (Tim Peters)
|
| 174 |
+
|
| 175 |
+
- Merge attr-tips and auto-expand. (Mark Hammond, Tim Peters)
|
| 176 |
+
|
| 177 |
+
- Python Shell should behave more like a "shell window" as users know
|
| 178 |
+
it -- i.e. you can only edit the current command, and the cursor can't
|
| 179 |
+
escape from the command area. (Albert Brandl)
|
| 180 |
+
|
| 181 |
+
- Set X11 class to "idle/Idle", set icon and title to something
|
| 182 |
+
beginning with "idle" -- for window manangers. (Randall Hopper)
|
| 183 |
+
|
| 184 |
+
- Config files editable through a preferences dialog. (me) DONE
|
| 185 |
+
|
| 186 |
+
- Config files still editable outside the preferences dialog.
|
| 187 |
+
(Randall Hopper) DONE
|
| 188 |
+
|
| 189 |
+
- When you're editing a command in PyShell, and there are only blank
|
| 190 |
+
lines below the cursor, hitting Return should ignore or delete those
|
| 191 |
+
blank lines rather than deciding you're not on the last line. (me)
|
| 192 |
+
|
| 193 |
+
- Run command (F5 c.s.) should be more like Pythonwin's Run -- a
|
| 194 |
+
dialog with options to give command line arguments, run the debugger,
|
| 195 |
+
etc. (me)
|
| 196 |
+
|
| 197 |
+
- Shouldn't be able to delete part of the prompt (or any text before
|
| 198 |
+
it) in the PyShell. (Martijn Faassen) DONE
|
| 199 |
+
|
| 200 |
+
- Emacs style auto-fill (also smart about comments and strings).
|
| 201 |
+
(Jeremy Hylton)
|
| 202 |
+
|
| 203 |
+
- Output of Run Script should go to a separate output window, not to
|
| 204 |
+
the shell window. Output of separate runs should all go to the same
|
| 205 |
+
window but clearly delimited. (David Scherer) REJECT FIRST, LATTER DONE
|
| 206 |
+
|
| 207 |
+
- GUI form designer to kick VB's butt. (Robert Geiger) THAT'S NOT IDLE
|
| 208 |
+
|
| 209 |
+
- Printing! Possibly via generation of PDF files which the user must
|
| 210 |
+
then send to the printer separately. (Dinu Gherman) FIRST CUT
|
evalkit_cambrian/lib/python3.10/idlelib/autocomplete_w.py
ADDED
|
@@ -0,0 +1,502 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
An auto-completion window for IDLE, used by the autocomplete extension
|
| 3 |
+
"""
|
| 4 |
+
import platform
|
| 5 |
+
|
| 6 |
+
from tkinter import *
|
| 7 |
+
from tkinter.ttk import Scrollbar
|
| 8 |
+
|
| 9 |
+
from idlelib.autocomplete import FILES, ATTRS
|
| 10 |
+
from idlelib.multicall import MC_SHIFT
|
| 11 |
+
|
| 12 |
+
HIDE_VIRTUAL_EVENT_NAME = "<<autocompletewindow-hide>>"
|
| 13 |
+
HIDE_FOCUS_OUT_SEQUENCE = "<FocusOut>"
|
| 14 |
+
HIDE_SEQUENCES = (HIDE_FOCUS_OUT_SEQUENCE, "<ButtonPress>")
|
| 15 |
+
KEYPRESS_VIRTUAL_EVENT_NAME = "<<autocompletewindow-keypress>>"
|
| 16 |
+
# We need to bind event beyond <Key> so that the function will be called
|
| 17 |
+
# before the default specific IDLE function
|
| 18 |
+
KEYPRESS_SEQUENCES = ("<Key>", "<Key-BackSpace>", "<Key-Return>", "<Key-Tab>",
|
| 19 |
+
"<Key-Up>", "<Key-Down>", "<Key-Home>", "<Key-End>",
|
| 20 |
+
"<Key-Prior>", "<Key-Next>", "<Key-Escape>")
|
| 21 |
+
KEYRELEASE_VIRTUAL_EVENT_NAME = "<<autocompletewindow-keyrelease>>"
|
| 22 |
+
KEYRELEASE_SEQUENCE = "<KeyRelease>"
|
| 23 |
+
LISTUPDATE_SEQUENCE = "<B1-ButtonRelease>"
|
| 24 |
+
WINCONFIG_SEQUENCE = "<Configure>"
|
| 25 |
+
DOUBLECLICK_SEQUENCE = "<B1-Double-ButtonRelease>"
|
| 26 |
+
|
| 27 |
+
class AutoCompleteWindow:
|
| 28 |
+
|
| 29 |
+
def __init__(self, widget, tags):
|
| 30 |
+
# The widget (Text) on which we place the AutoCompleteWindow
|
| 31 |
+
self.widget = widget
|
| 32 |
+
# Tags to mark inserted text with
|
| 33 |
+
self.tags = tags
|
| 34 |
+
# The widgets we create
|
| 35 |
+
self.autocompletewindow = self.listbox = self.scrollbar = None
|
| 36 |
+
# The default foreground and background of a selection. Saved because
|
| 37 |
+
# they are changed to the regular colors of list items when the
|
| 38 |
+
# completion start is not a prefix of the selected completion
|
| 39 |
+
self.origselforeground = self.origselbackground = None
|
| 40 |
+
# The list of completions
|
| 41 |
+
self.completions = None
|
| 42 |
+
# A list with more completions, or None
|
| 43 |
+
self.morecompletions = None
|
| 44 |
+
# The completion mode, either autocomplete.ATTRS or .FILES.
|
| 45 |
+
self.mode = None
|
| 46 |
+
# The current completion start, on the text box (a string)
|
| 47 |
+
self.start = None
|
| 48 |
+
# The index of the start of the completion
|
| 49 |
+
self.startindex = None
|
| 50 |
+
# The last typed start, used so that when the selection changes,
|
| 51 |
+
# the new start will be as close as possible to the last typed one.
|
| 52 |
+
self.lasttypedstart = None
|
| 53 |
+
# Do we have an indication that the user wants the completion window
|
| 54 |
+
# (for example, he clicked the list)
|
| 55 |
+
self.userwantswindow = None
|
| 56 |
+
# event ids
|
| 57 |
+
self.hideid = self.keypressid = self.listupdateid = \
|
| 58 |
+
self.winconfigid = self.keyreleaseid = self.doubleclickid = None
|
| 59 |
+
# Flag set if last keypress was a tab
|
| 60 |
+
self.lastkey_was_tab = False
|
| 61 |
+
# Flag set to avoid recursive <Configure> callback invocations.
|
| 62 |
+
self.is_configuring = False
|
| 63 |
+
|
| 64 |
+
def _change_start(self, newstart):
|
| 65 |
+
min_len = min(len(self.start), len(newstart))
|
| 66 |
+
i = 0
|
| 67 |
+
while i < min_len and self.start[i] == newstart[i]:
|
| 68 |
+
i += 1
|
| 69 |
+
if i < len(self.start):
|
| 70 |
+
self.widget.delete("%s+%dc" % (self.startindex, i),
|
| 71 |
+
"%s+%dc" % (self.startindex, len(self.start)))
|
| 72 |
+
if i < len(newstart):
|
| 73 |
+
self.widget.insert("%s+%dc" % (self.startindex, i),
|
| 74 |
+
newstart[i:],
|
| 75 |
+
self.tags)
|
| 76 |
+
self.start = newstart
|
| 77 |
+
|
| 78 |
+
def _binary_search(self, s):
|
| 79 |
+
"""Find the first index in self.completions where completions[i] is
|
| 80 |
+
greater or equal to s, or the last index if there is no such.
|
| 81 |
+
"""
|
| 82 |
+
i = 0; j = len(self.completions)
|
| 83 |
+
while j > i:
|
| 84 |
+
m = (i + j) // 2
|
| 85 |
+
if self.completions[m] >= s:
|
| 86 |
+
j = m
|
| 87 |
+
else:
|
| 88 |
+
i = m + 1
|
| 89 |
+
return min(i, len(self.completions)-1)
|
| 90 |
+
|
| 91 |
+
def _complete_string(self, s):
|
| 92 |
+
"""Assuming that s is the prefix of a string in self.completions,
|
| 93 |
+
return the longest string which is a prefix of all the strings which
|
| 94 |
+
s is a prefix of them. If s is not a prefix of a string, return s.
|
| 95 |
+
"""
|
| 96 |
+
first = self._binary_search(s)
|
| 97 |
+
if self.completions[first][:len(s)] != s:
|
| 98 |
+
# There is not even one completion which s is a prefix of.
|
| 99 |
+
return s
|
| 100 |
+
# Find the end of the range of completions where s is a prefix of.
|
| 101 |
+
i = first + 1
|
| 102 |
+
j = len(self.completions)
|
| 103 |
+
while j > i:
|
| 104 |
+
m = (i + j) // 2
|
| 105 |
+
if self.completions[m][:len(s)] != s:
|
| 106 |
+
j = m
|
| 107 |
+
else:
|
| 108 |
+
i = m + 1
|
| 109 |
+
last = i-1
|
| 110 |
+
|
| 111 |
+
if first == last: # only one possible completion
|
| 112 |
+
return self.completions[first]
|
| 113 |
+
|
| 114 |
+
# We should return the maximum prefix of first and last
|
| 115 |
+
first_comp = self.completions[first]
|
| 116 |
+
last_comp = self.completions[last]
|
| 117 |
+
min_len = min(len(first_comp), len(last_comp))
|
| 118 |
+
i = len(s)
|
| 119 |
+
while i < min_len and first_comp[i] == last_comp[i]:
|
| 120 |
+
i += 1
|
| 121 |
+
return first_comp[:i]
|
| 122 |
+
|
| 123 |
+
def _selection_changed(self):
|
| 124 |
+
"""Call when the selection of the Listbox has changed.
|
| 125 |
+
|
| 126 |
+
Updates the Listbox display and calls _change_start.
|
| 127 |
+
"""
|
| 128 |
+
cursel = int(self.listbox.curselection()[0])
|
| 129 |
+
|
| 130 |
+
self.listbox.see(cursel)
|
| 131 |
+
|
| 132 |
+
lts = self.lasttypedstart
|
| 133 |
+
selstart = self.completions[cursel]
|
| 134 |
+
if self._binary_search(lts) == cursel:
|
| 135 |
+
newstart = lts
|
| 136 |
+
else:
|
| 137 |
+
min_len = min(len(lts), len(selstart))
|
| 138 |
+
i = 0
|
| 139 |
+
while i < min_len and lts[i] == selstart[i]:
|
| 140 |
+
i += 1
|
| 141 |
+
newstart = selstart[:i]
|
| 142 |
+
self._change_start(newstart)
|
| 143 |
+
|
| 144 |
+
if self.completions[cursel][:len(self.start)] == self.start:
|
| 145 |
+
# start is a prefix of the selected completion
|
| 146 |
+
self.listbox.configure(selectbackground=self.origselbackground,
|
| 147 |
+
selectforeground=self.origselforeground)
|
| 148 |
+
else:
|
| 149 |
+
self.listbox.configure(selectbackground=self.listbox.cget("bg"),
|
| 150 |
+
selectforeground=self.listbox.cget("fg"))
|
| 151 |
+
# If there are more completions, show them, and call me again.
|
| 152 |
+
if self.morecompletions:
|
| 153 |
+
self.completions = self.morecompletions
|
| 154 |
+
self.morecompletions = None
|
| 155 |
+
self.listbox.delete(0, END)
|
| 156 |
+
for item in self.completions:
|
| 157 |
+
self.listbox.insert(END, item)
|
| 158 |
+
self.listbox.select_set(self._binary_search(self.start))
|
| 159 |
+
self._selection_changed()
|
| 160 |
+
|
| 161 |
+
def show_window(self, comp_lists, index, complete, mode, userWantsWin):
|
| 162 |
+
"""Show the autocomplete list, bind events.
|
| 163 |
+
|
| 164 |
+
If complete is True, complete the text, and if there is exactly
|
| 165 |
+
one matching completion, don't open a list.
|
| 166 |
+
"""
|
| 167 |
+
# Handle the start we already have
|
| 168 |
+
self.completions, self.morecompletions = comp_lists
|
| 169 |
+
self.mode = mode
|
| 170 |
+
self.startindex = self.widget.index(index)
|
| 171 |
+
self.start = self.widget.get(self.startindex, "insert")
|
| 172 |
+
if complete:
|
| 173 |
+
completed = self._complete_string(self.start)
|
| 174 |
+
start = self.start
|
| 175 |
+
self._change_start(completed)
|
| 176 |
+
i = self._binary_search(completed)
|
| 177 |
+
if self.completions[i] == completed and \
|
| 178 |
+
(i == len(self.completions)-1 or
|
| 179 |
+
self.completions[i+1][:len(completed)] != completed):
|
| 180 |
+
# There is exactly one matching completion
|
| 181 |
+
return completed == start
|
| 182 |
+
self.userwantswindow = userWantsWin
|
| 183 |
+
self.lasttypedstart = self.start
|
| 184 |
+
|
| 185 |
+
# Put widgets in place
|
| 186 |
+
self.autocompletewindow = acw = Toplevel(self.widget)
|
| 187 |
+
# Put it in a position so that it is not seen.
|
| 188 |
+
acw.wm_geometry("+10000+10000")
|
| 189 |
+
# Make it float
|
| 190 |
+
acw.wm_overrideredirect(1)
|
| 191 |
+
try:
|
| 192 |
+
# This command is only needed and available on Tk >= 8.4.0 for OSX
|
| 193 |
+
# Without it, call tips intrude on the typing process by grabbing
|
| 194 |
+
# the focus.
|
| 195 |
+
acw.tk.call("::tk::unsupported::MacWindowStyle", "style", acw._w,
|
| 196 |
+
"help", "noActivates")
|
| 197 |
+
except TclError:
|
| 198 |
+
pass
|
| 199 |
+
self.scrollbar = scrollbar = Scrollbar(acw, orient=VERTICAL)
|
| 200 |
+
self.listbox = listbox = Listbox(acw, yscrollcommand=scrollbar.set,
|
| 201 |
+
exportselection=False)
|
| 202 |
+
for item in self.completions:
|
| 203 |
+
listbox.insert(END, item)
|
| 204 |
+
self.origselforeground = listbox.cget("selectforeground")
|
| 205 |
+
self.origselbackground = listbox.cget("selectbackground")
|
| 206 |
+
scrollbar.config(command=listbox.yview)
|
| 207 |
+
scrollbar.pack(side=RIGHT, fill=Y)
|
| 208 |
+
listbox.pack(side=LEFT, fill=BOTH, expand=True)
|
| 209 |
+
#acw.update_idletasks() # Need for tk8.6.8 on macOS: #40128.
|
| 210 |
+
acw.lift() # work around bug in Tk 8.5.18+ (issue #24570)
|
| 211 |
+
|
| 212 |
+
# Initialize the listbox selection
|
| 213 |
+
self.listbox.select_set(self._binary_search(self.start))
|
| 214 |
+
self._selection_changed()
|
| 215 |
+
|
| 216 |
+
# bind events
|
| 217 |
+
self.hideaid = acw.bind(HIDE_VIRTUAL_EVENT_NAME, self.hide_event)
|
| 218 |
+
self.hidewid = self.widget.bind(HIDE_VIRTUAL_EVENT_NAME, self.hide_event)
|
| 219 |
+
acw.event_add(HIDE_VIRTUAL_EVENT_NAME, HIDE_FOCUS_OUT_SEQUENCE)
|
| 220 |
+
for seq in HIDE_SEQUENCES:
|
| 221 |
+
self.widget.event_add(HIDE_VIRTUAL_EVENT_NAME, seq)
|
| 222 |
+
|
| 223 |
+
self.keypressid = self.widget.bind(KEYPRESS_VIRTUAL_EVENT_NAME,
|
| 224 |
+
self.keypress_event)
|
| 225 |
+
for seq in KEYPRESS_SEQUENCES:
|
| 226 |
+
self.widget.event_add(KEYPRESS_VIRTUAL_EVENT_NAME, seq)
|
| 227 |
+
self.keyreleaseid = self.widget.bind(KEYRELEASE_VIRTUAL_EVENT_NAME,
|
| 228 |
+
self.keyrelease_event)
|
| 229 |
+
self.widget.event_add(KEYRELEASE_VIRTUAL_EVENT_NAME,KEYRELEASE_SEQUENCE)
|
| 230 |
+
self.listupdateid = listbox.bind(LISTUPDATE_SEQUENCE,
|
| 231 |
+
self.listselect_event)
|
| 232 |
+
self.is_configuring = False
|
| 233 |
+
self.winconfigid = acw.bind(WINCONFIG_SEQUENCE, self.winconfig_event)
|
| 234 |
+
self.doubleclickid = listbox.bind(DOUBLECLICK_SEQUENCE,
|
| 235 |
+
self.doubleclick_event)
|
| 236 |
+
return None
|
| 237 |
+
|
| 238 |
+
def winconfig_event(self, event):
|
| 239 |
+
if self.is_configuring:
|
| 240 |
+
# Avoid running on recursive <Configure> callback invocations.
|
| 241 |
+
return
|
| 242 |
+
|
| 243 |
+
self.is_configuring = True
|
| 244 |
+
if not self.is_active():
|
| 245 |
+
return
|
| 246 |
+
|
| 247 |
+
# Since the <Configure> event may occur after the completion window is gone,
|
| 248 |
+
# catch potential TclError exceptions when accessing acw. See: bpo-41611.
|
| 249 |
+
try:
|
| 250 |
+
# Position the completion list window
|
| 251 |
+
text = self.widget
|
| 252 |
+
text.see(self.startindex)
|
| 253 |
+
x, y, cx, cy = text.bbox(self.startindex)
|
| 254 |
+
acw = self.autocompletewindow
|
| 255 |
+
if platform.system().startswith('Windows'):
|
| 256 |
+
# On Windows an update() call is needed for the completion
|
| 257 |
+
# list window to be created, so that we can fetch its width
|
| 258 |
+
# and height. However, this is not needed on other platforms
|
| 259 |
+
# (tested on Ubuntu and macOS) but at one point began
|
| 260 |
+
# causing freezes on macOS. See issues 37849 and 41611.
|
| 261 |
+
acw.update()
|
| 262 |
+
acw_width, acw_height = acw.winfo_width(), acw.winfo_height()
|
| 263 |
+
text_width, text_height = text.winfo_width(), text.winfo_height()
|
| 264 |
+
new_x = text.winfo_rootx() + min(x, max(0, text_width - acw_width))
|
| 265 |
+
new_y = text.winfo_rooty() + y
|
| 266 |
+
if (text_height - (y + cy) >= acw_height # enough height below
|
| 267 |
+
or y < acw_height): # not enough height above
|
| 268 |
+
# place acw below current line
|
| 269 |
+
new_y += cy
|
| 270 |
+
else:
|
| 271 |
+
# place acw above current line
|
| 272 |
+
new_y -= acw_height
|
| 273 |
+
acw.wm_geometry("+%d+%d" % (new_x, new_y))
|
| 274 |
+
acw.update_idletasks()
|
| 275 |
+
except TclError:
|
| 276 |
+
pass
|
| 277 |
+
|
| 278 |
+
if platform.system().startswith('Windows'):
|
| 279 |
+
# See issue 15786. When on Windows platform, Tk will misbehave
|
| 280 |
+
# to call winconfig_event multiple times, we need to prevent this,
|
| 281 |
+
# otherwise mouse button double click will not be able to used.
|
| 282 |
+
try:
|
| 283 |
+
acw.unbind(WINCONFIG_SEQUENCE, self.winconfigid)
|
| 284 |
+
except TclError:
|
| 285 |
+
pass
|
| 286 |
+
self.winconfigid = None
|
| 287 |
+
|
| 288 |
+
self.is_configuring = False
|
| 289 |
+
|
| 290 |
+
def _hide_event_check(self):
|
| 291 |
+
if not self.autocompletewindow:
|
| 292 |
+
return
|
| 293 |
+
|
| 294 |
+
try:
|
| 295 |
+
if not self.autocompletewindow.focus_get():
|
| 296 |
+
self.hide_window()
|
| 297 |
+
except KeyError:
|
| 298 |
+
# See issue 734176, when user click on menu, acw.focus_get()
|
| 299 |
+
# will get KeyError.
|
| 300 |
+
self.hide_window()
|
| 301 |
+
|
| 302 |
+
def hide_event(self, event):
|
| 303 |
+
# Hide autocomplete list if it exists and does not have focus or
|
| 304 |
+
# mouse click on widget / text area.
|
| 305 |
+
if self.is_active():
|
| 306 |
+
if event.type == EventType.FocusOut:
|
| 307 |
+
# On Windows platform, it will need to delay the check for
|
| 308 |
+
# acw.focus_get() when click on acw, otherwise it will return
|
| 309 |
+
# None and close the window
|
| 310 |
+
self.widget.after(1, self._hide_event_check)
|
| 311 |
+
elif event.type == EventType.ButtonPress:
|
| 312 |
+
# ButtonPress event only bind to self.widget
|
| 313 |
+
self.hide_window()
|
| 314 |
+
|
| 315 |
+
def listselect_event(self, event):
|
| 316 |
+
if self.is_active():
|
| 317 |
+
self.userwantswindow = True
|
| 318 |
+
cursel = int(self.listbox.curselection()[0])
|
| 319 |
+
self._change_start(self.completions[cursel])
|
| 320 |
+
|
| 321 |
+
def doubleclick_event(self, event):
|
| 322 |
+
# Put the selected completion in the text, and close the list
|
| 323 |
+
cursel = int(self.listbox.curselection()[0])
|
| 324 |
+
self._change_start(self.completions[cursel])
|
| 325 |
+
self.hide_window()
|
| 326 |
+
|
| 327 |
+
def keypress_event(self, event):
|
| 328 |
+
if not self.is_active():
|
| 329 |
+
return None
|
| 330 |
+
keysym = event.keysym
|
| 331 |
+
if hasattr(event, "mc_state"):
|
| 332 |
+
state = event.mc_state
|
| 333 |
+
else:
|
| 334 |
+
state = 0
|
| 335 |
+
if keysym != "Tab":
|
| 336 |
+
self.lastkey_was_tab = False
|
| 337 |
+
if (len(keysym) == 1 or keysym in ("underscore", "BackSpace")
|
| 338 |
+
or (self.mode == FILES and keysym in
|
| 339 |
+
("period", "minus"))) \
|
| 340 |
+
and not (state & ~MC_SHIFT):
|
| 341 |
+
# Normal editing of text
|
| 342 |
+
if len(keysym) == 1:
|
| 343 |
+
self._change_start(self.start + keysym)
|
| 344 |
+
elif keysym == "underscore":
|
| 345 |
+
self._change_start(self.start + '_')
|
| 346 |
+
elif keysym == "period":
|
| 347 |
+
self._change_start(self.start + '.')
|
| 348 |
+
elif keysym == "minus":
|
| 349 |
+
self._change_start(self.start + '-')
|
| 350 |
+
else:
|
| 351 |
+
# keysym == "BackSpace"
|
| 352 |
+
if len(self.start) == 0:
|
| 353 |
+
self.hide_window()
|
| 354 |
+
return None
|
| 355 |
+
self._change_start(self.start[:-1])
|
| 356 |
+
self.lasttypedstart = self.start
|
| 357 |
+
self.listbox.select_clear(0, int(self.listbox.curselection()[0]))
|
| 358 |
+
self.listbox.select_set(self._binary_search(self.start))
|
| 359 |
+
self._selection_changed()
|
| 360 |
+
return "break"
|
| 361 |
+
|
| 362 |
+
elif keysym == "Return":
|
| 363 |
+
self.complete()
|
| 364 |
+
self.hide_window()
|
| 365 |
+
return 'break'
|
| 366 |
+
|
| 367 |
+
elif (self.mode == ATTRS and keysym in
|
| 368 |
+
("period", "space", "parenleft", "parenright", "bracketleft",
|
| 369 |
+
"bracketright")) or \
|
| 370 |
+
(self.mode == FILES and keysym in
|
| 371 |
+
("slash", "backslash", "quotedbl", "apostrophe")) \
|
| 372 |
+
and not (state & ~MC_SHIFT):
|
| 373 |
+
# If start is a prefix of the selection, but is not '' when
|
| 374 |
+
# completing file names, put the whole
|
| 375 |
+
# selected completion. Anyway, close the list.
|
| 376 |
+
cursel = int(self.listbox.curselection()[0])
|
| 377 |
+
if self.completions[cursel][:len(self.start)] == self.start \
|
| 378 |
+
and (self.mode == ATTRS or self.start):
|
| 379 |
+
self._change_start(self.completions[cursel])
|
| 380 |
+
self.hide_window()
|
| 381 |
+
return None
|
| 382 |
+
|
| 383 |
+
elif keysym in ("Home", "End", "Prior", "Next", "Up", "Down") and \
|
| 384 |
+
not state:
|
| 385 |
+
# Move the selection in the listbox
|
| 386 |
+
self.userwantswindow = True
|
| 387 |
+
cursel = int(self.listbox.curselection()[0])
|
| 388 |
+
if keysym == "Home":
|
| 389 |
+
newsel = 0
|
| 390 |
+
elif keysym == "End":
|
| 391 |
+
newsel = len(self.completions)-1
|
| 392 |
+
elif keysym in ("Prior", "Next"):
|
| 393 |
+
jump = self.listbox.nearest(self.listbox.winfo_height()) - \
|
| 394 |
+
self.listbox.nearest(0)
|
| 395 |
+
if keysym == "Prior":
|
| 396 |
+
newsel = max(0, cursel-jump)
|
| 397 |
+
else:
|
| 398 |
+
assert keysym == "Next"
|
| 399 |
+
newsel = min(len(self.completions)-1, cursel+jump)
|
| 400 |
+
elif keysym == "Up":
|
| 401 |
+
newsel = max(0, cursel-1)
|
| 402 |
+
else:
|
| 403 |
+
assert keysym == "Down"
|
| 404 |
+
newsel = min(len(self.completions)-1, cursel+1)
|
| 405 |
+
self.listbox.select_clear(cursel)
|
| 406 |
+
self.listbox.select_set(newsel)
|
| 407 |
+
self._selection_changed()
|
| 408 |
+
self._change_start(self.completions[newsel])
|
| 409 |
+
return "break"
|
| 410 |
+
|
| 411 |
+
elif (keysym == "Tab" and not state):
|
| 412 |
+
if self.lastkey_was_tab:
|
| 413 |
+
# two tabs in a row; insert current selection and close acw
|
| 414 |
+
cursel = int(self.listbox.curselection()[0])
|
| 415 |
+
self._change_start(self.completions[cursel])
|
| 416 |
+
self.hide_window()
|
| 417 |
+
return "break"
|
| 418 |
+
else:
|
| 419 |
+
# first tab; let AutoComplete handle the completion
|
| 420 |
+
self.userwantswindow = True
|
| 421 |
+
self.lastkey_was_tab = True
|
| 422 |
+
return None
|
| 423 |
+
|
| 424 |
+
elif any(s in keysym for s in ("Shift", "Control", "Alt",
|
| 425 |
+
"Meta", "Command", "Option")):
|
| 426 |
+
# A modifier key, so ignore
|
| 427 |
+
return None
|
| 428 |
+
|
| 429 |
+
elif event.char and event.char >= ' ':
|
| 430 |
+
# Regular character with a non-length-1 keycode
|
| 431 |
+
self._change_start(self.start + event.char)
|
| 432 |
+
self.lasttypedstart = self.start
|
| 433 |
+
self.listbox.select_clear(0, int(self.listbox.curselection()[0]))
|
| 434 |
+
self.listbox.select_set(self._binary_search(self.start))
|
| 435 |
+
self._selection_changed()
|
| 436 |
+
return "break"
|
| 437 |
+
|
| 438 |
+
else:
|
| 439 |
+
# Unknown event, close the window and let it through.
|
| 440 |
+
self.hide_window()
|
| 441 |
+
return None
|
| 442 |
+
|
| 443 |
+
def keyrelease_event(self, event):
|
| 444 |
+
if not self.is_active():
|
| 445 |
+
return
|
| 446 |
+
if self.widget.index("insert") != \
|
| 447 |
+
self.widget.index("%s+%dc" % (self.startindex, len(self.start))):
|
| 448 |
+
# If we didn't catch an event which moved the insert, close window
|
| 449 |
+
self.hide_window()
|
| 450 |
+
|
| 451 |
+
def is_active(self):
|
| 452 |
+
return self.autocompletewindow is not None
|
| 453 |
+
|
| 454 |
+
def complete(self):
|
| 455 |
+
self._change_start(self._complete_string(self.start))
|
| 456 |
+
# The selection doesn't change.
|
| 457 |
+
|
| 458 |
+
def hide_window(self):
|
| 459 |
+
if not self.is_active():
|
| 460 |
+
return
|
| 461 |
+
|
| 462 |
+
# unbind events
|
| 463 |
+
self.autocompletewindow.event_delete(HIDE_VIRTUAL_EVENT_NAME,
|
| 464 |
+
HIDE_FOCUS_OUT_SEQUENCE)
|
| 465 |
+
for seq in HIDE_SEQUENCES:
|
| 466 |
+
self.widget.event_delete(HIDE_VIRTUAL_EVENT_NAME, seq)
|
| 467 |
+
|
| 468 |
+
self.autocompletewindow.unbind(HIDE_VIRTUAL_EVENT_NAME, self.hideaid)
|
| 469 |
+
self.widget.unbind(HIDE_VIRTUAL_EVENT_NAME, self.hidewid)
|
| 470 |
+
self.hideaid = None
|
| 471 |
+
self.hidewid = None
|
| 472 |
+
for seq in KEYPRESS_SEQUENCES:
|
| 473 |
+
self.widget.event_delete(KEYPRESS_VIRTUAL_EVENT_NAME, seq)
|
| 474 |
+
self.widget.unbind(KEYPRESS_VIRTUAL_EVENT_NAME, self.keypressid)
|
| 475 |
+
self.keypressid = None
|
| 476 |
+
self.widget.event_delete(KEYRELEASE_VIRTUAL_EVENT_NAME,
|
| 477 |
+
KEYRELEASE_SEQUENCE)
|
| 478 |
+
self.widget.unbind(KEYRELEASE_VIRTUAL_EVENT_NAME, self.keyreleaseid)
|
| 479 |
+
self.keyreleaseid = None
|
| 480 |
+
self.listbox.unbind(LISTUPDATE_SEQUENCE, self.listupdateid)
|
| 481 |
+
self.listupdateid = None
|
| 482 |
+
if self.winconfigid:
|
| 483 |
+
self.autocompletewindow.unbind(WINCONFIG_SEQUENCE, self.winconfigid)
|
| 484 |
+
self.winconfigid = None
|
| 485 |
+
|
| 486 |
+
# Re-focusOn frame.text (See issue #15786)
|
| 487 |
+
self.widget.focus_set()
|
| 488 |
+
|
| 489 |
+
# destroy widgets
|
| 490 |
+
self.scrollbar.destroy()
|
| 491 |
+
self.scrollbar = None
|
| 492 |
+
self.listbox.destroy()
|
| 493 |
+
self.listbox = None
|
| 494 |
+
self.autocompletewindow.destroy()
|
| 495 |
+
self.autocompletewindow = None
|
| 496 |
+
|
| 497 |
+
|
| 498 |
+
if __name__ == '__main__':
|
| 499 |
+
from unittest import main
|
| 500 |
+
main('idlelib.idle_test.test_autocomplete_w', verbosity=2, exit=False)
|
| 501 |
+
|
| 502 |
+
# TODO: autocomplete/w htest here
|
evalkit_cambrian/lib/python3.10/idlelib/browser.py
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
| 7 |
+
- add popup menu with more options (e.g. doc strings, base classes, imports)
|
| 8 |
+
- add base classes to class browser tree
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
import os
|
| 12 |
+
import pyclbr
|
| 13 |
+
import sys
|
| 14 |
+
|
| 15 |
+
from idlelib.config import idleConf
|
| 16 |
+
from idlelib import pyshell
|
| 17 |
+
from idlelib.tree import TreeNode, TreeItem, ScrolledCanvas
|
| 18 |
+
from idlelib.util import py_extensions
|
| 19 |
+
from idlelib.window import ListedToplevel
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
file_open = None # Method...Item and Class...Item use this.
|
| 23 |
+
# Normally pyshell.flist.open, but there is no pyshell.flist for htest.
|
| 24 |
+
|
| 25 |
+
# The browser depends on pyclbr and importlib which do not support .pyi files.
|
| 26 |
+
browseable_extension_blocklist = ('.pyi',)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def is_browseable_extension(path):
|
| 30 |
+
_, ext = os.path.splitext(path)
|
| 31 |
+
ext = os.path.normcase(ext)
|
| 32 |
+
return ext in py_extensions and ext not in browseable_extension_blocklist
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def transform_children(child_dict, modname=None):
|
| 36 |
+
"""Transform a child dictionary to an ordered sequence of objects.
|
| 37 |
+
|
| 38 |
+
The dictionary maps names to pyclbr information objects.
|
| 39 |
+
Filter out imported objects.
|
| 40 |
+
Augment class names with bases.
|
| 41 |
+
The insertion order of the dictionary is assumed to have been in line
|
| 42 |
+
number order, so sorting is not necessary.
|
| 43 |
+
|
| 44 |
+
The current tree only calls this once per child_dict as it saves
|
| 45 |
+
TreeItems once created. A future tree and tests might violate this,
|
| 46 |
+
so a check prevents multiple in-place augmentations.
|
| 47 |
+
"""
|
| 48 |
+
obs = [] # Use list since values should already be sorted.
|
| 49 |
+
for key, obj in child_dict.items():
|
| 50 |
+
if modname is None or obj.module == modname:
|
| 51 |
+
if hasattr(obj, 'super') and obj.super and obj.name == key:
|
| 52 |
+
# If obj.name != key, it has already been suffixed.
|
| 53 |
+
supers = []
|
| 54 |
+
for sup in obj.super:
|
| 55 |
+
if isinstance(sup, str):
|
| 56 |
+
sname = sup
|
| 57 |
+
else:
|
| 58 |
+
sname = sup.name
|
| 59 |
+
if sup.module != obj.module:
|
| 60 |
+
sname = f'{sup.module}.{sname}'
|
| 61 |
+
supers.append(sname)
|
| 62 |
+
obj.name += '({})'.format(', '.join(supers))
|
| 63 |
+
obs.append(obj)
|
| 64 |
+
return obs
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
class ModuleBrowser:
|
| 68 |
+
"""Browse module classes and functions in IDLE.
|
| 69 |
+
"""
|
| 70 |
+
# This class is also the base class for pathbrowser.PathBrowser.
|
| 71 |
+
# Init and close are inherited, other methods are overridden.
|
| 72 |
+
# PathBrowser.__init__ does not call __init__ below.
|
| 73 |
+
|
| 74 |
+
def __init__(self, master, path, *, _htest=False, _utest=False):
|
| 75 |
+
"""Create a window for browsing a module's structure.
|
| 76 |
+
|
| 77 |
+
Args:
|
| 78 |
+
master: parent for widgets.
|
| 79 |
+
path: full path of file to browse.
|
| 80 |
+
_htest - bool; change box location when running htest.
|
| 81 |
+
-utest - bool; suppress contents when running unittest.
|
| 82 |
+
|
| 83 |
+
Global variables:
|
| 84 |
+
file_open: Function used for opening a file.
|
| 85 |
+
|
| 86 |
+
Instance variables:
|
| 87 |
+
name: Module name.
|
| 88 |
+
file: Full path and module with supported extension.
|
| 89 |
+
Used in creating ModuleBrowserTreeItem as the rootnode for
|
| 90 |
+
the tree and subsequently in the children.
|
| 91 |
+
"""
|
| 92 |
+
self.master = master
|
| 93 |
+
self.path = path
|
| 94 |
+
self._htest = _htest
|
| 95 |
+
self._utest = _utest
|
| 96 |
+
self.init()
|
| 97 |
+
|
| 98 |
+
def close(self, event=None):
|
| 99 |
+
"Dismiss the window and the tree nodes."
|
| 100 |
+
self.top.destroy()
|
| 101 |
+
self.node.destroy()
|
| 102 |
+
|
| 103 |
+
def init(self):
|
| 104 |
+
"Create browser tkinter widgets, including the tree."
|
| 105 |
+
global file_open
|
| 106 |
+
root = self.master
|
| 107 |
+
flist = (pyshell.flist if not (self._htest or self._utest)
|
| 108 |
+
else pyshell.PyShellFileList(root))
|
| 109 |
+
file_open = flist.open
|
| 110 |
+
pyclbr._modules.clear()
|
| 111 |
+
|
| 112 |
+
# create top
|
| 113 |
+
self.top = top = ListedToplevel(root)
|
| 114 |
+
top.protocol("WM_DELETE_WINDOW", self.close)
|
| 115 |
+
top.bind("<Escape>", self.close)
|
| 116 |
+
if self._htest: # place dialog below parent if running htest
|
| 117 |
+
top.geometry("+%d+%d" %
|
| 118 |
+
(root.winfo_rootx(), root.winfo_rooty() + 200))
|
| 119 |
+
self.settitle()
|
| 120 |
+
top.focus_set()
|
| 121 |
+
|
| 122 |
+
# create scrolled canvas
|
| 123 |
+
theme = idleConf.CurrentTheme()
|
| 124 |
+
background = idleConf.GetHighlight(theme, 'normal')['background']
|
| 125 |
+
sc = ScrolledCanvas(top, bg=background, highlightthickness=0,
|
| 126 |
+
takefocus=1)
|
| 127 |
+
sc.frame.pack(expand=1, fill="both")
|
| 128 |
+
item = self.rootnode()
|
| 129 |
+
self.node = node = TreeNode(sc.canvas, None, item)
|
| 130 |
+
if not self._utest:
|
| 131 |
+
node.update()
|
| 132 |
+
node.expand()
|
| 133 |
+
|
| 134 |
+
def settitle(self):
|
| 135 |
+
"Set the window title."
|
| 136 |
+
self.top.wm_title("Module Browser - " + os.path.basename(self.path))
|
| 137 |
+
self.top.wm_iconname("Module Browser")
|
| 138 |
+
|
| 139 |
+
def rootnode(self):
|
| 140 |
+
"Return a ModuleBrowserTreeItem as the root of the tree."
|
| 141 |
+
return ModuleBrowserTreeItem(self.path)
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
class ModuleBrowserTreeItem(TreeItem):
|
| 145 |
+
"""Browser tree for Python module.
|
| 146 |
+
|
| 147 |
+
Uses TreeItem as the basis for the structure of the tree.
|
| 148 |
+
Used by both browsers.
|
| 149 |
+
"""
|
| 150 |
+
|
| 151 |
+
def __init__(self, file):
|
| 152 |
+
"""Create a TreeItem for the file.
|
| 153 |
+
|
| 154 |
+
Args:
|
| 155 |
+
file: Full path and module name.
|
| 156 |
+
"""
|
| 157 |
+
self.file = file
|
| 158 |
+
|
| 159 |
+
def GetText(self):
|
| 160 |
+
"Return the module name as the text string to display."
|
| 161 |
+
return os.path.basename(self.file)
|
| 162 |
+
|
| 163 |
+
def GetIconName(self):
|
| 164 |
+
"Return the name of the icon to display."
|
| 165 |
+
return "python"
|
| 166 |
+
|
| 167 |
+
def GetSubList(self):
|
| 168 |
+
"Return ChildBrowserTreeItems for children."
|
| 169 |
+
return [ChildBrowserTreeItem(obj) for obj in self.listchildren()]
|
| 170 |
+
|
| 171 |
+
def OnDoubleClick(self):
|
| 172 |
+
"Open a module in an editor window when double clicked."
|
| 173 |
+
if not is_browseable_extension(self.file):
|
| 174 |
+
return
|
| 175 |
+
if not os.path.exists(self.file):
|
| 176 |
+
return
|
| 177 |
+
file_open(self.file)
|
| 178 |
+
|
| 179 |
+
def IsExpandable(self):
|
| 180 |
+
"Return True if Python file."
|
| 181 |
+
return is_browseable_extension(self.file)
|
| 182 |
+
|
| 183 |
+
def listchildren(self):
|
| 184 |
+
"Return sequenced classes and functions in the module."
|
| 185 |
+
if not is_browseable_extension(self.file):
|
| 186 |
+
return []
|
| 187 |
+
dir, base = os.path.split(self.file)
|
| 188 |
+
name, _ = os.path.splitext(base)
|
| 189 |
+
try:
|
| 190 |
+
tree = pyclbr.readmodule_ex(name, [dir] + sys.path)
|
| 191 |
+
except ImportError:
|
| 192 |
+
return []
|
| 193 |
+
return transform_children(tree, name)
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
class ChildBrowserTreeItem(TreeItem):
|
| 197 |
+
"""Browser tree for child nodes within the module.
|
| 198 |
+
|
| 199 |
+
Uses TreeItem as the basis for the structure of the tree.
|
| 200 |
+
"""
|
| 201 |
+
|
| 202 |
+
def __init__(self, obj):
|
| 203 |
+
"Create a TreeItem for a pyclbr class/function object."
|
| 204 |
+
self.obj = obj
|
| 205 |
+
self.name = obj.name
|
| 206 |
+
self.isfunction = isinstance(obj, pyclbr.Function)
|
| 207 |
+
|
| 208 |
+
def GetText(self):
|
| 209 |
+
"Return the name of the function/class to display."
|
| 210 |
+
name = self.name
|
| 211 |
+
if self.isfunction:
|
| 212 |
+
return "def " + name + "(...)"
|
| 213 |
+
else:
|
| 214 |
+
return "class " + name
|
| 215 |
+
|
| 216 |
+
def GetIconName(self):
|
| 217 |
+
"Return the name of the icon to display."
|
| 218 |
+
if self.isfunction:
|
| 219 |
+
return "python"
|
| 220 |
+
else:
|
| 221 |
+
return "folder"
|
| 222 |
+
|
| 223 |
+
def IsExpandable(self):
|
| 224 |
+
"Return True if self.obj has nested objects."
|
| 225 |
+
return self.obj.children != {}
|
| 226 |
+
|
| 227 |
+
def GetSubList(self):
|
| 228 |
+
"Return ChildBrowserTreeItems for children."
|
| 229 |
+
return [ChildBrowserTreeItem(obj)
|
| 230 |
+
for obj in transform_children(self.obj.children)]
|
| 231 |
+
|
| 232 |
+
def OnDoubleClick(self):
|
| 233 |
+
"Open module with file_open and position to lineno."
|
| 234 |
+
try:
|
| 235 |
+
edit = file_open(self.obj.file)
|
| 236 |
+
edit.gotoline(self.obj.lineno)
|
| 237 |
+
except (OSError, AttributeError):
|
| 238 |
+
pass
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
def _module_browser(parent): # htest #
|
| 242 |
+
if len(sys.argv) > 1: # If pass file on command line.
|
| 243 |
+
file = sys.argv[1]
|
| 244 |
+
else:
|
| 245 |
+
file = __file__
|
| 246 |
+
# Add nested objects for htest.
|
| 247 |
+
class Nested_in_func(TreeNode):
|
| 248 |
+
def nested_in_class(): pass
|
| 249 |
+
def closure():
|
| 250 |
+
class Nested_in_closure: pass
|
| 251 |
+
ModuleBrowser(parent, file, _htest=True)
|
| 252 |
+
|
| 253 |
+
if __name__ == "__main__":
|
| 254 |
+
if len(sys.argv) == 1: # If pass file on command line, unittest fails.
|
| 255 |
+
from unittest import main
|
| 256 |
+
main('idlelib.idle_test.test_browser', verbosity=2, exit=False)
|
| 257 |
+
from idlelib.idle_test.htest import run
|
| 258 |
+
run(_module_browser)
|
evalkit_cambrian/lib/python3.10/idlelib/codecontext.py
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""codecontext - display the block context above the edit window
|
| 2 |
+
|
| 3 |
+
Once code has scrolled off the top of a window, it can be difficult to
|
| 4 |
+
determine which block you are in. This extension implements a pane at the top
|
| 5 |
+
of each IDLE edit window which provides block structure hints. These hints are
|
| 6 |
+
the lines which contain the block opening keywords, e.g. 'if', for the
|
| 7 |
+
enclosing block. The number of hint lines is determined by the maxlines
|
| 8 |
+
variable in the codecontext section of config-extensions.def. Lines which do
|
| 9 |
+
not open blocks are not shown in the context hints pane.
|
| 10 |
+
|
| 11 |
+
For EditorWindows, <<toggle-code-context>> is bound to CodeContext(self).
|
| 12 |
+
toggle_code_context_event.
|
| 13 |
+
"""
|
| 14 |
+
import re
|
| 15 |
+
from sys import maxsize as INFINITY
|
| 16 |
+
|
| 17 |
+
from tkinter import Frame, Text, TclError
|
| 18 |
+
from tkinter.constants import NSEW, SUNKEN
|
| 19 |
+
|
| 20 |
+
from idlelib.config import idleConf
|
| 21 |
+
|
| 22 |
+
BLOCKOPENERS = {'class', 'def', 'if', 'elif', 'else', 'while', 'for',
|
| 23 |
+
'try', 'except', 'finally', 'with', 'async'}
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def get_spaces_firstword(codeline, c=re.compile(r"^(\s*)(\w*)")):
|
| 27 |
+
"Extract the beginning whitespace and first word from codeline."
|
| 28 |
+
return c.match(codeline).groups()
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def get_line_info(codeline):
|
| 32 |
+
"""Return tuple of (line indent value, codeline, block start keyword).
|
| 33 |
+
|
| 34 |
+
The indentation of empty lines (or comment lines) is INFINITY.
|
| 35 |
+
If the line does not start a block, the keyword value is False.
|
| 36 |
+
"""
|
| 37 |
+
spaces, firstword = get_spaces_firstword(codeline)
|
| 38 |
+
indent = len(spaces)
|
| 39 |
+
if len(codeline) == indent or codeline[indent] == '#':
|
| 40 |
+
indent = INFINITY
|
| 41 |
+
opener = firstword in BLOCKOPENERS and firstword
|
| 42 |
+
return indent, codeline, opener
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
class CodeContext:
|
| 46 |
+
"Display block context above the edit window."
|
| 47 |
+
UPDATEINTERVAL = 100 # millisec
|
| 48 |
+
|
| 49 |
+
def __init__(self, editwin):
|
| 50 |
+
"""Initialize settings for context block.
|
| 51 |
+
|
| 52 |
+
editwin is the Editor window for the context block.
|
| 53 |
+
self.text is the editor window text widget.
|
| 54 |
+
|
| 55 |
+
self.context displays the code context text above the editor text.
|
| 56 |
+
Initially None, it is toggled via <<toggle-code-context>>.
|
| 57 |
+
self.topvisible is the number of the top text line displayed.
|
| 58 |
+
self.info is a list of (line number, indent level, line text,
|
| 59 |
+
block keyword) tuples for the block structure above topvisible.
|
| 60 |
+
self.info[0] is initialized with a 'dummy' line which
|
| 61 |
+
starts the toplevel 'block' of the module.
|
| 62 |
+
|
| 63 |
+
self.t1 and self.t2 are two timer events on the editor text widget to
|
| 64 |
+
monitor for changes to the context text or editor font.
|
| 65 |
+
"""
|
| 66 |
+
self.editwin = editwin
|
| 67 |
+
self.text = editwin.text
|
| 68 |
+
self._reset()
|
| 69 |
+
|
| 70 |
+
def _reset(self):
|
| 71 |
+
self.context = None
|
| 72 |
+
self.cell00 = None
|
| 73 |
+
self.t1 = None
|
| 74 |
+
self.topvisible = 1
|
| 75 |
+
self.info = [(0, -1, "", False)]
|
| 76 |
+
|
| 77 |
+
@classmethod
|
| 78 |
+
def reload(cls):
|
| 79 |
+
"Load class variables from config."
|
| 80 |
+
cls.context_depth = idleConf.GetOption("extensions", "CodeContext",
|
| 81 |
+
"maxlines", type="int",
|
| 82 |
+
default=15)
|
| 83 |
+
|
| 84 |
+
def __del__(self):
|
| 85 |
+
"Cancel scheduled events."
|
| 86 |
+
if self.t1 is not None:
|
| 87 |
+
try:
|
| 88 |
+
self.text.after_cancel(self.t1)
|
| 89 |
+
except TclError: # pragma: no cover
|
| 90 |
+
pass
|
| 91 |
+
self.t1 = None
|
| 92 |
+
|
| 93 |
+
def toggle_code_context_event(self, event=None):
|
| 94 |
+
"""Toggle code context display.
|
| 95 |
+
|
| 96 |
+
If self.context doesn't exist, create it to match the size of the editor
|
| 97 |
+
window text (toggle on). If it does exist, destroy it (toggle off).
|
| 98 |
+
Return 'break' to complete the processing of the binding.
|
| 99 |
+
"""
|
| 100 |
+
if self.context is None:
|
| 101 |
+
# Calculate the border width and horizontal padding required to
|
| 102 |
+
# align the context with the text in the main Text widget.
|
| 103 |
+
#
|
| 104 |
+
# All values are passed through getint(), since some
|
| 105 |
+
# values may be pixel objects, which can't simply be added to ints.
|
| 106 |
+
widgets = self.editwin.text, self.editwin.text_frame
|
| 107 |
+
# Calculate the required horizontal padding and border width.
|
| 108 |
+
padx = 0
|
| 109 |
+
border = 0
|
| 110 |
+
for widget in widgets:
|
| 111 |
+
info = (widget.grid_info()
|
| 112 |
+
if widget is self.editwin.text
|
| 113 |
+
else widget.pack_info())
|
| 114 |
+
padx += widget.tk.getint(info['padx'])
|
| 115 |
+
padx += widget.tk.getint(widget.cget('padx'))
|
| 116 |
+
border += widget.tk.getint(widget.cget('border'))
|
| 117 |
+
context = self.context = Text(
|
| 118 |
+
self.editwin.text_frame,
|
| 119 |
+
height=1,
|
| 120 |
+
width=1, # Don't request more than we get.
|
| 121 |
+
highlightthickness=0,
|
| 122 |
+
padx=padx, border=border, relief=SUNKEN, state='disabled')
|
| 123 |
+
self.update_font()
|
| 124 |
+
self.update_highlight_colors()
|
| 125 |
+
context.bind('<ButtonRelease-1>', self.jumptoline)
|
| 126 |
+
# Get the current context and initiate the recurring update event.
|
| 127 |
+
self.timer_event()
|
| 128 |
+
# Grid the context widget above the text widget.
|
| 129 |
+
context.grid(row=0, column=1, sticky=NSEW)
|
| 130 |
+
|
| 131 |
+
line_number_colors = idleConf.GetHighlight(idleConf.CurrentTheme(),
|
| 132 |
+
'linenumber')
|
| 133 |
+
self.cell00 = Frame(self.editwin.text_frame,
|
| 134 |
+
bg=line_number_colors['background'])
|
| 135 |
+
self.cell00.grid(row=0, column=0, sticky=NSEW)
|
| 136 |
+
menu_status = 'Hide'
|
| 137 |
+
else:
|
| 138 |
+
self.context.destroy()
|
| 139 |
+
self.context = None
|
| 140 |
+
self.cell00.destroy()
|
| 141 |
+
self.cell00 = None
|
| 142 |
+
self.text.after_cancel(self.t1)
|
| 143 |
+
self._reset()
|
| 144 |
+
menu_status = 'Show'
|
| 145 |
+
self.editwin.update_menu_label(menu='options', index='*ode*ontext',
|
| 146 |
+
label=f'{menu_status} Code Context')
|
| 147 |
+
return "break"
|
| 148 |
+
|
| 149 |
+
def get_context(self, new_topvisible, stopline=1, stopindent=0):
|
| 150 |
+
"""Return a list of block line tuples and the 'last' indent.
|
| 151 |
+
|
| 152 |
+
The tuple fields are (linenum, indent, text, opener).
|
| 153 |
+
The list represents header lines from new_topvisible back to
|
| 154 |
+
stopline with successively shorter indents > stopindent.
|
| 155 |
+
The list is returned ordered by line number.
|
| 156 |
+
Last indent returned is the smallest indent observed.
|
| 157 |
+
"""
|
| 158 |
+
assert stopline > 0
|
| 159 |
+
lines = []
|
| 160 |
+
# The indentation level we are currently in.
|
| 161 |
+
lastindent = INFINITY
|
| 162 |
+
# For a line to be interesting, it must begin with a block opening
|
| 163 |
+
# keyword, and have less indentation than lastindent.
|
| 164 |
+
for linenum in range(new_topvisible, stopline-1, -1):
|
| 165 |
+
codeline = self.text.get(f'{linenum}.0', f'{linenum}.end')
|
| 166 |
+
indent, text, opener = get_line_info(codeline)
|
| 167 |
+
if indent < lastindent:
|
| 168 |
+
lastindent = indent
|
| 169 |
+
if opener in ("else", "elif"):
|
| 170 |
+
# Also show the if statement.
|
| 171 |
+
lastindent += 1
|
| 172 |
+
if opener and linenum < new_topvisible and indent >= stopindent:
|
| 173 |
+
lines.append((linenum, indent, text, opener))
|
| 174 |
+
if lastindent <= stopindent:
|
| 175 |
+
break
|
| 176 |
+
lines.reverse()
|
| 177 |
+
return lines, lastindent
|
| 178 |
+
|
| 179 |
+
def update_code_context(self):
|
| 180 |
+
"""Update context information and lines visible in the context pane.
|
| 181 |
+
|
| 182 |
+
No update is done if the text hasn't been scrolled. If the text
|
| 183 |
+
was scrolled, the lines that should be shown in the context will
|
| 184 |
+
be retrieved and the context area will be updated with the code,
|
| 185 |
+
up to the number of maxlines.
|
| 186 |
+
"""
|
| 187 |
+
new_topvisible = self.editwin.getlineno("@0,0")
|
| 188 |
+
if self.topvisible == new_topvisible: # Haven't scrolled.
|
| 189 |
+
return
|
| 190 |
+
if self.topvisible < new_topvisible: # Scroll down.
|
| 191 |
+
lines, lastindent = self.get_context(new_topvisible,
|
| 192 |
+
self.topvisible)
|
| 193 |
+
# Retain only context info applicable to the region
|
| 194 |
+
# between topvisible and new_topvisible.
|
| 195 |
+
while self.info[-1][1] >= lastindent:
|
| 196 |
+
del self.info[-1]
|
| 197 |
+
else: # self.topvisible > new_topvisible: # Scroll up.
|
| 198 |
+
stopindent = self.info[-1][1] + 1
|
| 199 |
+
# Retain only context info associated
|
| 200 |
+
# with lines above new_topvisible.
|
| 201 |
+
while self.info[-1][0] >= new_topvisible:
|
| 202 |
+
stopindent = self.info[-1][1]
|
| 203 |
+
del self.info[-1]
|
| 204 |
+
lines, lastindent = self.get_context(new_topvisible,
|
| 205 |
+
self.info[-1][0]+1,
|
| 206 |
+
stopindent)
|
| 207 |
+
self.info.extend(lines)
|
| 208 |
+
self.topvisible = new_topvisible
|
| 209 |
+
# Last context_depth context lines.
|
| 210 |
+
context_strings = [x[2] for x in self.info[-self.context_depth:]]
|
| 211 |
+
showfirst = 0 if context_strings[0] else 1
|
| 212 |
+
# Update widget.
|
| 213 |
+
self.context['height'] = len(context_strings) - showfirst
|
| 214 |
+
self.context['state'] = 'normal'
|
| 215 |
+
self.context.delete('1.0', 'end')
|
| 216 |
+
self.context.insert('end', '\n'.join(context_strings[showfirst:]))
|
| 217 |
+
self.context['state'] = 'disabled'
|
| 218 |
+
|
| 219 |
+
def jumptoline(self, event=None):
|
| 220 |
+
""" Show clicked context line at top of editor.
|
| 221 |
+
|
| 222 |
+
If a selection was made, don't jump; allow copying.
|
| 223 |
+
If no visible context, show the top line of the file.
|
| 224 |
+
"""
|
| 225 |
+
try:
|
| 226 |
+
self.context.index("sel.first")
|
| 227 |
+
except TclError:
|
| 228 |
+
lines = len(self.info)
|
| 229 |
+
if lines == 1: # No context lines are showing.
|
| 230 |
+
newtop = 1
|
| 231 |
+
else:
|
| 232 |
+
# Line number clicked.
|
| 233 |
+
contextline = int(float(self.context.index('insert')))
|
| 234 |
+
# Lines not displayed due to maxlines.
|
| 235 |
+
offset = max(1, lines - self.context_depth) - 1
|
| 236 |
+
newtop = self.info[offset + contextline][0]
|
| 237 |
+
self.text.yview(f'{newtop}.0')
|
| 238 |
+
self.update_code_context()
|
| 239 |
+
|
| 240 |
+
def timer_event(self):
|
| 241 |
+
"Event on editor text widget triggered every UPDATEINTERVAL ms."
|
| 242 |
+
if self.context is not None:
|
| 243 |
+
self.update_code_context()
|
| 244 |
+
self.t1 = self.text.after(self.UPDATEINTERVAL, self.timer_event)
|
| 245 |
+
|
| 246 |
+
def update_font(self):
|
| 247 |
+
if self.context is not None:
|
| 248 |
+
font = idleConf.GetFont(self.text, 'main', 'EditorWindow')
|
| 249 |
+
self.context['font'] = font
|
| 250 |
+
|
| 251 |
+
def update_highlight_colors(self):
|
| 252 |
+
if self.context is not None:
|
| 253 |
+
colors = idleConf.GetHighlight(idleConf.CurrentTheme(), 'context')
|
| 254 |
+
self.context['background'] = colors['background']
|
| 255 |
+
self.context['foreground'] = colors['foreground']
|
| 256 |
+
|
| 257 |
+
if self.cell00 is not None:
|
| 258 |
+
line_number_colors = idleConf.GetHighlight(idleConf.CurrentTheme(),
|
| 259 |
+
'linenumber')
|
| 260 |
+
self.cell00.config(bg=line_number_colors['background'])
|
| 261 |
+
|
| 262 |
+
|
| 263 |
+
CodeContext.reload()
|
| 264 |
+
|
| 265 |
+
|
| 266 |
+
if __name__ == "__main__":
|
| 267 |
+
from unittest import main
|
| 268 |
+
main('idlelib.idle_test.test_codecontext', verbosity=2, exit=False)
|
| 269 |
+
|
| 270 |
+
# Add htest.
|
evalkit_cambrian/lib/python3.10/idlelib/config.py
ADDED
|
@@ -0,0 +1,911 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""idlelib.config -- Manage IDLE configuration information.
|
| 2 |
+
|
| 3 |
+
The comments at the beginning of config-main.def describe the
|
| 4 |
+
configuration files and the design implemented to update user
|
| 5 |
+
configuration information. In particular, user configuration choices
|
| 6 |
+
which duplicate the defaults will be removed from the user's
|
| 7 |
+
configuration files, and if a user file becomes empty, it will be
|
| 8 |
+
deleted.
|
| 9 |
+
|
| 10 |
+
The configuration database maps options to values. Conceptually, the
|
| 11 |
+
database keys are tuples (config-type, section, item). As implemented,
|
| 12 |
+
there are separate dicts for default and user values. Each has
|
| 13 |
+
config-type keys 'main', 'extensions', 'highlight', and 'keys'. The
|
| 14 |
+
value for each key is a ConfigParser instance that maps section and item
|
| 15 |
+
to values. For 'main' and 'extensions', user values override
|
| 16 |
+
default values. For 'highlight' and 'keys', user sections augment the
|
| 17 |
+
default sections (and must, therefore, have distinct names).
|
| 18 |
+
|
| 19 |
+
Throughout this module there is an emphasis on returning useable defaults
|
| 20 |
+
when a problem occurs in returning a requested configuration value back to
|
| 21 |
+
idle. This is to allow IDLE to continue to function in spite of errors in
|
| 22 |
+
the retrieval of config information. When a default is returned instead of
|
| 23 |
+
a requested config value, a message is printed to stderr to aid in
|
| 24 |
+
configuration problem notification and resolution.
|
| 25 |
+
"""
|
| 26 |
+
# TODOs added Oct 2014, tjr
|
| 27 |
+
|
| 28 |
+
from configparser import ConfigParser
|
| 29 |
+
import os
|
| 30 |
+
import sys
|
| 31 |
+
|
| 32 |
+
from tkinter.font import Font
|
| 33 |
+
import idlelib
|
| 34 |
+
|
| 35 |
+
class InvalidConfigType(Exception): pass
|
| 36 |
+
class InvalidConfigSet(Exception): pass
|
| 37 |
+
class InvalidTheme(Exception): pass
|
| 38 |
+
|
| 39 |
+
class IdleConfParser(ConfigParser):
|
| 40 |
+
"""
|
| 41 |
+
A ConfigParser specialised for idle configuration file handling
|
| 42 |
+
"""
|
| 43 |
+
def __init__(self, cfgFile, cfgDefaults=None):
|
| 44 |
+
"""
|
| 45 |
+
cfgFile - string, fully specified configuration file name
|
| 46 |
+
"""
|
| 47 |
+
self.file = cfgFile # This is currently '' when testing.
|
| 48 |
+
ConfigParser.__init__(self, defaults=cfgDefaults, strict=False)
|
| 49 |
+
|
| 50 |
+
def Get(self, section, option, type=None, default=None, raw=False):
|
| 51 |
+
"""
|
| 52 |
+
Get an option value for given section/option or return default.
|
| 53 |
+
If type is specified, return as type.
|
| 54 |
+
"""
|
| 55 |
+
# TODO Use default as fallback, at least if not None
|
| 56 |
+
# Should also print Warning(file, section, option).
|
| 57 |
+
# Currently may raise ValueError
|
| 58 |
+
if not self.has_option(section, option):
|
| 59 |
+
return default
|
| 60 |
+
if type == 'bool':
|
| 61 |
+
return self.getboolean(section, option)
|
| 62 |
+
elif type == 'int':
|
| 63 |
+
return self.getint(section, option)
|
| 64 |
+
else:
|
| 65 |
+
return self.get(section, option, raw=raw)
|
| 66 |
+
|
| 67 |
+
def GetOptionList(self, section):
|
| 68 |
+
"Return a list of options for given section, else []."
|
| 69 |
+
if self.has_section(section):
|
| 70 |
+
return self.options(section)
|
| 71 |
+
else: #return a default value
|
| 72 |
+
return []
|
| 73 |
+
|
| 74 |
+
def Load(self):
|
| 75 |
+
"Load the configuration file from disk."
|
| 76 |
+
if self.file:
|
| 77 |
+
self.read(self.file)
|
| 78 |
+
|
| 79 |
+
class IdleUserConfParser(IdleConfParser):
|
| 80 |
+
"""
|
| 81 |
+
IdleConfigParser specialised for user configuration handling.
|
| 82 |
+
"""
|
| 83 |
+
|
| 84 |
+
def SetOption(self, section, option, value):
|
| 85 |
+
"""Return True if option is added or changed to value, else False.
|
| 86 |
+
|
| 87 |
+
Add section if required. False means option already had value.
|
| 88 |
+
"""
|
| 89 |
+
if self.has_option(section, option):
|
| 90 |
+
if self.get(section, option) == value:
|
| 91 |
+
return False
|
| 92 |
+
else:
|
| 93 |
+
self.set(section, option, value)
|
| 94 |
+
return True
|
| 95 |
+
else:
|
| 96 |
+
if not self.has_section(section):
|
| 97 |
+
self.add_section(section)
|
| 98 |
+
self.set(section, option, value)
|
| 99 |
+
return True
|
| 100 |
+
|
| 101 |
+
def RemoveOption(self, section, option):
|
| 102 |
+
"""Return True if option is removed from section, else False.
|
| 103 |
+
|
| 104 |
+
False if either section does not exist or did not have option.
|
| 105 |
+
"""
|
| 106 |
+
if self.has_section(section):
|
| 107 |
+
return self.remove_option(section, option)
|
| 108 |
+
return False
|
| 109 |
+
|
| 110 |
+
def AddSection(self, section):
|
| 111 |
+
"If section doesn't exist, add it."
|
| 112 |
+
if not self.has_section(section):
|
| 113 |
+
self.add_section(section)
|
| 114 |
+
|
| 115 |
+
def RemoveEmptySections(self):
|
| 116 |
+
"Remove any sections that have no options."
|
| 117 |
+
for section in self.sections():
|
| 118 |
+
if not self.GetOptionList(section):
|
| 119 |
+
self.remove_section(section)
|
| 120 |
+
|
| 121 |
+
def IsEmpty(self):
|
| 122 |
+
"Return True if no sections after removing empty sections."
|
| 123 |
+
self.RemoveEmptySections()
|
| 124 |
+
return not self.sections()
|
| 125 |
+
|
| 126 |
+
def Save(self):
|
| 127 |
+
"""Update user configuration file.
|
| 128 |
+
|
| 129 |
+
If self not empty after removing empty sections, write the file
|
| 130 |
+
to disk. Otherwise, remove the file from disk if it exists.
|
| 131 |
+
"""
|
| 132 |
+
fname = self.file
|
| 133 |
+
if fname and fname[0] != '#':
|
| 134 |
+
if not self.IsEmpty():
|
| 135 |
+
try:
|
| 136 |
+
cfgFile = open(fname, 'w')
|
| 137 |
+
except OSError:
|
| 138 |
+
os.unlink(fname)
|
| 139 |
+
cfgFile = open(fname, 'w')
|
| 140 |
+
with cfgFile:
|
| 141 |
+
self.write(cfgFile)
|
| 142 |
+
elif os.path.exists(self.file):
|
| 143 |
+
os.remove(self.file)
|
| 144 |
+
|
| 145 |
+
class IdleConf:
|
| 146 |
+
"""Hold config parsers for all idle config files in singleton instance.
|
| 147 |
+
|
| 148 |
+
Default config files, self.defaultCfg --
|
| 149 |
+
for config_type in self.config_types:
|
| 150 |
+
(idle install dir)/config-{config-type}.def
|
| 151 |
+
|
| 152 |
+
User config files, self.userCfg --
|
| 153 |
+
for config_type in self.config_types:
|
| 154 |
+
(user home dir)/.idlerc/config-{config-type}.cfg
|
| 155 |
+
"""
|
| 156 |
+
def __init__(self, _utest=False):
|
| 157 |
+
self.config_types = ('main', 'highlight', 'keys', 'extensions')
|
| 158 |
+
self.defaultCfg = {}
|
| 159 |
+
self.userCfg = {}
|
| 160 |
+
self.cfg = {} # TODO use to select userCfg vs defaultCfg
|
| 161 |
+
# self.blink_off_time = <first editor text>['insertofftime']
|
| 162 |
+
# See https:/bugs.python.org/issue4630, msg356516.
|
| 163 |
+
|
| 164 |
+
if not _utest:
|
| 165 |
+
self.CreateConfigHandlers()
|
| 166 |
+
self.LoadCfgFiles()
|
| 167 |
+
|
| 168 |
+
def CreateConfigHandlers(self):
|
| 169 |
+
"Populate default and user config parser dictionaries."
|
| 170 |
+
idledir = os.path.dirname(__file__)
|
| 171 |
+
self.userdir = userdir = '' if idlelib.testing else self.GetUserCfgDir()
|
| 172 |
+
for cfg_type in self.config_types:
|
| 173 |
+
self.defaultCfg[cfg_type] = IdleConfParser(
|
| 174 |
+
os.path.join(idledir, f'config-{cfg_type}.def'))
|
| 175 |
+
self.userCfg[cfg_type] = IdleUserConfParser(
|
| 176 |
+
os.path.join(userdir or '#', f'config-{cfg_type}.cfg'))
|
| 177 |
+
|
| 178 |
+
def GetUserCfgDir(self):
|
| 179 |
+
"""Return a filesystem directory for storing user config files.
|
| 180 |
+
|
| 181 |
+
Creates it if required.
|
| 182 |
+
"""
|
| 183 |
+
cfgDir = '.idlerc'
|
| 184 |
+
userDir = os.path.expanduser('~')
|
| 185 |
+
if userDir != '~': # expanduser() found user home dir
|
| 186 |
+
if not os.path.exists(userDir):
|
| 187 |
+
if not idlelib.testing:
|
| 188 |
+
warn = ('\n Warning: os.path.expanduser("~") points to\n ' +
|
| 189 |
+
userDir + ',\n but the path does not exist.')
|
| 190 |
+
try:
|
| 191 |
+
print(warn, file=sys.stderr)
|
| 192 |
+
except OSError:
|
| 193 |
+
pass
|
| 194 |
+
userDir = '~'
|
| 195 |
+
if userDir == "~": # still no path to home!
|
| 196 |
+
# traditionally IDLE has defaulted to os.getcwd(), is this adequate?
|
| 197 |
+
userDir = os.getcwd()
|
| 198 |
+
userDir = os.path.join(userDir, cfgDir)
|
| 199 |
+
if not os.path.exists(userDir):
|
| 200 |
+
try:
|
| 201 |
+
os.mkdir(userDir)
|
| 202 |
+
except OSError:
|
| 203 |
+
if not idlelib.testing:
|
| 204 |
+
warn = ('\n Warning: unable to create user config directory\n' +
|
| 205 |
+
userDir + '\n Check path and permissions.\n Exiting!\n')
|
| 206 |
+
try:
|
| 207 |
+
print(warn, file=sys.stderr)
|
| 208 |
+
except OSError:
|
| 209 |
+
pass
|
| 210 |
+
raise SystemExit
|
| 211 |
+
# TODO continue without userDIr instead of exit
|
| 212 |
+
return userDir
|
| 213 |
+
|
| 214 |
+
def GetOption(self, configType, section, option, default=None, type=None,
|
| 215 |
+
warn_on_default=True, raw=False):
|
| 216 |
+
"""Return a value for configType section option, or default.
|
| 217 |
+
|
| 218 |
+
If type is not None, return a value of that type. Also pass raw
|
| 219 |
+
to the config parser. First try to return a valid value
|
| 220 |
+
(including type) from a user configuration. If that fails, try
|
| 221 |
+
the default configuration. If that fails, return default, with a
|
| 222 |
+
default of None.
|
| 223 |
+
|
| 224 |
+
Warn if either user or default configurations have an invalid value.
|
| 225 |
+
Warn if default is returned and warn_on_default is True.
|
| 226 |
+
"""
|
| 227 |
+
try:
|
| 228 |
+
if self.userCfg[configType].has_option(section, option):
|
| 229 |
+
return self.userCfg[configType].Get(section, option,
|
| 230 |
+
type=type, raw=raw)
|
| 231 |
+
except ValueError:
|
| 232 |
+
warning = ('\n Warning: config.py - IdleConf.GetOption -\n'
|
| 233 |
+
' invalid %r value for configuration option %r\n'
|
| 234 |
+
' from section %r: %r' %
|
| 235 |
+
(type, option, section,
|
| 236 |
+
self.userCfg[configType].Get(section, option, raw=raw)))
|
| 237 |
+
_warn(warning, configType, section, option)
|
| 238 |
+
try:
|
| 239 |
+
if self.defaultCfg[configType].has_option(section,option):
|
| 240 |
+
return self.defaultCfg[configType].Get(
|
| 241 |
+
section, option, type=type, raw=raw)
|
| 242 |
+
except ValueError:
|
| 243 |
+
pass
|
| 244 |
+
#returning default, print warning
|
| 245 |
+
if warn_on_default:
|
| 246 |
+
warning = ('\n Warning: config.py - IdleConf.GetOption -\n'
|
| 247 |
+
' problem retrieving configuration option %r\n'
|
| 248 |
+
' from section %r.\n'
|
| 249 |
+
' returning default value: %r' %
|
| 250 |
+
(option, section, default))
|
| 251 |
+
_warn(warning, configType, section, option)
|
| 252 |
+
return default
|
| 253 |
+
|
| 254 |
+
def SetOption(self, configType, section, option, value):
|
| 255 |
+
"""Set section option to value in user config file."""
|
| 256 |
+
self.userCfg[configType].SetOption(section, option, value)
|
| 257 |
+
|
| 258 |
+
def GetSectionList(self, configSet, configType):
|
| 259 |
+
"""Return sections for configSet configType configuration.
|
| 260 |
+
|
| 261 |
+
configSet must be either 'user' or 'default'
|
| 262 |
+
configType must be in self.config_types.
|
| 263 |
+
"""
|
| 264 |
+
if not (configType in self.config_types):
|
| 265 |
+
raise InvalidConfigType('Invalid configType specified')
|
| 266 |
+
if configSet == 'user':
|
| 267 |
+
cfgParser = self.userCfg[configType]
|
| 268 |
+
elif configSet == 'default':
|
| 269 |
+
cfgParser=self.defaultCfg[configType]
|
| 270 |
+
else:
|
| 271 |
+
raise InvalidConfigSet('Invalid configSet specified')
|
| 272 |
+
return cfgParser.sections()
|
| 273 |
+
|
| 274 |
+
def GetHighlight(self, theme, element):
|
| 275 |
+
"""Return dict of theme element highlight colors.
|
| 276 |
+
|
| 277 |
+
The keys are 'foreground' and 'background'. The values are
|
| 278 |
+
tkinter color strings for configuring backgrounds and tags.
|
| 279 |
+
"""
|
| 280 |
+
cfg = ('default' if self.defaultCfg['highlight'].has_section(theme)
|
| 281 |
+
else 'user')
|
| 282 |
+
theme_dict = self.GetThemeDict(cfg, theme)
|
| 283 |
+
fore = theme_dict[element + '-foreground']
|
| 284 |
+
if element == 'cursor':
|
| 285 |
+
element = 'normal'
|
| 286 |
+
back = theme_dict[element + '-background']
|
| 287 |
+
return {"foreground": fore, "background": back}
|
| 288 |
+
|
| 289 |
+
def GetThemeDict(self, type, themeName):
|
| 290 |
+
"""Return {option:value} dict for elements in themeName.
|
| 291 |
+
|
| 292 |
+
type - string, 'default' or 'user' theme type
|
| 293 |
+
themeName - string, theme name
|
| 294 |
+
Values are loaded over ultimate fallback defaults to guarantee
|
| 295 |
+
that all theme elements are present in a newly created theme.
|
| 296 |
+
"""
|
| 297 |
+
if type == 'user':
|
| 298 |
+
cfgParser = self.userCfg['highlight']
|
| 299 |
+
elif type == 'default':
|
| 300 |
+
cfgParser = self.defaultCfg['highlight']
|
| 301 |
+
else:
|
| 302 |
+
raise InvalidTheme('Invalid theme type specified')
|
| 303 |
+
# Provide foreground and background colors for each theme
|
| 304 |
+
# element (other than cursor) even though some values are not
|
| 305 |
+
# yet used by idle, to allow for their use in the future.
|
| 306 |
+
# Default values are generally black and white.
|
| 307 |
+
# TODO copy theme from a class attribute.
|
| 308 |
+
theme ={'normal-foreground':'#000000',
|
| 309 |
+
'normal-background':'#ffffff',
|
| 310 |
+
'keyword-foreground':'#000000',
|
| 311 |
+
'keyword-background':'#ffffff',
|
| 312 |
+
'builtin-foreground':'#000000',
|
| 313 |
+
'builtin-background':'#ffffff',
|
| 314 |
+
'comment-foreground':'#000000',
|
| 315 |
+
'comment-background':'#ffffff',
|
| 316 |
+
'string-foreground':'#000000',
|
| 317 |
+
'string-background':'#ffffff',
|
| 318 |
+
'definition-foreground':'#000000',
|
| 319 |
+
'definition-background':'#ffffff',
|
| 320 |
+
'hilite-foreground':'#000000',
|
| 321 |
+
'hilite-background':'gray',
|
| 322 |
+
'break-foreground':'#ffffff',
|
| 323 |
+
'break-background':'#000000',
|
| 324 |
+
'hit-foreground':'#ffffff',
|
| 325 |
+
'hit-background':'#000000',
|
| 326 |
+
'error-foreground':'#ffffff',
|
| 327 |
+
'error-background':'#000000',
|
| 328 |
+
'context-foreground':'#000000',
|
| 329 |
+
'context-background':'#ffffff',
|
| 330 |
+
'linenumber-foreground':'#000000',
|
| 331 |
+
'linenumber-background':'#ffffff',
|
| 332 |
+
#cursor (only foreground can be set)
|
| 333 |
+
'cursor-foreground':'#000000',
|
| 334 |
+
#shell window
|
| 335 |
+
'stdout-foreground':'#000000',
|
| 336 |
+
'stdout-background':'#ffffff',
|
| 337 |
+
'stderr-foreground':'#000000',
|
| 338 |
+
'stderr-background':'#ffffff',
|
| 339 |
+
'console-foreground':'#000000',
|
| 340 |
+
'console-background':'#ffffff',
|
| 341 |
+
}
|
| 342 |
+
for element in theme:
|
| 343 |
+
if not (cfgParser.has_option(themeName, element) or
|
| 344 |
+
# Skip warning for new elements.
|
| 345 |
+
element.startswith(('context-', 'linenumber-'))):
|
| 346 |
+
# Print warning that will return a default color
|
| 347 |
+
warning = ('\n Warning: config.IdleConf.GetThemeDict'
|
| 348 |
+
' -\n problem retrieving theme element %r'
|
| 349 |
+
'\n from theme %r.\n'
|
| 350 |
+
' returning default color: %r' %
|
| 351 |
+
(element, themeName, theme[element]))
|
| 352 |
+
_warn(warning, 'highlight', themeName, element)
|
| 353 |
+
theme[element] = cfgParser.Get(
|
| 354 |
+
themeName, element, default=theme[element])
|
| 355 |
+
return theme
|
| 356 |
+
|
| 357 |
+
def CurrentTheme(self):
|
| 358 |
+
"Return the name of the currently active text color theme."
|
| 359 |
+
return self.current_colors_and_keys('Theme')
|
| 360 |
+
|
| 361 |
+
def CurrentKeys(self):
|
| 362 |
+
"""Return the name of the currently active key set."""
|
| 363 |
+
return self.current_colors_and_keys('Keys')
|
| 364 |
+
|
| 365 |
+
def current_colors_and_keys(self, section):
|
| 366 |
+
"""Return the currently active name for Theme or Keys section.
|
| 367 |
+
|
| 368 |
+
idlelib.config-main.def ('default') includes these sections
|
| 369 |
+
|
| 370 |
+
[Theme]
|
| 371 |
+
default= 1
|
| 372 |
+
name= IDLE Classic
|
| 373 |
+
name2=
|
| 374 |
+
|
| 375 |
+
[Keys]
|
| 376 |
+
default= 1
|
| 377 |
+
name=
|
| 378 |
+
name2=
|
| 379 |
+
|
| 380 |
+
Item 'name2', is used for built-in ('default') themes and keys
|
| 381 |
+
added after 2015 Oct 1 and 2016 July 1. This kludge is needed
|
| 382 |
+
because setting 'name' to a builtin not defined in older IDLEs
|
| 383 |
+
to display multiple error messages or quit.
|
| 384 |
+
See https://bugs.python.org/issue25313.
|
| 385 |
+
When default = True, 'name2' takes precedence over 'name',
|
| 386 |
+
while older IDLEs will just use name. When default = False,
|
| 387 |
+
'name2' may still be set, but it is ignored.
|
| 388 |
+
"""
|
| 389 |
+
cfgname = 'highlight' if section == 'Theme' else 'keys'
|
| 390 |
+
default = self.GetOption('main', section, 'default',
|
| 391 |
+
type='bool', default=True)
|
| 392 |
+
name = ''
|
| 393 |
+
if default:
|
| 394 |
+
name = self.GetOption('main', section, 'name2', default='')
|
| 395 |
+
if not name:
|
| 396 |
+
name = self.GetOption('main', section, 'name', default='')
|
| 397 |
+
if name:
|
| 398 |
+
source = self.defaultCfg if default else self.userCfg
|
| 399 |
+
if source[cfgname].has_section(name):
|
| 400 |
+
return name
|
| 401 |
+
return "IDLE Classic" if section == 'Theme' else self.default_keys()
|
| 402 |
+
|
| 403 |
+
@staticmethod
|
| 404 |
+
def default_keys():
|
| 405 |
+
if sys.platform[:3] == 'win':
|
| 406 |
+
return 'IDLE Classic Windows'
|
| 407 |
+
elif sys.platform == 'darwin':
|
| 408 |
+
return 'IDLE Classic OSX'
|
| 409 |
+
else:
|
| 410 |
+
return 'IDLE Modern Unix'
|
| 411 |
+
|
| 412 |
+
def GetExtensions(self, active_only=True,
|
| 413 |
+
editor_only=False, shell_only=False):
|
| 414 |
+
"""Return extensions in default and user config-extensions files.
|
| 415 |
+
|
| 416 |
+
If active_only True, only return active (enabled) extensions
|
| 417 |
+
and optionally only editor or shell extensions.
|
| 418 |
+
If active_only False, return all extensions.
|
| 419 |
+
"""
|
| 420 |
+
extns = self.RemoveKeyBindNames(
|
| 421 |
+
self.GetSectionList('default', 'extensions'))
|
| 422 |
+
userExtns = self.RemoveKeyBindNames(
|
| 423 |
+
self.GetSectionList('user', 'extensions'))
|
| 424 |
+
for extn in userExtns:
|
| 425 |
+
if extn not in extns: #user has added own extension
|
| 426 |
+
extns.append(extn)
|
| 427 |
+
for extn in ('AutoComplete','CodeContext',
|
| 428 |
+
'FormatParagraph','ParenMatch'):
|
| 429 |
+
extns.remove(extn)
|
| 430 |
+
# specific exclusions because we are storing config for mainlined old
|
| 431 |
+
# extensions in config-extensions.def for backward compatibility
|
| 432 |
+
if active_only:
|
| 433 |
+
activeExtns = []
|
| 434 |
+
for extn in extns:
|
| 435 |
+
if self.GetOption('extensions', extn, 'enable', default=True,
|
| 436 |
+
type='bool'):
|
| 437 |
+
#the extension is enabled
|
| 438 |
+
if editor_only or shell_only: # TODO both True contradict
|
| 439 |
+
if editor_only:
|
| 440 |
+
option = "enable_editor"
|
| 441 |
+
else:
|
| 442 |
+
option = "enable_shell"
|
| 443 |
+
if self.GetOption('extensions', extn,option,
|
| 444 |
+
default=True, type='bool',
|
| 445 |
+
warn_on_default=False):
|
| 446 |
+
activeExtns.append(extn)
|
| 447 |
+
else:
|
| 448 |
+
activeExtns.append(extn)
|
| 449 |
+
return activeExtns
|
| 450 |
+
else:
|
| 451 |
+
return extns
|
| 452 |
+
|
| 453 |
+
def RemoveKeyBindNames(self, extnNameList):
|
| 454 |
+
"Return extnNameList with keybinding section names removed."
|
| 455 |
+
return [n for n in extnNameList if not n.endswith(('_bindings', '_cfgBindings'))]
|
| 456 |
+
|
| 457 |
+
def GetExtnNameForEvent(self, virtualEvent):
|
| 458 |
+
"""Return the name of the extension binding virtualEvent, or None.
|
| 459 |
+
|
| 460 |
+
virtualEvent - string, name of the virtual event to test for,
|
| 461 |
+
without the enclosing '<< >>'
|
| 462 |
+
"""
|
| 463 |
+
extName = None
|
| 464 |
+
vEvent = '<<' + virtualEvent + '>>'
|
| 465 |
+
for extn in self.GetExtensions(active_only=0):
|
| 466 |
+
for event in self.GetExtensionKeys(extn):
|
| 467 |
+
if event == vEvent:
|
| 468 |
+
extName = extn # TODO return here?
|
| 469 |
+
return extName
|
| 470 |
+
|
| 471 |
+
def GetExtensionKeys(self, extensionName):
|
| 472 |
+
"""Return dict: {configurable extensionName event : active keybinding}.
|
| 473 |
+
|
| 474 |
+
Events come from default config extension_cfgBindings section.
|
| 475 |
+
Keybindings come from GetCurrentKeySet() active key dict,
|
| 476 |
+
where previously used bindings are disabled.
|
| 477 |
+
"""
|
| 478 |
+
keysName = extensionName + '_cfgBindings'
|
| 479 |
+
activeKeys = self.GetCurrentKeySet()
|
| 480 |
+
extKeys = {}
|
| 481 |
+
if self.defaultCfg['extensions'].has_section(keysName):
|
| 482 |
+
eventNames = self.defaultCfg['extensions'].GetOptionList(keysName)
|
| 483 |
+
for eventName in eventNames:
|
| 484 |
+
event = '<<' + eventName + '>>'
|
| 485 |
+
binding = activeKeys[event]
|
| 486 |
+
extKeys[event] = binding
|
| 487 |
+
return extKeys
|
| 488 |
+
|
| 489 |
+
def __GetRawExtensionKeys(self,extensionName):
|
| 490 |
+
"""Return dict {configurable extensionName event : keybinding list}.
|
| 491 |
+
|
| 492 |
+
Events come from default config extension_cfgBindings section.
|
| 493 |
+
Keybindings list come from the splitting of GetOption, which
|
| 494 |
+
tries user config before default config.
|
| 495 |
+
"""
|
| 496 |
+
keysName = extensionName+'_cfgBindings'
|
| 497 |
+
extKeys = {}
|
| 498 |
+
if self.defaultCfg['extensions'].has_section(keysName):
|
| 499 |
+
eventNames = self.defaultCfg['extensions'].GetOptionList(keysName)
|
| 500 |
+
for eventName in eventNames:
|
| 501 |
+
binding = self.GetOption(
|
| 502 |
+
'extensions', keysName, eventName, default='').split()
|
| 503 |
+
event = '<<' + eventName + '>>'
|
| 504 |
+
extKeys[event] = binding
|
| 505 |
+
return extKeys
|
| 506 |
+
|
| 507 |
+
def GetExtensionBindings(self, extensionName):
|
| 508 |
+
"""Return dict {extensionName event : active or defined keybinding}.
|
| 509 |
+
|
| 510 |
+
Augment self.GetExtensionKeys(extensionName) with mapping of non-
|
| 511 |
+
configurable events (from default config) to GetOption splits,
|
| 512 |
+
as in self.__GetRawExtensionKeys.
|
| 513 |
+
"""
|
| 514 |
+
bindsName = extensionName + '_bindings'
|
| 515 |
+
extBinds = self.GetExtensionKeys(extensionName)
|
| 516 |
+
#add the non-configurable bindings
|
| 517 |
+
if self.defaultCfg['extensions'].has_section(bindsName):
|
| 518 |
+
eventNames = self.defaultCfg['extensions'].GetOptionList(bindsName)
|
| 519 |
+
for eventName in eventNames:
|
| 520 |
+
binding = self.GetOption(
|
| 521 |
+
'extensions', bindsName, eventName, default='').split()
|
| 522 |
+
event = '<<' + eventName + '>>'
|
| 523 |
+
extBinds[event] = binding
|
| 524 |
+
|
| 525 |
+
return extBinds
|
| 526 |
+
|
| 527 |
+
def GetKeyBinding(self, keySetName, eventStr):
|
| 528 |
+
"""Return the keybinding list for keySetName eventStr.
|
| 529 |
+
|
| 530 |
+
keySetName - name of key binding set (config-keys section).
|
| 531 |
+
eventStr - virtual event, including brackets, as in '<<event>>'.
|
| 532 |
+
"""
|
| 533 |
+
eventName = eventStr[2:-2] #trim off the angle brackets
|
| 534 |
+
binding = self.GetOption('keys', keySetName, eventName, default='',
|
| 535 |
+
warn_on_default=False).split()
|
| 536 |
+
return binding
|
| 537 |
+
|
| 538 |
+
def GetCurrentKeySet(self):
|
| 539 |
+
"Return CurrentKeys with 'darwin' modifications."
|
| 540 |
+
result = self.GetKeySet(self.CurrentKeys())
|
| 541 |
+
|
| 542 |
+
if sys.platform == "darwin":
|
| 543 |
+
# macOS (OS X) Tk variants do not support the "Alt"
|
| 544 |
+
# keyboard modifier. Replace it with "Option".
|
| 545 |
+
# TODO (Ned?): the "Option" modifier does not work properly
|
| 546 |
+
# for Cocoa Tk and XQuartz Tk so we should not use it
|
| 547 |
+
# in the default 'OSX' keyset.
|
| 548 |
+
for k, v in result.items():
|
| 549 |
+
v2 = [ x.replace('<Alt-', '<Option-') for x in v ]
|
| 550 |
+
if v != v2:
|
| 551 |
+
result[k] = v2
|
| 552 |
+
|
| 553 |
+
return result
|
| 554 |
+
|
| 555 |
+
def GetKeySet(self, keySetName):
|
| 556 |
+
"""Return event-key dict for keySetName core plus active extensions.
|
| 557 |
+
|
| 558 |
+
If a binding defined in an extension is already in use, the
|
| 559 |
+
extension binding is disabled by being set to ''
|
| 560 |
+
"""
|
| 561 |
+
keySet = self.GetCoreKeys(keySetName)
|
| 562 |
+
activeExtns = self.GetExtensions(active_only=1)
|
| 563 |
+
for extn in activeExtns:
|
| 564 |
+
extKeys = self.__GetRawExtensionKeys(extn)
|
| 565 |
+
if extKeys: #the extension defines keybindings
|
| 566 |
+
for event in extKeys:
|
| 567 |
+
if extKeys[event] in keySet.values():
|
| 568 |
+
#the binding is already in use
|
| 569 |
+
extKeys[event] = '' #disable this binding
|
| 570 |
+
keySet[event] = extKeys[event] #add binding
|
| 571 |
+
return keySet
|
| 572 |
+
|
| 573 |
+
def IsCoreBinding(self, virtualEvent):
|
| 574 |
+
"""Return True if the virtual event is one of the core idle key events.
|
| 575 |
+
|
| 576 |
+
virtualEvent - string, name of the virtual event to test for,
|
| 577 |
+
without the enclosing '<< >>'
|
| 578 |
+
"""
|
| 579 |
+
return ('<<'+virtualEvent+'>>') in self.GetCoreKeys()
|
| 580 |
+
|
| 581 |
+
# TODO make keyBindings a file or class attribute used for test above
|
| 582 |
+
# and copied in function below.
|
| 583 |
+
|
| 584 |
+
former_extension_events = { # Those with user-configurable keys.
|
| 585 |
+
'<<force-open-completions>>', '<<expand-word>>',
|
| 586 |
+
'<<force-open-calltip>>', '<<flash-paren>>', '<<format-paragraph>>',
|
| 587 |
+
'<<run-module>>', '<<check-module>>', '<<zoom-height>>',
|
| 588 |
+
'<<run-custom>>',
|
| 589 |
+
}
|
| 590 |
+
|
| 591 |
+
def GetCoreKeys(self, keySetName=None):
|
| 592 |
+
"""Return dict of core virtual-key keybindings for keySetName.
|
| 593 |
+
|
| 594 |
+
The default keySetName None corresponds to the keyBindings base
|
| 595 |
+
dict. If keySetName is not None, bindings from the config
|
| 596 |
+
file(s) are loaded _over_ these defaults, so if there is a
|
| 597 |
+
problem getting any core binding there will be an 'ultimate last
|
| 598 |
+
resort fallback' to the CUA-ish bindings defined here.
|
| 599 |
+
"""
|
| 600 |
+
keyBindings={
|
| 601 |
+
'<<copy>>': ['<Control-c>', '<Control-C>'],
|
| 602 |
+
'<<cut>>': ['<Control-x>', '<Control-X>'],
|
| 603 |
+
'<<paste>>': ['<Control-v>', '<Control-V>'],
|
| 604 |
+
'<<beginning-of-line>>': ['<Control-a>', '<Home>'],
|
| 605 |
+
'<<center-insert>>': ['<Control-l>'],
|
| 606 |
+
'<<close-all-windows>>': ['<Control-q>'],
|
| 607 |
+
'<<close-window>>': ['<Alt-F4>'],
|
| 608 |
+
'<<do-nothing>>': ['<Control-x>'],
|
| 609 |
+
'<<end-of-file>>': ['<Control-d>'],
|
| 610 |
+
'<<python-docs>>': ['<F1>'],
|
| 611 |
+
'<<python-context-help>>': ['<Shift-F1>'],
|
| 612 |
+
'<<history-next>>': ['<Alt-n>'],
|
| 613 |
+
'<<history-previous>>': ['<Alt-p>'],
|
| 614 |
+
'<<interrupt-execution>>': ['<Control-c>'],
|
| 615 |
+
'<<view-restart>>': ['<F6>'],
|
| 616 |
+
'<<restart-shell>>': ['<Control-F6>'],
|
| 617 |
+
'<<open-class-browser>>': ['<Alt-c>'],
|
| 618 |
+
'<<open-module>>': ['<Alt-m>'],
|
| 619 |
+
'<<open-new-window>>': ['<Control-n>'],
|
| 620 |
+
'<<open-window-from-file>>': ['<Control-o>'],
|
| 621 |
+
'<<plain-newline-and-indent>>': ['<Control-j>'],
|
| 622 |
+
'<<print-window>>': ['<Control-p>'],
|
| 623 |
+
'<<redo>>': ['<Control-y>'],
|
| 624 |
+
'<<remove-selection>>': ['<Escape>'],
|
| 625 |
+
'<<save-copy-of-window-as-file>>': ['<Alt-Shift-S>'],
|
| 626 |
+
'<<save-window-as-file>>': ['<Alt-s>'],
|
| 627 |
+
'<<save-window>>': ['<Control-s>'],
|
| 628 |
+
'<<select-all>>': ['<Alt-a>'],
|
| 629 |
+
'<<toggle-auto-coloring>>': ['<Control-slash>'],
|
| 630 |
+
'<<undo>>': ['<Control-z>'],
|
| 631 |
+
'<<find-again>>': ['<Control-g>', '<F3>'],
|
| 632 |
+
'<<find-in-files>>': ['<Alt-F3>'],
|
| 633 |
+
'<<find-selection>>': ['<Control-F3>'],
|
| 634 |
+
'<<find>>': ['<Control-f>'],
|
| 635 |
+
'<<replace>>': ['<Control-h>'],
|
| 636 |
+
'<<goto-line>>': ['<Alt-g>'],
|
| 637 |
+
'<<smart-backspace>>': ['<Key-BackSpace>'],
|
| 638 |
+
'<<newline-and-indent>>': ['<Key-Return>', '<Key-KP_Enter>'],
|
| 639 |
+
'<<smart-indent>>': ['<Key-Tab>'],
|
| 640 |
+
'<<indent-region>>': ['<Control-Key-bracketright>'],
|
| 641 |
+
'<<dedent-region>>': ['<Control-Key-bracketleft>'],
|
| 642 |
+
'<<comment-region>>': ['<Alt-Key-3>'],
|
| 643 |
+
'<<uncomment-region>>': ['<Alt-Key-4>'],
|
| 644 |
+
'<<tabify-region>>': ['<Alt-Key-5>'],
|
| 645 |
+
'<<untabify-region>>': ['<Alt-Key-6>'],
|
| 646 |
+
'<<toggle-tabs>>': ['<Alt-Key-t>'],
|
| 647 |
+
'<<change-indentwidth>>': ['<Alt-Key-u>'],
|
| 648 |
+
'<<del-word-left>>': ['<Control-Key-BackSpace>'],
|
| 649 |
+
'<<del-word-right>>': ['<Control-Key-Delete>'],
|
| 650 |
+
'<<force-open-completions>>': ['<Control-Key-space>'],
|
| 651 |
+
'<<expand-word>>': ['<Alt-Key-slash>'],
|
| 652 |
+
'<<force-open-calltip>>': ['<Control-Key-backslash>'],
|
| 653 |
+
'<<flash-paren>>': ['<Control-Key-0>'],
|
| 654 |
+
'<<format-paragraph>>': ['<Alt-Key-q>'],
|
| 655 |
+
'<<run-module>>': ['<Key-F5>'],
|
| 656 |
+
'<<run-custom>>': ['<Shift-Key-F5>'],
|
| 657 |
+
'<<check-module>>': ['<Alt-Key-x>'],
|
| 658 |
+
'<<zoom-height>>': ['<Alt-Key-2>'],
|
| 659 |
+
}
|
| 660 |
+
|
| 661 |
+
if keySetName:
|
| 662 |
+
if not (self.userCfg['keys'].has_section(keySetName) or
|
| 663 |
+
self.defaultCfg['keys'].has_section(keySetName)):
|
| 664 |
+
warning = (
|
| 665 |
+
'\n Warning: config.py - IdleConf.GetCoreKeys -\n'
|
| 666 |
+
' key set %r is not defined, using default bindings.' %
|
| 667 |
+
(keySetName,)
|
| 668 |
+
)
|
| 669 |
+
_warn(warning, 'keys', keySetName)
|
| 670 |
+
else:
|
| 671 |
+
for event in keyBindings:
|
| 672 |
+
binding = self.GetKeyBinding(keySetName, event)
|
| 673 |
+
if binding:
|
| 674 |
+
keyBindings[event] = binding
|
| 675 |
+
# Otherwise return default in keyBindings.
|
| 676 |
+
elif event not in self.former_extension_events:
|
| 677 |
+
warning = (
|
| 678 |
+
'\n Warning: config.py - IdleConf.GetCoreKeys -\n'
|
| 679 |
+
' problem retrieving key binding for event %r\n'
|
| 680 |
+
' from key set %r.\n'
|
| 681 |
+
' returning default value: %r' %
|
| 682 |
+
(event, keySetName, keyBindings[event])
|
| 683 |
+
)
|
| 684 |
+
_warn(warning, 'keys', keySetName, event)
|
| 685 |
+
return keyBindings
|
| 686 |
+
|
| 687 |
+
def GetExtraHelpSourceList(self, configSet):
|
| 688 |
+
"""Return list of extra help sources from a given configSet.
|
| 689 |
+
|
| 690 |
+
Valid configSets are 'user' or 'default'. Return a list of tuples of
|
| 691 |
+
the form (menu_item , path_to_help_file , option), or return the empty
|
| 692 |
+
list. 'option' is the sequence number of the help resource. 'option'
|
| 693 |
+
values determine the position of the menu items on the Help menu,
|
| 694 |
+
therefore the returned list must be sorted by 'option'.
|
| 695 |
+
|
| 696 |
+
"""
|
| 697 |
+
helpSources = []
|
| 698 |
+
if configSet == 'user':
|
| 699 |
+
cfgParser = self.userCfg['main']
|
| 700 |
+
elif configSet == 'default':
|
| 701 |
+
cfgParser = self.defaultCfg['main']
|
| 702 |
+
else:
|
| 703 |
+
raise InvalidConfigSet('Invalid configSet specified')
|
| 704 |
+
options=cfgParser.GetOptionList('HelpFiles')
|
| 705 |
+
for option in options:
|
| 706 |
+
value=cfgParser.Get('HelpFiles', option, default=';')
|
| 707 |
+
if value.find(';') == -1: #malformed config entry with no ';'
|
| 708 |
+
menuItem = '' #make these empty
|
| 709 |
+
helpPath = '' #so value won't be added to list
|
| 710 |
+
else: #config entry contains ';' as expected
|
| 711 |
+
value=value.split(';')
|
| 712 |
+
menuItem=value[0].strip()
|
| 713 |
+
helpPath=value[1].strip()
|
| 714 |
+
if menuItem and helpPath: #neither are empty strings
|
| 715 |
+
helpSources.append( (menuItem,helpPath,option) )
|
| 716 |
+
helpSources.sort(key=lambda x: x[2])
|
| 717 |
+
return helpSources
|
| 718 |
+
|
| 719 |
+
def GetAllExtraHelpSourcesList(self):
|
| 720 |
+
"""Return a list of the details of all additional help sources.
|
| 721 |
+
|
| 722 |
+
Tuples in the list are those of GetExtraHelpSourceList.
|
| 723 |
+
"""
|
| 724 |
+
allHelpSources = (self.GetExtraHelpSourceList('default') +
|
| 725 |
+
self.GetExtraHelpSourceList('user') )
|
| 726 |
+
return allHelpSources
|
| 727 |
+
|
| 728 |
+
def GetFont(self, root, configType, section):
|
| 729 |
+
"""Retrieve a font from configuration (font, font-size, font-bold)
|
| 730 |
+
Intercept the special value 'TkFixedFont' and substitute
|
| 731 |
+
the actual font, factoring in some tweaks if needed for
|
| 732 |
+
appearance sakes.
|
| 733 |
+
|
| 734 |
+
The 'root' parameter can normally be any valid Tkinter widget.
|
| 735 |
+
|
| 736 |
+
Return a tuple (family, size, weight) suitable for passing
|
| 737 |
+
to tkinter.Font
|
| 738 |
+
"""
|
| 739 |
+
family = self.GetOption(configType, section, 'font', default='courier')
|
| 740 |
+
size = self.GetOption(configType, section, 'font-size', type='int',
|
| 741 |
+
default='10')
|
| 742 |
+
bold = self.GetOption(configType, section, 'font-bold', default=0,
|
| 743 |
+
type='bool')
|
| 744 |
+
if (family == 'TkFixedFont'):
|
| 745 |
+
f = Font(name='TkFixedFont', exists=True, root=root)
|
| 746 |
+
actualFont = Font.actual(f)
|
| 747 |
+
family = actualFont['family']
|
| 748 |
+
size = actualFont['size']
|
| 749 |
+
if size <= 0:
|
| 750 |
+
size = 10 # if font in pixels, ignore actual size
|
| 751 |
+
bold = actualFont['weight'] == 'bold'
|
| 752 |
+
return (family, size, 'bold' if bold else 'normal')
|
| 753 |
+
|
| 754 |
+
def LoadCfgFiles(self):
|
| 755 |
+
"Load all configuration files."
|
| 756 |
+
for key in self.defaultCfg:
|
| 757 |
+
self.defaultCfg[key].Load()
|
| 758 |
+
self.userCfg[key].Load() #same keys
|
| 759 |
+
|
| 760 |
+
def SaveUserCfgFiles(self):
|
| 761 |
+
"Write all loaded user configuration files to disk."
|
| 762 |
+
for key in self.userCfg:
|
| 763 |
+
self.userCfg[key].Save()
|
| 764 |
+
|
| 765 |
+
|
| 766 |
+
idleConf = IdleConf()
|
| 767 |
+
|
| 768 |
+
_warned = set()
|
| 769 |
+
def _warn(msg, *key):
|
| 770 |
+
key = (msg,) + key
|
| 771 |
+
if key not in _warned:
|
| 772 |
+
try:
|
| 773 |
+
print(msg, file=sys.stderr)
|
| 774 |
+
except OSError:
|
| 775 |
+
pass
|
| 776 |
+
_warned.add(key)
|
| 777 |
+
|
| 778 |
+
|
| 779 |
+
class ConfigChanges(dict):
|
| 780 |
+
"""Manage a user's proposed configuration option changes.
|
| 781 |
+
|
| 782 |
+
Names used across multiple methods:
|
| 783 |
+
page -- one of the 4 top-level dicts representing a
|
| 784 |
+
.idlerc/config-x.cfg file.
|
| 785 |
+
config_type -- name of a page.
|
| 786 |
+
section -- a section within a page/file.
|
| 787 |
+
option -- name of an option within a section.
|
| 788 |
+
value -- value for the option.
|
| 789 |
+
|
| 790 |
+
Methods
|
| 791 |
+
add_option: Add option and value to changes.
|
| 792 |
+
save_option: Save option and value to config parser.
|
| 793 |
+
save_all: Save all the changes to the config parser and file.
|
| 794 |
+
delete_section: If section exists,
|
| 795 |
+
delete from changes, userCfg, and file.
|
| 796 |
+
clear: Clear all changes by clearing each page.
|
| 797 |
+
"""
|
| 798 |
+
def __init__(self):
|
| 799 |
+
"Create a page for each configuration file"
|
| 800 |
+
self.pages = [] # List of unhashable dicts.
|
| 801 |
+
for config_type in idleConf.config_types:
|
| 802 |
+
self[config_type] = {}
|
| 803 |
+
self.pages.append(self[config_type])
|
| 804 |
+
|
| 805 |
+
def add_option(self, config_type, section, item, value):
|
| 806 |
+
"Add item/value pair for config_type and section."
|
| 807 |
+
page = self[config_type]
|
| 808 |
+
value = str(value) # Make sure we use a string.
|
| 809 |
+
if section not in page:
|
| 810 |
+
page[section] = {}
|
| 811 |
+
page[section][item] = value
|
| 812 |
+
|
| 813 |
+
@staticmethod
|
| 814 |
+
def save_option(config_type, section, item, value):
|
| 815 |
+
"""Return True if the configuration value was added or changed.
|
| 816 |
+
|
| 817 |
+
Helper for save_all.
|
| 818 |
+
"""
|
| 819 |
+
if idleConf.defaultCfg[config_type].has_option(section, item):
|
| 820 |
+
if idleConf.defaultCfg[config_type].Get(section, item) == value:
|
| 821 |
+
# The setting equals a default setting, remove it from user cfg.
|
| 822 |
+
return idleConf.userCfg[config_type].RemoveOption(section, item)
|
| 823 |
+
# If we got here, set the option.
|
| 824 |
+
return idleConf.userCfg[config_type].SetOption(section, item, value)
|
| 825 |
+
|
| 826 |
+
def save_all(self):
|
| 827 |
+
"""Save configuration changes to the user config file.
|
| 828 |
+
|
| 829 |
+
Clear self in preparation for additional changes.
|
| 830 |
+
Return changed for testing.
|
| 831 |
+
"""
|
| 832 |
+
idleConf.userCfg['main'].Save()
|
| 833 |
+
|
| 834 |
+
changed = False
|
| 835 |
+
for config_type in self:
|
| 836 |
+
cfg_type_changed = False
|
| 837 |
+
page = self[config_type]
|
| 838 |
+
for section in page:
|
| 839 |
+
if section == 'HelpFiles': # Remove it for replacement.
|
| 840 |
+
idleConf.userCfg['main'].remove_section('HelpFiles')
|
| 841 |
+
cfg_type_changed = True
|
| 842 |
+
for item, value in page[section].items():
|
| 843 |
+
if self.save_option(config_type, section, item, value):
|
| 844 |
+
cfg_type_changed = True
|
| 845 |
+
if cfg_type_changed:
|
| 846 |
+
idleConf.userCfg[config_type].Save()
|
| 847 |
+
changed = True
|
| 848 |
+
for config_type in ['keys', 'highlight']:
|
| 849 |
+
# Save these even if unchanged!
|
| 850 |
+
idleConf.userCfg[config_type].Save()
|
| 851 |
+
self.clear()
|
| 852 |
+
# ConfigDialog caller must add the following call
|
| 853 |
+
# self.save_all_changed_extensions() # Uses a different mechanism.
|
| 854 |
+
return changed
|
| 855 |
+
|
| 856 |
+
def delete_section(self, config_type, section):
|
| 857 |
+
"""Delete a section from self, userCfg, and file.
|
| 858 |
+
|
| 859 |
+
Used to delete custom themes and keysets.
|
| 860 |
+
"""
|
| 861 |
+
if section in self[config_type]:
|
| 862 |
+
del self[config_type][section]
|
| 863 |
+
configpage = idleConf.userCfg[config_type]
|
| 864 |
+
configpage.remove_section(section)
|
| 865 |
+
configpage.Save()
|
| 866 |
+
|
| 867 |
+
def clear(self):
|
| 868 |
+
"""Clear all 4 pages.
|
| 869 |
+
|
| 870 |
+
Called in save_all after saving to idleConf.
|
| 871 |
+
XXX Mark window *title* when there are changes; unmark here.
|
| 872 |
+
"""
|
| 873 |
+
for page in self.pages:
|
| 874 |
+
page.clear()
|
| 875 |
+
|
| 876 |
+
|
| 877 |
+
# TODO Revise test output, write expanded unittest
|
| 878 |
+
def _dump(): # htest # (not really, but ignore in coverage)
|
| 879 |
+
from zlib import crc32
|
| 880 |
+
line, crc = 0, 0
|
| 881 |
+
|
| 882 |
+
def sprint(obj):
|
| 883 |
+
global line, crc
|
| 884 |
+
txt = str(obj)
|
| 885 |
+
line += 1
|
| 886 |
+
crc = crc32(txt.encode(encoding='utf-8'), crc)
|
| 887 |
+
print(txt)
|
| 888 |
+
#print('***', line, crc, '***') # Uncomment for diagnosis.
|
| 889 |
+
|
| 890 |
+
def dumpCfg(cfg):
|
| 891 |
+
print('\n', cfg, '\n') # Cfg has variable '0xnnnnnnnn' address.
|
| 892 |
+
for key in sorted(cfg.keys()):
|
| 893 |
+
sections = cfg[key].sections()
|
| 894 |
+
sprint(key)
|
| 895 |
+
sprint(sections)
|
| 896 |
+
for section in sections:
|
| 897 |
+
options = cfg[key].options(section)
|
| 898 |
+
sprint(section)
|
| 899 |
+
sprint(options)
|
| 900 |
+
for option in options:
|
| 901 |
+
sprint(option + ' = ' + cfg[key].Get(section, option))
|
| 902 |
+
|
| 903 |
+
dumpCfg(idleConf.defaultCfg)
|
| 904 |
+
dumpCfg(idleConf.userCfg)
|
| 905 |
+
print('\nlines = ', line, ', crc = ', crc, sep='')
|
| 906 |
+
|
| 907 |
+
if __name__ == '__main__':
|
| 908 |
+
from unittest import main
|
| 909 |
+
main('idlelib.idle_test.test_config', verbosity=2, exit=False)
|
| 910 |
+
|
| 911 |
+
# Run revised _dump() as htest?
|
evalkit_cambrian/lib/python3.10/idlelib/debugobj.py
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# XXX TO DO:
|
| 2 |
+
# - popup menu
|
| 3 |
+
# - support partial or total redisplay
|
| 4 |
+
# - more doc strings
|
| 5 |
+
# - tooltips
|
| 6 |
+
|
| 7 |
+
# object browser
|
| 8 |
+
|
| 9 |
+
# XXX TO DO:
|
| 10 |
+
# - for classes/modules, add "open source" to object browser
|
| 11 |
+
from reprlib import Repr
|
| 12 |
+
|
| 13 |
+
from idlelib.tree import TreeItem, TreeNode, ScrolledCanvas
|
| 14 |
+
|
| 15 |
+
myrepr = Repr()
|
| 16 |
+
myrepr.maxstring = 100
|
| 17 |
+
myrepr.maxother = 100
|
| 18 |
+
|
| 19 |
+
class ObjectTreeItem(TreeItem):
|
| 20 |
+
def __init__(self, labeltext, object, setfunction=None):
|
| 21 |
+
self.labeltext = labeltext
|
| 22 |
+
self.object = object
|
| 23 |
+
self.setfunction = setfunction
|
| 24 |
+
def GetLabelText(self):
|
| 25 |
+
return self.labeltext
|
| 26 |
+
def GetText(self):
|
| 27 |
+
return myrepr.repr(self.object)
|
| 28 |
+
def GetIconName(self):
|
| 29 |
+
if not self.IsExpandable():
|
| 30 |
+
return "python"
|
| 31 |
+
def IsEditable(self):
|
| 32 |
+
return self.setfunction is not None
|
| 33 |
+
def SetText(self, text):
|
| 34 |
+
try:
|
| 35 |
+
value = eval(text)
|
| 36 |
+
self.setfunction(value)
|
| 37 |
+
except:
|
| 38 |
+
pass
|
| 39 |
+
else:
|
| 40 |
+
self.object = value
|
| 41 |
+
def IsExpandable(self):
|
| 42 |
+
return not not dir(self.object)
|
| 43 |
+
def GetSubList(self):
|
| 44 |
+
keys = dir(self.object)
|
| 45 |
+
sublist = []
|
| 46 |
+
for key in keys:
|
| 47 |
+
try:
|
| 48 |
+
value = getattr(self.object, key)
|
| 49 |
+
except AttributeError:
|
| 50 |
+
continue
|
| 51 |
+
item = make_objecttreeitem(
|
| 52 |
+
str(key) + " =",
|
| 53 |
+
value,
|
| 54 |
+
lambda value, key=key, object=self.object:
|
| 55 |
+
setattr(object, key, value))
|
| 56 |
+
sublist.append(item)
|
| 57 |
+
return sublist
|
| 58 |
+
|
| 59 |
+
class ClassTreeItem(ObjectTreeItem):
|
| 60 |
+
def IsExpandable(self):
|
| 61 |
+
return True
|
| 62 |
+
def GetSubList(self):
|
| 63 |
+
sublist = ObjectTreeItem.GetSubList(self)
|
| 64 |
+
if len(self.object.__bases__) == 1:
|
| 65 |
+
item = make_objecttreeitem("__bases__[0] =",
|
| 66 |
+
self.object.__bases__[0])
|
| 67 |
+
else:
|
| 68 |
+
item = make_objecttreeitem("__bases__ =", self.object.__bases__)
|
| 69 |
+
sublist.insert(0, item)
|
| 70 |
+
return sublist
|
| 71 |
+
|
| 72 |
+
class AtomicObjectTreeItem(ObjectTreeItem):
|
| 73 |
+
def IsExpandable(self):
|
| 74 |
+
return False
|
| 75 |
+
|
| 76 |
+
class SequenceTreeItem(ObjectTreeItem):
|
| 77 |
+
def IsExpandable(self):
|
| 78 |
+
return len(self.object) > 0
|
| 79 |
+
def keys(self):
|
| 80 |
+
return range(len(self.object))
|
| 81 |
+
def GetSubList(self):
|
| 82 |
+
sublist = []
|
| 83 |
+
for key in self.keys():
|
| 84 |
+
try:
|
| 85 |
+
value = self.object[key]
|
| 86 |
+
except KeyError:
|
| 87 |
+
continue
|
| 88 |
+
def setfunction(value, key=key, object=self.object):
|
| 89 |
+
object[key] = value
|
| 90 |
+
item = make_objecttreeitem("%r:" % (key,), value, setfunction)
|
| 91 |
+
sublist.append(item)
|
| 92 |
+
return sublist
|
| 93 |
+
|
| 94 |
+
class DictTreeItem(SequenceTreeItem):
|
| 95 |
+
def keys(self):
|
| 96 |
+
keys = list(self.object.keys())
|
| 97 |
+
try:
|
| 98 |
+
keys.sort()
|
| 99 |
+
except:
|
| 100 |
+
pass
|
| 101 |
+
return keys
|
| 102 |
+
|
| 103 |
+
dispatch = {
|
| 104 |
+
int: AtomicObjectTreeItem,
|
| 105 |
+
float: AtomicObjectTreeItem,
|
| 106 |
+
str: AtomicObjectTreeItem,
|
| 107 |
+
tuple: SequenceTreeItem,
|
| 108 |
+
list: SequenceTreeItem,
|
| 109 |
+
dict: DictTreeItem,
|
| 110 |
+
type: ClassTreeItem,
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
def make_objecttreeitem(labeltext, object, setfunction=None):
|
| 114 |
+
t = type(object)
|
| 115 |
+
if t in dispatch:
|
| 116 |
+
c = dispatch[t]
|
| 117 |
+
else:
|
| 118 |
+
c = ObjectTreeItem
|
| 119 |
+
return c(labeltext, object, setfunction)
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
def _object_browser(parent): # htest #
|
| 123 |
+
import sys
|
| 124 |
+
from tkinter import Toplevel
|
| 125 |
+
top = Toplevel(parent)
|
| 126 |
+
top.title("Test debug object browser")
|
| 127 |
+
x, y = map(int, parent.geometry().split('+')[1:])
|
| 128 |
+
top.geometry("+%d+%d" % (x + 100, y + 175))
|
| 129 |
+
top.configure(bd=0, bg="yellow")
|
| 130 |
+
top.focus_set()
|
| 131 |
+
sc = ScrolledCanvas(top, bg="white", highlightthickness=0, takefocus=1)
|
| 132 |
+
sc.frame.pack(expand=1, fill="both")
|
| 133 |
+
item = make_objecttreeitem("sys", sys)
|
| 134 |
+
node = TreeNode(sc.canvas, None, item)
|
| 135 |
+
node.update()
|
| 136 |
+
|
| 137 |
+
if __name__ == '__main__':
|
| 138 |
+
from unittest import main
|
| 139 |
+
main('idlelib.idle_test.test_debugobj', verbosity=2, exit=False)
|
| 140 |
+
|
| 141 |
+
from idlelib.idle_test.htest import run
|
| 142 |
+
run(_object_browser)
|
evalkit_cambrian/lib/python3.10/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)
|
evalkit_cambrian/lib/python3.10/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 cofig-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.
|
evalkit_cambrian/lib/python3.10/idlelib/filelist.py
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
"%r is a directory." % (filename,),
|
| 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 |
+
"You now have multiple edit windows open for %r" % (filename,),
|
| 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 |
+
if __name__ == '__main__':
|
| 128 |
+
from unittest import main
|
| 129 |
+
main('idlelib.idle_test.test_filelist', verbosity=2)
|
| 130 |
+
|
| 131 |
+
# _test()
|
evalkit_cambrian/lib/python3.10/idlelib/grep.py
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Grep dialog for Find in Files functionality.
|
| 2 |
+
|
| 3 |
+
Inherits from SearchDialogBase for GUI and uses searchengine
|
| 4 |
+
to prepare search pattern.
|
| 5 |
+
"""
|
| 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, END
|
| 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 |
+
|
| 208 |
+
def show_grep_dialog():
|
| 209 |
+
text.tag_add(SEL, "1.0", END)
|
| 210 |
+
grep(text, flist=flist)
|
| 211 |
+
text.tag_remove(SEL, "1.0", END)
|
| 212 |
+
|
| 213 |
+
button = Button(frame, text="Show GrepDialog", command=show_grep_dialog)
|
| 214 |
+
button.pack()
|
| 215 |
+
|
| 216 |
+
if __name__ == "__main__":
|
| 217 |
+
from unittest import main
|
| 218 |
+
main('idlelib.idle_test.test_grep', verbosity=2, exit=False)
|
| 219 |
+
|
| 220 |
+
from idlelib.idle_test.htest import run
|
| 221 |
+
run(_grep_dialog)
|
evalkit_cambrian/lib/python3.10/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 ealiest 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)
|
evalkit_cambrian/lib/python3.10/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
|
evalkit_cambrian/lib/python3.10/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'] = pyp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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 |
+
The idle tests are 'discovered' by
|
| 150 |
+
idlelib.idle_test.__init__.load_tests, which is also imported into
|
| 151 |
+
test.test_idle. Normally, neither file should be changed when working on
|
| 152 |
+
individual test modules. The third command runs unittest indirectly
|
| 153 |
+
through regrtest. The same happens when the entire test suite is run
|
| 154 |
+
with 'python -m test'. So that command must work for buildbots to stay
|
| 155 |
+
green. Idle tests must not disturb the environment in a way that makes
|
| 156 |
+
other tests fail (issue 18081).
|
| 157 |
+
|
| 158 |
+
To run an individual Testcase or test method, extend the dotted name
|
| 159 |
+
given to unittest on the command line or use the test -m option. The
|
| 160 |
+
latter allows use of other regrtest options. When using the latter,
|
| 161 |
+
all components of the pattern must be present, but any can be replaced
|
| 162 |
+
by '*'.
|
| 163 |
+
|
| 164 |
+
python -m unittest -v idlelib.idle_test.test_xyz.Test_case.test_meth
|
| 165 |
+
python -m test -m idlelib.idle_test.text_xyz.Test_case.test_meth test_idle
|
| 166 |
+
|
| 167 |
+
The test suite can be run in an IDLE user process from Shell.
|
| 168 |
+
>>> import test.autotest # Issue 25588, 2017/10/13, 3.6.4, 3.7.0a2.
|
| 169 |
+
There are currently failures not usually present, and this does not
|
| 170 |
+
work when run from the editor.
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
4. Human-mediated Tests
|
| 174 |
+
|
| 175 |
+
Human-mediated tests are widget tests that cannot be automated but need
|
| 176 |
+
human verification. They are contained in idlelib/idle_test/htest.py,
|
| 177 |
+
which has instructions. (Some modules need an auxiliary function,
|
| 178 |
+
identified with "# htest # on the header line.) The set is about
|
| 179 |
+
complete, though some tests need improvement. To run all htests, run the
|
| 180 |
+
htest file from an editor or from the command line with:
|
| 181 |
+
|
| 182 |
+
python -m idlelib.idle_test.htest
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
5. Test Coverage
|
| 186 |
+
|
| 187 |
+
Install the coverage package into your Python 3.6 site-packages
|
| 188 |
+
directory. (Its exact location depends on the OS).
|
| 189 |
+
> python3 -m pip install coverage
|
| 190 |
+
(On Windows, replace 'python3 with 'py -3.6' or perhaps just 'python'.)
|
| 191 |
+
|
| 192 |
+
The problem with running coverage with repository python is that
|
| 193 |
+
coverage uses absolute imports for its submodules, hence it needs to be
|
| 194 |
+
in a directory in sys.path. One solution: copy the package to the
|
| 195 |
+
directory containing the cpython repository. Call it 'dev'. Then run
|
| 196 |
+
coverage either directly or from a script in that directory so that
|
| 197 |
+
'dev' is prepended to sys.path.
|
| 198 |
+
|
| 199 |
+
Either edit or add dev/.coveragerc so it looks something like this.
|
| 200 |
+
---
|
| 201 |
+
# .coveragerc sets coverage options.
|
| 202 |
+
[run]
|
| 203 |
+
branch = True
|
| 204 |
+
|
| 205 |
+
[report]
|
| 206 |
+
# Regexes for lines to exclude from consideration
|
| 207 |
+
exclude_lines =
|
| 208 |
+
# Don't complain if non-runnable code isn't run:
|
| 209 |
+
if 0:
|
| 210 |
+
if __name__ == .__main__.:
|
| 211 |
+
|
| 212 |
+
.*# htest #
|
| 213 |
+
if not _utest:
|
| 214 |
+
if _htest:
|
| 215 |
+
---
|
| 216 |
+
The additions for IDLE are 'branch = True', to test coverage both ways,
|
| 217 |
+
and the last three exclude lines, to exclude things peculiar to IDLE
|
| 218 |
+
that are not executed during tests.
|
| 219 |
+
|
| 220 |
+
A script like the following cover.bat (for Windows) is very handy.
|
| 221 |
+
---
|
| 222 |
+
@echo off
|
| 223 |
+
rem Usage: cover filename [test_ suffix] # proper case required by coverage
|
| 224 |
+
rem filename without .py, 2nd parameter if test is not test_filename
|
| 225 |
+
setlocal
|
| 226 |
+
set py=f:\dev\3x\pcbuild\win32\python_d.exe
|
| 227 |
+
set src=idlelib.%1
|
| 228 |
+
if "%2" EQU "" set tst=f:/dev/3x/Lib/idlelib/idle_test/test_%1.py
|
| 229 |
+
if "%2" NEQ "" set tst=f:/dev/ex/Lib/idlelib/idle_test/test_%2.py
|
| 230 |
+
|
| 231 |
+
%py% -m coverage run --pylib --source=%src% %tst%
|
| 232 |
+
%py% -m coverage report --show-missing
|
| 233 |
+
%py% -m coverage html
|
| 234 |
+
start htmlcov\3x_Lib_idlelib_%1_py.html
|
| 235 |
+
rem Above opens new report; htmlcov\index.html displays report index
|
| 236 |
+
---
|
| 237 |
+
The second parameter was added for tests of module x not named test_x.
|
| 238 |
+
(There were several before modules were renamed, now only one is left.)
|
evalkit_cambrian/lib/python3.10/idlelib/idle_test/__init__.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''idlelib.idle_test is a private implementation of test.test_idle,
|
| 2 |
+
which tests the IDLE application as part of the stdlib test suite.
|
| 3 |
+
Run IDLE tests alone with "python -m test.test_idle".
|
| 4 |
+
Starting with Python 3.6, IDLE requires tcl/tk 8.5 or later.
|
| 5 |
+
|
| 6 |
+
This package and its contained modules are subject to change and
|
| 7 |
+
any direct use is at your own risk.
|
| 8 |
+
'''
|
| 9 |
+
from os.path import dirname
|
| 10 |
+
|
| 11 |
+
def load_tests(loader, standard_tests, pattern):
|
| 12 |
+
this_dir = dirname(__file__)
|
| 13 |
+
top_dir = dirname(dirname(this_dir))
|
| 14 |
+
package_tests = loader.discover(start_dir=this_dir, pattern='test*.py',
|
| 15 |
+
top_level_dir=top_dir)
|
| 16 |
+
standard_tests.addTests(package_tests)
|
| 17 |
+
return standard_tests
|
evalkit_cambrian/lib/python3.10/idlelib/idle_test/example_noext
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!usr/bin/env python
|
| 2 |
+
|
| 3 |
+
def example_function(some_argument):
|
| 4 |
+
pass
|
evalkit_cambrian/lib/python3.10/idlelib/idle_test/example_stub.pyi
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class Example:
|
| 2 |
+
def method(self, argument1: str, argument2: list[int]) -> None: ...
|
evalkit_cambrian/lib/python3.10/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
|
evalkit_cambrian/lib/python3.10/idlelib/idle_test/mock_tk.py
ADDED
|
@@ -0,0 +1,307 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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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
|
evalkit_cambrian/lib/python3.10/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)
|
evalkit_cambrian/lib/python3.10/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)
|
evalkit_cambrian/lib/python3.10/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)
|
evalkit_cambrian/lib/python3.10/idlelib/idle_test/test_autoexpand.py
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"Test autoexpand, 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)
|
evalkit_cambrian/lib/python3.10/idlelib/idle_test/test_browser.py
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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)
|
evalkit_cambrian/lib/python3.10/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)
|
evalkit_cambrian/lib/python3.10/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)
|
evalkit_cambrian/lib/python3.10/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)
|
evalkit_cambrian/lib/python3.10/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/cfgparser.1 from test_configparser.
|
| 89 |
+
config_path = findfile('cfgparser.1')
|
| 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, 'r') 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.keys(), conf.config_types)
|
| 278 |
+
self.assertCountEqual(conf.userCfg.keys(), 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/cfgparser.1 from test_configparser.
|
| 298 |
+
config_path = findfile('cfgparser.1')
|
| 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)
|
evalkit_cambrian/lib/python3.10/idlelib/idle_test/test_configdialog.py
ADDED
|
@@ -0,0 +1,1583 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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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 |
+
import unittest
|
| 9 |
+
from unittest import mock
|
| 10 |
+
from idlelib.idle_test.mock_idle import Func
|
| 11 |
+
from tkinter import (Tk, StringVar, IntVar, BooleanVar, DISABLED, NORMAL)
|
| 12 |
+
from idlelib import config
|
| 13 |
+
from idlelib.configdialog import idleConf, changes, tracers
|
| 14 |
+
|
| 15 |
+
# Tests should not depend on fortuitous user configurations.
|
| 16 |
+
# They must not affect actual user .cfg files.
|
| 17 |
+
# Use solution from test_config: empty parsers with no filename.
|
| 18 |
+
usercfg = idleConf.userCfg
|
| 19 |
+
testcfg = {
|
| 20 |
+
'main': config.IdleUserConfParser(''),
|
| 21 |
+
'highlight': config.IdleUserConfParser(''),
|
| 22 |
+
'keys': config.IdleUserConfParser(''),
|
| 23 |
+
'extensions': config.IdleUserConfParser(''),
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
root = None
|
| 27 |
+
dialog = None
|
| 28 |
+
mainpage = changes['main']
|
| 29 |
+
highpage = changes['highlight']
|
| 30 |
+
keyspage = changes['keys']
|
| 31 |
+
extpage = changes['extensions']
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def setUpModule():
|
| 35 |
+
global root, dialog
|
| 36 |
+
idleConf.userCfg = testcfg
|
| 37 |
+
root = Tk()
|
| 38 |
+
# root.withdraw() # Comment out, see issue 30870
|
| 39 |
+
dialog = configdialog.ConfigDialog(root, 'Test', _utest=True)
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def tearDownModule():
|
| 43 |
+
global root, dialog
|
| 44 |
+
idleConf.userCfg = usercfg
|
| 45 |
+
tracers.detach()
|
| 46 |
+
tracers.clear()
|
| 47 |
+
changes.clear()
|
| 48 |
+
root.update_idletasks()
|
| 49 |
+
root.destroy()
|
| 50 |
+
root = dialog = None
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
class ConfigDialogTest(unittest.TestCase):
|
| 54 |
+
|
| 55 |
+
def test_deactivate_current_config(self):
|
| 56 |
+
pass
|
| 57 |
+
|
| 58 |
+
def activate_config_changes(self):
|
| 59 |
+
pass
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
class ButtonTest(unittest.TestCase):
|
| 63 |
+
|
| 64 |
+
def test_click_ok(self):
|
| 65 |
+
d = dialog
|
| 66 |
+
apply = d.apply = mock.Mock()
|
| 67 |
+
destroy = d.destroy = mock.Mock()
|
| 68 |
+
d.buttons['Ok'].invoke()
|
| 69 |
+
apply.assert_called_once()
|
| 70 |
+
destroy.assert_called_once()
|
| 71 |
+
del d.destroy, d.apply
|
| 72 |
+
|
| 73 |
+
def test_click_apply(self):
|
| 74 |
+
d = dialog
|
| 75 |
+
deactivate = d.deactivate_current_config = mock.Mock()
|
| 76 |
+
save_ext = d.extpage.save_all_changed_extensions = mock.Mock()
|
| 77 |
+
activate = d.activate_config_changes = mock.Mock()
|
| 78 |
+
d.buttons['Apply'].invoke()
|
| 79 |
+
deactivate.assert_called_once()
|
| 80 |
+
save_ext.assert_called_once()
|
| 81 |
+
activate.assert_called_once()
|
| 82 |
+
del d.extpage.save_all_changed_extensions
|
| 83 |
+
del d.activate_config_changes, d.deactivate_current_config
|
| 84 |
+
|
| 85 |
+
def test_click_cancel(self):
|
| 86 |
+
d = dialog
|
| 87 |
+
d.destroy = Func()
|
| 88 |
+
changes['main']['something'] = 1
|
| 89 |
+
d.buttons['Cancel'].invoke()
|
| 90 |
+
self.assertEqual(changes['main'], {})
|
| 91 |
+
self.assertEqual(d.destroy.called, 1)
|
| 92 |
+
del d.destroy
|
| 93 |
+
|
| 94 |
+
def test_click_help(self):
|
| 95 |
+
dialog.note.select(dialog.keyspage)
|
| 96 |
+
with mock.patch.object(configdialog, 'view_text',
|
| 97 |
+
new_callable=Func) as view:
|
| 98 |
+
dialog.buttons['Help'].invoke()
|
| 99 |
+
title, contents = view.kwds['title'], view.kwds['contents']
|
| 100 |
+
self.assertEqual(title, 'Help for IDLE preferences')
|
| 101 |
+
self.assertTrue(contents.startswith('When you click') and
|
| 102 |
+
contents.endswith('a different name.\n'))
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
class FontPageTest(unittest.TestCase):
|
| 106 |
+
"""Test that font widgets enable users to make font changes.
|
| 107 |
+
|
| 108 |
+
Test that widget actions set vars, that var changes add three
|
| 109 |
+
options to changes and call set_samples, and that set_samples
|
| 110 |
+
changes the font of both sample boxes.
|
| 111 |
+
"""
|
| 112 |
+
@classmethod
|
| 113 |
+
def setUpClass(cls):
|
| 114 |
+
page = cls.page = dialog.fontpage
|
| 115 |
+
dialog.note.select(page)
|
| 116 |
+
page.set_samples = Func() # Mask instance method.
|
| 117 |
+
page.update()
|
| 118 |
+
|
| 119 |
+
@classmethod
|
| 120 |
+
def tearDownClass(cls):
|
| 121 |
+
del cls.page.set_samples # Unmask instance method.
|
| 122 |
+
|
| 123 |
+
def setUp(self):
|
| 124 |
+
changes.clear()
|
| 125 |
+
|
| 126 |
+
def test_load_font_cfg(self):
|
| 127 |
+
# Leave widget load test to human visual check.
|
| 128 |
+
# TODO Improve checks when add IdleConf.get_font_values.
|
| 129 |
+
tracers.detach()
|
| 130 |
+
d = self.page
|
| 131 |
+
d.font_name.set('Fake')
|
| 132 |
+
d.font_size.set('1')
|
| 133 |
+
d.font_bold.set(True)
|
| 134 |
+
d.set_samples.called = 0
|
| 135 |
+
d.load_font_cfg()
|
| 136 |
+
self.assertNotEqual(d.font_name.get(), 'Fake')
|
| 137 |
+
self.assertNotEqual(d.font_size.get(), '1')
|
| 138 |
+
self.assertFalse(d.font_bold.get())
|
| 139 |
+
self.assertEqual(d.set_samples.called, 1)
|
| 140 |
+
tracers.attach()
|
| 141 |
+
|
| 142 |
+
def test_fontlist_key(self):
|
| 143 |
+
# Up and Down keys should select a new font.
|
| 144 |
+
d = self.page
|
| 145 |
+
if d.fontlist.size() < 2:
|
| 146 |
+
self.skipTest('need at least 2 fonts')
|
| 147 |
+
fontlist = d.fontlist
|
| 148 |
+
fontlist.activate(0)
|
| 149 |
+
font = d.fontlist.get('active')
|
| 150 |
+
|
| 151 |
+
# Test Down key.
|
| 152 |
+
fontlist.focus_force()
|
| 153 |
+
fontlist.update()
|
| 154 |
+
fontlist.event_generate('<Key-Down>')
|
| 155 |
+
fontlist.event_generate('<KeyRelease-Down>')
|
| 156 |
+
|
| 157 |
+
down_font = fontlist.get('active')
|
| 158 |
+
self.assertNotEqual(down_font, font)
|
| 159 |
+
self.assertIn(d.font_name.get(), down_font.lower())
|
| 160 |
+
|
| 161 |
+
# Test Up key.
|
| 162 |
+
fontlist.focus_force()
|
| 163 |
+
fontlist.update()
|
| 164 |
+
fontlist.event_generate('<Key-Up>')
|
| 165 |
+
fontlist.event_generate('<KeyRelease-Up>')
|
| 166 |
+
|
| 167 |
+
up_font = fontlist.get('active')
|
| 168 |
+
self.assertEqual(up_font, font)
|
| 169 |
+
self.assertIn(d.font_name.get(), up_font.lower())
|
| 170 |
+
|
| 171 |
+
def test_fontlist_mouse(self):
|
| 172 |
+
# Click on item should select that item.
|
| 173 |
+
d = self.page
|
| 174 |
+
if d.fontlist.size() < 2:
|
| 175 |
+
self.skipTest('need at least 2 fonts')
|
| 176 |
+
fontlist = d.fontlist
|
| 177 |
+
fontlist.activate(0)
|
| 178 |
+
|
| 179 |
+
# Select next item in listbox
|
| 180 |
+
fontlist.focus_force()
|
| 181 |
+
fontlist.see(1)
|
| 182 |
+
fontlist.update()
|
| 183 |
+
x, y, dx, dy = fontlist.bbox(1)
|
| 184 |
+
x += dx // 2
|
| 185 |
+
y += dy // 2
|
| 186 |
+
fontlist.event_generate('<Button-1>', x=x, y=y)
|
| 187 |
+
fontlist.event_generate('<ButtonRelease-1>', x=x, y=y)
|
| 188 |
+
|
| 189 |
+
font1 = fontlist.get(1)
|
| 190 |
+
select_font = fontlist.get('anchor')
|
| 191 |
+
self.assertEqual(select_font, font1)
|
| 192 |
+
self.assertIn(d.font_name.get(), font1.lower())
|
| 193 |
+
|
| 194 |
+
def test_sizelist(self):
|
| 195 |
+
# Click on number should select that number
|
| 196 |
+
d = self.page
|
| 197 |
+
d.sizelist.variable.set(40)
|
| 198 |
+
self.assertEqual(d.font_size.get(), '40')
|
| 199 |
+
|
| 200 |
+
def test_bold_toggle(self):
|
| 201 |
+
# Click on checkbutton should invert it.
|
| 202 |
+
d = self.page
|
| 203 |
+
d.font_bold.set(False)
|
| 204 |
+
d.bold_toggle.invoke()
|
| 205 |
+
self.assertTrue(d.font_bold.get())
|
| 206 |
+
d.bold_toggle.invoke()
|
| 207 |
+
self.assertFalse(d.font_bold.get())
|
| 208 |
+
|
| 209 |
+
def test_font_set(self):
|
| 210 |
+
# Test that setting a font Variable results in 3 provisional
|
| 211 |
+
# change entries and a call to set_samples. Use values sure to
|
| 212 |
+
# not be defaults.
|
| 213 |
+
|
| 214 |
+
default_font = idleConf.GetFont(root, 'main', 'EditorWindow')
|
| 215 |
+
default_size = str(default_font[1])
|
| 216 |
+
default_bold = default_font[2] == 'bold'
|
| 217 |
+
d = self.page
|
| 218 |
+
d.font_size.set(default_size)
|
| 219 |
+
d.font_bold.set(default_bold)
|
| 220 |
+
d.set_samples.called = 0
|
| 221 |
+
|
| 222 |
+
d.font_name.set('Test Font')
|
| 223 |
+
expected = {'EditorWindow': {'font': 'Test Font',
|
| 224 |
+
'font-size': default_size,
|
| 225 |
+
'font-bold': str(default_bold)}}
|
| 226 |
+
self.assertEqual(mainpage, expected)
|
| 227 |
+
self.assertEqual(d.set_samples.called, 1)
|
| 228 |
+
changes.clear()
|
| 229 |
+
|
| 230 |
+
d.font_size.set('20')
|
| 231 |
+
expected = {'EditorWindow': {'font': 'Test Font',
|
| 232 |
+
'font-size': '20',
|
| 233 |
+
'font-bold': str(default_bold)}}
|
| 234 |
+
self.assertEqual(mainpage, expected)
|
| 235 |
+
self.assertEqual(d.set_samples.called, 2)
|
| 236 |
+
changes.clear()
|
| 237 |
+
|
| 238 |
+
d.font_bold.set(not default_bold)
|
| 239 |
+
expected = {'EditorWindow': {'font': 'Test Font',
|
| 240 |
+
'font-size': '20',
|
| 241 |
+
'font-bold': str(not default_bold)}}
|
| 242 |
+
self.assertEqual(mainpage, expected)
|
| 243 |
+
self.assertEqual(d.set_samples.called, 3)
|
| 244 |
+
|
| 245 |
+
def test_set_samples(self):
|
| 246 |
+
d = self.page
|
| 247 |
+
del d.set_samples # Unmask method for test
|
| 248 |
+
orig_samples = d.font_sample, d.highlight_sample
|
| 249 |
+
d.font_sample, d.highlight_sample = {}, {}
|
| 250 |
+
d.font_name.set('test')
|
| 251 |
+
d.font_size.set('5')
|
| 252 |
+
d.font_bold.set(1)
|
| 253 |
+
expected = {'font': ('test', '5', 'bold')}
|
| 254 |
+
|
| 255 |
+
# Test set_samples.
|
| 256 |
+
d.set_samples()
|
| 257 |
+
self.assertTrue(d.font_sample == d.highlight_sample == expected)
|
| 258 |
+
|
| 259 |
+
d.font_sample, d.highlight_sample = orig_samples
|
| 260 |
+
d.set_samples = Func() # Re-mask for other tests.
|
| 261 |
+
|
| 262 |
+
|
| 263 |
+
class HighPageTest(unittest.TestCase):
|
| 264 |
+
"""Test that highlight tab widgets enable users to make changes.
|
| 265 |
+
|
| 266 |
+
Test that widget actions set vars, that var changes add
|
| 267 |
+
options to changes and that themes work correctly.
|
| 268 |
+
"""
|
| 269 |
+
|
| 270 |
+
@classmethod
|
| 271 |
+
def setUpClass(cls):
|
| 272 |
+
page = cls.page = dialog.highpage
|
| 273 |
+
dialog.note.select(page)
|
| 274 |
+
page.set_theme_type = Func()
|
| 275 |
+
page.paint_theme_sample = Func()
|
| 276 |
+
page.set_highlight_target = Func()
|
| 277 |
+
page.set_color_sample = Func()
|
| 278 |
+
page.update()
|
| 279 |
+
|
| 280 |
+
@classmethod
|
| 281 |
+
def tearDownClass(cls):
|
| 282 |
+
d = cls.page
|
| 283 |
+
del d.set_theme_type, d.paint_theme_sample
|
| 284 |
+
del d.set_highlight_target, d.set_color_sample
|
| 285 |
+
|
| 286 |
+
def setUp(self):
|
| 287 |
+
d = self.page
|
| 288 |
+
# The following is needed for test_load_key_cfg, _delete_custom_keys.
|
| 289 |
+
# This may indicate a defect in some test or function.
|
| 290 |
+
for section in idleConf.GetSectionList('user', 'highlight'):
|
| 291 |
+
idleConf.userCfg['highlight'].remove_section(section)
|
| 292 |
+
changes.clear()
|
| 293 |
+
d.set_theme_type.called = 0
|
| 294 |
+
d.paint_theme_sample.called = 0
|
| 295 |
+
d.set_highlight_target.called = 0
|
| 296 |
+
d.set_color_sample.called = 0
|
| 297 |
+
|
| 298 |
+
def test_load_theme_cfg(self):
|
| 299 |
+
tracers.detach()
|
| 300 |
+
d = self.page
|
| 301 |
+
eq = self.assertEqual
|
| 302 |
+
|
| 303 |
+
# Use builtin theme with no user themes created.
|
| 304 |
+
idleConf.CurrentTheme = mock.Mock(return_value='IDLE Classic')
|
| 305 |
+
d.load_theme_cfg()
|
| 306 |
+
self.assertTrue(d.theme_source.get())
|
| 307 |
+
# builtinlist sets variable builtin_name to the CurrentTheme default.
|
| 308 |
+
eq(d.builtin_name.get(), 'IDLE Classic')
|
| 309 |
+
eq(d.custom_name.get(), '- no custom themes -')
|
| 310 |
+
eq(d.custom_theme_on.state(), ('disabled',))
|
| 311 |
+
eq(d.set_theme_type.called, 1)
|
| 312 |
+
eq(d.paint_theme_sample.called, 1)
|
| 313 |
+
eq(d.set_highlight_target.called, 1)
|
| 314 |
+
|
| 315 |
+
# Builtin theme with non-empty user theme list.
|
| 316 |
+
idleConf.SetOption('highlight', 'test1', 'option', 'value')
|
| 317 |
+
idleConf.SetOption('highlight', 'test2', 'option2', 'value2')
|
| 318 |
+
d.load_theme_cfg()
|
| 319 |
+
eq(d.builtin_name.get(), 'IDLE Classic')
|
| 320 |
+
eq(d.custom_name.get(), 'test1')
|
| 321 |
+
eq(d.set_theme_type.called, 2)
|
| 322 |
+
eq(d.paint_theme_sample.called, 2)
|
| 323 |
+
eq(d.set_highlight_target.called, 2)
|
| 324 |
+
|
| 325 |
+
# Use custom theme.
|
| 326 |
+
idleConf.CurrentTheme = mock.Mock(return_value='test2')
|
| 327 |
+
idleConf.SetOption('main', 'Theme', 'default', '0')
|
| 328 |
+
d.load_theme_cfg()
|
| 329 |
+
self.assertFalse(d.theme_source.get())
|
| 330 |
+
eq(d.builtin_name.get(), 'IDLE Classic')
|
| 331 |
+
eq(d.custom_name.get(), 'test2')
|
| 332 |
+
eq(d.set_theme_type.called, 3)
|
| 333 |
+
eq(d.paint_theme_sample.called, 3)
|
| 334 |
+
eq(d.set_highlight_target.called, 3)
|
| 335 |
+
|
| 336 |
+
del idleConf.CurrentTheme
|
| 337 |
+
tracers.attach()
|
| 338 |
+
|
| 339 |
+
def test_theme_source(self):
|
| 340 |
+
eq = self.assertEqual
|
| 341 |
+
d = self.page
|
| 342 |
+
# Test these separately.
|
| 343 |
+
d.var_changed_builtin_name = Func()
|
| 344 |
+
d.var_changed_custom_name = Func()
|
| 345 |
+
# Builtin selected.
|
| 346 |
+
d.builtin_theme_on.invoke()
|
| 347 |
+
eq(mainpage, {'Theme': {'default': 'True'}})
|
| 348 |
+
eq(d.var_changed_builtin_name.called, 1)
|
| 349 |
+
eq(d.var_changed_custom_name.called, 0)
|
| 350 |
+
changes.clear()
|
| 351 |
+
|
| 352 |
+
# Custom selected.
|
| 353 |
+
d.custom_theme_on.state(('!disabled',))
|
| 354 |
+
d.custom_theme_on.invoke()
|
| 355 |
+
self.assertEqual(mainpage, {'Theme': {'default': 'False'}})
|
| 356 |
+
eq(d.var_changed_builtin_name.called, 1)
|
| 357 |
+
eq(d.var_changed_custom_name.called, 1)
|
| 358 |
+
del d.var_changed_builtin_name, d.var_changed_custom_name
|
| 359 |
+
|
| 360 |
+
def test_builtin_name(self):
|
| 361 |
+
eq = self.assertEqual
|
| 362 |
+
d = self.page
|
| 363 |
+
item_list = ['IDLE Classic', 'IDLE Dark', 'IDLE New']
|
| 364 |
+
|
| 365 |
+
# Not in old_themes, defaults name to first item.
|
| 366 |
+
idleConf.SetOption('main', 'Theme', 'name', 'spam')
|
| 367 |
+
d.builtinlist.SetMenu(item_list, 'IDLE Dark')
|
| 368 |
+
eq(mainpage, {'Theme': {'name': 'IDLE Classic',
|
| 369 |
+
'name2': 'IDLE Dark'}})
|
| 370 |
+
eq(d.theme_message['text'], 'New theme, see Help')
|
| 371 |
+
eq(d.paint_theme_sample.called, 1)
|
| 372 |
+
|
| 373 |
+
# Not in old themes - uses name2.
|
| 374 |
+
changes.clear()
|
| 375 |
+
idleConf.SetOption('main', 'Theme', 'name', 'IDLE New')
|
| 376 |
+
d.builtinlist.SetMenu(item_list, 'IDLE Dark')
|
| 377 |
+
eq(mainpage, {'Theme': {'name2': 'IDLE Dark'}})
|
| 378 |
+
eq(d.theme_message['text'], 'New theme, see Help')
|
| 379 |
+
eq(d.paint_theme_sample.called, 2)
|
| 380 |
+
|
| 381 |
+
# Builtin name in old_themes.
|
| 382 |
+
changes.clear()
|
| 383 |
+
d.builtinlist.SetMenu(item_list, 'IDLE Classic')
|
| 384 |
+
eq(mainpage, {'Theme': {'name': 'IDLE Classic', 'name2': ''}})
|
| 385 |
+
eq(d.theme_message['text'], '')
|
| 386 |
+
eq(d.paint_theme_sample.called, 3)
|
| 387 |
+
|
| 388 |
+
def test_custom_name(self):
|
| 389 |
+
d = self.page
|
| 390 |
+
|
| 391 |
+
# If no selections, doesn't get added.
|
| 392 |
+
d.customlist.SetMenu([], '- no custom themes -')
|
| 393 |
+
self.assertNotIn('Theme', mainpage)
|
| 394 |
+
self.assertEqual(d.paint_theme_sample.called, 0)
|
| 395 |
+
|
| 396 |
+
# Custom name selected.
|
| 397 |
+
changes.clear()
|
| 398 |
+
d.customlist.SetMenu(['a', 'b', 'c'], 'c')
|
| 399 |
+
self.assertEqual(mainpage, {'Theme': {'name': 'c'}})
|
| 400 |
+
self.assertEqual(d.paint_theme_sample.called, 1)
|
| 401 |
+
|
| 402 |
+
def test_color(self):
|
| 403 |
+
d = self.page
|
| 404 |
+
d.on_new_color_set = Func()
|
| 405 |
+
# self.color is only set in get_color through colorchooser.
|
| 406 |
+
d.color.set('green')
|
| 407 |
+
self.assertEqual(d.on_new_color_set.called, 1)
|
| 408 |
+
del d.on_new_color_set
|
| 409 |
+
|
| 410 |
+
def test_highlight_target_list_mouse(self):
|
| 411 |
+
# Set highlight_target through targetlist.
|
| 412 |
+
eq = self.assertEqual
|
| 413 |
+
d = self.page
|
| 414 |
+
|
| 415 |
+
d.targetlist.SetMenu(['a', 'b', 'c'], 'c')
|
| 416 |
+
eq(d.highlight_target.get(), 'c')
|
| 417 |
+
eq(d.set_highlight_target.called, 1)
|
| 418 |
+
|
| 419 |
+
def test_highlight_target_text_mouse(self):
|
| 420 |
+
# Set highlight_target through clicking highlight_sample.
|
| 421 |
+
eq = self.assertEqual
|
| 422 |
+
d = self.page
|
| 423 |
+
|
| 424 |
+
elem = {}
|
| 425 |
+
count = 0
|
| 426 |
+
hs = d.highlight_sample
|
| 427 |
+
hs.focus_force()
|
| 428 |
+
hs.see(1.0)
|
| 429 |
+
hs.update_idletasks()
|
| 430 |
+
|
| 431 |
+
def tag_to_element(elem):
|
| 432 |
+
for element, tag in d.theme_elements.items():
|
| 433 |
+
elem[tag[0]] = element
|
| 434 |
+
|
| 435 |
+
def click_it(start):
|
| 436 |
+
x, y, dx, dy = hs.bbox(start)
|
| 437 |
+
x += dx // 2
|
| 438 |
+
y += dy // 2
|
| 439 |
+
hs.event_generate('<Enter>', x=0, y=0)
|
| 440 |
+
hs.event_generate('<Motion>', x=x, y=y)
|
| 441 |
+
hs.event_generate('<ButtonPress-1>', x=x, y=y)
|
| 442 |
+
hs.event_generate('<ButtonRelease-1>', x=x, y=y)
|
| 443 |
+
|
| 444 |
+
# Flip theme_elements to make the tag the key.
|
| 445 |
+
tag_to_element(elem)
|
| 446 |
+
|
| 447 |
+
# If highlight_sample has a tag that isn't in theme_elements, there
|
| 448 |
+
# will be a KeyError in the test run.
|
| 449 |
+
for tag in hs.tag_names():
|
| 450 |
+
for start_index in hs.tag_ranges(tag)[0::2]:
|
| 451 |
+
count += 1
|
| 452 |
+
click_it(start_index)
|
| 453 |
+
eq(d.highlight_target.get(), elem[tag])
|
| 454 |
+
eq(d.set_highlight_target.called, count)
|
| 455 |
+
|
| 456 |
+
def test_highlight_sample_double_click(self):
|
| 457 |
+
# Test double click on highlight_sample.
|
| 458 |
+
eq = self.assertEqual
|
| 459 |
+
d = self.page
|
| 460 |
+
|
| 461 |
+
hs = d.highlight_sample
|
| 462 |
+
hs.focus_force()
|
| 463 |
+
hs.see(1.0)
|
| 464 |
+
hs.update_idletasks()
|
| 465 |
+
|
| 466 |
+
# Test binding from configdialog.
|
| 467 |
+
hs.event_generate('<Enter>', x=0, y=0)
|
| 468 |
+
hs.event_generate('<Motion>', x=0, y=0)
|
| 469 |
+
# Double click is a sequence of two clicks in a row.
|
| 470 |
+
for _ in range(2):
|
| 471 |
+
hs.event_generate('<ButtonPress-1>', x=0, y=0)
|
| 472 |
+
hs.event_generate('<ButtonRelease-1>', x=0, y=0)
|
| 473 |
+
|
| 474 |
+
eq(hs.tag_ranges('sel'), ())
|
| 475 |
+
|
| 476 |
+
def test_highlight_sample_b1_motion(self):
|
| 477 |
+
# Test button motion on highlight_sample.
|
| 478 |
+
eq = self.assertEqual
|
| 479 |
+
d = self.page
|
| 480 |
+
|
| 481 |
+
hs = d.highlight_sample
|
| 482 |
+
hs.focus_force()
|
| 483 |
+
hs.see(1.0)
|
| 484 |
+
hs.update_idletasks()
|
| 485 |
+
|
| 486 |
+
x, y, dx, dy, offset = hs.dlineinfo('1.0')
|
| 487 |
+
|
| 488 |
+
# Test binding from configdialog.
|
| 489 |
+
hs.event_generate('<Leave>')
|
| 490 |
+
hs.event_generate('<Enter>')
|
| 491 |
+
hs.event_generate('<Motion>', x=x, y=y)
|
| 492 |
+
hs.event_generate('<ButtonPress-1>', x=x, y=y)
|
| 493 |
+
hs.event_generate('<B1-Motion>', x=dx, y=dy)
|
| 494 |
+
hs.event_generate('<ButtonRelease-1>', x=dx, y=dy)
|
| 495 |
+
|
| 496 |
+
eq(hs.tag_ranges('sel'), ())
|
| 497 |
+
|
| 498 |
+
def test_set_theme_type(self):
|
| 499 |
+
eq = self.assertEqual
|
| 500 |
+
d = self.page
|
| 501 |
+
del d.set_theme_type
|
| 502 |
+
|
| 503 |
+
# Builtin theme selected.
|
| 504 |
+
d.theme_source.set(True)
|
| 505 |
+
d.set_theme_type()
|
| 506 |
+
eq(d.builtinlist['state'], NORMAL)
|
| 507 |
+
eq(d.customlist['state'], DISABLED)
|
| 508 |
+
eq(d.button_delete_custom.state(), ('disabled',))
|
| 509 |
+
|
| 510 |
+
# Custom theme selected.
|
| 511 |
+
d.theme_source.set(False)
|
| 512 |
+
d.set_theme_type()
|
| 513 |
+
eq(d.builtinlist['state'], DISABLED)
|
| 514 |
+
eq(d.custom_theme_on.state(), ('selected',))
|
| 515 |
+
eq(d.customlist['state'], NORMAL)
|
| 516 |
+
eq(d.button_delete_custom.state(), ())
|
| 517 |
+
d.set_theme_type = Func()
|
| 518 |
+
|
| 519 |
+
def test_get_color(self):
|
| 520 |
+
eq = self.assertEqual
|
| 521 |
+
d = self.page
|
| 522 |
+
orig_chooser = configdialog.colorchooser.askcolor
|
| 523 |
+
chooser = configdialog.colorchooser.askcolor = Func()
|
| 524 |
+
gntn = d.get_new_theme_name = Func()
|
| 525 |
+
|
| 526 |
+
d.highlight_target.set('Editor Breakpoint')
|
| 527 |
+
d.color.set('#ffffff')
|
| 528 |
+
|
| 529 |
+
# Nothing selected.
|
| 530 |
+
chooser.result = (None, None)
|
| 531 |
+
d.button_set_color.invoke()
|
| 532 |
+
eq(d.color.get(), '#ffffff')
|
| 533 |
+
|
| 534 |
+
# Selection same as previous color.
|
| 535 |
+
chooser.result = ('', d.style.lookup(d.frame_color_set['style'], 'background'))
|
| 536 |
+
d.button_set_color.invoke()
|
| 537 |
+
eq(d.color.get(), '#ffffff')
|
| 538 |
+
|
| 539 |
+
# Select different color.
|
| 540 |
+
chooser.result = ((222.8671875, 0.0, 0.0), '#de0000')
|
| 541 |
+
|
| 542 |
+
# Default theme.
|
| 543 |
+
d.color.set('#ffffff')
|
| 544 |
+
d.theme_source.set(True)
|
| 545 |
+
|
| 546 |
+
# No theme name selected therefore color not saved.
|
| 547 |
+
gntn.result = ''
|
| 548 |
+
d.button_set_color.invoke()
|
| 549 |
+
eq(gntn.called, 1)
|
| 550 |
+
eq(d.color.get(), '#ffffff')
|
| 551 |
+
# Theme name selected.
|
| 552 |
+
gntn.result = 'My New Theme'
|
| 553 |
+
d.button_set_color.invoke()
|
| 554 |
+
eq(d.custom_name.get(), gntn.result)
|
| 555 |
+
eq(d.color.get(), '#de0000')
|
| 556 |
+
|
| 557 |
+
# Custom theme.
|
| 558 |
+
d.color.set('#ffffff')
|
| 559 |
+
d.theme_source.set(False)
|
| 560 |
+
d.button_set_color.invoke()
|
| 561 |
+
eq(d.color.get(), '#de0000')
|
| 562 |
+
|
| 563 |
+
del d.get_new_theme_name
|
| 564 |
+
configdialog.colorchooser.askcolor = orig_chooser
|
| 565 |
+
|
| 566 |
+
def test_on_new_color_set(self):
|
| 567 |
+
d = self.page
|
| 568 |
+
color = '#3f7cae'
|
| 569 |
+
d.custom_name.set('Python')
|
| 570 |
+
d.highlight_target.set('Selected Text')
|
| 571 |
+
d.fg_bg_toggle.set(True)
|
| 572 |
+
|
| 573 |
+
d.color.set(color)
|
| 574 |
+
self.assertEqual(d.style.lookup(d.frame_color_set['style'], 'background'), color)
|
| 575 |
+
self.assertEqual(d.highlight_sample.tag_cget('hilite', 'foreground'), color)
|
| 576 |
+
self.assertEqual(highpage,
|
| 577 |
+
{'Python': {'hilite-foreground': color}})
|
| 578 |
+
|
| 579 |
+
def test_get_new_theme_name(self):
|
| 580 |
+
orig_sectionname = configdialog.SectionName
|
| 581 |
+
sn = configdialog.SectionName = Func(return_self=True)
|
| 582 |
+
d = self.page
|
| 583 |
+
|
| 584 |
+
sn.result = 'New Theme'
|
| 585 |
+
self.assertEqual(d.get_new_theme_name(''), 'New Theme')
|
| 586 |
+
|
| 587 |
+
configdialog.SectionName = orig_sectionname
|
| 588 |
+
|
| 589 |
+
def test_save_as_new_theme(self):
|
| 590 |
+
d = self.page
|
| 591 |
+
gntn = d.get_new_theme_name = Func()
|
| 592 |
+
d.theme_source.set(True)
|
| 593 |
+
|
| 594 |
+
# No name entered.
|
| 595 |
+
gntn.result = ''
|
| 596 |
+
d.button_save_custom.invoke()
|
| 597 |
+
self.assertNotIn(gntn.result, idleConf.userCfg['highlight'])
|
| 598 |
+
|
| 599 |
+
# Name entered.
|
| 600 |
+
gntn.result = 'my new theme'
|
| 601 |
+
gntn.called = 0
|
| 602 |
+
self.assertNotIn(gntn.result, idleConf.userCfg['highlight'])
|
| 603 |
+
d.button_save_custom.invoke()
|
| 604 |
+
self.assertIn(gntn.result, idleConf.userCfg['highlight'])
|
| 605 |
+
|
| 606 |
+
del d.get_new_theme_name
|
| 607 |
+
|
| 608 |
+
def test_create_new_and_save_new(self):
|
| 609 |
+
eq = self.assertEqual
|
| 610 |
+
d = self.page
|
| 611 |
+
|
| 612 |
+
# Use default as previously active theme.
|
| 613 |
+
d.theme_source.set(True)
|
| 614 |
+
d.builtin_name.set('IDLE Classic')
|
| 615 |
+
first_new = 'my new custom theme'
|
| 616 |
+
second_new = 'my second custom theme'
|
| 617 |
+
|
| 618 |
+
# No changes, so themes are an exact copy.
|
| 619 |
+
self.assertNotIn(first_new, idleConf.userCfg)
|
| 620 |
+
d.create_new(first_new)
|
| 621 |
+
eq(idleConf.GetSectionList('user', 'highlight'), [first_new])
|
| 622 |
+
eq(idleConf.GetThemeDict('default', 'IDLE Classic'),
|
| 623 |
+
idleConf.GetThemeDict('user', first_new))
|
| 624 |
+
eq(d.custom_name.get(), first_new)
|
| 625 |
+
self.assertFalse(d.theme_source.get()) # Use custom set.
|
| 626 |
+
eq(d.set_theme_type.called, 1)
|
| 627 |
+
|
| 628 |
+
# Test that changed targets are in new theme.
|
| 629 |
+
changes.add_option('highlight', first_new, 'hit-background', 'yellow')
|
| 630 |
+
self.assertNotIn(second_new, idleConf.userCfg)
|
| 631 |
+
d.create_new(second_new)
|
| 632 |
+
eq(idleConf.GetSectionList('user', 'highlight'), [first_new, second_new])
|
| 633 |
+
self.assertNotEqual(idleConf.GetThemeDict('user', first_new),
|
| 634 |
+
idleConf.GetThemeDict('user', second_new))
|
| 635 |
+
# Check that difference in themes was in `hit-background` from `changes`.
|
| 636 |
+
idleConf.SetOption('highlight', first_new, 'hit-background', 'yellow')
|
| 637 |
+
eq(idleConf.GetThemeDict('user', first_new),
|
| 638 |
+
idleConf.GetThemeDict('user', second_new))
|
| 639 |
+
|
| 640 |
+
def test_set_highlight_target(self):
|
| 641 |
+
eq = self.assertEqual
|
| 642 |
+
d = self.page
|
| 643 |
+
del d.set_highlight_target
|
| 644 |
+
|
| 645 |
+
# Target is cursor.
|
| 646 |
+
d.highlight_target.set('Cursor')
|
| 647 |
+
eq(d.fg_on.state(), ('disabled', 'selected'))
|
| 648 |
+
eq(d.bg_on.state(), ('disabled',))
|
| 649 |
+
self.assertTrue(d.fg_bg_toggle)
|
| 650 |
+
eq(d.set_color_sample.called, 1)
|
| 651 |
+
|
| 652 |
+
# Target is not cursor.
|
| 653 |
+
d.highlight_target.set('Comment')
|
| 654 |
+
eq(d.fg_on.state(), ('selected',))
|
| 655 |
+
eq(d.bg_on.state(), ())
|
| 656 |
+
self.assertTrue(d.fg_bg_toggle)
|
| 657 |
+
eq(d.set_color_sample.called, 2)
|
| 658 |
+
|
| 659 |
+
d.set_highlight_target = Func()
|
| 660 |
+
|
| 661 |
+
def test_set_color_sample_binding(self):
|
| 662 |
+
d = self.page
|
| 663 |
+
scs = d.set_color_sample
|
| 664 |
+
|
| 665 |
+
d.fg_on.invoke()
|
| 666 |
+
self.assertEqual(scs.called, 1)
|
| 667 |
+
|
| 668 |
+
d.bg_on.invoke()
|
| 669 |
+
self.assertEqual(scs.called, 2)
|
| 670 |
+
|
| 671 |
+
def test_set_color_sample(self):
|
| 672 |
+
d = self.page
|
| 673 |
+
del d.set_color_sample
|
| 674 |
+
d.highlight_target.set('Selected Text')
|
| 675 |
+
d.fg_bg_toggle.set(True)
|
| 676 |
+
d.set_color_sample()
|
| 677 |
+
self.assertEqual(
|
| 678 |
+
d.style.lookup(d.frame_color_set['style'], 'background'),
|
| 679 |
+
d.highlight_sample.tag_cget('hilite', 'foreground'))
|
| 680 |
+
d.set_color_sample = Func()
|
| 681 |
+
|
| 682 |
+
def test_paint_theme_sample(self):
|
| 683 |
+
eq = self.assertEqual
|
| 684 |
+
page = self.page
|
| 685 |
+
del page.paint_theme_sample # Delete masking mock.
|
| 686 |
+
hs_tag = page.highlight_sample.tag_cget
|
| 687 |
+
gh = idleConf.GetHighlight
|
| 688 |
+
|
| 689 |
+
# Create custom theme based on IDLE Dark.
|
| 690 |
+
page.theme_source.set(True)
|
| 691 |
+
page.builtin_name.set('IDLE Dark')
|
| 692 |
+
theme = 'IDLE Test'
|
| 693 |
+
page.create_new(theme)
|
| 694 |
+
page.set_color_sample.called = 0
|
| 695 |
+
|
| 696 |
+
# Base theme with nothing in `changes`.
|
| 697 |
+
page.paint_theme_sample()
|
| 698 |
+
new_console = {'foreground': 'blue',
|
| 699 |
+
'background': 'yellow',}
|
| 700 |
+
for key, value in new_console.items():
|
| 701 |
+
self.assertNotEqual(hs_tag('console', key), value)
|
| 702 |
+
eq(page.set_color_sample.called, 1)
|
| 703 |
+
|
| 704 |
+
# Apply changes.
|
| 705 |
+
for key, value in new_console.items():
|
| 706 |
+
changes.add_option('highlight', theme, 'console-'+key, value)
|
| 707 |
+
page.paint_theme_sample()
|
| 708 |
+
for key, value in new_console.items():
|
| 709 |
+
eq(hs_tag('console', key), value)
|
| 710 |
+
eq(page.set_color_sample.called, 2)
|
| 711 |
+
|
| 712 |
+
page.paint_theme_sample = Func()
|
| 713 |
+
|
| 714 |
+
def test_delete_custom(self):
|
| 715 |
+
eq = self.assertEqual
|
| 716 |
+
d = self.page
|
| 717 |
+
d.button_delete_custom.state(('!disabled',))
|
| 718 |
+
yesno = d.askyesno = Func()
|
| 719 |
+
dialog.deactivate_current_config = Func()
|
| 720 |
+
dialog.activate_config_changes = Func()
|
| 721 |
+
|
| 722 |
+
theme_name = 'spam theme'
|
| 723 |
+
idleConf.userCfg['highlight'].SetOption(theme_name, 'name', 'value')
|
| 724 |
+
highpage[theme_name] = {'option': 'True'}
|
| 725 |
+
|
| 726 |
+
theme_name2 = 'other theme'
|
| 727 |
+
idleConf.userCfg['highlight'].SetOption(theme_name2, 'name', 'value')
|
| 728 |
+
highpage[theme_name2] = {'option': 'False'}
|
| 729 |
+
|
| 730 |
+
# Force custom theme.
|
| 731 |
+
d.custom_theme_on.state(('!disabled',))
|
| 732 |
+
d.custom_theme_on.invoke()
|
| 733 |
+
d.custom_name.set(theme_name)
|
| 734 |
+
|
| 735 |
+
# Cancel deletion.
|
| 736 |
+
yesno.result = False
|
| 737 |
+
d.button_delete_custom.invoke()
|
| 738 |
+
eq(yesno.called, 1)
|
| 739 |
+
eq(highpage[theme_name], {'option': 'True'})
|
| 740 |
+
eq(idleConf.GetSectionList('user', 'highlight'), [theme_name, theme_name2])
|
| 741 |
+
eq(dialog.deactivate_current_config.called, 0)
|
| 742 |
+
eq(dialog.activate_config_changes.called, 0)
|
| 743 |
+
eq(d.set_theme_type.called, 0)
|
| 744 |
+
|
| 745 |
+
# Confirm deletion.
|
| 746 |
+
yesno.result = True
|
| 747 |
+
d.button_delete_custom.invoke()
|
| 748 |
+
eq(yesno.called, 2)
|
| 749 |
+
self.assertNotIn(theme_name, highpage)
|
| 750 |
+
eq(idleConf.GetSectionList('user', 'highlight'), [theme_name2])
|
| 751 |
+
eq(d.custom_theme_on.state(), ())
|
| 752 |
+
eq(d.custom_name.get(), theme_name2)
|
| 753 |
+
eq(dialog.deactivate_current_config.called, 1)
|
| 754 |
+
eq(dialog.activate_config_changes.called, 1)
|
| 755 |
+
eq(d.set_theme_type.called, 1)
|
| 756 |
+
|
| 757 |
+
# Confirm deletion of second theme - empties list.
|
| 758 |
+
d.custom_name.set(theme_name2)
|
| 759 |
+
yesno.result = True
|
| 760 |
+
d.button_delete_custom.invoke()
|
| 761 |
+
eq(yesno.called, 3)
|
| 762 |
+
self.assertNotIn(theme_name, highpage)
|
| 763 |
+
eq(idleConf.GetSectionList('user', 'highlight'), [])
|
| 764 |
+
eq(d.custom_theme_on.state(), ('disabled',))
|
| 765 |
+
eq(d.custom_name.get(), '- no custom themes -')
|
| 766 |
+
eq(dialog.deactivate_current_config.called, 2)
|
| 767 |
+
eq(dialog.activate_config_changes.called, 2)
|
| 768 |
+
eq(d.set_theme_type.called, 2)
|
| 769 |
+
|
| 770 |
+
del dialog.activate_config_changes, dialog.deactivate_current_config
|
| 771 |
+
del d.askyesno
|
| 772 |
+
|
| 773 |
+
|
| 774 |
+
class KeysPageTest(unittest.TestCase):
|
| 775 |
+
"""Test that keys tab widgets enable users to make changes.
|
| 776 |
+
|
| 777 |
+
Test that widget actions set vars, that var changes add
|
| 778 |
+
options to changes and that key sets works correctly.
|
| 779 |
+
"""
|
| 780 |
+
|
| 781 |
+
@classmethod
|
| 782 |
+
def setUpClass(cls):
|
| 783 |
+
page = cls.page = dialog.keyspage
|
| 784 |
+
dialog.note.select(page)
|
| 785 |
+
page.set_keys_type = Func()
|
| 786 |
+
page.load_keys_list = Func()
|
| 787 |
+
|
| 788 |
+
@classmethod
|
| 789 |
+
def tearDownClass(cls):
|
| 790 |
+
page = cls.page
|
| 791 |
+
del page.set_keys_type, page.load_keys_list
|
| 792 |
+
|
| 793 |
+
def setUp(self):
|
| 794 |
+
d = self.page
|
| 795 |
+
# The following is needed for test_load_key_cfg, _delete_custom_keys.
|
| 796 |
+
# This may indicate a defect in some test or function.
|
| 797 |
+
for section in idleConf.GetSectionList('user', 'keys'):
|
| 798 |
+
idleConf.userCfg['keys'].remove_section(section)
|
| 799 |
+
changes.clear()
|
| 800 |
+
d.set_keys_type.called = 0
|
| 801 |
+
d.load_keys_list.called = 0
|
| 802 |
+
|
| 803 |
+
def test_load_key_cfg(self):
|
| 804 |
+
tracers.detach()
|
| 805 |
+
d = self.page
|
| 806 |
+
eq = self.assertEqual
|
| 807 |
+
|
| 808 |
+
# Use builtin keyset with no user keysets created.
|
| 809 |
+
idleConf.CurrentKeys = mock.Mock(return_value='IDLE Classic OSX')
|
| 810 |
+
d.load_key_cfg()
|
| 811 |
+
self.assertTrue(d.keyset_source.get())
|
| 812 |
+
# builtinlist sets variable builtin_name to the CurrentKeys default.
|
| 813 |
+
eq(d.builtin_name.get(), 'IDLE Classic OSX')
|
| 814 |
+
eq(d.custom_name.get(), '- no custom keys -')
|
| 815 |
+
eq(d.custom_keyset_on.state(), ('disabled',))
|
| 816 |
+
eq(d.set_keys_type.called, 1)
|
| 817 |
+
eq(d.load_keys_list.called, 1)
|
| 818 |
+
eq(d.load_keys_list.args, ('IDLE Classic OSX', ))
|
| 819 |
+
|
| 820 |
+
# Builtin keyset with non-empty user keyset list.
|
| 821 |
+
idleConf.SetOption('keys', 'test1', 'option', 'value')
|
| 822 |
+
idleConf.SetOption('keys', 'test2', 'option2', 'value2')
|
| 823 |
+
d.load_key_cfg()
|
| 824 |
+
eq(d.builtin_name.get(), 'IDLE Classic OSX')
|
| 825 |
+
eq(d.custom_name.get(), 'test1')
|
| 826 |
+
eq(d.set_keys_type.called, 2)
|
| 827 |
+
eq(d.load_keys_list.called, 2)
|
| 828 |
+
eq(d.load_keys_list.args, ('IDLE Classic OSX', ))
|
| 829 |
+
|
| 830 |
+
# Use custom keyset.
|
| 831 |
+
idleConf.CurrentKeys = mock.Mock(return_value='test2')
|
| 832 |
+
idleConf.default_keys = mock.Mock(return_value='IDLE Modern Unix')
|
| 833 |
+
idleConf.SetOption('main', 'Keys', 'default', '0')
|
| 834 |
+
d.load_key_cfg()
|
| 835 |
+
self.assertFalse(d.keyset_source.get())
|
| 836 |
+
eq(d.builtin_name.get(), 'IDLE Modern Unix')
|
| 837 |
+
eq(d.custom_name.get(), 'test2')
|
| 838 |
+
eq(d.set_keys_type.called, 3)
|
| 839 |
+
eq(d.load_keys_list.called, 3)
|
| 840 |
+
eq(d.load_keys_list.args, ('test2', ))
|
| 841 |
+
|
| 842 |
+
del idleConf.CurrentKeys, idleConf.default_keys
|
| 843 |
+
tracers.attach()
|
| 844 |
+
|
| 845 |
+
def test_keyset_source(self):
|
| 846 |
+
eq = self.assertEqual
|
| 847 |
+
d = self.page
|
| 848 |
+
# Test these separately.
|
| 849 |
+
d.var_changed_builtin_name = Func()
|
| 850 |
+
d.var_changed_custom_name = Func()
|
| 851 |
+
# Builtin selected.
|
| 852 |
+
d.builtin_keyset_on.invoke()
|
| 853 |
+
eq(mainpage, {'Keys': {'default': 'True'}})
|
| 854 |
+
eq(d.var_changed_builtin_name.called, 1)
|
| 855 |
+
eq(d.var_changed_custom_name.called, 0)
|
| 856 |
+
changes.clear()
|
| 857 |
+
|
| 858 |
+
# Custom selected.
|
| 859 |
+
d.custom_keyset_on.state(('!disabled',))
|
| 860 |
+
d.custom_keyset_on.invoke()
|
| 861 |
+
self.assertEqual(mainpage, {'Keys': {'default': 'False'}})
|
| 862 |
+
eq(d.var_changed_builtin_name.called, 1)
|
| 863 |
+
eq(d.var_changed_custom_name.called, 1)
|
| 864 |
+
del d.var_changed_builtin_name, d.var_changed_custom_name
|
| 865 |
+
|
| 866 |
+
def test_builtin_name(self):
|
| 867 |
+
eq = self.assertEqual
|
| 868 |
+
d = self.page
|
| 869 |
+
idleConf.userCfg['main'].remove_section('Keys')
|
| 870 |
+
item_list = ['IDLE Classic Windows', 'IDLE Classic OSX',
|
| 871 |
+
'IDLE Modern UNIX']
|
| 872 |
+
|
| 873 |
+
# Not in old_keys, defaults name to first item.
|
| 874 |
+
d.builtinlist.SetMenu(item_list, 'IDLE Modern UNIX')
|
| 875 |
+
eq(mainpage, {'Keys': {'name': 'IDLE Classic Windows',
|
| 876 |
+
'name2': 'IDLE Modern UNIX'}})
|
| 877 |
+
eq(d.keys_message['text'], 'New key set, see Help')
|
| 878 |
+
eq(d.load_keys_list.called, 1)
|
| 879 |
+
eq(d.load_keys_list.args, ('IDLE Modern UNIX', ))
|
| 880 |
+
|
| 881 |
+
# Not in old keys - uses name2.
|
| 882 |
+
changes.clear()
|
| 883 |
+
idleConf.SetOption('main', 'Keys', 'name', 'IDLE Classic Unix')
|
| 884 |
+
d.builtinlist.SetMenu(item_list, 'IDLE Modern UNIX')
|
| 885 |
+
eq(mainpage, {'Keys': {'name2': 'IDLE Modern UNIX'}})
|
| 886 |
+
eq(d.keys_message['text'], 'New key set, see Help')
|
| 887 |
+
eq(d.load_keys_list.called, 2)
|
| 888 |
+
eq(d.load_keys_list.args, ('IDLE Modern UNIX', ))
|
| 889 |
+
|
| 890 |
+
# Builtin name in old_keys.
|
| 891 |
+
changes.clear()
|
| 892 |
+
d.builtinlist.SetMenu(item_list, 'IDLE Classic OSX')
|
| 893 |
+
eq(mainpage, {'Keys': {'name': 'IDLE Classic OSX', 'name2': ''}})
|
| 894 |
+
eq(d.keys_message['text'], '')
|
| 895 |
+
eq(d.load_keys_list.called, 3)
|
| 896 |
+
eq(d.load_keys_list.args, ('IDLE Classic OSX', ))
|
| 897 |
+
|
| 898 |
+
def test_custom_name(self):
|
| 899 |
+
d = self.page
|
| 900 |
+
|
| 901 |
+
# If no selections, doesn't get added.
|
| 902 |
+
d.customlist.SetMenu([], '- no custom keys -')
|
| 903 |
+
self.assertNotIn('Keys', mainpage)
|
| 904 |
+
self.assertEqual(d.load_keys_list.called, 0)
|
| 905 |
+
|
| 906 |
+
# Custom name selected.
|
| 907 |
+
changes.clear()
|
| 908 |
+
d.customlist.SetMenu(['a', 'b', 'c'], 'c')
|
| 909 |
+
self.assertEqual(mainpage, {'Keys': {'name': 'c'}})
|
| 910 |
+
self.assertEqual(d.load_keys_list.called, 1)
|
| 911 |
+
|
| 912 |
+
def test_keybinding(self):
|
| 913 |
+
idleConf.SetOption('extensions', 'ZzDummy', 'enable', 'True')
|
| 914 |
+
d = self.page
|
| 915 |
+
d.custom_name.set('my custom keys')
|
| 916 |
+
d.bindingslist.delete(0, 'end')
|
| 917 |
+
d.bindingslist.insert(0, 'copy')
|
| 918 |
+
d.bindingslist.insert(1, 'z-in')
|
| 919 |
+
d.bindingslist.selection_set(0)
|
| 920 |
+
d.bindingslist.selection_anchor(0)
|
| 921 |
+
# Core binding - adds to keys.
|
| 922 |
+
d.keybinding.set('<Key-F11>')
|
| 923 |
+
self.assertEqual(keyspage,
|
| 924 |
+
{'my custom keys': {'copy': '<Key-F11>'}})
|
| 925 |
+
|
| 926 |
+
# Not a core binding - adds to extensions.
|
| 927 |
+
d.bindingslist.selection_set(1)
|
| 928 |
+
d.bindingslist.selection_anchor(1)
|
| 929 |
+
d.keybinding.set('<Key-F11>')
|
| 930 |
+
self.assertEqual(extpage,
|
| 931 |
+
{'ZzDummy_cfgBindings': {'z-in': '<Key-F11>'}})
|
| 932 |
+
|
| 933 |
+
def test_set_keys_type(self):
|
| 934 |
+
eq = self.assertEqual
|
| 935 |
+
d = self.page
|
| 936 |
+
del d.set_keys_type
|
| 937 |
+
|
| 938 |
+
# Builtin keyset selected.
|
| 939 |
+
d.keyset_source.set(True)
|
| 940 |
+
d.set_keys_type()
|
| 941 |
+
eq(d.builtinlist['state'], NORMAL)
|
| 942 |
+
eq(d.customlist['state'], DISABLED)
|
| 943 |
+
eq(d.button_delete_custom_keys.state(), ('disabled',))
|
| 944 |
+
|
| 945 |
+
# Custom keyset selected.
|
| 946 |
+
d.keyset_source.set(False)
|
| 947 |
+
d.set_keys_type()
|
| 948 |
+
eq(d.builtinlist['state'], DISABLED)
|
| 949 |
+
eq(d.custom_keyset_on.state(), ('selected',))
|
| 950 |
+
eq(d.customlist['state'], NORMAL)
|
| 951 |
+
eq(d.button_delete_custom_keys.state(), ())
|
| 952 |
+
d.set_keys_type = Func()
|
| 953 |
+
|
| 954 |
+
def test_get_new_keys(self):
|
| 955 |
+
eq = self.assertEqual
|
| 956 |
+
d = self.page
|
| 957 |
+
orig_getkeysdialog = configdialog.GetKeysWindow
|
| 958 |
+
gkd = configdialog.GetKeysWindow = Func(return_self=True)
|
| 959 |
+
gnkn = d.get_new_keys_name = Func()
|
| 960 |
+
|
| 961 |
+
d.button_new_keys.state(('!disabled',))
|
| 962 |
+
d.bindingslist.delete(0, 'end')
|
| 963 |
+
d.bindingslist.insert(0, 'copy - <Control-Shift-Key-C>')
|
| 964 |
+
d.bindingslist.selection_set(0)
|
| 965 |
+
d.bindingslist.selection_anchor(0)
|
| 966 |
+
d.keybinding.set('Key-a')
|
| 967 |
+
d.keyset_source.set(True) # Default keyset.
|
| 968 |
+
|
| 969 |
+
# Default keyset; no change to binding.
|
| 970 |
+
gkd.result = ''
|
| 971 |
+
d.button_new_keys.invoke()
|
| 972 |
+
eq(d.bindingslist.get('anchor'), 'copy - <Control-Shift-Key-C>')
|
| 973 |
+
# Keybinding isn't changed when there isn't a change entered.
|
| 974 |
+
eq(d.keybinding.get(), 'Key-a')
|
| 975 |
+
|
| 976 |
+
# Default keyset; binding changed.
|
| 977 |
+
gkd.result = '<Key-F11>'
|
| 978 |
+
# No keyset name selected therefore binding not saved.
|
| 979 |
+
gnkn.result = ''
|
| 980 |
+
d.button_new_keys.invoke()
|
| 981 |
+
eq(gnkn.called, 1)
|
| 982 |
+
eq(d.bindingslist.get('anchor'), 'copy - <Control-Shift-Key-C>')
|
| 983 |
+
# Keyset name selected.
|
| 984 |
+
gnkn.result = 'My New Key Set'
|
| 985 |
+
d.button_new_keys.invoke()
|
| 986 |
+
eq(d.custom_name.get(), gnkn.result)
|
| 987 |
+
eq(d.bindingslist.get('anchor'), 'copy - <Key-F11>')
|
| 988 |
+
eq(d.keybinding.get(), '<Key-F11>')
|
| 989 |
+
|
| 990 |
+
# User keyset; binding changed.
|
| 991 |
+
d.keyset_source.set(False) # Custom keyset.
|
| 992 |
+
gnkn.called = 0
|
| 993 |
+
gkd.result = '<Key-p>'
|
| 994 |
+
d.button_new_keys.invoke()
|
| 995 |
+
eq(gnkn.called, 0)
|
| 996 |
+
eq(d.bindingslist.get('anchor'), 'copy - <Key-p>')
|
| 997 |
+
eq(d.keybinding.get(), '<Key-p>')
|
| 998 |
+
|
| 999 |
+
del d.get_new_keys_name
|
| 1000 |
+
configdialog.GetKeysWindow = orig_getkeysdialog
|
| 1001 |
+
|
| 1002 |
+
def test_get_new_keys_name(self):
|
| 1003 |
+
orig_sectionname = configdialog.SectionName
|
| 1004 |
+
sn = configdialog.SectionName = Func(return_self=True)
|
| 1005 |
+
d = self.page
|
| 1006 |
+
|
| 1007 |
+
sn.result = 'New Keys'
|
| 1008 |
+
self.assertEqual(d.get_new_keys_name(''), 'New Keys')
|
| 1009 |
+
|
| 1010 |
+
configdialog.SectionName = orig_sectionname
|
| 1011 |
+
|
| 1012 |
+
def test_save_as_new_key_set(self):
|
| 1013 |
+
d = self.page
|
| 1014 |
+
gnkn = d.get_new_keys_name = Func()
|
| 1015 |
+
d.keyset_source.set(True)
|
| 1016 |
+
|
| 1017 |
+
# No name entered.
|
| 1018 |
+
gnkn.result = ''
|
| 1019 |
+
d.button_save_custom_keys.invoke()
|
| 1020 |
+
|
| 1021 |
+
# Name entered.
|
| 1022 |
+
gnkn.result = 'my new key set'
|
| 1023 |
+
gnkn.called = 0
|
| 1024 |
+
self.assertNotIn(gnkn.result, idleConf.userCfg['keys'])
|
| 1025 |
+
d.button_save_custom_keys.invoke()
|
| 1026 |
+
self.assertIn(gnkn.result, idleConf.userCfg['keys'])
|
| 1027 |
+
|
| 1028 |
+
del d.get_new_keys_name
|
| 1029 |
+
|
| 1030 |
+
def test_on_bindingslist_select(self):
|
| 1031 |
+
d = self.page
|
| 1032 |
+
b = d.bindingslist
|
| 1033 |
+
b.delete(0, 'end')
|
| 1034 |
+
b.insert(0, 'copy')
|
| 1035 |
+
b.insert(1, 'find')
|
| 1036 |
+
b.activate(0)
|
| 1037 |
+
|
| 1038 |
+
b.focus_force()
|
| 1039 |
+
b.see(1)
|
| 1040 |
+
b.update()
|
| 1041 |
+
x, y, dx, dy = b.bbox(1)
|
| 1042 |
+
x += dx // 2
|
| 1043 |
+
y += dy // 2
|
| 1044 |
+
b.event_generate('<Enter>', x=0, y=0)
|
| 1045 |
+
b.event_generate('<Motion>', x=x, y=y)
|
| 1046 |
+
b.event_generate('<Button-1>', x=x, y=y)
|
| 1047 |
+
b.event_generate('<ButtonRelease-1>', x=x, y=y)
|
| 1048 |
+
self.assertEqual(b.get('anchor'), 'find')
|
| 1049 |
+
self.assertEqual(d.button_new_keys.state(), ())
|
| 1050 |
+
|
| 1051 |
+
def test_create_new_key_set_and_save_new_key_set(self):
|
| 1052 |
+
eq = self.assertEqual
|
| 1053 |
+
d = self.page
|
| 1054 |
+
|
| 1055 |
+
# Use default as previously active keyset.
|
| 1056 |
+
d.keyset_source.set(True)
|
| 1057 |
+
d.builtin_name.set('IDLE Classic Windows')
|
| 1058 |
+
first_new = 'my new custom key set'
|
| 1059 |
+
second_new = 'my second custom keyset'
|
| 1060 |
+
|
| 1061 |
+
# No changes, so keysets are an exact copy.
|
| 1062 |
+
self.assertNotIn(first_new, idleConf.userCfg)
|
| 1063 |
+
d.create_new_key_set(first_new)
|
| 1064 |
+
eq(idleConf.GetSectionList('user', 'keys'), [first_new])
|
| 1065 |
+
eq(idleConf.GetKeySet('IDLE Classic Windows'),
|
| 1066 |
+
idleConf.GetKeySet(first_new))
|
| 1067 |
+
eq(d.custom_name.get(), first_new)
|
| 1068 |
+
self.assertFalse(d.keyset_source.get()) # Use custom set.
|
| 1069 |
+
eq(d.set_keys_type.called, 1)
|
| 1070 |
+
|
| 1071 |
+
# Test that changed keybindings are in new keyset.
|
| 1072 |
+
changes.add_option('keys', first_new, 'copy', '<Key-F11>')
|
| 1073 |
+
self.assertNotIn(second_new, idleConf.userCfg)
|
| 1074 |
+
d.create_new_key_set(second_new)
|
| 1075 |
+
eq(idleConf.GetSectionList('user', 'keys'), [first_new, second_new])
|
| 1076 |
+
self.assertNotEqual(idleConf.GetKeySet(first_new),
|
| 1077 |
+
idleConf.GetKeySet(second_new))
|
| 1078 |
+
# Check that difference in keysets was in option `copy` from `changes`.
|
| 1079 |
+
idleConf.SetOption('keys', first_new, 'copy', '<Key-F11>')
|
| 1080 |
+
eq(idleConf.GetKeySet(first_new), idleConf.GetKeySet(second_new))
|
| 1081 |
+
|
| 1082 |
+
def test_load_keys_list(self):
|
| 1083 |
+
eq = self.assertEqual
|
| 1084 |
+
d = self.page
|
| 1085 |
+
gks = idleConf.GetKeySet = Func()
|
| 1086 |
+
del d.load_keys_list
|
| 1087 |
+
b = d.bindingslist
|
| 1088 |
+
|
| 1089 |
+
b.delete(0, 'end')
|
| 1090 |
+
b.insert(0, '<<find>>')
|
| 1091 |
+
b.insert(1, '<<help>>')
|
| 1092 |
+
gks.result = {'<<copy>>': ['<Control-Key-c>', '<Control-Key-C>'],
|
| 1093 |
+
'<<force-open-completions>>': ['<Control-Key-space>'],
|
| 1094 |
+
'<<spam>>': ['<Key-F11>']}
|
| 1095 |
+
changes.add_option('keys', 'my keys', 'spam', '<Shift-Key-a>')
|
| 1096 |
+
expected = ('copy - <Control-Key-c> <Control-Key-C>',
|
| 1097 |
+
'force-open-completions - <Control-Key-space>',
|
| 1098 |
+
'spam - <Shift-Key-a>')
|
| 1099 |
+
|
| 1100 |
+
# No current selection.
|
| 1101 |
+
d.load_keys_list('my keys')
|
| 1102 |
+
eq(b.get(0, 'end'), expected)
|
| 1103 |
+
eq(b.get('anchor'), '')
|
| 1104 |
+
eq(b.curselection(), ())
|
| 1105 |
+
|
| 1106 |
+
# Check selection.
|
| 1107 |
+
b.selection_set(1)
|
| 1108 |
+
b.selection_anchor(1)
|
| 1109 |
+
d.load_keys_list('my keys')
|
| 1110 |
+
eq(b.get(0, 'end'), expected)
|
| 1111 |
+
eq(b.get('anchor'), 'force-open-completions - <Control-Key-space>')
|
| 1112 |
+
eq(b.curselection(), (1, ))
|
| 1113 |
+
|
| 1114 |
+
# Change selection.
|
| 1115 |
+
b.selection_set(2)
|
| 1116 |
+
b.selection_anchor(2)
|
| 1117 |
+
d.load_keys_list('my keys')
|
| 1118 |
+
eq(b.get(0, 'end'), expected)
|
| 1119 |
+
eq(b.get('anchor'), 'spam - <Shift-Key-a>')
|
| 1120 |
+
eq(b.curselection(), (2, ))
|
| 1121 |
+
d.load_keys_list = Func()
|
| 1122 |
+
|
| 1123 |
+
del idleConf.GetKeySet
|
| 1124 |
+
|
| 1125 |
+
def test_delete_custom_keys(self):
|
| 1126 |
+
eq = self.assertEqual
|
| 1127 |
+
d = self.page
|
| 1128 |
+
d.button_delete_custom_keys.state(('!disabled',))
|
| 1129 |
+
yesno = d.askyesno = Func()
|
| 1130 |
+
dialog.deactivate_current_config = Func()
|
| 1131 |
+
dialog.activate_config_changes = Func()
|
| 1132 |
+
|
| 1133 |
+
keyset_name = 'spam key set'
|
| 1134 |
+
idleConf.userCfg['keys'].SetOption(keyset_name, 'name', 'value')
|
| 1135 |
+
keyspage[keyset_name] = {'option': 'True'}
|
| 1136 |
+
|
| 1137 |
+
keyset_name2 = 'other key set'
|
| 1138 |
+
idleConf.userCfg['keys'].SetOption(keyset_name2, 'name', 'value')
|
| 1139 |
+
keyspage[keyset_name2] = {'option': 'False'}
|
| 1140 |
+
|
| 1141 |
+
# Force custom keyset.
|
| 1142 |
+
d.custom_keyset_on.state(('!disabled',))
|
| 1143 |
+
d.custom_keyset_on.invoke()
|
| 1144 |
+
d.custom_name.set(keyset_name)
|
| 1145 |
+
|
| 1146 |
+
# Cancel deletion.
|
| 1147 |
+
yesno.result = False
|
| 1148 |
+
d.button_delete_custom_keys.invoke()
|
| 1149 |
+
eq(yesno.called, 1)
|
| 1150 |
+
eq(keyspage[keyset_name], {'option': 'True'})
|
| 1151 |
+
eq(idleConf.GetSectionList('user', 'keys'), [keyset_name, keyset_name2])
|
| 1152 |
+
eq(dialog.deactivate_current_config.called, 0)
|
| 1153 |
+
eq(dialog.activate_config_changes.called, 0)
|
| 1154 |
+
eq(d.set_keys_type.called, 0)
|
| 1155 |
+
|
| 1156 |
+
# Confirm deletion.
|
| 1157 |
+
yesno.result = True
|
| 1158 |
+
d.button_delete_custom_keys.invoke()
|
| 1159 |
+
eq(yesno.called, 2)
|
| 1160 |
+
self.assertNotIn(keyset_name, keyspage)
|
| 1161 |
+
eq(idleConf.GetSectionList('user', 'keys'), [keyset_name2])
|
| 1162 |
+
eq(d.custom_keyset_on.state(), ())
|
| 1163 |
+
eq(d.custom_name.get(), keyset_name2)
|
| 1164 |
+
eq(dialog.deactivate_current_config.called, 1)
|
| 1165 |
+
eq(dialog.activate_config_changes.called, 1)
|
| 1166 |
+
eq(d.set_keys_type.called, 1)
|
| 1167 |
+
|
| 1168 |
+
# Confirm deletion of second keyset - empties list.
|
| 1169 |
+
d.custom_name.set(keyset_name2)
|
| 1170 |
+
yesno.result = True
|
| 1171 |
+
d.button_delete_custom_keys.invoke()
|
| 1172 |
+
eq(yesno.called, 3)
|
| 1173 |
+
self.assertNotIn(keyset_name, keyspage)
|
| 1174 |
+
eq(idleConf.GetSectionList('user', 'keys'), [])
|
| 1175 |
+
eq(d.custom_keyset_on.state(), ('disabled',))
|
| 1176 |
+
eq(d.custom_name.get(), '- no custom keys -')
|
| 1177 |
+
eq(dialog.deactivate_current_config.called, 2)
|
| 1178 |
+
eq(dialog.activate_config_changes.called, 2)
|
| 1179 |
+
eq(d.set_keys_type.called, 2)
|
| 1180 |
+
|
| 1181 |
+
del dialog.activate_config_changes, dialog.deactivate_current_config
|
| 1182 |
+
del d.askyesno
|
| 1183 |
+
|
| 1184 |
+
|
| 1185 |
+
class WinPageTest(unittest.TestCase):
|
| 1186 |
+
"""Test that general tab widgets enable users to make changes.
|
| 1187 |
+
|
| 1188 |
+
Test that widget actions set vars, that var changes add
|
| 1189 |
+
options to changes.
|
| 1190 |
+
"""
|
| 1191 |
+
@classmethod
|
| 1192 |
+
def setUpClass(cls):
|
| 1193 |
+
page = cls.page = dialog.winpage
|
| 1194 |
+
dialog.note.select(page)
|
| 1195 |
+
page.update()
|
| 1196 |
+
|
| 1197 |
+
def setUp(self):
|
| 1198 |
+
changes.clear()
|
| 1199 |
+
|
| 1200 |
+
def test_load_windows_cfg(self):
|
| 1201 |
+
# Set to wrong values, load, check right values.
|
| 1202 |
+
eq = self.assertEqual
|
| 1203 |
+
d = self.page
|
| 1204 |
+
d.startup_edit.set(1)
|
| 1205 |
+
d.win_width.set(1)
|
| 1206 |
+
d.win_height.set(1)
|
| 1207 |
+
d.load_windows_cfg()
|
| 1208 |
+
eq(d.startup_edit.get(), 0)
|
| 1209 |
+
eq(d.win_width.get(), '80')
|
| 1210 |
+
eq(d.win_height.get(), '40')
|
| 1211 |
+
|
| 1212 |
+
def test_startup(self):
|
| 1213 |
+
d = self.page
|
| 1214 |
+
d.startup_editor_on.invoke()
|
| 1215 |
+
self.assertEqual(mainpage,
|
| 1216 |
+
{'General': {'editor-on-startup': '1'}})
|
| 1217 |
+
changes.clear()
|
| 1218 |
+
d.startup_shell_on.invoke()
|
| 1219 |
+
self.assertEqual(mainpage,
|
| 1220 |
+
{'General': {'editor-on-startup': '0'}})
|
| 1221 |
+
|
| 1222 |
+
def test_editor_size(self):
|
| 1223 |
+
d = self.page
|
| 1224 |
+
d.win_height_int.delete(0, 'end')
|
| 1225 |
+
d.win_height_int.insert(0, '11')
|
| 1226 |
+
self.assertEqual(mainpage, {'EditorWindow': {'height': '11'}})
|
| 1227 |
+
changes.clear()
|
| 1228 |
+
d.win_width_int.delete(0, 'end')
|
| 1229 |
+
d.win_width_int.insert(0, '11')
|
| 1230 |
+
self.assertEqual(mainpage, {'EditorWindow': {'width': '11'}})
|
| 1231 |
+
|
| 1232 |
+
def test_indent_spaces(self):
|
| 1233 |
+
d = self.page
|
| 1234 |
+
d.indent_chooser.set(6)
|
| 1235 |
+
self.assertEqual(d.indent_spaces.get(), '6')
|
| 1236 |
+
self.assertEqual(mainpage, {'Indent': {'num-spaces': '6'}})
|
| 1237 |
+
|
| 1238 |
+
def test_cursor_blink(self):
|
| 1239 |
+
self.page.cursor_blink_bool.invoke()
|
| 1240 |
+
self.assertEqual(mainpage, {'EditorWindow': {'cursor-blink': 'False'}})
|
| 1241 |
+
|
| 1242 |
+
def test_autocomplete_wait(self):
|
| 1243 |
+
self.page.auto_wait_int.delete(0, 'end')
|
| 1244 |
+
self.page.auto_wait_int.insert(0, '11')
|
| 1245 |
+
self.assertEqual(extpage, {'AutoComplete': {'popupwait': '11'}})
|
| 1246 |
+
|
| 1247 |
+
def test_parenmatch(self):
|
| 1248 |
+
d = self.page
|
| 1249 |
+
eq = self.assertEqual
|
| 1250 |
+
d.paren_style_type['menu'].invoke(0)
|
| 1251 |
+
eq(extpage, {'ParenMatch': {'style': 'opener'}})
|
| 1252 |
+
changes.clear()
|
| 1253 |
+
d.paren_flash_time.delete(0, 'end')
|
| 1254 |
+
d.paren_flash_time.insert(0, '11')
|
| 1255 |
+
eq(extpage, {'ParenMatch': {'flash-delay': '11'}})
|
| 1256 |
+
changes.clear()
|
| 1257 |
+
d.bell_on.invoke()
|
| 1258 |
+
eq(extpage, {'ParenMatch': {'bell': 'False'}})
|
| 1259 |
+
|
| 1260 |
+
def test_paragraph(self):
|
| 1261 |
+
self.page.format_width_int.delete(0, 'end')
|
| 1262 |
+
self.page.format_width_int.insert(0, '11')
|
| 1263 |
+
self.assertEqual(extpage, {'FormatParagraph': {'max-width': '11'}})
|
| 1264 |
+
|
| 1265 |
+
|
| 1266 |
+
class ShedPageTest(unittest.TestCase):
|
| 1267 |
+
"""Test that shed tab widgets enable users to make changes.
|
| 1268 |
+
|
| 1269 |
+
Test that widget actions set vars, that var changes add
|
| 1270 |
+
options to changes.
|
| 1271 |
+
"""
|
| 1272 |
+
@classmethod
|
| 1273 |
+
def setUpClass(cls):
|
| 1274 |
+
page = cls.page = dialog.shedpage
|
| 1275 |
+
dialog.note.select(page)
|
| 1276 |
+
page.update()
|
| 1277 |
+
|
| 1278 |
+
def setUp(self):
|
| 1279 |
+
changes.clear()
|
| 1280 |
+
|
| 1281 |
+
def test_load_shelled_cfg(self):
|
| 1282 |
+
# Set to wrong values, load, check right values.
|
| 1283 |
+
eq = self.assertEqual
|
| 1284 |
+
d = self.page
|
| 1285 |
+
d.autosave.set(1)
|
| 1286 |
+
d.load_shelled_cfg()
|
| 1287 |
+
eq(d.autosave.get(), 0)
|
| 1288 |
+
|
| 1289 |
+
def test_autosave(self):
|
| 1290 |
+
d = self.page
|
| 1291 |
+
d.save_auto_on.invoke()
|
| 1292 |
+
self.assertEqual(mainpage, {'General': {'autosave': '1'}})
|
| 1293 |
+
d.save_ask_on.invoke()
|
| 1294 |
+
self.assertEqual(mainpage, {'General': {'autosave': '0'}})
|
| 1295 |
+
|
| 1296 |
+
def test_context(self):
|
| 1297 |
+
self.page.context_int.delete(0, 'end')
|
| 1298 |
+
self.page.context_int.insert(0, '1')
|
| 1299 |
+
self.assertEqual(extpage, {'CodeContext': {'maxlines': '1'}})
|
| 1300 |
+
|
| 1301 |
+
|
| 1302 |
+
#unittest.skip("Nothing here yet TODO")
|
| 1303 |
+
class ExtPageTest(unittest.TestCase):
|
| 1304 |
+
"""Test that the help source list works correctly."""
|
| 1305 |
+
@classmethod
|
| 1306 |
+
def setUpClass(cls):
|
| 1307 |
+
page = dialog.extpage
|
| 1308 |
+
dialog.note.select(page)
|
| 1309 |
+
|
| 1310 |
+
|
| 1311 |
+
class HelpSourceTest(unittest.TestCase):
|
| 1312 |
+
"""Test that the help source list works correctly."""
|
| 1313 |
+
@classmethod
|
| 1314 |
+
def setUpClass(cls):
|
| 1315 |
+
page = dialog.extpage
|
| 1316 |
+
dialog.note.select(page)
|
| 1317 |
+
frame = cls.frame = page.frame_help
|
| 1318 |
+
frame.set = frame.set_add_delete_state = Func()
|
| 1319 |
+
frame.upc = frame.update_help_changes = Func()
|
| 1320 |
+
frame.update()
|
| 1321 |
+
|
| 1322 |
+
@classmethod
|
| 1323 |
+
def tearDownClass(cls):
|
| 1324 |
+
frame = cls.frame
|
| 1325 |
+
del frame.set, frame.set_add_delete_state
|
| 1326 |
+
del frame.upc, frame.update_help_changes
|
| 1327 |
+
frame.helplist.delete(0, 'end')
|
| 1328 |
+
frame.user_helplist.clear()
|
| 1329 |
+
|
| 1330 |
+
def setUp(self):
|
| 1331 |
+
changes.clear()
|
| 1332 |
+
|
| 1333 |
+
def test_load_helplist(self):
|
| 1334 |
+
eq = self.assertEqual
|
| 1335 |
+
fr = self.frame
|
| 1336 |
+
fr.helplist.insert('end', 'bad')
|
| 1337 |
+
fr.user_helplist = ['bad', 'worse']
|
| 1338 |
+
idleConf.SetOption('main', 'HelpFiles', '1', 'name;file')
|
| 1339 |
+
fr.load_helplist()
|
| 1340 |
+
eq(fr.helplist.get(0, 'end'), ('name',))
|
| 1341 |
+
eq(fr.user_helplist, [('name', 'file', '1')])
|
| 1342 |
+
|
| 1343 |
+
def test_source_selected(self):
|
| 1344 |
+
fr = self.frame
|
| 1345 |
+
fr.set = fr.set_add_delete_state
|
| 1346 |
+
fr.upc = fr.update_help_changes
|
| 1347 |
+
helplist = fr.helplist
|
| 1348 |
+
dex = 'end'
|
| 1349 |
+
helplist.insert(dex, 'source')
|
| 1350 |
+
helplist.activate(dex)
|
| 1351 |
+
|
| 1352 |
+
helplist.focus_force()
|
| 1353 |
+
helplist.see(dex)
|
| 1354 |
+
helplist.update()
|
| 1355 |
+
x, y, dx, dy = helplist.bbox(dex)
|
| 1356 |
+
x += dx // 2
|
| 1357 |
+
y += dy // 2
|
| 1358 |
+
fr.set.called = fr.upc.called = 0
|
| 1359 |
+
helplist.event_generate('<Enter>', x=0, y=0)
|
| 1360 |
+
helplist.event_generate('<Motion>', x=x, y=y)
|
| 1361 |
+
helplist.event_generate('<Button-1>', x=x, y=y)
|
| 1362 |
+
helplist.event_generate('<ButtonRelease-1>', x=x, y=y)
|
| 1363 |
+
self.assertEqual(helplist.get('anchor'), 'source')
|
| 1364 |
+
self.assertTrue(fr.set.called)
|
| 1365 |
+
self.assertFalse(fr.upc.called)
|
| 1366 |
+
|
| 1367 |
+
def test_set_add_delete_state(self):
|
| 1368 |
+
# Call with 0 items, 1 unselected item, 1 selected item.
|
| 1369 |
+
eq = self.assertEqual
|
| 1370 |
+
fr = self.frame
|
| 1371 |
+
del fr.set_add_delete_state # Unmask method.
|
| 1372 |
+
sad = fr.set_add_delete_state
|
| 1373 |
+
h = fr.helplist
|
| 1374 |
+
|
| 1375 |
+
h.delete(0, 'end')
|
| 1376 |
+
sad()
|
| 1377 |
+
eq(fr.button_helplist_edit.state(), ('disabled',))
|
| 1378 |
+
eq(fr.button_helplist_remove.state(), ('disabled',))
|
| 1379 |
+
|
| 1380 |
+
h.insert(0, 'source')
|
| 1381 |
+
sad()
|
| 1382 |
+
eq(fr.button_helplist_edit.state(), ('disabled',))
|
| 1383 |
+
eq(fr.button_helplist_remove.state(), ('disabled',))
|
| 1384 |
+
|
| 1385 |
+
h.selection_set(0)
|
| 1386 |
+
sad()
|
| 1387 |
+
eq(fr.button_helplist_edit.state(), ())
|
| 1388 |
+
eq(fr.button_helplist_remove.state(), ())
|
| 1389 |
+
fr.set_add_delete_state = Func() # Mask method.
|
| 1390 |
+
|
| 1391 |
+
def test_helplist_item_add(self):
|
| 1392 |
+
# Call without and twice with HelpSource result.
|
| 1393 |
+
# Double call enables check on order.
|
| 1394 |
+
eq = self.assertEqual
|
| 1395 |
+
orig_helpsource = configdialog.HelpSource
|
| 1396 |
+
hs = configdialog.HelpSource = Func(return_self=True)
|
| 1397 |
+
fr = self.frame
|
| 1398 |
+
fr.helplist.delete(0, 'end')
|
| 1399 |
+
fr.user_helplist.clear()
|
| 1400 |
+
fr.set.called = fr.upc.called = 0
|
| 1401 |
+
|
| 1402 |
+
hs.result = ''
|
| 1403 |
+
fr.helplist_item_add()
|
| 1404 |
+
self.assertTrue(list(fr.helplist.get(0, 'end')) ==
|
| 1405 |
+
fr.user_helplist == [])
|
| 1406 |
+
self.assertFalse(fr.upc.called)
|
| 1407 |
+
|
| 1408 |
+
hs.result = ('name1', 'file1')
|
| 1409 |
+
fr.helplist_item_add()
|
| 1410 |
+
hs.result = ('name2', 'file2')
|
| 1411 |
+
fr.helplist_item_add()
|
| 1412 |
+
eq(fr.helplist.get(0, 'end'), ('name1', 'name2'))
|
| 1413 |
+
eq(fr.user_helplist, [('name1', 'file1'), ('name2', 'file2')])
|
| 1414 |
+
eq(fr.upc.called, 2)
|
| 1415 |
+
self.assertFalse(fr.set.called)
|
| 1416 |
+
|
| 1417 |
+
configdialog.HelpSource = orig_helpsource
|
| 1418 |
+
|
| 1419 |
+
def test_helplist_item_edit(self):
|
| 1420 |
+
# Call without and with HelpSource change.
|
| 1421 |
+
eq = self.assertEqual
|
| 1422 |
+
orig_helpsource = configdialog.HelpSource
|
| 1423 |
+
hs = configdialog.HelpSource = Func(return_self=True)
|
| 1424 |
+
fr = self.frame
|
| 1425 |
+
fr.helplist.delete(0, 'end')
|
| 1426 |
+
fr.helplist.insert(0, 'name1')
|
| 1427 |
+
fr.helplist.selection_set(0)
|
| 1428 |
+
fr.helplist.selection_anchor(0)
|
| 1429 |
+
fr.user_helplist.clear()
|
| 1430 |
+
fr.user_helplist.append(('name1', 'file1'))
|
| 1431 |
+
fr.set.called = fr.upc.called = 0
|
| 1432 |
+
|
| 1433 |
+
hs.result = ''
|
| 1434 |
+
fr.helplist_item_edit()
|
| 1435 |
+
hs.result = ('name1', 'file1')
|
| 1436 |
+
fr.helplist_item_edit()
|
| 1437 |
+
eq(fr.helplist.get(0, 'end'), ('name1',))
|
| 1438 |
+
eq(fr.user_helplist, [('name1', 'file1')])
|
| 1439 |
+
self.assertFalse(fr.upc.called)
|
| 1440 |
+
|
| 1441 |
+
hs.result = ('name2', 'file2')
|
| 1442 |
+
fr.helplist_item_edit()
|
| 1443 |
+
eq(fr.helplist.get(0, 'end'), ('name2',))
|
| 1444 |
+
eq(fr.user_helplist, [('name2', 'file2')])
|
| 1445 |
+
self.assertTrue(fr.upc.called == fr.set.called == 1)
|
| 1446 |
+
|
| 1447 |
+
configdialog.HelpSource = orig_helpsource
|
| 1448 |
+
|
| 1449 |
+
def test_helplist_item_remove(self):
|
| 1450 |
+
eq = self.assertEqual
|
| 1451 |
+
fr = self.frame
|
| 1452 |
+
fr.helplist.delete(0, 'end')
|
| 1453 |
+
fr.helplist.insert(0, 'name1')
|
| 1454 |
+
fr.helplist.selection_set(0)
|
| 1455 |
+
fr.helplist.selection_anchor(0)
|
| 1456 |
+
fr.user_helplist.clear()
|
| 1457 |
+
fr.user_helplist.append(('name1', 'file1'))
|
| 1458 |
+
fr.set.called = fr.upc.called = 0
|
| 1459 |
+
|
| 1460 |
+
fr.helplist_item_remove()
|
| 1461 |
+
eq(fr.helplist.get(0, 'end'), ())
|
| 1462 |
+
eq(fr.user_helplist, [])
|
| 1463 |
+
self.assertTrue(fr.upc.called == fr.set.called == 1)
|
| 1464 |
+
|
| 1465 |
+
def test_update_help_changes(self):
|
| 1466 |
+
fr = self.frame
|
| 1467 |
+
del fr.update_help_changes
|
| 1468 |
+
fr.user_helplist.clear()
|
| 1469 |
+
fr.user_helplist.append(('name1', 'file1'))
|
| 1470 |
+
fr.user_helplist.append(('name2', 'file2'))
|
| 1471 |
+
|
| 1472 |
+
fr.update_help_changes()
|
| 1473 |
+
self.assertEqual(mainpage['HelpFiles'],
|
| 1474 |
+
{'1': 'name1;file1', '2': 'name2;file2'})
|
| 1475 |
+
fr.update_help_changes = Func()
|
| 1476 |
+
|
| 1477 |
+
|
| 1478 |
+
class VarTraceTest(unittest.TestCase):
|
| 1479 |
+
|
| 1480 |
+
@classmethod
|
| 1481 |
+
def setUpClass(cls):
|
| 1482 |
+
cls.tracers = configdialog.VarTrace()
|
| 1483 |
+
cls.iv = IntVar(root)
|
| 1484 |
+
cls.bv = BooleanVar(root)
|
| 1485 |
+
|
| 1486 |
+
@classmethod
|
| 1487 |
+
def tearDownClass(cls):
|
| 1488 |
+
del cls.tracers, cls.iv, cls.bv
|
| 1489 |
+
|
| 1490 |
+
def setUp(self):
|
| 1491 |
+
self.tracers.clear()
|
| 1492 |
+
self.called = 0
|
| 1493 |
+
|
| 1494 |
+
def var_changed_increment(self, *params):
|
| 1495 |
+
self.called += 13
|
| 1496 |
+
|
| 1497 |
+
def var_changed_boolean(self, *params):
|
| 1498 |
+
pass
|
| 1499 |
+
|
| 1500 |
+
def test_init(self):
|
| 1501 |
+
tr = self.tracers
|
| 1502 |
+
tr.__init__()
|
| 1503 |
+
self.assertEqual(tr.untraced, [])
|
| 1504 |
+
self.assertEqual(tr.traced, [])
|
| 1505 |
+
|
| 1506 |
+
def test_clear(self):
|
| 1507 |
+
tr = self.tracers
|
| 1508 |
+
tr.untraced.append(0)
|
| 1509 |
+
tr.traced.append(1)
|
| 1510 |
+
tr.clear()
|
| 1511 |
+
self.assertEqual(tr.untraced, [])
|
| 1512 |
+
self.assertEqual(tr.traced, [])
|
| 1513 |
+
|
| 1514 |
+
def test_add(self):
|
| 1515 |
+
tr = self.tracers
|
| 1516 |
+
func = Func()
|
| 1517 |
+
cb = tr.make_callback = mock.Mock(return_value=func)
|
| 1518 |
+
|
| 1519 |
+
iv = tr.add(self.iv, self.var_changed_increment)
|
| 1520 |
+
self.assertIs(iv, self.iv)
|
| 1521 |
+
bv = tr.add(self.bv, self.var_changed_boolean)
|
| 1522 |
+
self.assertIs(bv, self.bv)
|
| 1523 |
+
|
| 1524 |
+
sv = StringVar(root)
|
| 1525 |
+
sv2 = tr.add(sv, ('main', 'section', 'option'))
|
| 1526 |
+
self.assertIs(sv2, sv)
|
| 1527 |
+
cb.assert_called_once()
|
| 1528 |
+
cb.assert_called_with(sv, ('main', 'section', 'option'))
|
| 1529 |
+
|
| 1530 |
+
expected = [(iv, self.var_changed_increment),
|
| 1531 |
+
(bv, self.var_changed_boolean),
|
| 1532 |
+
(sv, func)]
|
| 1533 |
+
self.assertEqual(tr.traced, [])
|
| 1534 |
+
self.assertEqual(tr.untraced, expected)
|
| 1535 |
+
|
| 1536 |
+
del tr.make_callback
|
| 1537 |
+
|
| 1538 |
+
def test_make_callback(self):
|
| 1539 |
+
cb = self.tracers.make_callback(self.iv, ('main', 'section', 'option'))
|
| 1540 |
+
self.assertTrue(callable(cb))
|
| 1541 |
+
self.iv.set(42)
|
| 1542 |
+
# Not attached, so set didn't invoke the callback.
|
| 1543 |
+
self.assertNotIn('section', changes['main'])
|
| 1544 |
+
# Invoke callback manually.
|
| 1545 |
+
cb()
|
| 1546 |
+
self.assertIn('section', changes['main'])
|
| 1547 |
+
self.assertEqual(changes['main']['section']['option'], '42')
|
| 1548 |
+
changes.clear()
|
| 1549 |
+
|
| 1550 |
+
def test_attach_detach(self):
|
| 1551 |
+
tr = self.tracers
|
| 1552 |
+
iv = tr.add(self.iv, self.var_changed_increment)
|
| 1553 |
+
bv = tr.add(self.bv, self.var_changed_boolean)
|
| 1554 |
+
expected = [(iv, self.var_changed_increment),
|
| 1555 |
+
(bv, self.var_changed_boolean)]
|
| 1556 |
+
|
| 1557 |
+
# Attach callbacks and test call increment.
|
| 1558 |
+
tr.attach()
|
| 1559 |
+
self.assertEqual(tr.untraced, [])
|
| 1560 |
+
self.assertCountEqual(tr.traced, expected)
|
| 1561 |
+
iv.set(1)
|
| 1562 |
+
self.assertEqual(iv.get(), 1)
|
| 1563 |
+
self.assertEqual(self.called, 13)
|
| 1564 |
+
|
| 1565 |
+
# Check that only one callback is attached to a variable.
|
| 1566 |
+
# If more than one callback were attached, then var_changed_increment
|
| 1567 |
+
# would be called twice and the counter would be 2.
|
| 1568 |
+
self.called = 0
|
| 1569 |
+
tr.attach()
|
| 1570 |
+
iv.set(1)
|
| 1571 |
+
self.assertEqual(self.called, 13)
|
| 1572 |
+
|
| 1573 |
+
# Detach callbacks.
|
| 1574 |
+
self.called = 0
|
| 1575 |
+
tr.detach()
|
| 1576 |
+
self.assertEqual(tr.traced, [])
|
| 1577 |
+
self.assertCountEqual(tr.untraced, expected)
|
| 1578 |
+
iv.set(1)
|
| 1579 |
+
self.assertEqual(self.called, 0)
|
| 1580 |
+
|
| 1581 |
+
|
| 1582 |
+
if __name__ == '__main__':
|
| 1583 |
+
unittest.main(verbosity=2)
|
evalkit_cambrian/lib/python3.10/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)
|
evalkit_cambrian/lib/python3.10/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])
|
| 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])
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
if __name__ == '__main__':
|
| 57 |
+
unittest.main(verbosity=2)
|
evalkit_cambrian/lib/python3.10/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>>')
|
| 70 |
+
self.assertEqual(spin.get(), ans)
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
if __name__ == '__main__':
|
| 74 |
+
unittest.main(verbosity=2)
|
evalkit_cambrian/lib/python3.10/idlelib/idle_test/test_editor.py
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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5 |
+
from collections import namedtuple
|
| 6 |
+
from test.support import requires
|
| 7 |
+
from tkinter import Tk
|
| 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 TestGetLineIndent(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() # 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 RMenuTest(unittest.TestCase):
|
| 185 |
+
|
| 186 |
+
@classmethod
|
| 187 |
+
def setUpClass(cls):
|
| 188 |
+
requires('gui')
|
| 189 |
+
cls.root = Tk()
|
| 190 |
+
cls.root.withdraw()
|
| 191 |
+
cls.window = Editor(root=cls.root)
|
| 192 |
+
|
| 193 |
+
@classmethod
|
| 194 |
+
def tearDownClass(cls):
|
| 195 |
+
cls.window._close()
|
| 196 |
+
del cls.window
|
| 197 |
+
cls.root.update_idletasks()
|
| 198 |
+
for id in cls.root.tk.call('after', 'info'):
|
| 199 |
+
cls.root.after_cancel(id)
|
| 200 |
+
cls.root.destroy()
|
| 201 |
+
del cls.root
|
| 202 |
+
|
| 203 |
+
class DummyRMenu:
|
| 204 |
+
def tk_popup(x, y): pass
|
| 205 |
+
|
| 206 |
+
def test_rclick(self):
|
| 207 |
+
pass
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
if __name__ == '__main__':
|
| 211 |
+
unittest.main(verbosity=2)
|
evalkit_cambrian/lib/python3.10/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)
|
evalkit_cambrian/lib/python3.10/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()
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 idlelib.idle_test.mock_tk import Var
|
| 12 |
+
import os
|
| 13 |
+
import re
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class Dummy_searchengine:
|
| 17 |
+
'''GrepDialog.__init__ calls parent SearchDiabolBase which attaches the
|
| 18 |
+
passed in SearchEngine instance as attribute 'engine'. Only a few of the
|
| 19 |
+
many possible self.engine.x attributes are needed here.
|
| 20 |
+
'''
|
| 21 |
+
def getpat(self):
|
| 22 |
+
return self._pat
|
| 23 |
+
|
| 24 |
+
searchengine = Dummy_searchengine()
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
class Dummy_grep:
|
| 28 |
+
# Methods tested
|
| 29 |
+
#default_command = GrepDialog.default_command
|
| 30 |
+
grep_it = grep.GrepDialog.grep_it
|
| 31 |
+
# Other stuff needed
|
| 32 |
+
recvar = Var(False)
|
| 33 |
+
engine = searchengine
|
| 34 |
+
def close(self): # gui method
|
| 35 |
+
pass
|
| 36 |
+
|
| 37 |
+
_grep = Dummy_grep()
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
class FindfilesTest(unittest.TestCase):
|
| 41 |
+
|
| 42 |
+
@classmethod
|
| 43 |
+
def setUpClass(cls):
|
| 44 |
+
cls.realpath = os.path.realpath(__file__)
|
| 45 |
+
cls.path = os.path.dirname(cls.realpath)
|
| 46 |
+
|
| 47 |
+
@classmethod
|
| 48 |
+
def tearDownClass(cls):
|
| 49 |
+
del cls.realpath, cls.path
|
| 50 |
+
|
| 51 |
+
def test_invaliddir(self):
|
| 52 |
+
with captured_stdout() as s:
|
| 53 |
+
filelist = list(grep.findfiles('invaliddir', '*.*', False))
|
| 54 |
+
self.assertEqual(filelist, [])
|
| 55 |
+
self.assertIn('invalid', s.getvalue())
|
| 56 |
+
|
| 57 |
+
def test_curdir(self):
|
| 58 |
+
# Test os.curdir.
|
| 59 |
+
ff = grep.findfiles
|
| 60 |
+
save_cwd = os.getcwd()
|
| 61 |
+
os.chdir(self.path)
|
| 62 |
+
filename = 'test_grep.py'
|
| 63 |
+
filelist = list(ff(os.curdir, filename, False))
|
| 64 |
+
self.assertIn(os.path.join(os.curdir, filename), filelist)
|
| 65 |
+
os.chdir(save_cwd)
|
| 66 |
+
|
| 67 |
+
def test_base(self):
|
| 68 |
+
ff = grep.findfiles
|
| 69 |
+
readme = os.path.join(self.path, 'README.txt')
|
| 70 |
+
|
| 71 |
+
# Check for Python files in path where this file lives.
|
| 72 |
+
filelist = list(ff(self.path, '*.py', False))
|
| 73 |
+
# This directory has many Python files.
|
| 74 |
+
self.assertGreater(len(filelist), 10)
|
| 75 |
+
self.assertIn(self.realpath, filelist)
|
| 76 |
+
self.assertNotIn(readme, filelist)
|
| 77 |
+
|
| 78 |
+
# Look for .txt files in path where this file lives.
|
| 79 |
+
filelist = list(ff(self.path, '*.txt', False))
|
| 80 |
+
self.assertNotEqual(len(filelist), 0)
|
| 81 |
+
self.assertNotIn(self.realpath, filelist)
|
| 82 |
+
self.assertIn(readme, filelist)
|
| 83 |
+
|
| 84 |
+
# Look for non-matching pattern.
|
| 85 |
+
filelist = list(ff(self.path, 'grep.*', False))
|
| 86 |
+
self.assertEqual(len(filelist), 0)
|
| 87 |
+
self.assertNotIn(self.realpath, filelist)
|
| 88 |
+
|
| 89 |
+
def test_recurse(self):
|
| 90 |
+
ff = grep.findfiles
|
| 91 |
+
parent = os.path.dirname(self.path)
|
| 92 |
+
grepfile = os.path.join(parent, 'grep.py')
|
| 93 |
+
pat = '*.py'
|
| 94 |
+
|
| 95 |
+
# Get Python files only in parent directory.
|
| 96 |
+
filelist = list(ff(parent, pat, False))
|
| 97 |
+
parent_size = len(filelist)
|
| 98 |
+
# Lots of Python files in idlelib.
|
| 99 |
+
self.assertGreater(parent_size, 20)
|
| 100 |
+
self.assertIn(grepfile, filelist)
|
| 101 |
+
# Without subdirectories, this file isn't returned.
|
| 102 |
+
self.assertNotIn(self.realpath, filelist)
|
| 103 |
+
|
| 104 |
+
# Include subdirectories.
|
| 105 |
+
filelist = list(ff(parent, pat, True))
|
| 106 |
+
# More files found now.
|
| 107 |
+
self.assertGreater(len(filelist), parent_size)
|
| 108 |
+
self.assertIn(grepfile, filelist)
|
| 109 |
+
# This file exists in list now.
|
| 110 |
+
self.assertIn(self.realpath, filelist)
|
| 111 |
+
|
| 112 |
+
# Check another level up the tree.
|
| 113 |
+
parent = os.path.dirname(parent)
|
| 114 |
+
filelist = list(ff(parent, '*.py', True))
|
| 115 |
+
self.assertIn(self.realpath, filelist)
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
class Grep_itTest(unittest.TestCase):
|
| 119 |
+
# Test captured reports with 0 and some hits.
|
| 120 |
+
# Should test file names, but Windows reports have mixed / and \ separators
|
| 121 |
+
# from incomplete replacement, so 'later'.
|
| 122 |
+
|
| 123 |
+
def report(self, pat):
|
| 124 |
+
_grep.engine._pat = pat
|
| 125 |
+
with captured_stdout() as s:
|
| 126 |
+
_grep.grep_it(re.compile(pat), __file__)
|
| 127 |
+
lines = s.getvalue().split('\n')
|
| 128 |
+
lines.pop() # remove bogus '' after last \n
|
| 129 |
+
return lines
|
| 130 |
+
|
| 131 |
+
def test_unfound(self):
|
| 132 |
+
pat = 'xyz*'*7
|
| 133 |
+
lines = self.report(pat)
|
| 134 |
+
self.assertEqual(len(lines), 2)
|
| 135 |
+
self.assertIn(pat, lines[0])
|
| 136 |
+
self.assertEqual(lines[1], 'No hits.')
|
| 137 |
+
|
| 138 |
+
def test_found(self):
|
| 139 |
+
|
| 140 |
+
pat = '""" !Changing this line will break Test_findfile.test_found!'
|
| 141 |
+
lines = self.report(pat)
|
| 142 |
+
self.assertEqual(len(lines), 5)
|
| 143 |
+
self.assertIn(pat, lines[0])
|
| 144 |
+
self.assertIn('py: 1:', lines[1]) # line number 1
|
| 145 |
+
self.assertIn('2', lines[3]) # hits found 2
|
| 146 |
+
self.assertTrue(lines[4].startswith('(Hint:'))
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
class Default_commandTest(unittest.TestCase):
|
| 150 |
+
# To write this, move outwin import to top of GrepDialog
|
| 151 |
+
# so it can be replaced by captured_stdout in class setup/teardown.
|
| 152 |
+
pass
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
if __name__ == '__main__':
|
| 156 |
+
unittest.main(verbosity=2)
|
evalkit_cambrian/lib/python3.10/idlelib/idle_test/test_help.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"Test help, coverage 87%."
|
| 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 HelpFrameTest(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 |
+
helpfile = join(dirname(dirname(abspath(__file__))), 'help.html')
|
| 19 |
+
cls.frame = help.HelpFrame(root, helpfile)
|
| 20 |
+
|
| 21 |
+
@classmethod
|
| 22 |
+
def tearDownClass(cls):
|
| 23 |
+
del cls.frame
|
| 24 |
+
cls.root.update_idletasks()
|
| 25 |
+
cls.root.destroy()
|
| 26 |
+
del cls.root
|
| 27 |
+
|
| 28 |
+
def test_line1(self):
|
| 29 |
+
text = self.frame.text
|
| 30 |
+
self.assertEqual(text.get('1.0', '1.end'), ' IDLE ')
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
if __name__ == '__main__':
|
| 34 |
+
unittest.main(verbosity=2)
|
evalkit_cambrian/lib/python3.10/idlelib/idle_test/test_help_about.py
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Test help_about, coverage 100%.
|
| 2 |
+
help_about.build_bits branches on sys.platform='darwin'.
|
| 3 |
+
'100% combines coverage on Mac and others.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
from idlelib import help_about
|
| 7 |
+
import unittest
|
| 8 |
+
from test.support import requires, findfile
|
| 9 |
+
from tkinter import Tk, TclError
|
| 10 |
+
from idlelib.idle_test.mock_idle import Func
|
| 11 |
+
from idlelib.idle_test.mock_tk import Mbox_func
|
| 12 |
+
from idlelib import textview
|
| 13 |
+
import os.path
|
| 14 |
+
from platform import python_version
|
| 15 |
+
|
| 16 |
+
About = help_about.AboutDialog
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class LiveDialogTest(unittest.TestCase):
|
| 20 |
+
"""Simulate user clicking buttons other than [Close].
|
| 21 |
+
|
| 22 |
+
Test that invoked textview has text from source.
|
| 23 |
+
"""
|
| 24 |
+
@classmethod
|
| 25 |
+
def setUpClass(cls):
|
| 26 |
+
requires('gui')
|
| 27 |
+
cls.root = Tk()
|
| 28 |
+
cls.root.withdraw()
|
| 29 |
+
cls.dialog = About(cls.root, 'About IDLE', _utest=True)
|
| 30 |
+
|
| 31 |
+
@classmethod
|
| 32 |
+
def tearDownClass(cls):
|
| 33 |
+
del cls.dialog
|
| 34 |
+
cls.root.update_idletasks()
|
| 35 |
+
cls.root.destroy()
|
| 36 |
+
del cls.root
|
| 37 |
+
|
| 38 |
+
def test_build_bits(self):
|
| 39 |
+
self.assertIn(help_about.build_bits(), ('32', '64'))
|
| 40 |
+
|
| 41 |
+
def test_dialog_title(self):
|
| 42 |
+
"""Test about dialog title"""
|
| 43 |
+
self.assertEqual(self.dialog.title(), 'About IDLE')
|
| 44 |
+
|
| 45 |
+
def test_dialog_logo(self):
|
| 46 |
+
"""Test about dialog logo."""
|
| 47 |
+
path, file = os.path.split(self.dialog.icon_image['file'])
|
| 48 |
+
fn, ext = os.path.splitext(file)
|
| 49 |
+
self.assertEqual(fn, 'idle_48')
|
| 50 |
+
|
| 51 |
+
def test_printer_buttons(self):
|
| 52 |
+
"""Test buttons whose commands use printer function."""
|
| 53 |
+
dialog = self.dialog
|
| 54 |
+
button_sources = [(dialog.py_license, license, 'license'),
|
| 55 |
+
(dialog.py_copyright, copyright, 'copyright'),
|
| 56 |
+
(dialog.py_credits, credits, 'credits')]
|
| 57 |
+
|
| 58 |
+
for button, printer, name in button_sources:
|
| 59 |
+
with self.subTest(name=name):
|
| 60 |
+
printer._Printer__setup()
|
| 61 |
+
button.invoke()
|
| 62 |
+
get = dialog._current_textview.viewframe.textframe.text.get
|
| 63 |
+
lines = printer._Printer__lines
|
| 64 |
+
if len(lines) < 2:
|
| 65 |
+
self.fail(name + ' full text was not found')
|
| 66 |
+
self.assertEqual(lines[0], get('1.0', '1.end'))
|
| 67 |
+
self.assertEqual(lines[1], get('2.0', '2.end'))
|
| 68 |
+
dialog._current_textview.destroy()
|
| 69 |
+
|
| 70 |
+
def test_file_buttons(self):
|
| 71 |
+
"""Test buttons that display files."""
|
| 72 |
+
dialog = self.dialog
|
| 73 |
+
button_sources = [(self.dialog.readme, 'README.txt', 'readme'),
|
| 74 |
+
(self.dialog.idle_news, 'NEWS.txt', 'news'),
|
| 75 |
+
(self.dialog.idle_credits, 'CREDITS.txt', 'credits')]
|
| 76 |
+
|
| 77 |
+
for button, filename, name in button_sources:
|
| 78 |
+
with self.subTest(name=name):
|
| 79 |
+
button.invoke()
|
| 80 |
+
fn = findfile(filename, subdir='idlelib')
|
| 81 |
+
get = dialog._current_textview.viewframe.textframe.text.get
|
| 82 |
+
with open(fn, encoding='utf-8') as f:
|
| 83 |
+
self.assertEqual(f.readline().strip(), get('1.0', '1.end'))
|
| 84 |
+
f.readline()
|
| 85 |
+
self.assertEqual(f.readline().strip(), get('3.0', '3.end'))
|
| 86 |
+
dialog._current_textview.destroy()
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
class DefaultTitleTest(unittest.TestCase):
|
| 90 |
+
"Test default title."
|
| 91 |
+
|
| 92 |
+
@classmethod
|
| 93 |
+
def setUpClass(cls):
|
| 94 |
+
requires('gui')
|
| 95 |
+
cls.root = Tk()
|
| 96 |
+
cls.root.withdraw()
|
| 97 |
+
cls.dialog = About(cls.root, _utest=True)
|
| 98 |
+
|
| 99 |
+
@classmethod
|
| 100 |
+
def tearDownClass(cls):
|
| 101 |
+
del cls.dialog
|
| 102 |
+
cls.root.update_idletasks()
|
| 103 |
+
cls.root.destroy()
|
| 104 |
+
del cls.root
|
| 105 |
+
|
| 106 |
+
def test_dialog_title(self):
|
| 107 |
+
"""Test about dialog title"""
|
| 108 |
+
self.assertEqual(self.dialog.title(),
|
| 109 |
+
f'About IDLE {python_version()}'
|
| 110 |
+
f' ({help_about.build_bits()} bit)')
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
class CloseTest(unittest.TestCase):
|
| 114 |
+
"""Simulate user clicking [Close] button"""
|
| 115 |
+
|
| 116 |
+
@classmethod
|
| 117 |
+
def setUpClass(cls):
|
| 118 |
+
requires('gui')
|
| 119 |
+
cls.root = Tk()
|
| 120 |
+
cls.root.withdraw()
|
| 121 |
+
cls.dialog = About(cls.root, 'About IDLE', _utest=True)
|
| 122 |
+
|
| 123 |
+
@classmethod
|
| 124 |
+
def tearDownClass(cls):
|
| 125 |
+
del cls.dialog
|
| 126 |
+
cls.root.update_idletasks()
|
| 127 |
+
cls.root.destroy()
|
| 128 |
+
del cls.root
|
| 129 |
+
|
| 130 |
+
def test_close(self):
|
| 131 |
+
self.assertEqual(self.dialog.winfo_class(), 'Toplevel')
|
| 132 |
+
self.dialog.button_ok.invoke()
|
| 133 |
+
with self.assertRaises(TclError):
|
| 134 |
+
self.dialog.winfo_class()
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
class Dummy_about_dialog:
|
| 138 |
+
# Dummy class for testing file display functions.
|
| 139 |
+
idle_credits = About.show_idle_credits
|
| 140 |
+
idle_readme = About.show_readme
|
| 141 |
+
idle_news = About.show_idle_news
|
| 142 |
+
# Called by the above
|
| 143 |
+
display_file_text = About.display_file_text
|
| 144 |
+
_utest = True
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
class DisplayFileTest(unittest.TestCase):
|
| 148 |
+
"""Test functions that display files.
|
| 149 |
+
|
| 150 |
+
While somewhat redundant with gui-based test_file_dialog,
|
| 151 |
+
these unit tests run on all buildbots, not just a few.
|
| 152 |
+
"""
|
| 153 |
+
dialog = Dummy_about_dialog()
|
| 154 |
+
|
| 155 |
+
@classmethod
|
| 156 |
+
def setUpClass(cls):
|
| 157 |
+
cls.orig_error = textview.showerror
|
| 158 |
+
cls.orig_view = textview.view_text
|
| 159 |
+
cls.error = Mbox_func()
|
| 160 |
+
cls.view = Func()
|
| 161 |
+
textview.showerror = cls.error
|
| 162 |
+
textview.view_text = cls.view
|
| 163 |
+
|
| 164 |
+
@classmethod
|
| 165 |
+
def tearDownClass(cls):
|
| 166 |
+
textview.showerror = cls.orig_error
|
| 167 |
+
textview.view_text = cls.orig_view
|
| 168 |
+
|
| 169 |
+
def test_file_display(self):
|
| 170 |
+
for handler in (self.dialog.idle_credits,
|
| 171 |
+
self.dialog.idle_readme,
|
| 172 |
+
self.dialog.idle_news):
|
| 173 |
+
self.error.message = ''
|
| 174 |
+
self.view.called = False
|
| 175 |
+
with self.subTest(handler=handler):
|
| 176 |
+
handler()
|
| 177 |
+
self.assertEqual(self.error.message, '')
|
| 178 |
+
self.assertEqual(self.view.called, True)
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
if __name__ == '__main__':
|
| 182 |
+
unittest.main(verbosity=2)
|
evalkit_cambrian/lib/python3.10/idlelib/idle_test/test_hyperparser.py
ADDED
|
@@ -0,0 +1,276 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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, coverage 98%."
|
| 2 |
+
|
| 3 |
+
from idlelib.hyperparser import HyperParser
|
| 4 |
+
import unittest
|
| 5 |
+
from test.support import requires
|
| 6 |
+
from tkinter import Tk, Text
|
| 7 |
+
from idlelib.editor import EditorWindow
|
| 8 |
+
|
| 9 |
+
class DummyEditwin:
|
| 10 |
+
def __init__(self, text):
|
| 11 |
+
self.text = text
|
| 12 |
+
self.indentwidth = 8
|
| 13 |
+
self.tabwidth = 8
|
| 14 |
+
self.prompt_last_line = '>>>'
|
| 15 |
+
self.num_context_lines = 50, 500, 1000
|
| 16 |
+
|
| 17 |
+
_build_char_in_string_func = EditorWindow._build_char_in_string_func
|
| 18 |
+
is_char_in_string = EditorWindow.is_char_in_string
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
class HyperParserTest(unittest.TestCase):
|
| 22 |
+
code = (
|
| 23 |
+
'"""This is a module docstring"""\n'
|
| 24 |
+
'# this line is a comment\n'
|
| 25 |
+
'x = "this is a string"\n'
|
| 26 |
+
"y = 'this is also a string'\n"
|
| 27 |
+
'l = [i for i in range(10)]\n'
|
| 28 |
+
'm = [py*py for # comment\n'
|
| 29 |
+
' py in l]\n'
|
| 30 |
+
'x.__len__\n'
|
| 31 |
+
"z = ((r'asdf')+('a')))\n"
|
| 32 |
+
'[x for x in\n'
|
| 33 |
+
'for = False\n'
|
| 34 |
+
'cliché = "this is a string with unicode, what a cliché"'
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
@classmethod
|
| 38 |
+
def setUpClass(cls):
|
| 39 |
+
requires('gui')
|
| 40 |
+
cls.root = Tk()
|
| 41 |
+
cls.root.withdraw()
|
| 42 |
+
cls.text = Text(cls.root)
|
| 43 |
+
cls.editwin = DummyEditwin(cls.text)
|
| 44 |
+
|
| 45 |
+
@classmethod
|
| 46 |
+
def tearDownClass(cls):
|
| 47 |
+
del cls.text, cls.editwin
|
| 48 |
+
cls.root.destroy()
|
| 49 |
+
del cls.root
|
| 50 |
+
|
| 51 |
+
def setUp(self):
|
| 52 |
+
self.text.insert('insert', self.code)
|
| 53 |
+
|
| 54 |
+
def tearDown(self):
|
| 55 |
+
self.text.delete('1.0', 'end')
|
| 56 |
+
self.editwin.prompt_last_line = '>>>'
|
| 57 |
+
|
| 58 |
+
def get_parser(self, index):
|
| 59 |
+
"""
|
| 60 |
+
Return a parser object with index at 'index'
|
| 61 |
+
"""
|
| 62 |
+
return HyperParser(self.editwin, index)
|
| 63 |
+
|
| 64 |
+
def test_init(self):
|
| 65 |
+
"""
|
| 66 |
+
test corner cases in the init method
|
| 67 |
+
"""
|
| 68 |
+
with self.assertRaises(ValueError) as ve:
|
| 69 |
+
self.text.tag_add('console', '1.0', '1.end')
|
| 70 |
+
p = self.get_parser('1.5')
|
| 71 |
+
self.assertIn('precedes', str(ve.exception))
|
| 72 |
+
|
| 73 |
+
# test without ps1
|
| 74 |
+
self.editwin.prompt_last_line = ''
|
| 75 |
+
|
| 76 |
+
# number of lines lesser than 50
|
| 77 |
+
p = self.get_parser('end')
|
| 78 |
+
self.assertEqual(p.rawtext, self.text.get('1.0', 'end'))
|
| 79 |
+
|
| 80 |
+
# number of lines greater than 50
|
| 81 |
+
self.text.insert('end', self.text.get('1.0', 'end')*4)
|
| 82 |
+
p = self.get_parser('54.5')
|
| 83 |
+
|
| 84 |
+
def test_is_in_string(self):
|
| 85 |
+
get = self.get_parser
|
| 86 |
+
|
| 87 |
+
p = get('1.0')
|
| 88 |
+
self.assertFalse(p.is_in_string())
|
| 89 |
+
p = get('1.4')
|
| 90 |
+
self.assertTrue(p.is_in_string())
|
| 91 |
+
p = get('2.3')
|
| 92 |
+
self.assertFalse(p.is_in_string())
|
| 93 |
+
p = get('3.3')
|
| 94 |
+
self.assertFalse(p.is_in_string())
|
| 95 |
+
p = get('3.7')
|
| 96 |
+
self.assertTrue(p.is_in_string())
|
| 97 |
+
p = get('4.6')
|
| 98 |
+
self.assertTrue(p.is_in_string())
|
| 99 |
+
p = get('12.54')
|
| 100 |
+
self.assertTrue(p.is_in_string())
|
| 101 |
+
|
| 102 |
+
def test_is_in_code(self):
|
| 103 |
+
get = self.get_parser
|
| 104 |
+
|
| 105 |
+
p = get('1.0')
|
| 106 |
+
self.assertTrue(p.is_in_code())
|
| 107 |
+
p = get('1.1')
|
| 108 |
+
self.assertFalse(p.is_in_code())
|
| 109 |
+
p = get('2.5')
|
| 110 |
+
self.assertFalse(p.is_in_code())
|
| 111 |
+
p = get('3.4')
|
| 112 |
+
self.assertTrue(p.is_in_code())
|
| 113 |
+
p = get('3.6')
|
| 114 |
+
self.assertFalse(p.is_in_code())
|
| 115 |
+
p = get('4.14')
|
| 116 |
+
self.assertFalse(p.is_in_code())
|
| 117 |
+
|
| 118 |
+
def test_get_surrounding_bracket(self):
|
| 119 |
+
get = self.get_parser
|
| 120 |
+
|
| 121 |
+
def without_mustclose(parser):
|
| 122 |
+
# a utility function to get surrounding bracket
|
| 123 |
+
# with mustclose=False
|
| 124 |
+
return parser.get_surrounding_brackets(mustclose=False)
|
| 125 |
+
|
| 126 |
+
def with_mustclose(parser):
|
| 127 |
+
# a utility function to get surrounding bracket
|
| 128 |
+
# with mustclose=True
|
| 129 |
+
return parser.get_surrounding_brackets(mustclose=True)
|
| 130 |
+
|
| 131 |
+
p = get('3.2')
|
| 132 |
+
self.assertIsNone(with_mustclose(p))
|
| 133 |
+
self.assertIsNone(without_mustclose(p))
|
| 134 |
+
|
| 135 |
+
p = get('5.6')
|
| 136 |
+
self.assertTupleEqual(without_mustclose(p), ('5.4', '5.25'))
|
| 137 |
+
self.assertTupleEqual(without_mustclose(p), with_mustclose(p))
|
| 138 |
+
|
| 139 |
+
p = get('5.23')
|
| 140 |
+
self.assertTupleEqual(without_mustclose(p), ('5.21', '5.24'))
|
| 141 |
+
self.assertTupleEqual(without_mustclose(p), with_mustclose(p))
|
| 142 |
+
|
| 143 |
+
p = get('6.15')
|
| 144 |
+
self.assertTupleEqual(without_mustclose(p), ('6.4', '6.end'))
|
| 145 |
+
self.assertIsNone(with_mustclose(p))
|
| 146 |
+
|
| 147 |
+
p = get('9.end')
|
| 148 |
+
self.assertIsNone(with_mustclose(p))
|
| 149 |
+
self.assertIsNone(without_mustclose(p))
|
| 150 |
+
|
| 151 |
+
def test_get_expression(self):
|
| 152 |
+
get = self.get_parser
|
| 153 |
+
|
| 154 |
+
p = get('4.2')
|
| 155 |
+
self.assertEqual(p.get_expression(), 'y ')
|
| 156 |
+
|
| 157 |
+
p = get('4.7')
|
| 158 |
+
with self.assertRaises(ValueError) as ve:
|
| 159 |
+
p.get_expression()
|
| 160 |
+
self.assertIn('is inside a code', str(ve.exception))
|
| 161 |
+
|
| 162 |
+
p = get('5.25')
|
| 163 |
+
self.assertEqual(p.get_expression(), 'range(10)')
|
| 164 |
+
|
| 165 |
+
p = get('6.7')
|
| 166 |
+
self.assertEqual(p.get_expression(), 'py')
|
| 167 |
+
|
| 168 |
+
p = get('6.8')
|
| 169 |
+
self.assertEqual(p.get_expression(), '')
|
| 170 |
+
|
| 171 |
+
p = get('7.9')
|
| 172 |
+
self.assertEqual(p.get_expression(), 'py')
|
| 173 |
+
|
| 174 |
+
p = get('8.end')
|
| 175 |
+
self.assertEqual(p.get_expression(), 'x.__len__')
|
| 176 |
+
|
| 177 |
+
p = get('9.13')
|
| 178 |
+
self.assertEqual(p.get_expression(), "r'asdf'")
|
| 179 |
+
|
| 180 |
+
p = get('9.17')
|
| 181 |
+
with self.assertRaises(ValueError) as ve:
|
| 182 |
+
p.get_expression()
|
| 183 |
+
self.assertIn('is inside a code', str(ve.exception))
|
| 184 |
+
|
| 185 |
+
p = get('10.0')
|
| 186 |
+
self.assertEqual(p.get_expression(), '')
|
| 187 |
+
|
| 188 |
+
p = get('10.6')
|
| 189 |
+
self.assertEqual(p.get_expression(), '')
|
| 190 |
+
|
| 191 |
+
p = get('10.11')
|
| 192 |
+
self.assertEqual(p.get_expression(), '')
|
| 193 |
+
|
| 194 |
+
p = get('11.3')
|
| 195 |
+
self.assertEqual(p.get_expression(), '')
|
| 196 |
+
|
| 197 |
+
p = get('11.11')
|
| 198 |
+
self.assertEqual(p.get_expression(), 'False')
|
| 199 |
+
|
| 200 |
+
p = get('12.6')
|
| 201 |
+
self.assertEqual(p.get_expression(), 'cliché')
|
| 202 |
+
|
| 203 |
+
def test_eat_identifier(self):
|
| 204 |
+
def is_valid_id(candidate):
|
| 205 |
+
result = HyperParser._eat_identifier(candidate, 0, len(candidate))
|
| 206 |
+
if result == len(candidate):
|
| 207 |
+
return True
|
| 208 |
+
elif result == 0:
|
| 209 |
+
return False
|
| 210 |
+
else:
|
| 211 |
+
err_msg = "Unexpected result: {} (expected 0 or {}".format(
|
| 212 |
+
result, len(candidate)
|
| 213 |
+
)
|
| 214 |
+
raise Exception(err_msg)
|
| 215 |
+
|
| 216 |
+
# invalid first character which is valid elsewhere in an identifier
|
| 217 |
+
self.assertFalse(is_valid_id('2notid'))
|
| 218 |
+
|
| 219 |
+
# ASCII-only valid identifiers
|
| 220 |
+
self.assertTrue(is_valid_id('valid_id'))
|
| 221 |
+
self.assertTrue(is_valid_id('_valid_id'))
|
| 222 |
+
self.assertTrue(is_valid_id('valid_id_'))
|
| 223 |
+
self.assertTrue(is_valid_id('_2valid_id'))
|
| 224 |
+
|
| 225 |
+
# keywords which should be "eaten"
|
| 226 |
+
self.assertTrue(is_valid_id('True'))
|
| 227 |
+
self.assertTrue(is_valid_id('False'))
|
| 228 |
+
self.assertTrue(is_valid_id('None'))
|
| 229 |
+
|
| 230 |
+
# keywords which should not be "eaten"
|
| 231 |
+
self.assertFalse(is_valid_id('for'))
|
| 232 |
+
self.assertFalse(is_valid_id('import'))
|
| 233 |
+
self.assertFalse(is_valid_id('return'))
|
| 234 |
+
|
| 235 |
+
# valid unicode identifiers
|
| 236 |
+
self.assertTrue(is_valid_id('cliche'))
|
| 237 |
+
self.assertTrue(is_valid_id('cliché'))
|
| 238 |
+
self.assertTrue(is_valid_id('a٢'))
|
| 239 |
+
|
| 240 |
+
# invalid unicode identifiers
|
| 241 |
+
self.assertFalse(is_valid_id('2a'))
|
| 242 |
+
self.assertFalse(is_valid_id('٢a'))
|
| 243 |
+
self.assertFalse(is_valid_id('a²'))
|
| 244 |
+
|
| 245 |
+
# valid identifier after "punctuation"
|
| 246 |
+
self.assertEqual(HyperParser._eat_identifier('+ var', 0, 5), len('var'))
|
| 247 |
+
self.assertEqual(HyperParser._eat_identifier('+var', 0, 4), len('var'))
|
| 248 |
+
self.assertEqual(HyperParser._eat_identifier('.var', 0, 4), len('var'))
|
| 249 |
+
|
| 250 |
+
# invalid identifiers
|
| 251 |
+
self.assertFalse(is_valid_id('+'))
|
| 252 |
+
self.assertFalse(is_valid_id(' '))
|
| 253 |
+
self.assertFalse(is_valid_id(':'))
|
| 254 |
+
self.assertFalse(is_valid_id('?'))
|
| 255 |
+
self.assertFalse(is_valid_id('^'))
|
| 256 |
+
self.assertFalse(is_valid_id('\\'))
|
| 257 |
+
self.assertFalse(is_valid_id('"'))
|
| 258 |
+
self.assertFalse(is_valid_id('"a string"'))
|
| 259 |
+
|
| 260 |
+
def test_eat_identifier_various_lengths(self):
|
| 261 |
+
eat_id = HyperParser._eat_identifier
|
| 262 |
+
|
| 263 |
+
for length in range(1, 21):
|
| 264 |
+
self.assertEqual(eat_id('a' * length, 0, length), length)
|
| 265 |
+
self.assertEqual(eat_id('é' * length, 0, length), length)
|
| 266 |
+
self.assertEqual(eat_id('a' + '2' * (length - 1), 0, length), length)
|
| 267 |
+
self.assertEqual(eat_id('é' + '2' * (length - 1), 0, length), length)
|
| 268 |
+
self.assertEqual(eat_id('é' + 'a' * (length - 1), 0, length), length)
|
| 269 |
+
self.assertEqual(eat_id('é' * (length - 1) + 'a', 0, length), length)
|
| 270 |
+
self.assertEqual(eat_id('+' * length, 0, length), 0)
|
| 271 |
+
self.assertEqual(eat_id('2' + 'a' * (length - 1), 0, length), 0)
|
| 272 |
+
self.assertEqual(eat_id('2' + 'é' * (length - 1), 0, length), 0)
|
| 273 |
+
|
| 274 |
+
|
| 275 |
+
if __name__ == '__main__':
|
| 276 |
+
unittest.main(verbosity=2)
|