Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- micromamba_root/envs/pytorch_env/Lib/idlelib/Icons/README.txt +13 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/Icons/idle.ico +0 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/README.txt +241 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/example_noext +4 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/example_stub.pyi +4 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/htest.py +442 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/mock_idle.py +61 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/mock_tk.py +307 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/template.py +30 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_autocomplete.py +305 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_autocomplete_w.py +32 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_autoexpand.py +155 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_browser.py +257 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_calltip.py +372 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_calltip_w.py +29 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_codecontext.py +455 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_colorizer.py +622 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_config.py +805 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_config_key.py +356 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_configdialog.py +1580 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_debugger.py +297 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_debugger_r.py +36 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_debugobj.py +57 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_debugobj_r.py +22 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_delegator.py +44 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_editmenu.py +74 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_editor.py +241 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_filelist.py +33 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_format.py +668 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_grep.py +156 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_help.py +36 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_help_about.py +182 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_history.py +172 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_hyperparser.py +276 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_iomenu.py +84 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_macosx.py +113 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_mainmenu.py +42 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_multicall.py +48 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_outwin.py +166 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_parenmatch.py +112 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_pathbrowser.py +86 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_percolator.py +118 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_pyparse.py +483 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_pyshell.py +148 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_query.py +451 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_redirector.py +122 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_replace.py +294 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_rpc.py +29 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_run.py +429 -0
- micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_runscript.py +33 -0
micromamba_root/envs/pytorch_env/Lib/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
|
micromamba_root/envs/pytorch_env/Lib/idlelib/Icons/idle.ico
ADDED
|
|
micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/README.txt
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
README FOR IDLE TESTS IN IDLELIB.IDLE_TEST
|
| 2 |
+
|
| 3 |
+
0. Quick Start
|
| 4 |
+
|
| 5 |
+
Automated unit tests were added in 3.3 for Python 3.x.
|
| 6 |
+
To run the tests from a command line:
|
| 7 |
+
|
| 8 |
+
python -m test.test_idle
|
| 9 |
+
|
| 10 |
+
Human-mediated tests were added later in 3.4.
|
| 11 |
+
|
| 12 |
+
python -m idlelib.idle_test.htest
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
1. Test Files
|
| 16 |
+
|
| 17 |
+
The idle directory, idlelib, has over 60 xyz.py files. The idle_test
|
| 18 |
+
subdirectory contains test_xyz.py for each implementation file xyz.py.
|
| 19 |
+
To add a test for abc.py, open idle_test/template.py and immediately
|
| 20 |
+
Save As test_abc.py. Insert 'abc' on the first line, and replace
|
| 21 |
+
'zzdummy' with 'abc.
|
| 22 |
+
|
| 23 |
+
Remove the imports of requires and tkinter if not needed. Otherwise,
|
| 24 |
+
add to the tkinter imports as needed.
|
| 25 |
+
|
| 26 |
+
Add a prefix to 'Test' for the initial test class. The template class
|
| 27 |
+
contains code needed or possibly needed for gui tests. See the next
|
| 28 |
+
section if doing gui tests. If not, and not needed for further classes,
|
| 29 |
+
this code can be removed.
|
| 30 |
+
|
| 31 |
+
Add the following at the end of abc.py. If an htest was added first,
|
| 32 |
+
insert the import and main lines before the htest lines.
|
| 33 |
+
|
| 34 |
+
if __name__ == "__main__":
|
| 35 |
+
from unittest import main
|
| 36 |
+
main('idlelib.idle_test.test_abc', verbosity=2, exit=False)
|
| 37 |
+
|
| 38 |
+
The ', exit=False' is only needed if an htest follows.
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
2. GUI Tests
|
| 43 |
+
|
| 44 |
+
When run as part of the Python test suite, Idle GUI tests need to run
|
| 45 |
+
test.support.requires('gui'). A test is a GUI test if it creates a
|
| 46 |
+
tkinter.Tk root or master object either directly or indirectly by
|
| 47 |
+
instantiating a tkinter or idle class. GUI tests cannot run in test
|
| 48 |
+
processes that either have no graphical environment available or are not
|
| 49 |
+
allowed to use it.
|
| 50 |
+
|
| 51 |
+
To guard a module consisting entirely of GUI tests, start with
|
| 52 |
+
|
| 53 |
+
from test.support import requires
|
| 54 |
+
requires('gui')
|
| 55 |
+
|
| 56 |
+
To guard a test class, put "requires('gui')" in its setUpClass function.
|
| 57 |
+
The template.py file does this.
|
| 58 |
+
|
| 59 |
+
To avoid interfering with other GUI tests, all GUI objects must be
|
| 60 |
+
destroyed and deleted by the end of the test. The Tk root created in a
|
| 61 |
+
setUpX function should be destroyed in the corresponding tearDownX and
|
| 62 |
+
the module or class attribute deleted. Others widgets should descend
|
| 63 |
+
from the single root and the attributes deleted BEFORE root is
|
| 64 |
+
destroyed. See https://bugs.python.org/issue20567.
|
| 65 |
+
|
| 66 |
+
@classmethod
|
| 67 |
+
def setUpClass(cls):
|
| 68 |
+
requires('gui')
|
| 69 |
+
cls.root = tk.Tk()
|
| 70 |
+
cls.text = tk.Text(root)
|
| 71 |
+
|
| 72 |
+
@classmethod
|
| 73 |
+
def tearDownClass(cls):
|
| 74 |
+
del cls.text
|
| 75 |
+
cls.root.update_idletasks()
|
| 76 |
+
cls.root.destroy()
|
| 77 |
+
del cls.root
|
| 78 |
+
|
| 79 |
+
The update_idletasks call is sometimes needed to prevent the following
|
| 80 |
+
warning either when running a test alone or as part of the test suite
|
| 81 |
+
(#27196). It should not hurt if not needed.
|
| 82 |
+
|
| 83 |
+
can't invoke "event" command: application has been destroyed
|
| 84 |
+
...
|
| 85 |
+
"ttk::ThemeChanged"
|
| 86 |
+
|
| 87 |
+
If a test creates instance 'e' of EditorWindow, call 'e._close()' before
|
| 88 |
+
or as the first part of teardown. The effect of omitting this depends
|
| 89 |
+
on the later shutdown. Then enable the after_cancel loop in the
|
| 90 |
+
template. This prevents messages like the following.
|
| 91 |
+
|
| 92 |
+
bgerror failed to handle background error.
|
| 93 |
+
Original error: invalid command name "106096696timer_event"
|
| 94 |
+
Error in bgerror: can't invoke "tk" command: application has been destroyed
|
| 95 |
+
|
| 96 |
+
Requires('gui') causes the test(s) it guards to be skipped if any of
|
| 97 |
+
these conditions are met:
|
| 98 |
+
|
| 99 |
+
- The tests are being run by regrtest.py, and it was started without
|
| 100 |
+
enabling the "gui" resource with the "-u" command line option.
|
| 101 |
+
|
| 102 |
+
- The tests are being run on Windows by a service that is not allowed
|
| 103 |
+
to interact with the graphical environment.
|
| 104 |
+
|
| 105 |
+
- The tests are being run on Linux and X Windows is not available.
|
| 106 |
+
|
| 107 |
+
- The tests are being run on Mac OSX in a process that cannot make a
|
| 108 |
+
window manager connection.
|
| 109 |
+
|
| 110 |
+
- tkinter.Tk cannot be successfully instantiated for some reason.
|
| 111 |
+
|
| 112 |
+
- test.support.use_resources has been set by something other than
|
| 113 |
+
regrtest.py and does not contain "gui".
|
| 114 |
+
|
| 115 |
+
Tests of non-GUI operations should avoid creating tk widgets. Incidental
|
| 116 |
+
uses of tk variables and messageboxes can be replaced by the mock
|
| 117 |
+
classes in idle_test/mock_tk.py. The mock text handles some uses of the
|
| 118 |
+
tk Text widget.
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
3. Running Unit Tests
|
| 122 |
+
|
| 123 |
+
Assume that xyz.py and test_xyz.py both end with a unittest.main() call.
|
| 124 |
+
Running either from an Idle editor runs all tests in the test_xyz file
|
| 125 |
+
with the version of Python running Idle. Test output appears in the
|
| 126 |
+
Shell window. The 'verbosity=2' option lists all test methods in the
|
| 127 |
+
file, which is appropriate when developing tests. The 'exit=False'
|
| 128 |
+
option is needed in xyx.py files when an htest follows.
|
| 129 |
+
|
| 130 |
+
The following command lines also run all test methods, including
|
| 131 |
+
GUI tests, in test_xyz.py. (Both '-m idlelib' and '-m idlelib.idle'
|
| 132 |
+
start Idle and so cannot run tests.)
|
| 133 |
+
|
| 134 |
+
python -m idlelib.xyz
|
| 135 |
+
python -m idlelib.idle_test.test_xyz
|
| 136 |
+
|
| 137 |
+
The following runs all idle_test/test_*.py tests interactively.
|
| 138 |
+
|
| 139 |
+
>>> import unittest
|
| 140 |
+
>>> unittest.main('idlelib.idle_test', verbosity=2)
|
| 141 |
+
|
| 142 |
+
The following run all Idle tests at a command line. Option '-v' is the
|
| 143 |
+
same as 'verbosity=2'.
|
| 144 |
+
|
| 145 |
+
python -m unittest -v idlelib.idle_test
|
| 146 |
+
python -m test -v -ugui test_idle
|
| 147 |
+
python -m test.test_idle
|
| 148 |
+
|
| 149 |
+
IDLE tests are 'discovered' by idlelib.idle_test.__init__.load_tests
|
| 150 |
+
when this is imported into test.test_idle. Normally, neither file
|
| 151 |
+
should be changed when working on individual test modules. The third
|
| 152 |
+
command runs unittest indirectly through regrtest. The same happens when
|
| 153 |
+
the entire test suite is run with 'python -m test'. So that command must
|
| 154 |
+
work for buildbots to stay green. IDLE tests must not disturb the
|
| 155 |
+
environment in a way that makes other tests fail (GH-62281).
|
| 156 |
+
|
| 157 |
+
To test subsets of modules, see idlelib.idle_test.__init__. This
|
| 158 |
+
can be used to find refleaks or possible sources of "Theme changed"
|
| 159 |
+
tcl messages (GH-71383).
|
| 160 |
+
|
| 161 |
+
To run an individual Testcase or test method, extend the dotted name
|
| 162 |
+
given to unittest on the command line or use the test -m option. The
|
| 163 |
+
latter allows use of other regrtest options. When using the latter,
|
| 164 |
+
all components of the pattern must be present, but any can be replaced
|
| 165 |
+
by '*'.
|
| 166 |
+
|
| 167 |
+
python -m unittest -v idlelib.idle_test.test_xyz.Test_case.test_meth
|
| 168 |
+
python -m test -m idlelib.idle_test.text_xyz.Test_case.test_meth test_idle
|
| 169 |
+
|
| 170 |
+
The test suite can be run in an IDLE user process from Shell.
|
| 171 |
+
>>> import test.autotest # Issue 25588, 2017/10/13, 3.6.4, 3.7.0a2.
|
| 172 |
+
There are currently failures not usually present, and this does not
|
| 173 |
+
work when run from the editor.
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
4. Human-mediated Tests
|
| 177 |
+
|
| 178 |
+
Human-mediated tests are widget tests that cannot be automated but need
|
| 179 |
+
human verification. They are contained in idlelib/idle_test/htest.py,
|
| 180 |
+
which has instructions. (Some modules need an auxiliary function,
|
| 181 |
+
identified with "# htest # on the header line.) The set is about
|
| 182 |
+
complete, though some tests need improvement. To run all htests, run the
|
| 183 |
+
htest file from an editor or from the command line with:
|
| 184 |
+
|
| 185 |
+
python -m idlelib.idle_test.htest
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
5. Test Coverage
|
| 189 |
+
|
| 190 |
+
Install the coverage package into your Python 3.6 site-packages
|
| 191 |
+
directory. (Its exact location depends on the OS).
|
| 192 |
+
> python3 -m pip install coverage
|
| 193 |
+
(On Windows, replace 'python3 with 'py -3.6' or perhaps just 'python'.)
|
| 194 |
+
|
| 195 |
+
The problem with running coverage with repository python is that
|
| 196 |
+
coverage uses absolute imports for its submodules, hence it needs to be
|
| 197 |
+
in a directory in sys.path. One solution: copy the package to the
|
| 198 |
+
directory containing the cpython repository. Call it 'dev'. Then run
|
| 199 |
+
coverage either directly or from a script in that directory so that
|
| 200 |
+
'dev' is prepended to sys.path.
|
| 201 |
+
|
| 202 |
+
Either edit or add dev/.coveragerc so it looks something like this.
|
| 203 |
+
---
|
| 204 |
+
# .coveragerc sets coverage options.
|
| 205 |
+
[run]
|
| 206 |
+
branch = True
|
| 207 |
+
|
| 208 |
+
[report]
|
| 209 |
+
# Regexes for lines to exclude from consideration
|
| 210 |
+
exclude_lines =
|
| 211 |
+
# Don't complain if non-runnable code isn't run:
|
| 212 |
+
if 0:
|
| 213 |
+
if __name__ == .__main__.:
|
| 214 |
+
|
| 215 |
+
.*# htest #
|
| 216 |
+
if not _utest:
|
| 217 |
+
if _htest:
|
| 218 |
+
---
|
| 219 |
+
The additions for IDLE are 'branch = True', to test coverage both ways,
|
| 220 |
+
and the last three exclude lines, to exclude things peculiar to IDLE
|
| 221 |
+
that are not executed during tests.
|
| 222 |
+
|
| 223 |
+
A script like the following cover.bat (for Windows) is very handy.
|
| 224 |
+
---
|
| 225 |
+
@echo off
|
| 226 |
+
rem Usage: cover filename [test_ suffix] # proper case required by coverage
|
| 227 |
+
rem filename without .py, 2nd parameter if test is not test_filename
|
| 228 |
+
setlocal
|
| 229 |
+
set py=f:\dev\3x\pcbuild\win32\python_d.exe
|
| 230 |
+
set src=idlelib.%1
|
| 231 |
+
if "%2" EQU "" set tst=f:/dev/3x/Lib/idlelib/idle_test/test_%1.py
|
| 232 |
+
if "%2" NEQ "" set tst=f:/dev/ex/Lib/idlelib/idle_test/test_%2.py
|
| 233 |
+
|
| 234 |
+
%py% -m coverage run --pylib --source=%src% %tst%
|
| 235 |
+
%py% -m coverage report --show-missing
|
| 236 |
+
%py% -m coverage html
|
| 237 |
+
start htmlcov\3x_Lib_idlelib_%1_py.html
|
| 238 |
+
rem Above opens new report; htmlcov\index.html displays report index
|
| 239 |
+
---
|
| 240 |
+
The second parameter was added for tests of module x not named test_x.
|
| 241 |
+
(There were several before modules were renamed, now only one is left.)
|
micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/example_noext
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!usr/bin/env python
|
| 2 |
+
|
| 3 |
+
def example_function(some_argument):
|
| 4 |
+
pass
|
micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/example_stub.pyi
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
" Example to test recognition of .pyi file as Python source code.
|
| 2 |
+
|
| 3 |
+
class Example:
|
| 4 |
+
def method(self, argument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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Run human tests of Idle's window, dialog, and popup widgets.
|
| 2 |
+
|
| 3 |
+
run(*tests) Create a master Tk() htest window. Within that, run each
|
| 4 |
+
callable in tests after finding the matching test spec in this file. If
|
| 5 |
+
tests is empty, run an htest for each spec dict in this file after
|
| 6 |
+
finding the matching callable in the module named in the spec. Close
|
| 7 |
+
the master window to end testing.
|
| 8 |
+
|
| 9 |
+
In a tested module, let X be a global name bound to a callable (class or
|
| 10 |
+
function) whose .__name__ attribute is also X (the usual situation). The
|
| 11 |
+
first parameter of X must be 'parent' or 'master'. When called, the
|
| 12 |
+
first argument will be the root window. X must create a child
|
| 13 |
+
Toplevel(parent/master) (or subclass thereof). The Toplevel may be a
|
| 14 |
+
test widget or dialog, in which case the callable is the corresponding
|
| 15 |
+
class. Or the Toplevel may contain the widget to be tested or set up a
|
| 16 |
+
context in which a test widget is invoked. In this latter case, the
|
| 17 |
+
callable is a wrapper function that sets up the Toplevel and other
|
| 18 |
+
objects. Wrapper function names, such as _editor_window', should start
|
| 19 |
+
with '_' and be lowercase.
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
End the module with
|
| 23 |
+
|
| 24 |
+
if __name__ == '__main__':
|
| 25 |
+
<run unittest.main with 'exit=False'>
|
| 26 |
+
from idlelib.idle_test.htest import run
|
| 27 |
+
run(callable) # There could be multiple comma-separated callables.
|
| 28 |
+
|
| 29 |
+
To have wrapper functions ignored by coverage reports, tag the def
|
| 30 |
+
header like so: "def _wrapper(parent): # htest #". Use the same tag
|
| 31 |
+
for htest lines in widget code. Make sure that the 'if __name__' line
|
| 32 |
+
matches the above. Then have make sure that .coveragerc includes the
|
| 33 |
+
following:
|
| 34 |
+
|
| 35 |
+
[report]
|
| 36 |
+
exclude_lines =
|
| 37 |
+
.*# htest #
|
| 38 |
+
if __name__ == .__main__.:
|
| 39 |
+
|
| 40 |
+
(The "." instead of "'" is intentional and necessary.)
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
To run any X, this file must contain a matching instance of the
|
| 44 |
+
following template, with X.__name__ prepended to '_spec'.
|
| 45 |
+
When all tests are run, the prefix is use to get X.
|
| 46 |
+
|
| 47 |
+
callable_spec = {
|
| 48 |
+
'file': '',
|
| 49 |
+
'kwds': {'title': ''},
|
| 50 |
+
'msg': ""
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
file (no .py): run() imports file.py.
|
| 54 |
+
kwds: augmented with {'parent':root} and passed to X as **kwds.
|
| 55 |
+
title: an example kwd; some widgets need this, delete line if not.
|
| 56 |
+
msg: master window hints about testing the widget.
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
TODO test these modules and classes:
|
| 60 |
+
autocomplete_w.AutoCompleteWindow
|
| 61 |
+
debugger.Debugger
|
| 62 |
+
outwin.OutputWindow (indirectly being tested with grep test)
|
| 63 |
+
pyshell.PyShellEditorWindow
|
| 64 |
+
"""
|
| 65 |
+
|
| 66 |
+
import idlelib.pyshell # Set Windows DPI awareness before Tk().
|
| 67 |
+
from importlib import import_module
|
| 68 |
+
import textwrap
|
| 69 |
+
import tkinter as tk
|
| 70 |
+
from tkinter.ttk import Scrollbar
|
| 71 |
+
tk.NoDefaultRoot()
|
| 72 |
+
|
| 73 |
+
AboutDialog_spec = {
|
| 74 |
+
'file': 'help_about',
|
| 75 |
+
'kwds': {'title': 'help_about test',
|
| 76 |
+
'_htest': True,
|
| 77 |
+
},
|
| 78 |
+
'msg': "Click on URL to open in default browser.\n"
|
| 79 |
+
"Verify x.y.z versions and test each button, including Close.\n "
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
# TODO implement ^\; adding '<Control-Key-\\>' to function does not work.
|
| 83 |
+
_calltip_window_spec = {
|
| 84 |
+
'file': 'calltip_w',
|
| 85 |
+
'kwds': {},
|
| 86 |
+
'msg': "Typing '(' should display a calltip.\n"
|
| 87 |
+
"Typing ') should hide the calltip.\n"
|
| 88 |
+
"So should moving cursor out of argument area.\n"
|
| 89 |
+
"Force-open-calltip does not work here.\n"
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
_color_delegator_spec = {
|
| 93 |
+
'file': 'colorizer',
|
| 94 |
+
'kwds': {},
|
| 95 |
+
'msg': "The text is sample Python code.\n"
|
| 96 |
+
"Ensure components like comments, keywords, builtins,\n"
|
| 97 |
+
"string, definitions, and break are correctly colored.\n"
|
| 98 |
+
"The default color scheme is in idlelib/config-highlight.def"
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
ConfigDialog_spec = {
|
| 102 |
+
'file': 'configdialog',
|
| 103 |
+
'kwds': {'title': 'ConfigDialogTest',
|
| 104 |
+
'_htest': True,},
|
| 105 |
+
'msg': "IDLE preferences dialog.\n"
|
| 106 |
+
"In the 'Fonts/Tabs' tab, changing font face, should update the "
|
| 107 |
+
"font face of the text in the area below it.\nIn the "
|
| 108 |
+
"'Highlighting' tab, try different color schemes. Clicking "
|
| 109 |
+
"items in the sample program should update the choices above it."
|
| 110 |
+
"\nIn the 'Keys', 'General' and 'Extensions' tabs, test settings "
|
| 111 |
+
"of interest."
|
| 112 |
+
"\n[Ok] to close the dialog.[Apply] to apply the settings and "
|
| 113 |
+
"and [Cancel] to revert all changes.\nRe-run the test to ensure "
|
| 114 |
+
"changes made have persisted."
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
CustomRun_spec = {
|
| 118 |
+
'file': 'query',
|
| 119 |
+
'kwds': {'title': 'Customize query.py Run',
|
| 120 |
+
'_htest': True},
|
| 121 |
+
'msg': "Enter with <Return> or [OK]. Print valid entry to Shell\n"
|
| 122 |
+
"Arguments are parsed into a list\n"
|
| 123 |
+
"Mode is currently restart True or False\n"
|
| 124 |
+
"Close dialog with valid entry, <Escape>, [Cancel], [X]"
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
_debug_object_browser_spec = {
|
| 128 |
+
'file': 'debugobj',
|
| 129 |
+
'kwds': {},
|
| 130 |
+
'msg': "Double click on items up to the lowest level.\n"
|
| 131 |
+
"Attributes of the objects and related information "
|
| 132 |
+
"will be displayed side-by-side at each level."
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
# TODO Improve message
|
| 136 |
+
_dyn_option_menu_spec = {
|
| 137 |
+
'file': 'dynoption',
|
| 138 |
+
'kwds': {},
|
| 139 |
+
'msg': "Select one of the many options in the 'old option set'.\n"
|
| 140 |
+
"Click the button to change the option set.\n"
|
| 141 |
+
"Select one of the many options in the 'new option set'."
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
# TODO edit wrapper
|
| 145 |
+
_editor_window_spec = {
|
| 146 |
+
'file': 'editor',
|
| 147 |
+
'kwds': {},
|
| 148 |
+
'msg': "Test editor functions of interest.\n"
|
| 149 |
+
"Best to close editor first."
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
GetKeysWindow_spec = {
|
| 153 |
+
'file': 'config_key',
|
| 154 |
+
'kwds': {'title': 'Test keybindings',
|
| 155 |
+
'action': 'find-again',
|
| 156 |
+
'current_key_sequences': [['<Control-Key-g>', '<Key-F3>', '<Control-Key-G>']],
|
| 157 |
+
'_htest': True,
|
| 158 |
+
},
|
| 159 |
+
'msg': "Test for different key modifier sequences.\n"
|
| 160 |
+
"<nothing> is invalid.\n"
|
| 161 |
+
"No modifier key is invalid.\n"
|
| 162 |
+
"Shift key with [a-z],[0-9], function key, move key, tab, space "
|
| 163 |
+
"is invalid.\nNo validity checking if advanced key binding "
|
| 164 |
+
"entry is used."
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
_grep_dialog_spec = {
|
| 168 |
+
'file': 'grep',
|
| 169 |
+
'kwds': {},
|
| 170 |
+
'msg': "Click the 'Show GrepDialog' button.\n"
|
| 171 |
+
"Test the various 'Find-in-files' functions.\n"
|
| 172 |
+
"The results should be displayed in a new '*Output*' window.\n"
|
| 173 |
+
"'Right-click'->'Go to file/line' in the search results\n "
|
| 174 |
+
"should open that file in a new EditorWindow."
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
HelpSource_spec = {
|
| 178 |
+
'file': 'query',
|
| 179 |
+
'kwds': {'title': 'Help name and source',
|
| 180 |
+
'menuitem': 'test',
|
| 181 |
+
'filepath': __file__,
|
| 182 |
+
'used_names': {'abc'},
|
| 183 |
+
'_htest': True},
|
| 184 |
+
'msg': "Enter menu item name and help file path\n"
|
| 185 |
+
"'', > than 30 chars, and 'abc' are invalid menu item names.\n"
|
| 186 |
+
"'' and file does not exist are invalid path items.\n"
|
| 187 |
+
"Any url ('www...', 'http...') is accepted.\n"
|
| 188 |
+
"Test Browse with and without path, as cannot unittest.\n"
|
| 189 |
+
"[Ok] or <Return> prints valid entry to shell\n"
|
| 190 |
+
"<Escape>, [Cancel], or [X] prints None to shell"
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
_io_binding_spec = {
|
| 194 |
+
'file': 'iomenu',
|
| 195 |
+
'kwds': {},
|
| 196 |
+
'msg': "Test the following bindings.\n"
|
| 197 |
+
"<Control-o> to open file from dialog.\n"
|
| 198 |
+
"Edit the file.\n"
|
| 199 |
+
"<Control-p> to print the file.\n"
|
| 200 |
+
"<Control-s> to save the file.\n"
|
| 201 |
+
"<Alt-s> to save-as another file.\n"
|
| 202 |
+
"<Control-c> to save-copy-as another file.\n"
|
| 203 |
+
"Check that changes were saved by opening the file elsewhere."
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
_multi_call_spec = {
|
| 207 |
+
'file': 'multicall',
|
| 208 |
+
'kwds': {},
|
| 209 |
+
'msg': "The following should trigger a print to console or IDLE Shell.\n"
|
| 210 |
+
"Entering and leaving the text area, key entry, <Control-Key>,\n"
|
| 211 |
+
"<Alt-Key-a>, <Control-Key-a>, <Alt-Control-Key-a>, \n"
|
| 212 |
+
"<Control-Button-1>, <Alt-Button-1> and focusing elsewhere."
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
_module_browser_spec = {
|
| 216 |
+
'file': 'browser',
|
| 217 |
+
'kwds': {},
|
| 218 |
+
'msg': textwrap.dedent("""
|
| 219 |
+
"Inspect names of module, class(with superclass if applicable),
|
| 220 |
+
"methods and functions. Toggle nested items. Double clicking
|
| 221 |
+
"on items prints a traceback for an exception that is ignored.""")
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
_multistatus_bar_spec = {
|
| 225 |
+
'file': 'statusbar',
|
| 226 |
+
'kwds': {},
|
| 227 |
+
'msg': "Ensure presence of multi-status bar below text area.\n"
|
| 228 |
+
"Click 'Update Status' to change the status text"
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
PathBrowser_spec = {
|
| 232 |
+
'file': 'pathbrowser',
|
| 233 |
+
'kwds': {'_htest': True},
|
| 234 |
+
'msg': "Test for correct display of all paths in sys.path.\n"
|
| 235 |
+
"Toggle nested items out to the lowest level.\n"
|
| 236 |
+
"Double clicking on an item prints a traceback\n"
|
| 237 |
+
"for an exception that is ignored."
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
_percolator_spec = {
|
| 241 |
+
'file': 'percolator',
|
| 242 |
+
'kwds': {},
|
| 243 |
+
'msg': "There are two tracers which can be toggled using a checkbox.\n"
|
| 244 |
+
"Toggling a tracer 'on' by checking it should print tracer "
|
| 245 |
+
"output to the console or to the IDLE shell.\n"
|
| 246 |
+
"If both the tracers are 'on', the output from the tracer which "
|
| 247 |
+
"was switched 'on' later, should be printed first\n"
|
| 248 |
+
"Test for actions like text entry, and removal."
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
Query_spec = {
|
| 252 |
+
'file': 'query',
|
| 253 |
+
'kwds': {'title': 'Query',
|
| 254 |
+
'message': 'Enter something',
|
| 255 |
+
'text0': 'Go',
|
| 256 |
+
'_htest': True},
|
| 257 |
+
'msg': "Enter with <Return> or [Ok]. Print valid entry to Shell\n"
|
| 258 |
+
"Blank line, after stripping, is ignored\n"
|
| 259 |
+
"Close dialog with valid entry, <Escape>, [Cancel], [X]"
|
| 260 |
+
}
|
| 261 |
+
|
| 262 |
+
|
| 263 |
+
_replace_dialog_spec = {
|
| 264 |
+
'file': 'replace',
|
| 265 |
+
'kwds': {},
|
| 266 |
+
'msg': "Click the 'Replace' button.\n"
|
| 267 |
+
"Test various replace options in the 'Replace dialog'.\n"
|
| 268 |
+
"Click [Close] or [X] to close the 'Replace Dialog'."
|
| 269 |
+
}
|
| 270 |
+
|
| 271 |
+
_scrolled_list_spec = {
|
| 272 |
+
'file': 'scrolledlist',
|
| 273 |
+
'kwds': {},
|
| 274 |
+
'msg': "You should see a scrollable list of items\n"
|
| 275 |
+
"Selecting (clicking) or double clicking an item "
|
| 276 |
+
"prints the name to the console or Idle shell.\n"
|
| 277 |
+
"Right clicking an item will display a popup."
|
| 278 |
+
}
|
| 279 |
+
|
| 280 |
+
_search_dialog_spec = {
|
| 281 |
+
'file': 'search',
|
| 282 |
+
'kwds': {},
|
| 283 |
+
'msg': "Click the 'Search' button.\n"
|
| 284 |
+
"Test various search options in the 'Search dialog'.\n"
|
| 285 |
+
"Click [Close] or [X] to close the 'Search Dialog'."
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
_searchbase_spec = {
|
| 289 |
+
'file': 'searchbase',
|
| 290 |
+
'kwds': {},
|
| 291 |
+
'msg': "Check the appearance of the base search dialog\n"
|
| 292 |
+
"Its only action is to close."
|
| 293 |
+
}
|
| 294 |
+
|
| 295 |
+
show_idlehelp_spec = {
|
| 296 |
+
'file': 'help',
|
| 297 |
+
'kwds': {},
|
| 298 |
+
'msg': "If the help text displays, this works.\n"
|
| 299 |
+
"Text is selectable. Window is scrollable."
|
| 300 |
+
}
|
| 301 |
+
|
| 302 |
+
_sidebar_number_scrolling_spec = {
|
| 303 |
+
'file': 'sidebar',
|
| 304 |
+
'kwds': {},
|
| 305 |
+
'msg': textwrap.dedent("""\
|
| 306 |
+
1. Click on the line numbers and drag down below the edge of the
|
| 307 |
+
window, moving the mouse a bit and then leaving it there for a
|
| 308 |
+
while. The text and line numbers should gradually scroll down,
|
| 309 |
+
with the selection updated continuously.
|
| 310 |
+
|
| 311 |
+
2. With the lines still selected, click on a line number above
|
| 312 |
+
or below the selected lines. Only the line whose number was
|
| 313 |
+
clicked should be selected.
|
| 314 |
+
|
| 315 |
+
3. Repeat step #1, dragging to above the window. The text and
|
| 316 |
+
line numbers should gradually scroll up, with the selection
|
| 317 |
+
updated continuously.
|
| 318 |
+
|
| 319 |
+
4. Repeat step #2, clicking a line number below the selection."""),
|
| 320 |
+
}
|
| 321 |
+
|
| 322 |
+
_stackbrowser_spec = {
|
| 323 |
+
'file': 'stackviewer',
|
| 324 |
+
'kwds': {},
|
| 325 |
+
'msg': "A stacktrace for a NameError exception.\n"
|
| 326 |
+
"Should have NameError and 1 traceback line."
|
| 327 |
+
}
|
| 328 |
+
|
| 329 |
+
_tooltip_spec = {
|
| 330 |
+
'file': 'tooltip',
|
| 331 |
+
'kwds': {},
|
| 332 |
+
'msg': "Place mouse cursor over both the buttons\n"
|
| 333 |
+
"A tooltip should appear with some text."
|
| 334 |
+
}
|
| 335 |
+
|
| 336 |
+
_tree_widget_spec = {
|
| 337 |
+
'file': 'tree',
|
| 338 |
+
'kwds': {},
|
| 339 |
+
'msg': "The canvas is scrollable.\n"
|
| 340 |
+
"Click on folders up to to the lowest level."
|
| 341 |
+
}
|
| 342 |
+
|
| 343 |
+
_undo_delegator_spec = {
|
| 344 |
+
'file': 'undo',
|
| 345 |
+
'kwds': {},
|
| 346 |
+
'msg': "Click [Undo] to undo any action.\n"
|
| 347 |
+
"Click [Redo] to redo any action.\n"
|
| 348 |
+
"Click [Dump] to dump the current state "
|
| 349 |
+
"by printing to the console or the IDLE shell.\n"
|
| 350 |
+
}
|
| 351 |
+
|
| 352 |
+
ViewWindow_spec = {
|
| 353 |
+
'file': 'textview',
|
| 354 |
+
'kwds': {'title': 'Test textview',
|
| 355 |
+
'contents': 'The quick brown fox jumps over the lazy dog.\n'*35,
|
| 356 |
+
'_htest': True},
|
| 357 |
+
'msg': "Test for read-only property of text.\n"
|
| 358 |
+
"Select text, scroll window, close"
|
| 359 |
+
}
|
| 360 |
+
|
| 361 |
+
_widget_redirector_spec = {
|
| 362 |
+
'file': 'redirector',
|
| 363 |
+
'kwds': {},
|
| 364 |
+
'msg': "Every text insert should be printed to the console "
|
| 365 |
+
"or the IDLE shell."
|
| 366 |
+
}
|
| 367 |
+
|
| 368 |
+
def run(*tests):
|
| 369 |
+
"Run callables in tests."
|
| 370 |
+
root = tk.Tk()
|
| 371 |
+
root.title('IDLE htest')
|
| 372 |
+
root.resizable(0, 0)
|
| 373 |
+
|
| 374 |
+
# A scrollable Label-like constant width text widget.
|
| 375 |
+
frameLabel = tk.Frame(root, padx=10)
|
| 376 |
+
frameLabel.pack()
|
| 377 |
+
text = tk.Text(frameLabel, wrap='word')
|
| 378 |
+
text.configure(bg=root.cget('bg'), relief='flat', height=4, width=70)
|
| 379 |
+
scrollbar = Scrollbar(frameLabel, command=text.yview)
|
| 380 |
+
text.config(yscrollcommand=scrollbar.set)
|
| 381 |
+
scrollbar.pack(side='right', fill='y', expand=False)
|
| 382 |
+
text.pack(side='left', fill='both', expand=True)
|
| 383 |
+
|
| 384 |
+
test_list = [] # Make list of (spec, callable) tuples.
|
| 385 |
+
if tests:
|
| 386 |
+
for test in tests:
|
| 387 |
+
test_spec = globals()[test.__name__ + '_spec']
|
| 388 |
+
test_spec['name'] = test.__name__
|
| 389 |
+
test_list.append((test_spec, test))
|
| 390 |
+
else:
|
| 391 |
+
for key, dic in globals().items():
|
| 392 |
+
if key.endswith('_spec'):
|
| 393 |
+
test_name = key[:-5]
|
| 394 |
+
test_spec = dic
|
| 395 |
+
test_spec['name'] = test_name
|
| 396 |
+
mod = import_module('idlelib.' + test_spec['file'])
|
| 397 |
+
test = getattr(mod, test_name)
|
| 398 |
+
test_list.append((test_spec, test))
|
| 399 |
+
test_list.reverse() # So can pop in proper order in next_test.
|
| 400 |
+
|
| 401 |
+
test_name = tk.StringVar(root)
|
| 402 |
+
callable_object = None
|
| 403 |
+
test_kwds = None
|
| 404 |
+
|
| 405 |
+
def next_test():
|
| 406 |
+
nonlocal test_name, callable_object, test_kwds
|
| 407 |
+
if len(test_list) == 1:
|
| 408 |
+
next_button.pack_forget()
|
| 409 |
+
test_spec, callable_object = test_list.pop()
|
| 410 |
+
test_kwds = test_spec['kwds']
|
| 411 |
+
test_name.set('Test ' + test_spec['name'])
|
| 412 |
+
|
| 413 |
+
text['state'] = 'normal' # Enable text replacement.
|
| 414 |
+
text.delete('1.0', 'end')
|
| 415 |
+
text.insert("1.0", test_spec['msg'])
|
| 416 |
+
text['state'] = 'disabled' # Restore read-only property.
|
| 417 |
+
|
| 418 |
+
def run_test(_=None):
|
| 419 |
+
widget = callable_object(root, **test_kwds)
|
| 420 |
+
try:
|
| 421 |
+
print(widget.result) # Only true for query classes(?).
|
| 422 |
+
except AttributeError:
|
| 423 |
+
pass
|
| 424 |
+
|
| 425 |
+
def close(_=None):
|
| 426 |
+
root.destroy()
|
| 427 |
+
|
| 428 |
+
button = tk.Button(root, textvariable=test_name,
|
| 429 |
+
default='active', command=run_test)
|
| 430 |
+
next_button = tk.Button(root, text="Next", command=next_test)
|
| 431 |
+
button.pack()
|
| 432 |
+
next_button.pack()
|
| 433 |
+
next_button.focus_set()
|
| 434 |
+
root.bind('<Key-Return>', run_test)
|
| 435 |
+
root.bind('<Key-Escape>', close)
|
| 436 |
+
|
| 437 |
+
next_test()
|
| 438 |
+
root.mainloop()
|
| 439 |
+
|
| 440 |
+
|
| 441 |
+
if __name__ == '__main__':
|
| 442 |
+
run()
|
micromamba_root/envs/pytorch_env/Lib/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 |
+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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
|
micromamba_root/envs/pytorch_env/Lib/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)
|
micromamba_root/envs/pytorch_env/Lib/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)
|
micromamba_root/envs/pytorch_env/Lib/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)
|
mic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."
|
| 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)
|
micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_browser.py
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"Test browser, coverage 90%."
|
| 2 |
+
|
| 3 |
+
from idlelib import browser
|
| 4 |
+
from test.support import requires
|
| 5 |
+
import unittest
|
| 6 |
+
from unittest import mock
|
| 7 |
+
from idlelib.idle_test.mock_idle import Func
|
| 8 |
+
from idlelib.util import py_extensions
|
| 9 |
+
|
| 10 |
+
from collections import deque
|
| 11 |
+
import os.path
|
| 12 |
+
import pyclbr
|
| 13 |
+
from tkinter import Tk
|
| 14 |
+
|
| 15 |
+
from idlelib.tree import TreeNode
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class ModuleBrowserTest(unittest.TestCase):
|
| 19 |
+
|
| 20 |
+
@classmethod
|
| 21 |
+
def setUpClass(cls):
|
| 22 |
+
requires('gui')
|
| 23 |
+
cls.root = Tk()
|
| 24 |
+
cls.root.withdraw()
|
| 25 |
+
cls.mb = browser.ModuleBrowser(cls.root, __file__, _utest=True)
|
| 26 |
+
|
| 27 |
+
@classmethod
|
| 28 |
+
def tearDownClass(cls):
|
| 29 |
+
cls.mb.close()
|
| 30 |
+
cls.root.update_idletasks()
|
| 31 |
+
cls.root.destroy()
|
| 32 |
+
del cls.root, cls.mb
|
| 33 |
+
|
| 34 |
+
def test_init(self):
|
| 35 |
+
mb = self.mb
|
| 36 |
+
eq = self.assertEqual
|
| 37 |
+
eq(mb.path, __file__)
|
| 38 |
+
eq(pyclbr._modules, {})
|
| 39 |
+
self.assertIsInstance(mb.node, TreeNode)
|
| 40 |
+
self.assertIsNotNone(browser.file_open)
|
| 41 |
+
|
| 42 |
+
def test_settitle(self):
|
| 43 |
+
mb = self.mb
|
| 44 |
+
self.assertIn(os.path.basename(__file__), mb.top.title())
|
| 45 |
+
self.assertEqual(mb.top.iconname(), 'Module Browser')
|
| 46 |
+
|
| 47 |
+
def test_rootnode(self):
|
| 48 |
+
mb = self.mb
|
| 49 |
+
rn = mb.rootnode()
|
| 50 |
+
self.assertIsInstance(rn, browser.ModuleBrowserTreeItem)
|
| 51 |
+
|
| 52 |
+
def test_close(self):
|
| 53 |
+
mb = self.mb
|
| 54 |
+
mb.top.destroy = Func()
|
| 55 |
+
mb.node.destroy = Func()
|
| 56 |
+
mb.close()
|
| 57 |
+
self.assertTrue(mb.top.destroy.called)
|
| 58 |
+
self.assertTrue(mb.node.destroy.called)
|
| 59 |
+
del mb.top.destroy, mb.node.destroy
|
| 60 |
+
|
| 61 |
+
def test_is_browseable_extension(self):
|
| 62 |
+
path = "/path/to/file"
|
| 63 |
+
for ext in py_extensions:
|
| 64 |
+
with self.subTest(ext=ext):
|
| 65 |
+
filename = f'{path}{ext}'
|
| 66 |
+
actual = browser.is_browseable_extension(filename)
|
| 67 |
+
expected = ext not in browser.browseable_extension_blocklist
|
| 68 |
+
self.assertEqual(actual, expected)
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
# Nested tree same as in test_pyclbr.py except for supers on C0. C1.
|
| 72 |
+
mb = pyclbr
|
| 73 |
+
module, fname = 'test', 'test.py'
|
| 74 |
+
C0 = mb.Class(module, 'C0', ['base'], fname, 1, end_lineno=9)
|
| 75 |
+
F1 = mb._nest_function(C0, 'F1', 3, 5)
|
| 76 |
+
C1 = mb._nest_class(C0, 'C1', 6, 9, [''])
|
| 77 |
+
C2 = mb._nest_class(C1, 'C2', 7, 9)
|
| 78 |
+
F3 = mb._nest_function(C2, 'F3', 9, 9)
|
| 79 |
+
f0 = mb.Function(module, 'f0', fname, 11, end_lineno=15)
|
| 80 |
+
f1 = mb._nest_function(f0, 'f1', 12, 14)
|
| 81 |
+
f2 = mb._nest_function(f1, 'f2', 13, 13)
|
| 82 |
+
c1 = mb._nest_class(f0, 'c1', 15, 15)
|
| 83 |
+
mock_pyclbr_tree = {'C0': C0, 'f0': f0}
|
| 84 |
+
|
| 85 |
+
# Adjust C0.name, C1.name so tests do not depend on order.
|
| 86 |
+
browser.transform_children(mock_pyclbr_tree, 'test') # C0(base)
|
| 87 |
+
browser.transform_children(C0.children) # C1()
|
| 88 |
+
|
| 89 |
+
# The class below checks that the calls above are correct
|
| 90 |
+
# and that duplicate calls have no effect.
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
class TransformChildrenTest(unittest.TestCase):
|
| 94 |
+
|
| 95 |
+
def test_transform_module_children(self):
|
| 96 |
+
eq = self.assertEqual
|
| 97 |
+
transform = browser.transform_children
|
| 98 |
+
# Parameter matches tree module.
|
| 99 |
+
tcl = list(transform(mock_pyclbr_tree, 'test'))
|
| 100 |
+
eq(tcl, [C0, f0])
|
| 101 |
+
eq(tcl[0].name, 'C0(base)')
|
| 102 |
+
eq(tcl[1].name, 'f0')
|
| 103 |
+
# Check that second call does not change suffix.
|
| 104 |
+
tcl = list(transform(mock_pyclbr_tree, 'test'))
|
| 105 |
+
eq(tcl[0].name, 'C0(base)')
|
| 106 |
+
# Nothing to traverse if parameter name isn't same as tree module.
|
| 107 |
+
tcl = list(transform(mock_pyclbr_tree, 'different name'))
|
| 108 |
+
eq(tcl, [])
|
| 109 |
+
|
| 110 |
+
def test_transform_node_children(self):
|
| 111 |
+
eq = self.assertEqual
|
| 112 |
+
transform = browser.transform_children
|
| 113 |
+
# Class with two children, one name altered.
|
| 114 |
+
tcl = list(transform(C0.children))
|
| 115 |
+
eq(tcl, [F1, C1])
|
| 116 |
+
eq(tcl[0].name, 'F1')
|
| 117 |
+
eq(tcl[1].name, 'C1()')
|
| 118 |
+
tcl = list(transform(C0.children))
|
| 119 |
+
eq(tcl[1].name, 'C1()')
|
| 120 |
+
# Function with two children.
|
| 121 |
+
eq(list(transform(f0.children)), [f1, c1])
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
class ModuleBrowserTreeItemTest(unittest.TestCase):
|
| 125 |
+
|
| 126 |
+
@classmethod
|
| 127 |
+
def setUpClass(cls):
|
| 128 |
+
cls.mbt = browser.ModuleBrowserTreeItem(fname)
|
| 129 |
+
|
| 130 |
+
def test_init(self):
|
| 131 |
+
self.assertEqual(self.mbt.file, fname)
|
| 132 |
+
|
| 133 |
+
def test_gettext(self):
|
| 134 |
+
self.assertEqual(self.mbt.GetText(), fname)
|
| 135 |
+
|
| 136 |
+
def test_geticonname(self):
|
| 137 |
+
self.assertEqual(self.mbt.GetIconName(), 'python')
|
| 138 |
+
|
| 139 |
+
def test_isexpandable(self):
|
| 140 |
+
self.assertTrue(self.mbt.IsExpandable())
|
| 141 |
+
|
| 142 |
+
def test_listchildren(self):
|
| 143 |
+
save_rex = browser.pyclbr.readmodule_ex
|
| 144 |
+
save_tc = browser.transform_children
|
| 145 |
+
browser.pyclbr.readmodule_ex = Func(result=mock_pyclbr_tree)
|
| 146 |
+
browser.transform_children = Func(result=[f0, C0])
|
| 147 |
+
try:
|
| 148 |
+
self.assertEqual(self.mbt.listchildren(), [f0, C0])
|
| 149 |
+
finally:
|
| 150 |
+
browser.pyclbr.readmodule_ex = save_rex
|
| 151 |
+
browser.transform_children = save_tc
|
| 152 |
+
|
| 153 |
+
def test_getsublist(self):
|
| 154 |
+
mbt = self.mbt
|
| 155 |
+
mbt.listchildren = Func(result=[f0, C0])
|
| 156 |
+
sub0, sub1 = mbt.GetSubList()
|
| 157 |
+
del mbt.listchildren
|
| 158 |
+
self.assertIsInstance(sub0, browser.ChildBrowserTreeItem)
|
| 159 |
+
self.assertIsInstance(sub1, browser.ChildBrowserTreeItem)
|
| 160 |
+
self.assertEqual(sub0.name, 'f0')
|
| 161 |
+
self.assertEqual(sub1.name, 'C0(base)')
|
| 162 |
+
|
| 163 |
+
@mock.patch('idlelib.browser.file_open')
|
| 164 |
+
def test_ondoubleclick(self, fopen):
|
| 165 |
+
mbt = self.mbt
|
| 166 |
+
|
| 167 |
+
with mock.patch('os.path.exists', return_value=False):
|
| 168 |
+
mbt.OnDoubleClick()
|
| 169 |
+
fopen.assert_not_called()
|
| 170 |
+
|
| 171 |
+
with mock.patch('os.path.exists', return_value=True):
|
| 172 |
+
mbt.OnDoubleClick()
|
| 173 |
+
fopen.assert_called_once_with(fname)
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
class ChildBrowserTreeItemTest(unittest.TestCase):
|
| 177 |
+
|
| 178 |
+
@classmethod
|
| 179 |
+
def setUpClass(cls):
|
| 180 |
+
CBT = browser.ChildBrowserTreeItem
|
| 181 |
+
cls.cbt_f1 = CBT(f1)
|
| 182 |
+
cls.cbt_C1 = CBT(C1)
|
| 183 |
+
cls.cbt_F1 = CBT(F1)
|
| 184 |
+
|
| 185 |
+
@classmethod
|
| 186 |
+
def tearDownClass(cls):
|
| 187 |
+
del cls.cbt_C1, cls.cbt_f1, cls.cbt_F1
|
| 188 |
+
|
| 189 |
+
def test_init(self):
|
| 190 |
+
eq = self.assertEqual
|
| 191 |
+
eq(self.cbt_C1.name, 'C1()')
|
| 192 |
+
self.assertFalse(self.cbt_C1.isfunction)
|
| 193 |
+
eq(self.cbt_f1.name, 'f1')
|
| 194 |
+
self.assertTrue(self.cbt_f1.isfunction)
|
| 195 |
+
|
| 196 |
+
def test_gettext(self):
|
| 197 |
+
self.assertEqual(self.cbt_C1.GetText(), 'class C1()')
|
| 198 |
+
self.assertEqual(self.cbt_f1.GetText(), 'def f1(...)')
|
| 199 |
+
|
| 200 |
+
def test_geticonname(self):
|
| 201 |
+
self.assertEqual(self.cbt_C1.GetIconName(), 'folder')
|
| 202 |
+
self.assertEqual(self.cbt_f1.GetIconName(), 'python')
|
| 203 |
+
|
| 204 |
+
def test_isexpandable(self):
|
| 205 |
+
self.assertTrue(self.cbt_C1.IsExpandable())
|
| 206 |
+
self.assertTrue(self.cbt_f1.IsExpandable())
|
| 207 |
+
self.assertFalse(self.cbt_F1.IsExpandable())
|
| 208 |
+
|
| 209 |
+
def test_getsublist(self):
|
| 210 |
+
eq = self.assertEqual
|
| 211 |
+
CBT = browser.ChildBrowserTreeItem
|
| 212 |
+
|
| 213 |
+
f1sublist = self.cbt_f1.GetSubList()
|
| 214 |
+
self.assertIsInstance(f1sublist[0], CBT)
|
| 215 |
+
eq(len(f1sublist), 1)
|
| 216 |
+
eq(f1sublist[0].name, 'f2')
|
| 217 |
+
|
| 218 |
+
eq(self.cbt_F1.GetSubList(), [])
|
| 219 |
+
|
| 220 |
+
@mock.patch('idlelib.browser.file_open')
|
| 221 |
+
def test_ondoubleclick(self, fopen):
|
| 222 |
+
goto = fopen.return_value.gotoline = mock.Mock()
|
| 223 |
+
self.cbt_F1.OnDoubleClick()
|
| 224 |
+
fopen.assert_called()
|
| 225 |
+
goto.assert_called()
|
| 226 |
+
goto.assert_called_with(self.cbt_F1.obj.lineno)
|
| 227 |
+
# Failure test would have to raise OSError or AttributeError.
|
| 228 |
+
|
| 229 |
+
|
| 230 |
+
class NestedChildrenTest(unittest.TestCase):
|
| 231 |
+
"Test that all the nodes in a nested tree are added to the BrowserTree."
|
| 232 |
+
|
| 233 |
+
def test_nested(self):
|
| 234 |
+
queue = deque()
|
| 235 |
+
actual_names = []
|
| 236 |
+
# The tree items are processed in breadth first order.
|
| 237 |
+
# Verify that processing each sublist hits every node and
|
| 238 |
+
# in the right order.
|
| 239 |
+
expected_names = ['f0', 'C0(base)',
|
| 240 |
+
'f1', 'c1', 'F1', 'C1()',
|
| 241 |
+
'f2', 'C2',
|
| 242 |
+
'F3']
|
| 243 |
+
CBT = browser.ChildBrowserTreeItem
|
| 244 |
+
queue.extend((CBT(f0), CBT(C0)))
|
| 245 |
+
while queue:
|
| 246 |
+
cb = queue.popleft()
|
| 247 |
+
sublist = cb.GetSubList()
|
| 248 |
+
queue.extend(sublist)
|
| 249 |
+
self.assertIn(cb.name, cb.GetText())
|
| 250 |
+
self.assertIn(cb.GetIconName(), ('python', 'folder'))
|
| 251 |
+
self.assertIs(cb.IsExpandable(), sublist != [])
|
| 252 |
+
actual_names.append(cb.name)
|
| 253 |
+
self.assertEqual(actual_names, expected_names)
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
if __name__ == '__main__':
|
| 257 |
+
unittest.main(verbosity=2)
|
micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_calltip.py
ADDED
|
@@ -0,0 +1,372 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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est.mock import Mock
|
| 6 |
+
import textwrap
|
| 7 |
+
import types
|
| 8 |
+
import re
|
| 9 |
+
from idlelib.idle_test.mock_tk import Text
|
| 10 |
+
from test.support import MISSING_C_DOCSTRINGS
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
# Test Class TC is used in multiple get_argspec test methods
|
| 14 |
+
class TC:
|
| 15 |
+
'doc'
|
| 16 |
+
tip = "(ai=None, *b)"
|
| 17 |
+
def __init__(self, ai=None, *b): 'doc'
|
| 18 |
+
__init__.tip = "(self, ai=None, *b)"
|
| 19 |
+
def t1(self): 'doc'
|
| 20 |
+
t1.tip = "(self)"
|
| 21 |
+
def t2(self, ai, b=None): 'doc'
|
| 22 |
+
t2.tip = "(self, ai, b=None)"
|
| 23 |
+
def t3(self, ai, *args): 'doc'
|
| 24 |
+
t3.tip = "(self, ai, *args)"
|
| 25 |
+
def t4(self, *args): 'doc'
|
| 26 |
+
t4.tip = "(self, *args)"
|
| 27 |
+
def t5(self, ai, b=None, *args, **kw): 'doc'
|
| 28 |
+
t5.tip = "(self, ai, b=None, *args, **kw)"
|
| 29 |
+
def t6(no, self): 'doc'
|
| 30 |
+
t6.tip = "(no, self)"
|
| 31 |
+
def __call__(self, ci): 'doc'
|
| 32 |
+
__call__.tip = "(self, ci)"
|
| 33 |
+
def nd(self): pass # No doc.
|
| 34 |
+
# attaching .tip to wrapped methods does not work
|
| 35 |
+
@classmethod
|
| 36 |
+
def cm(cls, a): 'doc'
|
| 37 |
+
@staticmethod
|
| 38 |
+
def sm(b): 'doc'
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
tc = TC()
|
| 42 |
+
default_tip = calltip._default_callable_argspec
|
| 43 |
+
get_spec = calltip.get_argspec
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
class Get_argspecTest(unittest.TestCase):
|
| 47 |
+
# The get_spec function must return a string, even if blank.
|
| 48 |
+
# Test a variety of objects to be sure that none cause it to raise
|
| 49 |
+
# (quite aside from getting as correct an answer as possible).
|
| 50 |
+
# The tests of builtins may break if inspect or the docstrings change,
|
| 51 |
+
# but a red buildbot is better than a user crash (as has happened).
|
| 52 |
+
# For a simple mismatch, change the expected output to the actual.
|
| 53 |
+
|
| 54 |
+
@unittest.skipIf(MISSING_C_DOCSTRINGS,
|
| 55 |
+
"Signature information for builtins requires docstrings")
|
| 56 |
+
def test_builtins(self):
|
| 57 |
+
|
| 58 |
+
def tiptest(obj, out):
|
| 59 |
+
self.assertEqual(get_spec(obj), out)
|
| 60 |
+
|
| 61 |
+
# Python class that inherits builtin methods
|
| 62 |
+
class List(list): "List() doc"
|
| 63 |
+
|
| 64 |
+
# Simulate builtin with no docstring for default tip test
|
| 65 |
+
class SB: __call__ = None
|
| 66 |
+
|
| 67 |
+
if List.__doc__ is not None:
|
| 68 |
+
tiptest(List,
|
| 69 |
+
f'(iterable=(), /)'
|
| 70 |
+
f'\n{List.__doc__}')
|
| 71 |
+
tiptest(list.__new__,
|
| 72 |
+
'(*args, **kwargs)\n'
|
| 73 |
+
'Create and return a new object. '
|
| 74 |
+
'See help(type) for accurate signature.')
|
| 75 |
+
tiptest(list.__init__,
|
| 76 |
+
'(self, /, *args, **kwargs)\n'
|
| 77 |
+
'Initialize self. See help(type(self)) for accurate signature.')
|
| 78 |
+
append_doc = "\nAppend object to the end of the list."
|
| 79 |
+
tiptest(list.append, '(self, object, /)' + append_doc)
|
| 80 |
+
tiptest(List.append, '(self, object, /)' + append_doc)
|
| 81 |
+
tiptest([].append, '(object, /)' + append_doc)
|
| 82 |
+
# The use of 'object' above matches the signature text.
|
| 83 |
+
|
| 84 |
+
tiptest(types.MethodType,
|
| 85 |
+
'(function, instance, /)\n'
|
| 86 |
+
'Create a bound instance method object.')
|
| 87 |
+
tiptest(SB(), default_tip)
|
| 88 |
+
|
| 89 |
+
p = re.compile('')
|
| 90 |
+
tiptest(re.sub, '''\
|
| 91 |
+
(pattern, repl, string, count=0, flags=0)
|
| 92 |
+
Return the string obtained by replacing the leftmost
|
| 93 |
+
non-overlapping occurrences of the pattern in string by the
|
| 94 |
+
replacement repl. repl can be either a string or a callable;
|
| 95 |
+
if a string, backslash escapes in it are processed. If it is
|
| 96 |
+
a callable, it's passed the Match object and must return''')
|
| 97 |
+
tiptest(p.sub, '''\
|
| 98 |
+
(repl, string, count=0)
|
| 99 |
+
Return the string obtained by replacing the leftmost \
|
| 100 |
+
non-overlapping occurrences o...''')
|
| 101 |
+
|
| 102 |
+
def test_signature_wrap(self):
|
| 103 |
+
if textwrap.TextWrapper.__doc__ is not None:
|
| 104 |
+
self.assertEqual(get_spec(textwrap.TextWrapper), '''\
|
| 105 |
+
(width=70, initial_indent='', subsequent_indent='', expand_tabs=True,
|
| 106 |
+
replace_whitespace=True, fix_sentence_endings=False, break_long_words=True,
|
| 107 |
+
drop_whitespace=True, break_on_hyphens=True, tabsize=8, *, max_lines=None,
|
| 108 |
+
placeholder=' [...]')
|
| 109 |
+
Object for wrapping/filling text. The public interface consists of
|
| 110 |
+
the wrap() and fill() methods; the other methods are just there for
|
| 111 |
+
subclasses to override in order to tweak the default behaviour.
|
| 112 |
+
If you want to completely replace the main wrapping algorithm,
|
| 113 |
+
you\'ll probably have to override _wrap_chunks().''')
|
| 114 |
+
|
| 115 |
+
def test_properly_formatted(self):
|
| 116 |
+
|
| 117 |
+
def foo(s='a'*100):
|
| 118 |
+
pass
|
| 119 |
+
|
| 120 |
+
def bar(s='a'*100):
|
| 121 |
+
"""Hello Guido"""
|
| 122 |
+
pass
|
| 123 |
+
|
| 124 |
+
def baz(s='a'*100, z='b'*100):
|
| 125 |
+
pass
|
| 126 |
+
|
| 127 |
+
indent = calltip._INDENT
|
| 128 |
+
|
| 129 |
+
sfoo = "(s='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"\
|
| 130 |
+
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" + indent + "aaaaaaaaa"\
|
| 131 |
+
"aaaaaaaaaa')"
|
| 132 |
+
sbar = "(s='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"\
|
| 133 |
+
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" + indent + "aaaaaaaaa"\
|
| 134 |
+
"aaaaaaaaaa')\nHello Guido"
|
| 135 |
+
sbaz = "(s='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"\
|
| 136 |
+
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" + indent + "aaaaaaaaa"\
|
| 137 |
+
"aaaaaaaaaa', z='bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"\
|
| 138 |
+
"bbbbbbbbbbbbbbbbb\n" + indent + "bbbbbbbbbbbbbbbbbbbbbb"\
|
| 139 |
+
"bbbbbbbbbbbbbbbbbbbbbb')"
|
| 140 |
+
|
| 141 |
+
for func,doc in [(foo, sfoo), (bar, sbar), (baz, sbaz)]:
|
| 142 |
+
with self.subTest(func=func, doc=doc):
|
| 143 |
+
self.assertEqual(get_spec(func), doc)
|
| 144 |
+
|
| 145 |
+
def test_docline_truncation(self):
|
| 146 |
+
def f(): pass
|
| 147 |
+
f.__doc__ = 'a'*300
|
| 148 |
+
self.assertEqual(get_spec(f), f"()\n{'a'*(calltip._MAX_COLS-3) + '...'}")
|
| 149 |
+
|
| 150 |
+
@unittest.skipIf(MISSING_C_DOCSTRINGS,
|
| 151 |
+
"Signature information for builtins requires docstrings")
|
| 152 |
+
def test_multiline_docstring(self):
|
| 153 |
+
# Test fewer lines than max.
|
| 154 |
+
self.assertEqual(get_spec(range),
|
| 155 |
+
"range(stop) -> range object\n"
|
| 156 |
+
"range(start, stop[, step]) -> range object")
|
| 157 |
+
|
| 158 |
+
# Test max lines
|
| 159 |
+
self.assertEqual(get_spec(bytes), '''\
|
| 160 |
+
bytes(iterable_of_ints) -> bytes
|
| 161 |
+
bytes(string, encoding[, errors]) -> bytes
|
| 162 |
+
bytes(bytes_or_buffer) -> immutable copy of bytes_or_buffer
|
| 163 |
+
bytes(int) -> bytes object of size given by the parameter initialized with null bytes
|
| 164 |
+
bytes() -> empty bytes object''')
|
| 165 |
+
|
| 166 |
+
def test_multiline_docstring_2(self):
|
| 167 |
+
# Test more than max lines
|
| 168 |
+
def f(): pass
|
| 169 |
+
f.__doc__ = 'a\n' * 15
|
| 170 |
+
self.assertEqual(get_spec(f), '()' + '\na' * calltip._MAX_LINES)
|
| 171 |
+
|
| 172 |
+
def test_functions(self):
|
| 173 |
+
def t1(): 'doc'
|
| 174 |
+
t1.tip = "()"
|
| 175 |
+
def t2(a, b=None): 'doc'
|
| 176 |
+
t2.tip = "(a, b=None)"
|
| 177 |
+
def t3(a, *args): 'doc'
|
| 178 |
+
t3.tip = "(a, *args)"
|
| 179 |
+
def t4(*args): 'doc'
|
| 180 |
+
t4.tip = "(*args)"
|
| 181 |
+
def t5(a, b=None, *args, **kw): 'doc'
|
| 182 |
+
t5.tip = "(a, b=None, *args, **kw)"
|
| 183 |
+
|
| 184 |
+
doc = '\ndoc' if t1.__doc__ is not None else ''
|
| 185 |
+
for func in (t1, t2, t3, t4, t5, TC):
|
| 186 |
+
with self.subTest(func=func):
|
| 187 |
+
self.assertEqual(get_spec(func), func.tip + doc)
|
| 188 |
+
|
| 189 |
+
def test_methods(self):
|
| 190 |
+
doc = '\ndoc' if TC.__doc__ is not None else ''
|
| 191 |
+
for meth in (TC.t1, TC.t2, TC.t3, TC.t4, TC.t5, TC.t6, TC.__call__):
|
| 192 |
+
with self.subTest(meth=meth):
|
| 193 |
+
self.assertEqual(get_spec(meth), meth.tip + doc)
|
| 194 |
+
self.assertEqual(get_spec(TC.cm), "(a)" + doc)
|
| 195 |
+
self.assertEqual(get_spec(TC.sm), "(b)" + doc)
|
| 196 |
+
|
| 197 |
+
def test_bound_methods(self):
|
| 198 |
+
# test that first parameter is correctly removed from argspec
|
| 199 |
+
doc = '\ndoc' if TC.__doc__ is not None else ''
|
| 200 |
+
for meth, mtip in ((tc.t1, "()"), (tc.t4, "(*args)"),
|
| 201 |
+
(tc.t6, "(self)"), (tc.__call__, '(ci)'),
|
| 202 |
+
(tc, '(ci)'), (TC.cm, "(a)"),):
|
| 203 |
+
with self.subTest(meth=meth, mtip=mtip):
|
| 204 |
+
self.assertEqual(get_spec(meth), mtip + doc)
|
| 205 |
+
|
| 206 |
+
def test_starred_parameter(self):
|
| 207 |
+
# test that starred first parameter is *not* removed from argspec
|
| 208 |
+
class C:
|
| 209 |
+
def m1(*args): pass
|
| 210 |
+
c = C()
|
| 211 |
+
for meth, mtip in ((C.m1, '(*args)'), (c.m1, "(*args)"),):
|
| 212 |
+
with self.subTest(meth=meth, mtip=mtip):
|
| 213 |
+
self.assertEqual(get_spec(meth), mtip)
|
| 214 |
+
|
| 215 |
+
def test_invalid_method_get_spec(self):
|
| 216 |
+
class C:
|
| 217 |
+
def m2(**kwargs): pass
|
| 218 |
+
class Test:
|
| 219 |
+
def __call__(*, a): pass
|
| 220 |
+
|
| 221 |
+
mtip = calltip._invalid_method
|
| 222 |
+
self.assertEqual(get_spec(C().m2), mtip)
|
| 223 |
+
self.assertEqual(get_spec(Test()), mtip)
|
| 224 |
+
|
| 225 |
+
def test_non_ascii_name(self):
|
| 226 |
+
# test that re works to delete a first parameter name that
|
| 227 |
+
# includes non-ascii chars, such as various forms of A.
|
| 228 |
+
uni = "(A\u0391\u0410\u05d0\u0627\u0905\u1e00\u3042, a)"
|
| 229 |
+
assert calltip._first_param.sub('', uni) == '(a)'
|
| 230 |
+
|
| 231 |
+
def test_no_docstring(self):
|
| 232 |
+
for meth, mtip in ((TC.nd, "(self)"), (tc.nd, "()")):
|
| 233 |
+
with self.subTest(meth=meth, mtip=mtip):
|
| 234 |
+
self.assertEqual(get_spec(meth), mtip)
|
| 235 |
+
|
| 236 |
+
def test_buggy_getattr_class(self):
|
| 237 |
+
class NoCall:
|
| 238 |
+
def __getattr__(self, name): # Not invoked for class attribute.
|
| 239 |
+
raise IndexError # Bug.
|
| 240 |
+
class CallA(NoCall):
|
| 241 |
+
def __call__(self, ci): # Bug does not matter.
|
| 242 |
+
pass
|
| 243 |
+
class CallB(NoCall):
|
| 244 |
+
def __call__(oui, a, b, c): # Non-standard 'self'.
|
| 245 |
+
pass
|
| 246 |
+
|
| 247 |
+
for meth, mtip in ((NoCall, default_tip), (CallA, default_tip),
|
| 248 |
+
(NoCall(), ''), (CallA(), '(ci)'),
|
| 249 |
+
(CallB(), '(a, b, c)')):
|
| 250 |
+
with self.subTest(meth=meth, mtip=mtip):
|
| 251 |
+
self.assertEqual(get_spec(meth), mtip)
|
| 252 |
+
|
| 253 |
+
def test_metaclass_class(self): # Failure case for issue 38689.
|
| 254 |
+
class Type(type): # Type() requires 3 type args, returns class.
|
| 255 |
+
__class__ = property({}.__getitem__, {}.__setitem__)
|
| 256 |
+
class Object(metaclass=Type):
|
| 257 |
+
__slots__ = '__class__'
|
| 258 |
+
for meth, mtip in ((Type, get_spec(type)), (Object, default_tip),
|
| 259 |
+
(Object(), '')):
|
| 260 |
+
with self.subTest(meth=meth, mtip=mtip):
|
| 261 |
+
self.assertEqual(get_spec(meth), mtip)
|
| 262 |
+
|
| 263 |
+
def test_non_callables(self):
|
| 264 |
+
for obj in (0, 0.0, '0', b'0', [], {}):
|
| 265 |
+
with self.subTest(obj=obj):
|
| 266 |
+
self.assertEqual(get_spec(obj), '')
|
| 267 |
+
|
| 268 |
+
|
| 269 |
+
class Get_entityTest(unittest.TestCase):
|
| 270 |
+
def test_bad_entity(self):
|
| 271 |
+
self.assertIsNone(calltip.get_entity('1/0'))
|
| 272 |
+
def test_good_entity(self):
|
| 273 |
+
self.assertIs(calltip.get_entity('int'), int)
|
| 274 |
+
|
| 275 |
+
|
| 276 |
+
# Test the 9 Calltip methods.
|
| 277 |
+
# open_calltip is about half the code; the others are fairly trivial.
|
| 278 |
+
# The default mocks are what are needed for open_calltip.
|
| 279 |
+
|
| 280 |
+
class mock_Shell:
|
| 281 |
+
"Return mock sufficient to pass to hyperparser."
|
| 282 |
+
def __init__(self, text):
|
| 283 |
+
text.tag_prevrange = Mock(return_value=None)
|
| 284 |
+
self.text = text
|
| 285 |
+
self.prompt_last_line = ">>> "
|
| 286 |
+
self.indentwidth = 4
|
| 287 |
+
self.tabwidth = 8
|
| 288 |
+
|
| 289 |
+
|
| 290 |
+
class mock_TipWindow:
|
| 291 |
+
def __init__(self):
|
| 292 |
+
pass
|
| 293 |
+
|
| 294 |
+
def showtip(self, text, parenleft, parenright):
|
| 295 |
+
self.args = parenleft, parenright
|
| 296 |
+
self.parenline, self.parencol = map(int, parenleft.split('.'))
|
| 297 |
+
|
| 298 |
+
|
| 299 |
+
class WrappedCalltip(calltip.Calltip):
|
| 300 |
+
def _make_tk_calltip_window(self):
|
| 301 |
+
return mock_TipWindow()
|
| 302 |
+
|
| 303 |
+
def remove_calltip_window(self, event=None):
|
| 304 |
+
if self.active_calltip: # Setup to None.
|
| 305 |
+
self.active_calltip = None
|
| 306 |
+
self.tips_removed += 1 # Setup to 0.
|
| 307 |
+
|
| 308 |
+
def fetch_tip(self, expression):
|
| 309 |
+
return 'tip'
|
| 310 |
+
|
| 311 |
+
|
| 312 |
+
class CalltipTest(unittest.TestCase):
|
| 313 |
+
|
| 314 |
+
@classmethod
|
| 315 |
+
def setUpClass(cls):
|
| 316 |
+
cls.text = Text()
|
| 317 |
+
cls.ct = WrappedCalltip(mock_Shell(cls.text))
|
| 318 |
+
|
| 319 |
+
def setUp(self):
|
| 320 |
+
self.text.delete('1.0', 'end') # Insert and call
|
| 321 |
+
self.ct.active_calltip = None
|
| 322 |
+
# Test .active_calltip, +args
|
| 323 |
+
self.ct.tips_removed = 0
|
| 324 |
+
|
| 325 |
+
def open_close(self, testfunc):
|
| 326 |
+
# Open-close template with testfunc called in between.
|
| 327 |
+
opentip = self.ct.open_calltip
|
| 328 |
+
self.text.insert(1.0, 'f(')
|
| 329 |
+
opentip(False)
|
| 330 |
+
self.tip = self.ct.active_calltip
|
| 331 |
+
testfunc(self) ###
|
| 332 |
+
self.text.insert('insert', ')')
|
| 333 |
+
opentip(False)
|
| 334 |
+
self.assertIsNone(self.ct.active_calltip, None)
|
| 335 |
+
|
| 336 |
+
def test_open_close(self):
|
| 337 |
+
def args(self):
|
| 338 |
+
self.assertEqual(self.tip.args, ('1.1', '1.end'))
|
| 339 |
+
self.open_close(args)
|
| 340 |
+
|
| 341 |
+
def test_repeated_force(self):
|
| 342 |
+
def force(self):
|
| 343 |
+
for char in 'abc':
|
| 344 |
+
self.text.insert('insert', 'a')
|
| 345 |
+
self.ct.open_calltip(True)
|
| 346 |
+
self.ct.open_calltip(True)
|
| 347 |
+
self.assertIs(self.ct.active_calltip, self.tip)
|
| 348 |
+
self.open_close(force)
|
| 349 |
+
|
| 350 |
+
def test_repeated_parens(self):
|
| 351 |
+
def parens(self):
|
| 352 |
+
for context in "a", "'":
|
| 353 |
+
with self.subTest(context=context):
|
| 354 |
+
self.text.insert('insert', context)
|
| 355 |
+
for char in '(()())':
|
| 356 |
+
self.text.insert('insert', char)
|
| 357 |
+
self.assertIs(self.ct.active_calltip, self.tip)
|
| 358 |
+
self.text.insert('insert', "'")
|
| 359 |
+
self.open_close(parens)
|
| 360 |
+
|
| 361 |
+
def test_comment_parens(self):
|
| 362 |
+
def comment(self):
|
| 363 |
+
self.text.insert('insert', "# ")
|
| 364 |
+
for char in '(()())':
|
| 365 |
+
self.text.insert('insert', char)
|
| 366 |
+
self.assertIs(self.ct.active_calltip, self.tip)
|
| 367 |
+
self.text.insert('insert', "\n")
|
| 368 |
+
self.open_close(comment)
|
| 369 |
+
|
| 370 |
+
|
| 371 |
+
if __name__ == '__main__':
|
| 372 |
+
unittest.main(verbosity=2)
|
micromamba_root/envs/pytorch_env/Lib/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)
|
micromamba_root/envs/pytorch_env/Lib/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)
|
micromamba_root/envs/pytorch_env/Lib/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)
|
micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_config.py
ADDED
|
@@ -0,0 +1,805 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
| 1 |
+
"""Test config, coverage 93%.
|
| 2 |
+
(100% for IdleConfParser, IdleUserConfParser*, ConfigChanges).
|
| 3 |
+
* Exception is OSError clause in Save method.
|
| 4 |
+
Much of IdleConf is also exercised by ConfigDialog and test_configdialog.
|
| 5 |
+
"""
|
| 6 |
+
from idlelib import config
|
| 7 |
+
import sys
|
| 8 |
+
import os
|
| 9 |
+
import tempfile
|
| 10 |
+
from test.support import captured_stderr, findfile
|
| 11 |
+
import unittest
|
| 12 |
+
from unittest import mock
|
| 13 |
+
import idlelib
|
| 14 |
+
from idlelib.idle_test.mock_idle import Func
|
| 15 |
+
|
| 16 |
+
# Tests should not depend on fortuitous user configurations.
|
| 17 |
+
# They must not affect actual user .cfg files.
|
| 18 |
+
# Replace user parsers with empty parsers that cannot be saved
|
| 19 |
+
# due to getting '' as the filename when created.
|
| 20 |
+
|
| 21 |
+
idleConf = config.idleConf
|
| 22 |
+
usercfg = idleConf.userCfg
|
| 23 |
+
testcfg = {}
|
| 24 |
+
usermain = testcfg['main'] = config.IdleUserConfParser('')
|
| 25 |
+
userhigh = testcfg['highlight'] = config.IdleUserConfParser('')
|
| 26 |
+
userkeys = testcfg['keys'] = config.IdleUserConfParser('')
|
| 27 |
+
userextn = testcfg['extensions'] = config.IdleUserConfParser('')
|
| 28 |
+
|
| 29 |
+
def setUpModule():
|
| 30 |
+
idleConf.userCfg = testcfg
|
| 31 |
+
idlelib.testing = True
|
| 32 |
+
|
| 33 |
+
def tearDownModule():
|
| 34 |
+
idleConf.userCfg = usercfg
|
| 35 |
+
idlelib.testing = False
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
class IdleConfParserTest(unittest.TestCase):
|
| 39 |
+
"""Test that IdleConfParser works"""
|
| 40 |
+
|
| 41 |
+
config = """
|
| 42 |
+
[one]
|
| 43 |
+
one = false
|
| 44 |
+
two = true
|
| 45 |
+
three = 10
|
| 46 |
+
|
| 47 |
+
[two]
|
| 48 |
+
one = a string
|
| 49 |
+
two = true
|
| 50 |
+
three = false
|
| 51 |
+
"""
|
| 52 |
+
|
| 53 |
+
def test_get(self):
|
| 54 |
+
parser = config.IdleConfParser('')
|
| 55 |
+
parser.read_string(self.config)
|
| 56 |
+
eq = self.assertEqual
|
| 57 |
+
|
| 58 |
+
# Test with type argument.
|
| 59 |
+
self.assertIs(parser.Get('one', 'one', type='bool'), False)
|
| 60 |
+
self.assertIs(parser.Get('one', 'two', type='bool'), True)
|
| 61 |
+
eq(parser.Get('one', 'three', type='int'), 10)
|
| 62 |
+
eq(parser.Get('two', 'one'), 'a string')
|
| 63 |
+
self.assertIs(parser.Get('two', 'two', type='bool'), True)
|
| 64 |
+
self.assertIs(parser.Get('two', 'three', type='bool'), False)
|
| 65 |
+
|
| 66 |
+
# Test without type should fallback to string.
|
| 67 |
+
eq(parser.Get('two', 'two'), 'true')
|
| 68 |
+
eq(parser.Get('two', 'three'), 'false')
|
| 69 |
+
|
| 70 |
+
# If option not exist, should return None, or default.
|
| 71 |
+
self.assertIsNone(parser.Get('not', 'exist'))
|
| 72 |
+
eq(parser.Get('not', 'exist', default='DEFAULT'), 'DEFAULT')
|
| 73 |
+
|
| 74 |
+
def test_get_option_list(self):
|
| 75 |
+
parser = config.IdleConfParser('')
|
| 76 |
+
parser.read_string(self.config)
|
| 77 |
+
get_list = parser.GetOptionList
|
| 78 |
+
self.assertCountEqual(get_list('one'), ['one', 'two', 'three'])
|
| 79 |
+
self.assertCountEqual(get_list('two'), ['one', 'two', 'three'])
|
| 80 |
+
self.assertEqual(get_list('not exist'), [])
|
| 81 |
+
|
| 82 |
+
def test_load_nothing(self):
|
| 83 |
+
parser = config.IdleConfParser('')
|
| 84 |
+
parser.Load()
|
| 85 |
+
self.assertEqual(parser.sections(), [])
|
| 86 |
+
|
| 87 |
+
def test_load_file(self):
|
| 88 |
+
# Borrow test/configdata/cfgparser.1 from test_configparser.
|
| 89 |
+
config_path = findfile('cfgparser.1', subdir='configdata')
|
| 90 |
+
parser = config.IdleConfParser(config_path)
|
| 91 |
+
parser.Load()
|
| 92 |
+
|
| 93 |
+
self.assertEqual(parser.Get('Foo Bar', 'foo'), 'newbar')
|
| 94 |
+
self.assertEqual(parser.GetOptionList('Foo Bar'), ['foo'])
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
class IdleUserConfParserTest(unittest.TestCase):
|
| 98 |
+
"""Test that IdleUserConfParser works"""
|
| 99 |
+
|
| 100 |
+
def new_parser(self, path=''):
|
| 101 |
+
return config.IdleUserConfParser(path)
|
| 102 |
+
|
| 103 |
+
def test_set_option(self):
|
| 104 |
+
parser = self.new_parser()
|
| 105 |
+
parser.add_section('Foo')
|
| 106 |
+
# Setting new option in existing section should return True.
|
| 107 |
+
self.assertTrue(parser.SetOption('Foo', 'bar', 'true'))
|
| 108 |
+
# Setting existing option with same value should return False.
|
| 109 |
+
self.assertFalse(parser.SetOption('Foo', 'bar', 'true'))
|
| 110 |
+
# Setting exiting option with new value should return True.
|
| 111 |
+
self.assertTrue(parser.SetOption('Foo', 'bar', 'false'))
|
| 112 |
+
self.assertEqual(parser.Get('Foo', 'bar'), 'false')
|
| 113 |
+
|
| 114 |
+
# Setting option in new section should create section and return True.
|
| 115 |
+
self.assertTrue(parser.SetOption('Bar', 'bar', 'true'))
|
| 116 |
+
self.assertCountEqual(parser.sections(), ['Bar', 'Foo'])
|
| 117 |
+
self.assertEqual(parser.Get('Bar', 'bar'), 'true')
|
| 118 |
+
|
| 119 |
+
def test_remove_option(self):
|
| 120 |
+
parser = self.new_parser()
|
| 121 |
+
parser.AddSection('Foo')
|
| 122 |
+
parser.SetOption('Foo', 'bar', 'true')
|
| 123 |
+
|
| 124 |
+
self.assertTrue(parser.RemoveOption('Foo', 'bar'))
|
| 125 |
+
self.assertFalse(parser.RemoveOption('Foo', 'bar'))
|
| 126 |
+
self.assertFalse(parser.RemoveOption('Not', 'Exist'))
|
| 127 |
+
|
| 128 |
+
def test_add_section(self):
|
| 129 |
+
parser = self.new_parser()
|
| 130 |
+
self.assertEqual(parser.sections(), [])
|
| 131 |
+
|
| 132 |
+
# Should not add duplicate section.
|
| 133 |
+
# Configparser raises DuplicateError, IdleParser not.
|
| 134 |
+
parser.AddSection('Foo')
|
| 135 |
+
parser.AddSection('Foo')
|
| 136 |
+
parser.AddSection('Bar')
|
| 137 |
+
self.assertCountEqual(parser.sections(), ['Bar', 'Foo'])
|
| 138 |
+
|
| 139 |
+
def test_remove_empty_sections(self):
|
| 140 |
+
parser = self.new_parser()
|
| 141 |
+
|
| 142 |
+
parser.AddSection('Foo')
|
| 143 |
+
parser.AddSection('Bar')
|
| 144 |
+
parser.SetOption('Idle', 'name', 'val')
|
| 145 |
+
self.assertCountEqual(parser.sections(), ['Bar', 'Foo', 'Idle'])
|
| 146 |
+
parser.RemoveEmptySections()
|
| 147 |
+
self.assertEqual(parser.sections(), ['Idle'])
|
| 148 |
+
|
| 149 |
+
def test_is_empty(self):
|
| 150 |
+
parser = self.new_parser()
|
| 151 |
+
|
| 152 |
+
parser.AddSection('Foo')
|
| 153 |
+
parser.AddSection('Bar')
|
| 154 |
+
self.assertTrue(parser.IsEmpty())
|
| 155 |
+
self.assertEqual(parser.sections(), [])
|
| 156 |
+
|
| 157 |
+
parser.SetOption('Foo', 'bar', 'false')
|
| 158 |
+
parser.AddSection('Bar')
|
| 159 |
+
self.assertFalse(parser.IsEmpty())
|
| 160 |
+
self.assertCountEqual(parser.sections(), ['Foo'])
|
| 161 |
+
|
| 162 |
+
def test_save(self):
|
| 163 |
+
with tempfile.TemporaryDirectory() as tdir:
|
| 164 |
+
path = os.path.join(tdir, 'test.cfg')
|
| 165 |
+
parser = self.new_parser(path)
|
| 166 |
+
parser.AddSection('Foo')
|
| 167 |
+
parser.SetOption('Foo', 'bar', 'true')
|
| 168 |
+
|
| 169 |
+
# Should save to path when config is not empty.
|
| 170 |
+
self.assertFalse(os.path.exists(path))
|
| 171 |
+
parser.Save()
|
| 172 |
+
self.assertTrue(os.path.exists(path))
|
| 173 |
+
|
| 174 |
+
# Should remove the file from disk when config is empty.
|
| 175 |
+
parser.remove_section('Foo')
|
| 176 |
+
parser.Save()
|
| 177 |
+
self.assertFalse(os.path.exists(path))
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
class IdleConfTest(unittest.TestCase):
|
| 181 |
+
"""Test for idleConf"""
|
| 182 |
+
|
| 183 |
+
@classmethod
|
| 184 |
+
def setUpClass(cls):
|
| 185 |
+
cls.config_string = {}
|
| 186 |
+
|
| 187 |
+
conf = config.IdleConf(_utest=True)
|
| 188 |
+
if __name__ != '__main__':
|
| 189 |
+
idle_dir = os.path.dirname(__file__)
|
| 190 |
+
else:
|
| 191 |
+
idle_dir = os.path.abspath(sys.path[0])
|
| 192 |
+
for ctype in conf.config_types:
|
| 193 |
+
config_path = os.path.join(idle_dir, '../config-%s.def' % ctype)
|
| 194 |
+
with open(config_path) as f:
|
| 195 |
+
cls.config_string[ctype] = f.read()
|
| 196 |
+
|
| 197 |
+
cls.orig_warn = config._warn
|
| 198 |
+
config._warn = Func()
|
| 199 |
+
|
| 200 |
+
@classmethod
|
| 201 |
+
def tearDownClass(cls):
|
| 202 |
+
config._warn = cls.orig_warn
|
| 203 |
+
|
| 204 |
+
def new_config(self, _utest=False):
|
| 205 |
+
return config.IdleConf(_utest=_utest)
|
| 206 |
+
|
| 207 |
+
def mock_config(self):
|
| 208 |
+
"""Return a mocked idleConf
|
| 209 |
+
|
| 210 |
+
Both default and user config used the same config-*.def
|
| 211 |
+
"""
|
| 212 |
+
conf = config.IdleConf(_utest=True)
|
| 213 |
+
for ctype in conf.config_types:
|
| 214 |
+
conf.defaultCfg[ctype] = config.IdleConfParser('')
|
| 215 |
+
conf.defaultCfg[ctype].read_string(self.config_string[ctype])
|
| 216 |
+
conf.userCfg[ctype] = config.IdleUserConfParser('')
|
| 217 |
+
conf.userCfg[ctype].read_string(self.config_string[ctype])
|
| 218 |
+
|
| 219 |
+
return conf
|
| 220 |
+
|
| 221 |
+
@unittest.skipIf(sys.platform.startswith('win'), 'this is test for unix system')
|
| 222 |
+
def test_get_user_cfg_dir_unix(self):
|
| 223 |
+
# Test to get user config directory under unix.
|
| 224 |
+
conf = self.new_config(_utest=True)
|
| 225 |
+
|
| 226 |
+
# Check normal way should success
|
| 227 |
+
with mock.patch('os.path.expanduser', return_value='/home/foo'):
|
| 228 |
+
with mock.patch('os.path.exists', return_value=True):
|
| 229 |
+
self.assertEqual(conf.GetUserCfgDir(), '/home/foo/.idlerc')
|
| 230 |
+
|
| 231 |
+
# Check os.getcwd should success
|
| 232 |
+
with mock.patch('os.path.expanduser', return_value='~'):
|
| 233 |
+
with mock.patch('os.getcwd', return_value='/home/foo/cpython'):
|
| 234 |
+
with mock.patch('os.mkdir'):
|
| 235 |
+
self.assertEqual(conf.GetUserCfgDir(),
|
| 236 |
+
'/home/foo/cpython/.idlerc')
|
| 237 |
+
|
| 238 |
+
# Check user dir not exists and created failed should raise SystemExit
|
| 239 |
+
with mock.patch('os.path.join', return_value='/path/not/exists'):
|
| 240 |
+
with self.assertRaises(SystemExit):
|
| 241 |
+
with self.assertRaises(FileNotFoundError):
|
| 242 |
+
conf.GetUserCfgDir()
|
| 243 |
+
|
| 244 |
+
@unittest.skipIf(not sys.platform.startswith('win'), 'this is test for Windows system')
|
| 245 |
+
def test_get_user_cfg_dir_windows(self):
|
| 246 |
+
# Test to get user config directory under Windows.
|
| 247 |
+
conf = self.new_config(_utest=True)
|
| 248 |
+
|
| 249 |
+
# Check normal way should success
|
| 250 |
+
with mock.patch('os.path.expanduser', return_value='C:\\foo'):
|
| 251 |
+
with mock.patch('os.path.exists', return_value=True):
|
| 252 |
+
self.assertEqual(conf.GetUserCfgDir(), 'C:\\foo\\.idlerc')
|
| 253 |
+
|
| 254 |
+
# Check os.getcwd should success
|
| 255 |
+
with mock.patch('os.path.expanduser', return_value='~'):
|
| 256 |
+
with mock.patch('os.getcwd', return_value='C:\\foo\\cpython'):
|
| 257 |
+
with mock.patch('os.mkdir'):
|
| 258 |
+
self.assertEqual(conf.GetUserCfgDir(),
|
| 259 |
+
'C:\\foo\\cpython\\.idlerc')
|
| 260 |
+
|
| 261 |
+
# Check user dir not exists and created failed should raise SystemExit
|
| 262 |
+
with mock.patch('os.path.join', return_value='/path/not/exists'):
|
| 263 |
+
with self.assertRaises(SystemExit):
|
| 264 |
+
with self.assertRaises(FileNotFoundError):
|
| 265 |
+
conf.GetUserCfgDir()
|
| 266 |
+
|
| 267 |
+
def test_create_config_handlers(self):
|
| 268 |
+
conf = self.new_config(_utest=True)
|
| 269 |
+
|
| 270 |
+
# Mock out idle_dir
|
| 271 |
+
idle_dir = '/home/foo'
|
| 272 |
+
with mock.patch.dict({'__name__': '__foo__'}):
|
| 273 |
+
with mock.patch('os.path.dirname', return_value=idle_dir):
|
| 274 |
+
conf.CreateConfigHandlers()
|
| 275 |
+
|
| 276 |
+
# Check keys are equal
|
| 277 |
+
self.assertCountEqual(conf.defaultCfg, conf.config_types)
|
| 278 |
+
self.assertCountEqual(conf.userCfg, conf.config_types)
|
| 279 |
+
|
| 280 |
+
# Check conf parser are correct type
|
| 281 |
+
for default_parser in conf.defaultCfg.values():
|
| 282 |
+
self.assertIsInstance(default_parser, config.IdleConfParser)
|
| 283 |
+
for user_parser in conf.userCfg.values():
|
| 284 |
+
self.assertIsInstance(user_parser, config.IdleUserConfParser)
|
| 285 |
+
|
| 286 |
+
# Check config path are correct
|
| 287 |
+
for cfg_type, parser in conf.defaultCfg.items():
|
| 288 |
+
self.assertEqual(parser.file,
|
| 289 |
+
os.path.join(idle_dir, f'config-{cfg_type}.def'))
|
| 290 |
+
for cfg_type, parser in conf.userCfg.items():
|
| 291 |
+
self.assertEqual(parser.file,
|
| 292 |
+
os.path.join(conf.userdir or '#', f'config-{cfg_type}.cfg'))
|
| 293 |
+
|
| 294 |
+
def test_load_cfg_files(self):
|
| 295 |
+
conf = self.new_config(_utest=True)
|
| 296 |
+
|
| 297 |
+
# Borrow test/configdata/cfgparser.1 from test_configparser.
|
| 298 |
+
config_path = findfile('cfgparser.1', subdir='configdata')
|
| 299 |
+
conf.defaultCfg['foo'] = config.IdleConfParser(config_path)
|
| 300 |
+
conf.userCfg['foo'] = config.IdleUserConfParser(config_path)
|
| 301 |
+
|
| 302 |
+
# Load all config from path
|
| 303 |
+
conf.LoadCfgFiles()
|
| 304 |
+
|
| 305 |
+
eq = self.assertEqual
|
| 306 |
+
|
| 307 |
+
# Check defaultCfg is loaded
|
| 308 |
+
eq(conf.defaultCfg['foo'].Get('Foo Bar', 'foo'), 'newbar')
|
| 309 |
+
eq(conf.defaultCfg['foo'].GetOptionList('Foo Bar'), ['foo'])
|
| 310 |
+
|
| 311 |
+
# Check userCfg is loaded
|
| 312 |
+
eq(conf.userCfg['foo'].Get('Foo Bar', 'foo'), 'newbar')
|
| 313 |
+
eq(conf.userCfg['foo'].GetOptionList('Foo Bar'), ['foo'])
|
| 314 |
+
|
| 315 |
+
def test_save_user_cfg_files(self):
|
| 316 |
+
conf = self.mock_config()
|
| 317 |
+
|
| 318 |
+
with mock.patch('idlelib.config.IdleUserConfParser.Save') as m:
|
| 319 |
+
conf.SaveUserCfgFiles()
|
| 320 |
+
self.assertEqual(m.call_count, len(conf.userCfg))
|
| 321 |
+
|
| 322 |
+
def test_get_option(self):
|
| 323 |
+
conf = self.mock_config()
|
| 324 |
+
|
| 325 |
+
eq = self.assertEqual
|
| 326 |
+
eq(conf.GetOption('main', 'EditorWindow', 'width'), '80')
|
| 327 |
+
eq(conf.GetOption('main', 'EditorWindow', 'width', type='int'), 80)
|
| 328 |
+
with mock.patch('idlelib.config._warn') as _warn:
|
| 329 |
+
eq(conf.GetOption('main', 'EditorWindow', 'font', type='int'), None)
|
| 330 |
+
eq(conf.GetOption('main', 'EditorWindow', 'NotExists'), None)
|
| 331 |
+
eq(conf.GetOption('main', 'EditorWindow', 'NotExists', default='NE'), 'NE')
|
| 332 |
+
eq(_warn.call_count, 4)
|
| 333 |
+
|
| 334 |
+
def test_set_option(self):
|
| 335 |
+
conf = self.mock_config()
|
| 336 |
+
|
| 337 |
+
conf.SetOption('main', 'Foo', 'bar', 'newbar')
|
| 338 |
+
self.assertEqual(conf.GetOption('main', 'Foo', 'bar'), 'newbar')
|
| 339 |
+
|
| 340 |
+
def test_get_section_list(self):
|
| 341 |
+
conf = self.mock_config()
|
| 342 |
+
|
| 343 |
+
self.assertCountEqual(
|
| 344 |
+
conf.GetSectionList('default', 'main'),
|
| 345 |
+
['General', 'EditorWindow', 'PyShell', 'Indent', 'Theme',
|
| 346 |
+
'Keys', 'History', 'HelpFiles'])
|
| 347 |
+
self.assertCountEqual(
|
| 348 |
+
conf.GetSectionList('user', 'main'),
|
| 349 |
+
['General', 'EditorWindow', 'PyShell', 'Indent', 'Theme',
|
| 350 |
+
'Keys', 'History', 'HelpFiles'])
|
| 351 |
+
|
| 352 |
+
with self.assertRaises(config.InvalidConfigSet):
|
| 353 |
+
conf.GetSectionList('foobar', 'main')
|
| 354 |
+
with self.assertRaises(config.InvalidConfigType):
|
| 355 |
+
conf.GetSectionList('default', 'notexists')
|
| 356 |
+
|
| 357 |
+
def test_get_highlight(self):
|
| 358 |
+
conf = self.mock_config()
|
| 359 |
+
|
| 360 |
+
eq = self.assertEqual
|
| 361 |
+
eq(conf.GetHighlight('IDLE Classic', 'normal'), {'foreground': '#000000',
|
| 362 |
+
'background': '#ffffff'})
|
| 363 |
+
|
| 364 |
+
# Test cursor (this background should be normal-background)
|
| 365 |
+
eq(conf.GetHighlight('IDLE Classic', 'cursor'), {'foreground': 'black',
|
| 366 |
+
'background': '#ffffff'})
|
| 367 |
+
|
| 368 |
+
# Test get user themes
|
| 369 |
+
conf.SetOption('highlight', 'Foobar', 'normal-foreground', '#747474')
|
| 370 |
+
conf.SetOption('highlight', 'Foobar', 'normal-background', '#171717')
|
| 371 |
+
with mock.patch('idlelib.config._warn'):
|
| 372 |
+
eq(conf.GetHighlight('Foobar', 'normal'), {'foreground': '#747474',
|
| 373 |
+
'background': '#171717'})
|
| 374 |
+
|
| 375 |
+
def test_get_theme_dict(self):
|
| 376 |
+
# TODO: finish.
|
| 377 |
+
conf = self.mock_config()
|
| 378 |
+
|
| 379 |
+
# These two should be the same
|
| 380 |
+
self.assertEqual(
|
| 381 |
+
conf.GetThemeDict('default', 'IDLE Classic'),
|
| 382 |
+
conf.GetThemeDict('user', 'IDLE Classic'))
|
| 383 |
+
|
| 384 |
+
with self.assertRaises(config.InvalidTheme):
|
| 385 |
+
conf.GetThemeDict('bad', 'IDLE Classic')
|
| 386 |
+
|
| 387 |
+
def test_get_current_theme_and_keys(self):
|
| 388 |
+
conf = self.mock_config()
|
| 389 |
+
|
| 390 |
+
self.assertEqual(conf.CurrentTheme(), conf.current_colors_and_keys('Theme'))
|
| 391 |
+
self.assertEqual(conf.CurrentKeys(), conf.current_colors_and_keys('Keys'))
|
| 392 |
+
|
| 393 |
+
def test_current_colors_and_keys(self):
|
| 394 |
+
conf = self.mock_config()
|
| 395 |
+
|
| 396 |
+
self.assertEqual(conf.current_colors_and_keys('Theme'), 'IDLE Classic')
|
| 397 |
+
|
| 398 |
+
def test_default_keys(self):
|
| 399 |
+
current_platform = sys.platform
|
| 400 |
+
conf = self.new_config(_utest=True)
|
| 401 |
+
|
| 402 |
+
sys.platform = 'win32'
|
| 403 |
+
self.assertEqual(conf.default_keys(), 'IDLE Classic Windows')
|
| 404 |
+
|
| 405 |
+
sys.platform = 'darwin'
|
| 406 |
+
self.assertEqual(conf.default_keys(), 'IDLE Classic OSX')
|
| 407 |
+
|
| 408 |
+
sys.platform = 'some-linux'
|
| 409 |
+
self.assertEqual(conf.default_keys(), 'IDLE Modern Unix')
|
| 410 |
+
|
| 411 |
+
# Restore platform
|
| 412 |
+
sys.platform = current_platform
|
| 413 |
+
|
| 414 |
+
def test_get_extensions(self):
|
| 415 |
+
userextn.read_string('''
|
| 416 |
+
[ZzDummy]
|
| 417 |
+
enable = True
|
| 418 |
+
[DISABLE]
|
| 419 |
+
enable = False
|
| 420 |
+
''')
|
| 421 |
+
eq = self.assertEqual
|
| 422 |
+
iGE = idleConf.GetExtensions
|
| 423 |
+
eq(iGE(shell_only=True), [])
|
| 424 |
+
eq(iGE(), ['ZzDummy'])
|
| 425 |
+
eq(iGE(editor_only=True), ['ZzDummy'])
|
| 426 |
+
eq(iGE(active_only=False), ['ZzDummy', 'DISABLE'])
|
| 427 |
+
eq(iGE(active_only=False, editor_only=True), ['ZzDummy', 'DISABLE'])
|
| 428 |
+
userextn.remove_section('ZzDummy')
|
| 429 |
+
userextn.remove_section('DISABLE')
|
| 430 |
+
|
| 431 |
+
|
| 432 |
+
def test_remove_key_bind_names(self):
|
| 433 |
+
conf = self.mock_config()
|
| 434 |
+
|
| 435 |
+
self.assertCountEqual(
|
| 436 |
+
conf.RemoveKeyBindNames(conf.GetSectionList('default', 'extensions')),
|
| 437 |
+
['AutoComplete', 'CodeContext', 'FormatParagraph', 'ParenMatch', 'ZzDummy'])
|
| 438 |
+
|
| 439 |
+
def test_get_extn_name_for_event(self):
|
| 440 |
+
userextn.read_string('''
|
| 441 |
+
[ZzDummy]
|
| 442 |
+
enable = True
|
| 443 |
+
''')
|
| 444 |
+
eq = self.assertEqual
|
| 445 |
+
eq(idleConf.GetExtnNameForEvent('z-in'), 'ZzDummy')
|
| 446 |
+
eq(idleConf.GetExtnNameForEvent('z-out'), None)
|
| 447 |
+
userextn.remove_section('ZzDummy')
|
| 448 |
+
|
| 449 |
+
def test_get_extension_keys(self):
|
| 450 |
+
userextn.read_string('''
|
| 451 |
+
[ZzDummy]
|
| 452 |
+
enable = True
|
| 453 |
+
''')
|
| 454 |
+
self.assertEqual(idleConf.GetExtensionKeys('ZzDummy'),
|
| 455 |
+
{'<<z-in>>': ['<Control-Shift-KeyRelease-Insert>']})
|
| 456 |
+
userextn.remove_section('ZzDummy')
|
| 457 |
+
# need option key test
|
| 458 |
+
## key = ['<Option-Key-2>'] if sys.platform == 'darwin' else ['<Alt-Key-2>']
|
| 459 |
+
## eq(conf.GetExtensionKeys('ZoomHeight'), {'<<zoom-height>>': key})
|
| 460 |
+
|
| 461 |
+
def test_get_extension_bindings(self):
|
| 462 |
+
userextn.read_string('''
|
| 463 |
+
[ZzDummy]
|
| 464 |
+
enable = True
|
| 465 |
+
''')
|
| 466 |
+
eq = self.assertEqual
|
| 467 |
+
iGEB = idleConf.GetExtensionBindings
|
| 468 |
+
eq(iGEB('NotExists'), {})
|
| 469 |
+
expect = {'<<z-in>>': ['<Control-Shift-KeyRelease-Insert>'],
|
| 470 |
+
'<<z-out>>': ['<Control-Shift-KeyRelease-Delete>']}
|
| 471 |
+
eq(iGEB('ZzDummy'), expect)
|
| 472 |
+
userextn.remove_section('ZzDummy')
|
| 473 |
+
|
| 474 |
+
def test_get_keybinding(self):
|
| 475 |
+
conf = self.mock_config()
|
| 476 |
+
|
| 477 |
+
eq = self.assertEqual
|
| 478 |
+
eq(conf.GetKeyBinding('IDLE Modern Unix', '<<copy>>'),
|
| 479 |
+
['<Control-Shift-Key-C>', '<Control-Key-Insert>'])
|
| 480 |
+
eq(conf.GetKeyBinding('IDLE Classic Unix', '<<copy>>'),
|
| 481 |
+
['<Alt-Key-w>', '<Meta-Key-w>'])
|
| 482 |
+
eq(conf.GetKeyBinding('IDLE Classic Windows', '<<copy>>'),
|
| 483 |
+
['<Control-Key-c>', '<Control-Key-C>'])
|
| 484 |
+
eq(conf.GetKeyBinding('IDLE Classic Mac', '<<copy>>'), ['<Command-Key-c>'])
|
| 485 |
+
eq(conf.GetKeyBinding('IDLE Classic OSX', '<<copy>>'), ['<Command-Key-c>'])
|
| 486 |
+
|
| 487 |
+
# Test keybinding not exists
|
| 488 |
+
eq(conf.GetKeyBinding('NOT EXISTS', '<<copy>>'), [])
|
| 489 |
+
eq(conf.GetKeyBinding('IDLE Modern Unix', 'NOT EXISTS'), [])
|
| 490 |
+
|
| 491 |
+
def test_get_current_keyset(self):
|
| 492 |
+
current_platform = sys.platform
|
| 493 |
+
conf = self.mock_config()
|
| 494 |
+
|
| 495 |
+
# Ensure that platform isn't darwin
|
| 496 |
+
sys.platform = 'some-linux'
|
| 497 |
+
self.assertEqual(conf.GetCurrentKeySet(), conf.GetKeySet(conf.CurrentKeys()))
|
| 498 |
+
|
| 499 |
+
# This should not be the same, since replace <Alt- to <Option-.
|
| 500 |
+
# Above depended on config-extensions.def having Alt keys,
|
| 501 |
+
# which is no longer true.
|
| 502 |
+
# sys.platform = 'darwin'
|
| 503 |
+
# self.assertNotEqual(conf.GetCurrentKeySet(), conf.GetKeySet(conf.CurrentKeys()))
|
| 504 |
+
|
| 505 |
+
# Restore platform
|
| 506 |
+
sys.platform = current_platform
|
| 507 |
+
|
| 508 |
+
def test_get_keyset(self):
|
| 509 |
+
conf = self.mock_config()
|
| 510 |
+
|
| 511 |
+
# Conflict with key set, should be disable to ''
|
| 512 |
+
conf.defaultCfg['extensions'].add_section('Foobar')
|
| 513 |
+
conf.defaultCfg['extensions'].add_section('Foobar_cfgBindings')
|
| 514 |
+
conf.defaultCfg['extensions'].set('Foobar', 'enable', 'True')
|
| 515 |
+
conf.defaultCfg['extensions'].set('Foobar_cfgBindings', 'newfoo', '<Key-F3>')
|
| 516 |
+
self.assertEqual(conf.GetKeySet('IDLE Modern Unix')['<<newfoo>>'], '')
|
| 517 |
+
|
| 518 |
+
def test_is_core_binding(self):
|
| 519 |
+
# XXX: Should move out the core keys to config file or other place
|
| 520 |
+
conf = self.mock_config()
|
| 521 |
+
|
| 522 |
+
self.assertTrue(conf.IsCoreBinding('copy'))
|
| 523 |
+
self.assertTrue(conf.IsCoreBinding('cut'))
|
| 524 |
+
self.assertTrue(conf.IsCoreBinding('del-word-right'))
|
| 525 |
+
self.assertFalse(conf.IsCoreBinding('not-exists'))
|
| 526 |
+
|
| 527 |
+
def test_extra_help_source_list(self):
|
| 528 |
+
# Test GetExtraHelpSourceList and GetAllExtraHelpSourcesList in same
|
| 529 |
+
# place to prevent prepare input data twice.
|
| 530 |
+
conf = self.mock_config()
|
| 531 |
+
|
| 532 |
+
# Test default with no extra help source
|
| 533 |
+
self.assertEqual(conf.GetExtraHelpSourceList('default'), [])
|
| 534 |
+
self.assertEqual(conf.GetExtraHelpSourceList('user'), [])
|
| 535 |
+
with self.assertRaises(config.InvalidConfigSet):
|
| 536 |
+
self.assertEqual(conf.GetExtraHelpSourceList('bad'), [])
|
| 537 |
+
self.assertCountEqual(
|
| 538 |
+
conf.GetAllExtraHelpSourcesList(),
|
| 539 |
+
conf.GetExtraHelpSourceList('default') + conf.GetExtraHelpSourceList('user'))
|
| 540 |
+
|
| 541 |
+
# Add help source to user config
|
| 542 |
+
conf.userCfg['main'].SetOption('HelpFiles', '4', 'Python;https://python.org') # This is bad input
|
| 543 |
+
conf.userCfg['main'].SetOption('HelpFiles', '3', 'Python:https://python.org') # This is bad input
|
| 544 |
+
conf.userCfg['main'].SetOption('HelpFiles', '2', 'Pillow;https://pillow.readthedocs.io/en/latest/')
|
| 545 |
+
conf.userCfg['main'].SetOption('HelpFiles', '1', 'IDLE;C:/Programs/Python36/Lib/idlelib/help.html')
|
| 546 |
+
self.assertEqual(conf.GetExtraHelpSourceList('user'),
|
| 547 |
+
[('IDLE', 'C:/Programs/Python36/Lib/idlelib/help.html', '1'),
|
| 548 |
+
('Pillow', 'https://pillow.readthedocs.io/en/latest/', '2'),
|
| 549 |
+
('Python', 'https://python.org', '4')])
|
| 550 |
+
self.assertCountEqual(
|
| 551 |
+
conf.GetAllExtraHelpSourcesList(),
|
| 552 |
+
conf.GetExtraHelpSourceList('default') + conf.GetExtraHelpSourceList('user'))
|
| 553 |
+
|
| 554 |
+
def test_get_font(self):
|
| 555 |
+
from test.support import requires
|
| 556 |
+
from tkinter import Tk
|
| 557 |
+
from tkinter.font import Font
|
| 558 |
+
conf = self.mock_config()
|
| 559 |
+
|
| 560 |
+
requires('gui')
|
| 561 |
+
root = Tk()
|
| 562 |
+
root.withdraw()
|
| 563 |
+
|
| 564 |
+
f = Font.actual(Font(name='TkFixedFont', exists=True, root=root))
|
| 565 |
+
self.assertEqual(
|
| 566 |
+
conf.GetFont(root, 'main', 'EditorWindow'),
|
| 567 |
+
(f['family'], 10 if f['size'] <= 0 else f['size'], f['weight']))
|
| 568 |
+
|
| 569 |
+
# Cleanup root
|
| 570 |
+
root.destroy()
|
| 571 |
+
del root
|
| 572 |
+
|
| 573 |
+
def test_get_core_keys(self):
|
| 574 |
+
conf = self.mock_config()
|
| 575 |
+
|
| 576 |
+
eq = self.assertEqual
|
| 577 |
+
eq(conf.GetCoreKeys()['<<center-insert>>'], ['<Control-l>'])
|
| 578 |
+
eq(conf.GetCoreKeys()['<<copy>>'], ['<Control-c>', '<Control-C>'])
|
| 579 |
+
eq(conf.GetCoreKeys()['<<history-next>>'], ['<Alt-n>'])
|
| 580 |
+
eq(conf.GetCoreKeys('IDLE Classic Windows')['<<center-insert>>'],
|
| 581 |
+
['<Control-Key-l>', '<Control-Key-L>'])
|
| 582 |
+
eq(conf.GetCoreKeys('IDLE Classic OSX')['<<copy>>'], ['<Command-Key-c>'])
|
| 583 |
+
eq(conf.GetCoreKeys('IDLE Classic Unix')['<<history-next>>'],
|
| 584 |
+
['<Alt-Key-n>', '<Meta-Key-n>'])
|
| 585 |
+
eq(conf.GetCoreKeys('IDLE Modern Unix')['<<history-next>>'],
|
| 586 |
+
['<Alt-Key-n>', '<Meta-Key-n>'])
|
| 587 |
+
|
| 588 |
+
|
| 589 |
+
class CurrentColorKeysTest(unittest.TestCase):
|
| 590 |
+
""" Test colorkeys function with user config [Theme] and [Keys] patterns.
|
| 591 |
+
|
| 592 |
+
colorkeys = config.IdleConf.current_colors_and_keys
|
| 593 |
+
Test all patterns written by IDLE and some errors
|
| 594 |
+
Item 'default' should really be 'builtin' (versus 'custom).
|
| 595 |
+
"""
|
| 596 |
+
colorkeys = idleConf.current_colors_and_keys
|
| 597 |
+
default_theme = 'IDLE Classic'
|
| 598 |
+
default_keys = idleConf.default_keys()
|
| 599 |
+
|
| 600 |
+
def test_old_builtin_theme(self):
|
| 601 |
+
# On initial installation, user main is blank.
|
| 602 |
+
self.assertEqual(self.colorkeys('Theme'), self.default_theme)
|
| 603 |
+
# For old default, name2 must be blank.
|
| 604 |
+
usermain.read_string('''
|
| 605 |
+
[Theme]
|
| 606 |
+
default = True
|
| 607 |
+
''')
|
| 608 |
+
# IDLE omits 'name' for default old builtin theme.
|
| 609 |
+
self.assertEqual(self.colorkeys('Theme'), self.default_theme)
|
| 610 |
+
# IDLE adds 'name' for non-default old builtin theme.
|
| 611 |
+
usermain['Theme']['name'] = 'IDLE New'
|
| 612 |
+
self.assertEqual(self.colorkeys('Theme'), 'IDLE New')
|
| 613 |
+
# Erroneous non-default old builtin reverts to default.
|
| 614 |
+
usermain['Theme']['name'] = 'non-existent'
|
| 615 |
+
self.assertEqual(self.colorkeys('Theme'), self.default_theme)
|
| 616 |
+
usermain.remove_section('Theme')
|
| 617 |
+
|
| 618 |
+
def test_new_builtin_theme(self):
|
| 619 |
+
# IDLE writes name2 for new builtins.
|
| 620 |
+
usermain.read_string('''
|
| 621 |
+
[Theme]
|
| 622 |
+
default = True
|
| 623 |
+
name2 = IDLE Dark
|
| 624 |
+
''')
|
| 625 |
+
self.assertEqual(self.colorkeys('Theme'), 'IDLE Dark')
|
| 626 |
+
# Leftover 'name', not removed, is ignored.
|
| 627 |
+
usermain['Theme']['name'] = 'IDLE New'
|
| 628 |
+
self.assertEqual(self.colorkeys('Theme'), 'IDLE Dark')
|
| 629 |
+
# Erroneous non-default new builtin reverts to default.
|
| 630 |
+
usermain['Theme']['name2'] = 'non-existent'
|
| 631 |
+
self.assertEqual(self.colorkeys('Theme'), self.default_theme)
|
| 632 |
+
usermain.remove_section('Theme')
|
| 633 |
+
|
| 634 |
+
def test_user_override_theme(self):
|
| 635 |
+
# Erroneous custom name (no definition) reverts to default.
|
| 636 |
+
usermain.read_string('''
|
| 637 |
+
[Theme]
|
| 638 |
+
default = False
|
| 639 |
+
name = Custom Dark
|
| 640 |
+
''')
|
| 641 |
+
self.assertEqual(self.colorkeys('Theme'), self.default_theme)
|
| 642 |
+
# Custom name is valid with matching Section name.
|
| 643 |
+
userhigh.read_string('[Custom Dark]\na=b')
|
| 644 |
+
self.assertEqual(self.colorkeys('Theme'), 'Custom Dark')
|
| 645 |
+
# Name2 is ignored.
|
| 646 |
+
usermain['Theme']['name2'] = 'non-existent'
|
| 647 |
+
self.assertEqual(self.colorkeys('Theme'), 'Custom Dark')
|
| 648 |
+
usermain.remove_section('Theme')
|
| 649 |
+
userhigh.remove_section('Custom Dark')
|
| 650 |
+
|
| 651 |
+
def test_old_builtin_keys(self):
|
| 652 |
+
# On initial installation, user main is blank.
|
| 653 |
+
self.assertEqual(self.colorkeys('Keys'), self.default_keys)
|
| 654 |
+
# For old default, name2 must be blank, name is always used.
|
| 655 |
+
usermain.read_string('''
|
| 656 |
+
[Keys]
|
| 657 |
+
default = True
|
| 658 |
+
name = IDLE Classic Unix
|
| 659 |
+
''')
|
| 660 |
+
self.assertEqual(self.colorkeys('Keys'), 'IDLE Classic Unix')
|
| 661 |
+
# Erroneous non-default old builtin reverts to default.
|
| 662 |
+
usermain['Keys']['name'] = 'non-existent'
|
| 663 |
+
self.assertEqual(self.colorkeys('Keys'), self.default_keys)
|
| 664 |
+
usermain.remove_section('Keys')
|
| 665 |
+
|
| 666 |
+
def test_new_builtin_keys(self):
|
| 667 |
+
# IDLE writes name2 for new builtins.
|
| 668 |
+
usermain.read_string('''
|
| 669 |
+
[Keys]
|
| 670 |
+
default = True
|
| 671 |
+
name2 = IDLE Modern Unix
|
| 672 |
+
''')
|
| 673 |
+
self.assertEqual(self.colorkeys('Keys'), 'IDLE Modern Unix')
|
| 674 |
+
# Leftover 'name', not removed, is ignored.
|
| 675 |
+
usermain['Keys']['name'] = 'IDLE Classic Unix'
|
| 676 |
+
self.assertEqual(self.colorkeys('Keys'), 'IDLE Modern Unix')
|
| 677 |
+
# Erroneous non-default new builtin reverts to default.
|
| 678 |
+
usermain['Keys']['name2'] = 'non-existent'
|
| 679 |
+
self.assertEqual(self.colorkeys('Keys'), self.default_keys)
|
| 680 |
+
usermain.remove_section('Keys')
|
| 681 |
+
|
| 682 |
+
def test_user_override_keys(self):
|
| 683 |
+
# Erroneous custom name (no definition) reverts to default.
|
| 684 |
+
usermain.read_string('''
|
| 685 |
+
[Keys]
|
| 686 |
+
default = False
|
| 687 |
+
name = Custom Keys
|
| 688 |
+
''')
|
| 689 |
+
self.assertEqual(self.colorkeys('Keys'), self.default_keys)
|
| 690 |
+
# Custom name is valid with matching Section name.
|
| 691 |
+
userkeys.read_string('[Custom Keys]\na=b')
|
| 692 |
+
self.assertEqual(self.colorkeys('Keys'), 'Custom Keys')
|
| 693 |
+
# Name2 is ignored.
|
| 694 |
+
usermain['Keys']['name2'] = 'non-existent'
|
| 695 |
+
self.assertEqual(self.colorkeys('Keys'), 'Custom Keys')
|
| 696 |
+
usermain.remove_section('Keys')
|
| 697 |
+
userkeys.remove_section('Custom Keys')
|
| 698 |
+
|
| 699 |
+
|
| 700 |
+
class ChangesTest(unittest.TestCase):
|
| 701 |
+
|
| 702 |
+
empty = {'main':{}, 'highlight':{}, 'keys':{}, 'extensions':{}}
|
| 703 |
+
|
| 704 |
+
def load(self): # Test_add_option verifies that this works.
|
| 705 |
+
changes = self.changes
|
| 706 |
+
changes.add_option('main', 'Msec', 'mitem', 'mval')
|
| 707 |
+
changes.add_option('highlight', 'Hsec', 'hitem', 'hval')
|
| 708 |
+
changes.add_option('keys', 'Ksec', 'kitem', 'kval')
|
| 709 |
+
return changes
|
| 710 |
+
|
| 711 |
+
loaded = {'main': {'Msec': {'mitem': 'mval'}},
|
| 712 |
+
'highlight': {'Hsec': {'hitem': 'hval'}},
|
| 713 |
+
'keys': {'Ksec': {'kitem':'kval'}},
|
| 714 |
+
'extensions': {}}
|
| 715 |
+
|
| 716 |
+
def setUp(self):
|
| 717 |
+
self.changes = config.ConfigChanges()
|
| 718 |
+
|
| 719 |
+
def test_init(self):
|
| 720 |
+
self.assertEqual(self.changes, self.empty)
|
| 721 |
+
|
| 722 |
+
def test_add_option(self):
|
| 723 |
+
changes = self.load()
|
| 724 |
+
self.assertEqual(changes, self.loaded)
|
| 725 |
+
changes.add_option('main', 'Msec', 'mitem', 'mval')
|
| 726 |
+
self.assertEqual(changes, self.loaded)
|
| 727 |
+
|
| 728 |
+
def test_save_option(self): # Static function does not touch changes.
|
| 729 |
+
save_option = self.changes.save_option
|
| 730 |
+
self.assertTrue(save_option('main', 'Indent', 'what', '0'))
|
| 731 |
+
self.assertFalse(save_option('main', 'Indent', 'what', '0'))
|
| 732 |
+
self.assertEqual(usermain['Indent']['what'], '0')
|
| 733 |
+
|
| 734 |
+
self.assertTrue(save_option('main', 'Indent', 'use-spaces', '0'))
|
| 735 |
+
self.assertEqual(usermain['Indent']['use-spaces'], '0')
|
| 736 |
+
self.assertTrue(save_option('main', 'Indent', 'use-spaces', '1'))
|
| 737 |
+
self.assertFalse(usermain.has_option('Indent', 'use-spaces'))
|
| 738 |
+
usermain.remove_section('Indent')
|
| 739 |
+
|
| 740 |
+
def test_save_added(self):
|
| 741 |
+
changes = self.load()
|
| 742 |
+
self.assertTrue(changes.save_all())
|
| 743 |
+
self.assertEqual(usermain['Msec']['mitem'], 'mval')
|
| 744 |
+
self.assertEqual(userhigh['Hsec']['hitem'], 'hval')
|
| 745 |
+
self.assertEqual(userkeys['Ksec']['kitem'], 'kval')
|
| 746 |
+
changes.add_option('main', 'Msec', 'mitem', 'mval')
|
| 747 |
+
self.assertFalse(changes.save_all())
|
| 748 |
+
usermain.remove_section('Msec')
|
| 749 |
+
userhigh.remove_section('Hsec')
|
| 750 |
+
userkeys.remove_section('Ksec')
|
| 751 |
+
|
| 752 |
+
def test_save_help(self):
|
| 753 |
+
# Any change to HelpFiles overwrites entire section.
|
| 754 |
+
changes = self.changes
|
| 755 |
+
changes.save_option('main', 'HelpFiles', 'IDLE', 'idledoc')
|
| 756 |
+
changes.add_option('main', 'HelpFiles', 'ELDI', 'codeldi')
|
| 757 |
+
changes.save_all()
|
| 758 |
+
self.assertFalse(usermain.has_option('HelpFiles', 'IDLE'))
|
| 759 |
+
self.assertTrue(usermain.has_option('HelpFiles', 'ELDI'))
|
| 760 |
+
|
| 761 |
+
def test_save_default(self): # Cover 2nd and 3rd false branches.
|
| 762 |
+
changes = self.changes
|
| 763 |
+
changes.add_option('main', 'Indent', 'use-spaces', '1')
|
| 764 |
+
# save_option returns False; cfg_type_changed remains False.
|
| 765 |
+
|
| 766 |
+
# TODO: test that save_all calls usercfg Saves.
|
| 767 |
+
|
| 768 |
+
def test_delete_section(self):
|
| 769 |
+
changes = self.load()
|
| 770 |
+
changes.delete_section('main', 'fake') # Test no exception.
|
| 771 |
+
self.assertEqual(changes, self.loaded) # Test nothing deleted.
|
| 772 |
+
for cfgtype, section in (('main', 'Msec'), ('keys', 'Ksec')):
|
| 773 |
+
testcfg[cfgtype].SetOption(section, 'name', 'value')
|
| 774 |
+
changes.delete_section(cfgtype, section)
|
| 775 |
+
with self.assertRaises(KeyError):
|
| 776 |
+
changes[cfgtype][section] # Test section gone from changes
|
| 777 |
+
testcfg[cfgtype][section] # and from mock userCfg.
|
| 778 |
+
# TODO test for save call.
|
| 779 |
+
|
| 780 |
+
def test_clear(self):
|
| 781 |
+
changes = self.load()
|
| 782 |
+
changes.clear()
|
| 783 |
+
self.assertEqual(changes, self.empty)
|
| 784 |
+
|
| 785 |
+
|
| 786 |
+
class WarningTest(unittest.TestCase):
|
| 787 |
+
|
| 788 |
+
def test_warn(self):
|
| 789 |
+
Equal = self.assertEqual
|
| 790 |
+
config._warned = set()
|
| 791 |
+
with captured_stderr() as stderr:
|
| 792 |
+
config._warn('warning', 'key')
|
| 793 |
+
Equal(config._warned, {('warning','key')})
|
| 794 |
+
Equal(stderr.getvalue(), 'warning'+'\n')
|
| 795 |
+
with captured_stderr() as stderr:
|
| 796 |
+
config._warn('warning', 'key')
|
| 797 |
+
Equal(stderr.getvalue(), '')
|
| 798 |
+
with captured_stderr() as stderr:
|
| 799 |
+
config._warn('warn2', 'yek')
|
| 800 |
+
Equal(config._warned, {('warning','key'), ('warn2','yek')})
|
| 801 |
+
Equal(stderr.getvalue(), 'warn2'+'\n')
|
| 802 |
+
|
| 803 |
+
|
| 804 |
+
if __name__ == '__main__':
|
| 805 |
+
unittest.main(verbosity=2)
|
micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_config_key.py
ADDED
|
@@ -0,0 +1,356 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Test config_key, coverage 98%.
|
| 2 |
+
|
| 3 |
+
Coverage is effectively 100%. Tkinter dialog is mocked, Mac-only line
|
| 4 |
+
may be skipped, and dummy function in bind test should not be called.
|
| 5 |
+
Not tested: exit with 'self.advanced or self.keys_ok(keys) ...' False.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
from idlelib import config_key
|
| 9 |
+
from test.support import requires
|
| 10 |
+
import unittest
|
| 11 |
+
from unittest import mock
|
| 12 |
+
from tkinter import Tk, TclError
|
| 13 |
+
from idlelib.idle_test.mock_idle import Func
|
| 14 |
+
from idlelib.idle_test.mock_tk import Mbox_func
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
class ValidationTest(unittest.TestCase):
|
| 18 |
+
"Test validation methods: ok, keys_ok, bind_ok."
|
| 19 |
+
|
| 20 |
+
class Validator(config_key.GetKeysFrame):
|
| 21 |
+
def __init__(self, *args, **kwargs):
|
| 22 |
+
super().__init__(*args, **kwargs)
|
| 23 |
+
class list_keys_final:
|
| 24 |
+
get = Func()
|
| 25 |
+
self.list_keys_final = list_keys_final
|
| 26 |
+
get_modifiers = Func()
|
| 27 |
+
showerror = Mbox_func()
|
| 28 |
+
|
| 29 |
+
@classmethod
|
| 30 |
+
def setUpClass(cls):
|
| 31 |
+
requires('gui')
|
| 32 |
+
cls.root = Tk()
|
| 33 |
+
cls.root.withdraw()
|
| 34 |
+
keylist = [['<Key-F12>'], ['<Control-Key-x>', '<Control-Key-X>']]
|
| 35 |
+
cls.dialog = cls.Validator(cls.root, '<<Test>>', keylist)
|
| 36 |
+
|
| 37 |
+
@classmethod
|
| 38 |
+
def tearDownClass(cls):
|
| 39 |
+
del cls.dialog
|
| 40 |
+
cls.root.update_idletasks()
|
| 41 |
+
cls.root.destroy()
|
| 42 |
+
del cls.root
|
| 43 |
+
|
| 44 |
+
def setUp(self):
|
| 45 |
+
self.dialog.showerror.message = ''
|
| 46 |
+
# A test that needs a particular final key value should set it.
|
| 47 |
+
# A test that sets a non-blank modifier list should reset it to [].
|
| 48 |
+
|
| 49 |
+
def test_ok_empty(self):
|
| 50 |
+
self.dialog.key_string.set(' ')
|
| 51 |
+
self.dialog.ok()
|
| 52 |
+
self.assertEqual(self.dialog.result, '')
|
| 53 |
+
self.assertEqual(self.dialog.showerror.message, 'No key specified.')
|
| 54 |
+
|
| 55 |
+
def test_ok_good(self):
|
| 56 |
+
self.dialog.key_string.set('<Key-F11>')
|
| 57 |
+
self.dialog.list_keys_final.get.result = 'F11'
|
| 58 |
+
self.dialog.ok()
|
| 59 |
+
self.assertEqual(self.dialog.result, '<Key-F11>')
|
| 60 |
+
self.assertEqual(self.dialog.showerror.message, '')
|
| 61 |
+
|
| 62 |
+
def test_keys_no_ending(self):
|
| 63 |
+
self.assertFalse(self.dialog.keys_ok('<Control-Shift'))
|
| 64 |
+
self.assertIn('Missing the final', self.dialog.showerror.message)
|
| 65 |
+
|
| 66 |
+
def test_keys_no_modifier_bad(self):
|
| 67 |
+
self.dialog.list_keys_final.get.result = 'A'
|
| 68 |
+
self.assertFalse(self.dialog.keys_ok('<Key-A>'))
|
| 69 |
+
self.assertIn('No modifier', self.dialog.showerror.message)
|
| 70 |
+
|
| 71 |
+
def test_keys_no_modifier_ok(self):
|
| 72 |
+
self.dialog.list_keys_final.get.result = 'F11'
|
| 73 |
+
self.assertTrue(self.dialog.keys_ok('<Key-F11>'))
|
| 74 |
+
self.assertEqual(self.dialog.showerror.message, '')
|
| 75 |
+
|
| 76 |
+
def test_keys_shift_bad(self):
|
| 77 |
+
self.dialog.list_keys_final.get.result = 'a'
|
| 78 |
+
self.dialog.get_modifiers.result = ['Shift']
|
| 79 |
+
self.assertFalse(self.dialog.keys_ok('<a>'))
|
| 80 |
+
self.assertIn('shift modifier', self.dialog.showerror.message)
|
| 81 |
+
self.dialog.get_modifiers.result = []
|
| 82 |
+
|
| 83 |
+
def test_keys_dup(self):
|
| 84 |
+
for mods, final, seq in (([], 'F12', '<Key-F12>'),
|
| 85 |
+
(['Control'], 'x', '<Control-Key-x>'),
|
| 86 |
+
(['Control'], 'X', '<Control-Key-X>')):
|
| 87 |
+
with self.subTest(m=mods, f=final, s=seq):
|
| 88 |
+
self.dialog.list_keys_final.get.result = final
|
| 89 |
+
self.dialog.get_modifiers.result = mods
|
| 90 |
+
self.assertFalse(self.dialog.keys_ok(seq))
|
| 91 |
+
self.assertIn('already in use', self.dialog.showerror.message)
|
| 92 |
+
self.dialog.get_modifiers.result = []
|
| 93 |
+
|
| 94 |
+
def test_bind_ok(self):
|
| 95 |
+
self.assertTrue(self.dialog.bind_ok('<Control-Shift-Key-a>'))
|
| 96 |
+
self.assertEqual(self.dialog.showerror.message, '')
|
| 97 |
+
|
| 98 |
+
def test_bind_not_ok(self):
|
| 99 |
+
self.assertFalse(self.dialog.bind_ok('<Control-Shift>'))
|
| 100 |
+
self.assertIn('not accepted', self.dialog.showerror.message)
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
class ToggleLevelTest(unittest.TestCase):
|
| 104 |
+
"Test toggle between Basic and Advanced frames."
|
| 105 |
+
|
| 106 |
+
@classmethod
|
| 107 |
+
def setUpClass(cls):
|
| 108 |
+
requires('gui')
|
| 109 |
+
cls.root = Tk()
|
| 110 |
+
cls.root.withdraw()
|
| 111 |
+
cls.dialog = config_key.GetKeysFrame(cls.root, '<<Test>>', [])
|
| 112 |
+
|
| 113 |
+
@classmethod
|
| 114 |
+
def tearDownClass(cls):
|
| 115 |
+
del cls.dialog
|
| 116 |
+
cls.root.update_idletasks()
|
| 117 |
+
cls.root.destroy()
|
| 118 |
+
del cls.root
|
| 119 |
+
|
| 120 |
+
def test_toggle_level(self):
|
| 121 |
+
dialog = self.dialog
|
| 122 |
+
|
| 123 |
+
def stackorder():
|
| 124 |
+
"""Get the stack order of the children of the frame.
|
| 125 |
+
|
| 126 |
+
winfo_children() stores the children in stack order, so
|
| 127 |
+
this can be used to check whether a frame is above or
|
| 128 |
+
below another one.
|
| 129 |
+
"""
|
| 130 |
+
for index, child in enumerate(dialog.winfo_children()):
|
| 131 |
+
if child._name == 'keyseq_basic':
|
| 132 |
+
basic = index
|
| 133 |
+
if child._name == 'keyseq_advanced':
|
| 134 |
+
advanced = index
|
| 135 |
+
return basic, advanced
|
| 136 |
+
|
| 137 |
+
# New window starts at basic level.
|
| 138 |
+
self.assertFalse(dialog.advanced)
|
| 139 |
+
self.assertIn('Advanced', dialog.button_level['text'])
|
| 140 |
+
basic, advanced = stackorder()
|
| 141 |
+
self.assertGreater(basic, advanced)
|
| 142 |
+
|
| 143 |
+
# Toggle to advanced.
|
| 144 |
+
dialog.toggle_level()
|
| 145 |
+
self.assertTrue(dialog.advanced)
|
| 146 |
+
self.assertIn('Basic', dialog.button_level['text'])
|
| 147 |
+
basic, advanced = stackorder()
|
| 148 |
+
self.assertGreater(advanced, basic)
|
| 149 |
+
|
| 150 |
+
# Toggle to basic.
|
| 151 |
+
dialog.button_level.invoke()
|
| 152 |
+
self.assertFalse(dialog.advanced)
|
| 153 |
+
self.assertIn('Advanced', dialog.button_level['text'])
|
| 154 |
+
basic, advanced = stackorder()
|
| 155 |
+
self.assertGreater(basic, advanced)
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
class KeySelectionTest(unittest.TestCase):
|
| 159 |
+
"Test selecting key on Basic frames."
|
| 160 |
+
|
| 161 |
+
class Basic(config_key.GetKeysFrame):
|
| 162 |
+
def __init__(self, *args, **kwargs):
|
| 163 |
+
super().__init__(*args, **kwargs)
|
| 164 |
+
class list_keys_final:
|
| 165 |
+
get = Func()
|
| 166 |
+
select_clear = Func()
|
| 167 |
+
yview = Func()
|
| 168 |
+
self.list_keys_final = list_keys_final
|
| 169 |
+
def set_modifiers_for_platform(self):
|
| 170 |
+
self.modifiers = ['foo', 'bar', 'BAZ']
|
| 171 |
+
self.modifier_label = {'BAZ': 'ZZZ'}
|
| 172 |
+
showerror = Mbox_func()
|
| 173 |
+
|
| 174 |
+
@classmethod
|
| 175 |
+
def setUpClass(cls):
|
| 176 |
+
requires('gui')
|
| 177 |
+
cls.root = Tk()
|
| 178 |
+
cls.root.withdraw()
|
| 179 |
+
cls.dialog = cls.Basic(cls.root, '<<Test>>', [])
|
| 180 |
+
|
| 181 |
+
@classmethod
|
| 182 |
+
def tearDownClass(cls):
|
| 183 |
+
del cls.dialog
|
| 184 |
+
cls.root.update_idletasks()
|
| 185 |
+
cls.root.destroy()
|
| 186 |
+
del cls.root
|
| 187 |
+
|
| 188 |
+
def setUp(self):
|
| 189 |
+
self.dialog.clear_key_seq()
|
| 190 |
+
|
| 191 |
+
def test_get_modifiers(self):
|
| 192 |
+
dialog = self.dialog
|
| 193 |
+
gm = dialog.get_modifiers
|
| 194 |
+
eq = self.assertEqual
|
| 195 |
+
|
| 196 |
+
# Modifiers are set on/off by invoking the checkbutton.
|
| 197 |
+
dialog.modifier_checkbuttons['foo'].invoke()
|
| 198 |
+
eq(gm(), ['foo'])
|
| 199 |
+
|
| 200 |
+
dialog.modifier_checkbuttons['BAZ'].invoke()
|
| 201 |
+
eq(gm(), ['foo', 'BAZ'])
|
| 202 |
+
|
| 203 |
+
dialog.modifier_checkbuttons['foo'].invoke()
|
| 204 |
+
eq(gm(), ['BAZ'])
|
| 205 |
+
|
| 206 |
+
@mock.patch.object(config_key.GetKeysFrame, 'get_modifiers')
|
| 207 |
+
def test_build_key_string(self, mock_modifiers):
|
| 208 |
+
dialog = self.dialog
|
| 209 |
+
key = dialog.list_keys_final
|
| 210 |
+
string = dialog.key_string.get
|
| 211 |
+
eq = self.assertEqual
|
| 212 |
+
|
| 213 |
+
key.get.result = 'a'
|
| 214 |
+
mock_modifiers.return_value = []
|
| 215 |
+
dialog.build_key_string()
|
| 216 |
+
eq(string(), '<Key-a>')
|
| 217 |
+
|
| 218 |
+
mock_modifiers.return_value = ['mymod']
|
| 219 |
+
dialog.build_key_string()
|
| 220 |
+
eq(string(), '<mymod-Key-a>')
|
| 221 |
+
|
| 222 |
+
key.get.result = ''
|
| 223 |
+
mock_modifiers.return_value = ['mymod', 'test']
|
| 224 |
+
dialog.build_key_string()
|
| 225 |
+
eq(string(), '<mymod-test>')
|
| 226 |
+
|
| 227 |
+
@mock.patch.object(config_key.GetKeysFrame, 'get_modifiers')
|
| 228 |
+
def test_final_key_selected(self, mock_modifiers):
|
| 229 |
+
dialog = self.dialog
|
| 230 |
+
key = dialog.list_keys_final
|
| 231 |
+
string = dialog.key_string.get
|
| 232 |
+
eq = self.assertEqual
|
| 233 |
+
|
| 234 |
+
mock_modifiers.return_value = ['Shift']
|
| 235 |
+
key.get.result = '{'
|
| 236 |
+
dialog.final_key_selected()
|
| 237 |
+
eq(string(), '<Shift-Key-braceleft>')
|
| 238 |
+
|
| 239 |
+
|
| 240 |
+
class CancelWindowTest(unittest.TestCase):
|
| 241 |
+
"Simulate user clicking [Cancel] button."
|
| 242 |
+
|
| 243 |
+
@classmethod
|
| 244 |
+
def setUpClass(cls):
|
| 245 |
+
requires('gui')
|
| 246 |
+
cls.root = Tk()
|
| 247 |
+
cls.root.withdraw()
|
| 248 |
+
cls.dialog = config_key.GetKeysWindow(
|
| 249 |
+
cls.root, 'Title', '<<Test>>', [], _utest=True)
|
| 250 |
+
|
| 251 |
+
@classmethod
|
| 252 |
+
def tearDownClass(cls):
|
| 253 |
+
cls.dialog.cancel()
|
| 254 |
+
del cls.dialog
|
| 255 |
+
cls.root.update_idletasks()
|
| 256 |
+
cls.root.destroy()
|
| 257 |
+
del cls.root
|
| 258 |
+
|
| 259 |
+
@mock.patch.object(config_key.GetKeysFrame, 'ok')
|
| 260 |
+
def test_cancel(self, mock_frame_ok):
|
| 261 |
+
self.assertEqual(self.dialog.winfo_class(), 'Toplevel')
|
| 262 |
+
self.dialog.button_cancel.invoke()
|
| 263 |
+
with self.assertRaises(TclError):
|
| 264 |
+
self.dialog.winfo_class()
|
| 265 |
+
self.assertEqual(self.dialog.result, '')
|
| 266 |
+
mock_frame_ok.assert_not_called()
|
| 267 |
+
|
| 268 |
+
|
| 269 |
+
class OKWindowTest(unittest.TestCase):
|
| 270 |
+
"Simulate user clicking [OK] button."
|
| 271 |
+
|
| 272 |
+
@classmethod
|
| 273 |
+
def setUpClass(cls):
|
| 274 |
+
requires('gui')
|
| 275 |
+
cls.root = Tk()
|
| 276 |
+
cls.root.withdraw()
|
| 277 |
+
cls.dialog = config_key.GetKeysWindow(
|
| 278 |
+
cls.root, 'Title', '<<Test>>', [], _utest=True)
|
| 279 |
+
|
| 280 |
+
@classmethod
|
| 281 |
+
def tearDownClass(cls):
|
| 282 |
+
cls.dialog.cancel()
|
| 283 |
+
del cls.dialog
|
| 284 |
+
cls.root.update_idletasks()
|
| 285 |
+
cls.root.destroy()
|
| 286 |
+
del cls.root
|
| 287 |
+
|
| 288 |
+
@mock.patch.object(config_key.GetKeysFrame, 'ok')
|
| 289 |
+
def test_ok(self, mock_frame_ok):
|
| 290 |
+
self.assertEqual(self.dialog.winfo_class(), 'Toplevel')
|
| 291 |
+
self.dialog.button_ok.invoke()
|
| 292 |
+
with self.assertRaises(TclError):
|
| 293 |
+
self.dialog.winfo_class()
|
| 294 |
+
mock_frame_ok.assert_called()
|
| 295 |
+
|
| 296 |
+
|
| 297 |
+
class WindowResultTest(unittest.TestCase):
|
| 298 |
+
"Test window result get and set."
|
| 299 |
+
|
| 300 |
+
@classmethod
|
| 301 |
+
def setUpClass(cls):
|
| 302 |
+
requires('gui')
|
| 303 |
+
cls.root = Tk()
|
| 304 |
+
cls.root.withdraw()
|
| 305 |
+
cls.dialog = config_key.GetKeysWindow(
|
| 306 |
+
cls.root, 'Title', '<<Test>>', [], _utest=True)
|
| 307 |
+
|
| 308 |
+
@classmethod
|
| 309 |
+
def tearDownClass(cls):
|
| 310 |
+
cls.dialog.cancel()
|
| 311 |
+
del cls.dialog
|
| 312 |
+
cls.root.update_idletasks()
|
| 313 |
+
cls.root.destroy()
|
| 314 |
+
del cls.root
|
| 315 |
+
|
| 316 |
+
def test_result(self):
|
| 317 |
+
dialog = self.dialog
|
| 318 |
+
eq = self.assertEqual
|
| 319 |
+
|
| 320 |
+
dialog.result = ''
|
| 321 |
+
eq(dialog.result, '')
|
| 322 |
+
eq(dialog.frame.result,'')
|
| 323 |
+
|
| 324 |
+
dialog.result = 'bar'
|
| 325 |
+
eq(dialog.result,'bar')
|
| 326 |
+
eq(dialog.frame.result,'bar')
|
| 327 |
+
|
| 328 |
+
dialog.frame.result = 'foo'
|
| 329 |
+
eq(dialog.result, 'foo')
|
| 330 |
+
eq(dialog.frame.result,'foo')
|
| 331 |
+
|
| 332 |
+
|
| 333 |
+
class HelperTest(unittest.TestCase):
|
| 334 |
+
"Test module level helper functions."
|
| 335 |
+
|
| 336 |
+
def test_translate_key(self):
|
| 337 |
+
tr = config_key.translate_key
|
| 338 |
+
eq = self.assertEqual
|
| 339 |
+
|
| 340 |
+
# Letters return unchanged with no 'Shift'.
|
| 341 |
+
eq(tr('q', []), 'Key-q')
|
| 342 |
+
eq(tr('q', ['Control', 'Alt']), 'Key-q')
|
| 343 |
+
|
| 344 |
+
# 'Shift' uppercases single lowercase letters.
|
| 345 |
+
eq(tr('q', ['Shift']), 'Key-Q')
|
| 346 |
+
eq(tr('q', ['Control', 'Shift']), 'Key-Q')
|
| 347 |
+
eq(tr('q', ['Control', 'Alt', 'Shift']), 'Key-Q')
|
| 348 |
+
|
| 349 |
+
# Convert key name to keysym.
|
| 350 |
+
eq(tr('Page Up', []), 'Key-Prior')
|
| 351 |
+
# 'Shift' doesn't change case when it's not a single char.
|
| 352 |
+
eq(tr('*', ['Shift']), 'Key-asterisk')
|
| 353 |
+
|
| 354 |
+
|
| 355 |
+
if __name__ == '__main__':
|
| 356 |
+
unittest.main(verbosity=2)
|
micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_configdialog.py
ADDED
|
@@ -0,0 +1,1580 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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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 |
+
hs = d.highlight_sample
|
| 424 |
+
hs.focus_force()
|
| 425 |
+
|
| 426 |
+
def click_char(index):
|
| 427 |
+
"Simulate click on character at *index*."
|
| 428 |
+
hs.see(index)
|
| 429 |
+
hs.update_idletasks()
|
| 430 |
+
x, y, dx, dy = hs.bbox(index)
|
| 431 |
+
x += dx // 2
|
| 432 |
+
y += dy // 2
|
| 433 |
+
hs.event_generate('<Enter>', x=0, y=0)
|
| 434 |
+
hs.event_generate('<Motion>', x=x, y=y)
|
| 435 |
+
hs.event_generate('<ButtonPress-1>', x=x, y=y)
|
| 436 |
+
hs.event_generate('<ButtonRelease-1>', x=x, y=y)
|
| 437 |
+
|
| 438 |
+
# Reverse theme_elements to make the tag the key.
|
| 439 |
+
elem = {tag: element for element, tag in d.theme_elements.items()}
|
| 440 |
+
|
| 441 |
+
# If highlight_sample has a tag that isn't in theme_elements, there
|
| 442 |
+
# will be a KeyError in the test run.
|
| 443 |
+
count = 0
|
| 444 |
+
for tag in hs.tag_names():
|
| 445 |
+
try:
|
| 446 |
+
click_char(hs.tag_nextrange(tag, "1.0")[0])
|
| 447 |
+
eq(d.highlight_target.get(), elem[tag])
|
| 448 |
+
count += 1
|
| 449 |
+
eq(d.set_highlight_target.called, count)
|
| 450 |
+
except IndexError:
|
| 451 |
+
pass # Skip unused theme_elements tag, like 'sel'.
|
| 452 |
+
|
| 453 |
+
def test_highlight_sample_double_click(self):
|
| 454 |
+
# Test double click on highlight_sample.
|
| 455 |
+
eq = self.assertEqual
|
| 456 |
+
d = self.page
|
| 457 |
+
|
| 458 |
+
hs = d.highlight_sample
|
| 459 |
+
hs.focus_force()
|
| 460 |
+
hs.see(1.0)
|
| 461 |
+
hs.update_idletasks()
|
| 462 |
+
|
| 463 |
+
# Test binding from configdialog.
|
| 464 |
+
hs.event_generate('<Enter>', x=0, y=0)
|
| 465 |
+
hs.event_generate('<Motion>', x=0, y=0)
|
| 466 |
+
# Double click is a sequence of two clicks in a row.
|
| 467 |
+
for _ in range(2):
|
| 468 |
+
hs.event_generate('<ButtonPress-1>', x=0, y=0)
|
| 469 |
+
hs.event_generate('<ButtonRelease-1>', x=0, y=0)
|
| 470 |
+
|
| 471 |
+
eq(hs.tag_ranges('sel'), ())
|
| 472 |
+
|
| 473 |
+
def test_highlight_sample_b1_motion(self):
|
| 474 |
+
# Test button motion on highlight_sample.
|
| 475 |
+
eq = self.assertEqual
|
| 476 |
+
d = self.page
|
| 477 |
+
|
| 478 |
+
hs = d.highlight_sample
|
| 479 |
+
hs.focus_force()
|
| 480 |
+
hs.see(1.0)
|
| 481 |
+
hs.update_idletasks()
|
| 482 |
+
|
| 483 |
+
x, y, dx, dy, offset = hs.dlineinfo('1.0')
|
| 484 |
+
|
| 485 |
+
# Test binding from configdialog.
|
| 486 |
+
hs.event_generate('<Leave>')
|
| 487 |
+
hs.event_generate('<Enter>')
|
| 488 |
+
hs.event_generate('<Motion>', x=x, y=y)
|
| 489 |
+
hs.event_generate('<ButtonPress-1>', x=x, y=y)
|
| 490 |
+
hs.event_generate('<B1-Motion>', x=dx, y=dy)
|
| 491 |
+
hs.event_generate('<ButtonRelease-1>', x=dx, y=dy)
|
| 492 |
+
|
| 493 |
+
eq(hs.tag_ranges('sel'), ())
|
| 494 |
+
|
| 495 |
+
def test_set_theme_type(self):
|
| 496 |
+
eq = self.assertEqual
|
| 497 |
+
d = self.page
|
| 498 |
+
del d.set_theme_type
|
| 499 |
+
|
| 500 |
+
# Builtin theme selected.
|
| 501 |
+
d.theme_source.set(True)
|
| 502 |
+
d.set_theme_type()
|
| 503 |
+
eq(d.builtinlist['state'], NORMAL)
|
| 504 |
+
eq(d.customlist['state'], DISABLED)
|
| 505 |
+
eq(d.button_delete_custom.state(), ('disabled',))
|
| 506 |
+
|
| 507 |
+
# Custom theme selected.
|
| 508 |
+
d.theme_source.set(False)
|
| 509 |
+
d.set_theme_type()
|
| 510 |
+
eq(d.builtinlist['state'], DISABLED)
|
| 511 |
+
eq(d.custom_theme_on.state(), ('selected',))
|
| 512 |
+
eq(d.customlist['state'], NORMAL)
|
| 513 |
+
eq(d.button_delete_custom.state(), ())
|
| 514 |
+
d.set_theme_type = Func()
|
| 515 |
+
|
| 516 |
+
def test_get_color(self):
|
| 517 |
+
eq = self.assertEqual
|
| 518 |
+
d = self.page
|
| 519 |
+
orig_chooser = configdialog.colorchooser.askcolor
|
| 520 |
+
chooser = configdialog.colorchooser.askcolor = Func()
|
| 521 |
+
gntn = d.get_new_theme_name = Func()
|
| 522 |
+
|
| 523 |
+
d.highlight_target.set('Editor Breakpoint')
|
| 524 |
+
d.color.set('#ffffff')
|
| 525 |
+
|
| 526 |
+
# Nothing selected.
|
| 527 |
+
chooser.result = (None, None)
|
| 528 |
+
d.button_set_color.invoke()
|
| 529 |
+
eq(d.color.get(), '#ffffff')
|
| 530 |
+
|
| 531 |
+
# Selection same as previous color.
|
| 532 |
+
chooser.result = ('', d.style.lookup(d.frame_color_set['style'], 'background'))
|
| 533 |
+
d.button_set_color.invoke()
|
| 534 |
+
eq(d.color.get(), '#ffffff')
|
| 535 |
+
|
| 536 |
+
# Select different color.
|
| 537 |
+
chooser.result = ((222.8671875, 0.0, 0.0), '#de0000')
|
| 538 |
+
|
| 539 |
+
# Default theme.
|
| 540 |
+
d.color.set('#ffffff')
|
| 541 |
+
d.theme_source.set(True)
|
| 542 |
+
|
| 543 |
+
# No theme name selected therefore color not saved.
|
| 544 |
+
gntn.result = ''
|
| 545 |
+
d.button_set_color.invoke()
|
| 546 |
+
eq(gntn.called, 1)
|
| 547 |
+
eq(d.color.get(), '#ffffff')
|
| 548 |
+
# Theme name selected.
|
| 549 |
+
gntn.result = 'My New Theme'
|
| 550 |
+
d.button_set_color.invoke()
|
| 551 |
+
eq(d.custom_name.get(), gntn.result)
|
| 552 |
+
eq(d.color.get(), '#de0000')
|
| 553 |
+
|
| 554 |
+
# Custom theme.
|
| 555 |
+
d.color.set('#ffffff')
|
| 556 |
+
d.theme_source.set(False)
|
| 557 |
+
d.button_set_color.invoke()
|
| 558 |
+
eq(d.color.get(), '#de0000')
|
| 559 |
+
|
| 560 |
+
del d.get_new_theme_name
|
| 561 |
+
configdialog.colorchooser.askcolor = orig_chooser
|
| 562 |
+
|
| 563 |
+
def test_on_new_color_set(self):
|
| 564 |
+
d = self.page
|
| 565 |
+
color = '#3f7cae'
|
| 566 |
+
d.custom_name.set('Python')
|
| 567 |
+
d.highlight_target.set('Selected Text')
|
| 568 |
+
d.fg_bg_toggle.set(True)
|
| 569 |
+
|
| 570 |
+
d.color.set(color)
|
| 571 |
+
self.assertEqual(d.style.lookup(d.frame_color_set['style'], 'background'), color)
|
| 572 |
+
self.assertEqual(d.highlight_sample.tag_cget('hilite', 'foreground'), color)
|
| 573 |
+
self.assertEqual(highpage,
|
| 574 |
+
{'Python': {'hilite-foreground': color}})
|
| 575 |
+
|
| 576 |
+
def test_get_new_theme_name(self):
|
| 577 |
+
orig_sectionname = configdialog.SectionName
|
| 578 |
+
sn = configdialog.SectionName = Func(return_self=True)
|
| 579 |
+
d = self.page
|
| 580 |
+
|
| 581 |
+
sn.result = 'New Theme'
|
| 582 |
+
self.assertEqual(d.get_new_theme_name(''), 'New Theme')
|
| 583 |
+
|
| 584 |
+
configdialog.SectionName = orig_sectionname
|
| 585 |
+
|
| 586 |
+
def test_save_as_new_theme(self):
|
| 587 |
+
d = self.page
|
| 588 |
+
gntn = d.get_new_theme_name = Func()
|
| 589 |
+
d.theme_source.set(True)
|
| 590 |
+
|
| 591 |
+
# No name entered.
|
| 592 |
+
gntn.result = ''
|
| 593 |
+
d.button_save_custom.invoke()
|
| 594 |
+
self.assertNotIn(gntn.result, idleConf.userCfg['highlight'])
|
| 595 |
+
|
| 596 |
+
# Name entered.
|
| 597 |
+
gntn.result = 'my new theme'
|
| 598 |
+
gntn.called = 0
|
| 599 |
+
self.assertNotIn(gntn.result, idleConf.userCfg['highlight'])
|
| 600 |
+
d.button_save_custom.invoke()
|
| 601 |
+
self.assertIn(gntn.result, idleConf.userCfg['highlight'])
|
| 602 |
+
|
| 603 |
+
del d.get_new_theme_name
|
| 604 |
+
|
| 605 |
+
def test_create_new_and_save_new(self):
|
| 606 |
+
eq = self.assertEqual
|
| 607 |
+
d = self.page
|
| 608 |
+
|
| 609 |
+
# Use default as previously active theme.
|
| 610 |
+
d.theme_source.set(True)
|
| 611 |
+
d.builtin_name.set('IDLE Classic')
|
| 612 |
+
first_new = 'my new custom theme'
|
| 613 |
+
second_new = 'my second custom theme'
|
| 614 |
+
|
| 615 |
+
# No changes, so themes are an exact copy.
|
| 616 |
+
self.assertNotIn(first_new, idleConf.userCfg)
|
| 617 |
+
d.create_new(first_new)
|
| 618 |
+
eq(idleConf.GetSectionList('user', 'highlight'), [first_new])
|
| 619 |
+
eq(idleConf.GetThemeDict('default', 'IDLE Classic'),
|
| 620 |
+
idleConf.GetThemeDict('user', first_new))
|
| 621 |
+
eq(d.custom_name.get(), first_new)
|
| 622 |
+
self.assertFalse(d.theme_source.get()) # Use custom set.
|
| 623 |
+
eq(d.set_theme_type.called, 1)
|
| 624 |
+
|
| 625 |
+
# Test that changed targets are in new theme.
|
| 626 |
+
changes.add_option('highlight', first_new, 'hit-background', 'yellow')
|
| 627 |
+
self.assertNotIn(second_new, idleConf.userCfg)
|
| 628 |
+
d.create_new(second_new)
|
| 629 |
+
eq(idleConf.GetSectionList('user', 'highlight'), [first_new, second_new])
|
| 630 |
+
self.assertNotEqual(idleConf.GetThemeDict('user', first_new),
|
| 631 |
+
idleConf.GetThemeDict('user', second_new))
|
| 632 |
+
# Check that difference in themes was in `hit-background` from `changes`.
|
| 633 |
+
idleConf.SetOption('highlight', first_new, 'hit-background', 'yellow')
|
| 634 |
+
eq(idleConf.GetThemeDict('user', first_new),
|
| 635 |
+
idleConf.GetThemeDict('user', second_new))
|
| 636 |
+
|
| 637 |
+
def test_set_highlight_target(self):
|
| 638 |
+
eq = self.assertEqual
|
| 639 |
+
d = self.page
|
| 640 |
+
del d.set_highlight_target
|
| 641 |
+
|
| 642 |
+
# Target is cursor.
|
| 643 |
+
d.highlight_target.set('Cursor')
|
| 644 |
+
eq(d.fg_on.state(), ('disabled', 'selected'))
|
| 645 |
+
eq(d.bg_on.state(), ('disabled',))
|
| 646 |
+
self.assertTrue(d.fg_bg_toggle)
|
| 647 |
+
eq(d.set_color_sample.called, 1)
|
| 648 |
+
|
| 649 |
+
# Target is not cursor.
|
| 650 |
+
d.highlight_target.set('Comment')
|
| 651 |
+
eq(d.fg_on.state(), ('selected',))
|
| 652 |
+
eq(d.bg_on.state(), ())
|
| 653 |
+
self.assertTrue(d.fg_bg_toggle)
|
| 654 |
+
eq(d.set_color_sample.called, 2)
|
| 655 |
+
|
| 656 |
+
d.set_highlight_target = Func()
|
| 657 |
+
|
| 658 |
+
def test_set_color_sample_binding(self):
|
| 659 |
+
d = self.page
|
| 660 |
+
scs = d.set_color_sample
|
| 661 |
+
|
| 662 |
+
d.fg_on.invoke()
|
| 663 |
+
self.assertEqual(scs.called, 1)
|
| 664 |
+
|
| 665 |
+
d.bg_on.invoke()
|
| 666 |
+
self.assertEqual(scs.called, 2)
|
| 667 |
+
|
| 668 |
+
def test_set_color_sample(self):
|
| 669 |
+
d = self.page
|
| 670 |
+
del d.set_color_sample
|
| 671 |
+
d.highlight_target.set('Selected Text')
|
| 672 |
+
d.fg_bg_toggle.set(True)
|
| 673 |
+
d.set_color_sample()
|
| 674 |
+
self.assertEqual(
|
| 675 |
+
d.style.lookup(d.frame_color_set['style'], 'background'),
|
| 676 |
+
d.highlight_sample.tag_cget('hilite', 'foreground'))
|
| 677 |
+
d.set_color_sample = Func()
|
| 678 |
+
|
| 679 |
+
def test_paint_theme_sample(self):
|
| 680 |
+
eq = self.assertEqual
|
| 681 |
+
page = self.page
|
| 682 |
+
del page.paint_theme_sample # Delete masking mock.
|
| 683 |
+
hs_tag = page.highlight_sample.tag_cget
|
| 684 |
+
gh = idleConf.GetHighlight
|
| 685 |
+
|
| 686 |
+
# Create custom theme based on IDLE Dark.
|
| 687 |
+
page.theme_source.set(True)
|
| 688 |
+
page.builtin_name.set('IDLE Dark')
|
| 689 |
+
theme = 'IDLE Test'
|
| 690 |
+
page.create_new(theme)
|
| 691 |
+
page.set_color_sample.called = 0
|
| 692 |
+
|
| 693 |
+
# Base theme with nothing in `changes`.
|
| 694 |
+
page.paint_theme_sample()
|
| 695 |
+
new_console = {'foreground': 'blue',
|
| 696 |
+
'background': 'yellow',}
|
| 697 |
+
for key, value in new_console.items():
|
| 698 |
+
self.assertNotEqual(hs_tag('console', key), value)
|
| 699 |
+
eq(page.set_color_sample.called, 1)
|
| 700 |
+
|
| 701 |
+
# Apply changes.
|
| 702 |
+
for key, value in new_console.items():
|
| 703 |
+
changes.add_option('highlight', theme, 'console-'+key, value)
|
| 704 |
+
page.paint_theme_sample()
|
| 705 |
+
for key, value in new_console.items():
|
| 706 |
+
eq(hs_tag('console', key), value)
|
| 707 |
+
eq(page.set_color_sample.called, 2)
|
| 708 |
+
|
| 709 |
+
page.paint_theme_sample = Func()
|
| 710 |
+
|
| 711 |
+
def test_delete_custom(self):
|
| 712 |
+
eq = self.assertEqual
|
| 713 |
+
d = self.page
|
| 714 |
+
d.button_delete_custom.state(('!disabled',))
|
| 715 |
+
yesno = d.askyesno = Func()
|
| 716 |
+
dialog.deactivate_current_config = Func()
|
| 717 |
+
dialog.activate_config_changes = Func()
|
| 718 |
+
|
| 719 |
+
theme_name = 'spam theme'
|
| 720 |
+
idleConf.userCfg['highlight'].SetOption(theme_name, 'name', 'value')
|
| 721 |
+
highpage[theme_name] = {'option': 'True'}
|
| 722 |
+
|
| 723 |
+
theme_name2 = 'other theme'
|
| 724 |
+
idleConf.userCfg['highlight'].SetOption(theme_name2, 'name', 'value')
|
| 725 |
+
highpage[theme_name2] = {'option': 'False'}
|
| 726 |
+
|
| 727 |
+
# Force custom theme.
|
| 728 |
+
d.custom_theme_on.state(('!disabled',))
|
| 729 |
+
d.custom_theme_on.invoke()
|
| 730 |
+
d.custom_name.set(theme_name)
|
| 731 |
+
|
| 732 |
+
# Cancel deletion.
|
| 733 |
+
yesno.result = False
|
| 734 |
+
d.button_delete_custom.invoke()
|
| 735 |
+
eq(yesno.called, 1)
|
| 736 |
+
eq(highpage[theme_name], {'option': 'True'})
|
| 737 |
+
eq(idleConf.GetSectionList('user', 'highlight'), [theme_name, theme_name2])
|
| 738 |
+
eq(dialog.deactivate_current_config.called, 0)
|
| 739 |
+
eq(dialog.activate_config_changes.called, 0)
|
| 740 |
+
eq(d.set_theme_type.called, 0)
|
| 741 |
+
|
| 742 |
+
# Confirm deletion.
|
| 743 |
+
yesno.result = True
|
| 744 |
+
d.button_delete_custom.invoke()
|
| 745 |
+
eq(yesno.called, 2)
|
| 746 |
+
self.assertNotIn(theme_name, highpage)
|
| 747 |
+
eq(idleConf.GetSectionList('user', 'highlight'), [theme_name2])
|
| 748 |
+
eq(d.custom_theme_on.state(), ())
|
| 749 |
+
eq(d.custom_name.get(), theme_name2)
|
| 750 |
+
eq(dialog.deactivate_current_config.called, 1)
|
| 751 |
+
eq(dialog.activate_config_changes.called, 1)
|
| 752 |
+
eq(d.set_theme_type.called, 1)
|
| 753 |
+
|
| 754 |
+
# Confirm deletion of second theme - empties list.
|
| 755 |
+
d.custom_name.set(theme_name2)
|
| 756 |
+
yesno.result = True
|
| 757 |
+
d.button_delete_custom.invoke()
|
| 758 |
+
eq(yesno.called, 3)
|
| 759 |
+
self.assertNotIn(theme_name, highpage)
|
| 760 |
+
eq(idleConf.GetSectionList('user', 'highlight'), [])
|
| 761 |
+
eq(d.custom_theme_on.state(), ('disabled',))
|
| 762 |
+
eq(d.custom_name.get(), '- no custom themes -')
|
| 763 |
+
eq(dialog.deactivate_current_config.called, 2)
|
| 764 |
+
eq(dialog.activate_config_changes.called, 2)
|
| 765 |
+
eq(d.set_theme_type.called, 2)
|
| 766 |
+
|
| 767 |
+
del dialog.activate_config_changes, dialog.deactivate_current_config
|
| 768 |
+
del d.askyesno
|
| 769 |
+
|
| 770 |
+
|
| 771 |
+
class KeysPageTest(unittest.TestCase):
|
| 772 |
+
"""Test that keys tab widgets enable users to make changes.
|
| 773 |
+
|
| 774 |
+
Test that widget actions set vars, that var changes add
|
| 775 |
+
options to changes and that key sets works correctly.
|
| 776 |
+
"""
|
| 777 |
+
|
| 778 |
+
@classmethod
|
| 779 |
+
def setUpClass(cls):
|
| 780 |
+
page = cls.page = dialog.keyspage
|
| 781 |
+
dialog.note.select(page)
|
| 782 |
+
page.set_keys_type = Func()
|
| 783 |
+
page.load_keys_list = Func()
|
| 784 |
+
|
| 785 |
+
@classmethod
|
| 786 |
+
def tearDownClass(cls):
|
| 787 |
+
page = cls.page
|
| 788 |
+
del page.set_keys_type, page.load_keys_list
|
| 789 |
+
|
| 790 |
+
def setUp(self):
|
| 791 |
+
d = self.page
|
| 792 |
+
# The following is needed for test_load_key_cfg, _delete_custom_keys.
|
| 793 |
+
# This may indicate a defect in some test or function.
|
| 794 |
+
for section in idleConf.GetSectionList('user', 'keys'):
|
| 795 |
+
idleConf.userCfg['keys'].remove_section(section)
|
| 796 |
+
changes.clear()
|
| 797 |
+
d.set_keys_type.called = 0
|
| 798 |
+
d.load_keys_list.called = 0
|
| 799 |
+
|
| 800 |
+
def test_load_key_cfg(self):
|
| 801 |
+
tracers.detach()
|
| 802 |
+
d = self.page
|
| 803 |
+
eq = self.assertEqual
|
| 804 |
+
|
| 805 |
+
# Use builtin keyset with no user keysets created.
|
| 806 |
+
idleConf.CurrentKeys = mock.Mock(return_value='IDLE Classic OSX')
|
| 807 |
+
d.load_key_cfg()
|
| 808 |
+
self.assertTrue(d.keyset_source.get())
|
| 809 |
+
# builtinlist sets variable builtin_name to the CurrentKeys default.
|
| 810 |
+
eq(d.builtin_name.get(), 'IDLE Classic OSX')
|
| 811 |
+
eq(d.custom_name.get(), '- no custom keys -')
|
| 812 |
+
eq(d.custom_keyset_on.state(), ('disabled',))
|
| 813 |
+
eq(d.set_keys_type.called, 1)
|
| 814 |
+
eq(d.load_keys_list.called, 1)
|
| 815 |
+
eq(d.load_keys_list.args, ('IDLE Classic OSX', ))
|
| 816 |
+
|
| 817 |
+
# Builtin keyset with non-empty user keyset list.
|
| 818 |
+
idleConf.SetOption('keys', 'test1', 'option', 'value')
|
| 819 |
+
idleConf.SetOption('keys', 'test2', 'option2', 'value2')
|
| 820 |
+
d.load_key_cfg()
|
| 821 |
+
eq(d.builtin_name.get(), 'IDLE Classic OSX')
|
| 822 |
+
eq(d.custom_name.get(), 'test1')
|
| 823 |
+
eq(d.set_keys_type.called, 2)
|
| 824 |
+
eq(d.load_keys_list.called, 2)
|
| 825 |
+
eq(d.load_keys_list.args, ('IDLE Classic OSX', ))
|
| 826 |
+
|
| 827 |
+
# Use custom keyset.
|
| 828 |
+
idleConf.CurrentKeys = mock.Mock(return_value='test2')
|
| 829 |
+
idleConf.default_keys = mock.Mock(return_value='IDLE Modern Unix')
|
| 830 |
+
idleConf.SetOption('main', 'Keys', 'default', '0')
|
| 831 |
+
d.load_key_cfg()
|
| 832 |
+
self.assertFalse(d.keyset_source.get())
|
| 833 |
+
eq(d.builtin_name.get(), 'IDLE Modern Unix')
|
| 834 |
+
eq(d.custom_name.get(), 'test2')
|
| 835 |
+
eq(d.set_keys_type.called, 3)
|
| 836 |
+
eq(d.load_keys_list.called, 3)
|
| 837 |
+
eq(d.load_keys_list.args, ('test2', ))
|
| 838 |
+
|
| 839 |
+
del idleConf.CurrentKeys, idleConf.default_keys
|
| 840 |
+
tracers.attach()
|
| 841 |
+
|
| 842 |
+
def test_keyset_source(self):
|
| 843 |
+
eq = self.assertEqual
|
| 844 |
+
d = self.page
|
| 845 |
+
# Test these separately.
|
| 846 |
+
d.var_changed_builtin_name = Func()
|
| 847 |
+
d.var_changed_custom_name = Func()
|
| 848 |
+
# Builtin selected.
|
| 849 |
+
d.builtin_keyset_on.invoke()
|
| 850 |
+
eq(mainpage, {'Keys': {'default': 'True'}})
|
| 851 |
+
eq(d.var_changed_builtin_name.called, 1)
|
| 852 |
+
eq(d.var_changed_custom_name.called, 0)
|
| 853 |
+
changes.clear()
|
| 854 |
+
|
| 855 |
+
# Custom selected.
|
| 856 |
+
d.custom_keyset_on.state(('!disabled',))
|
| 857 |
+
d.custom_keyset_on.invoke()
|
| 858 |
+
self.assertEqual(mainpage, {'Keys': {'default': 'False'}})
|
| 859 |
+
eq(d.var_changed_builtin_name.called, 1)
|
| 860 |
+
eq(d.var_changed_custom_name.called, 1)
|
| 861 |
+
del d.var_changed_builtin_name, d.var_changed_custom_name
|
| 862 |
+
|
| 863 |
+
def test_builtin_name(self):
|
| 864 |
+
eq = self.assertEqual
|
| 865 |
+
d = self.page
|
| 866 |
+
idleConf.userCfg['main'].remove_section('Keys')
|
| 867 |
+
item_list = ['IDLE Classic Windows', 'IDLE Classic OSX',
|
| 868 |
+
'IDLE Modern UNIX']
|
| 869 |
+
|
| 870 |
+
# Not in old_keys, defaults name to first item.
|
| 871 |
+
d.builtinlist.SetMenu(item_list, 'IDLE Modern UNIX')
|
| 872 |
+
eq(mainpage, {'Keys': {'name': 'IDLE Classic Windows',
|
| 873 |
+
'name2': 'IDLE Modern UNIX'}})
|
| 874 |
+
eq(d.keys_message['text'], 'New key set, see Help')
|
| 875 |
+
eq(d.load_keys_list.called, 1)
|
| 876 |
+
eq(d.load_keys_list.args, ('IDLE Modern UNIX', ))
|
| 877 |
+
|
| 878 |
+
# Not in old keys - uses name2.
|
| 879 |
+
changes.clear()
|
| 880 |
+
idleConf.SetOption('main', 'Keys', 'name', 'IDLE Classic Unix')
|
| 881 |
+
d.builtinlist.SetMenu(item_list, 'IDLE Modern UNIX')
|
| 882 |
+
eq(mainpage, {'Keys': {'name2': 'IDLE Modern UNIX'}})
|
| 883 |
+
eq(d.keys_message['text'], 'New key set, see Help')
|
| 884 |
+
eq(d.load_keys_list.called, 2)
|
| 885 |
+
eq(d.load_keys_list.args, ('IDLE Modern UNIX', ))
|
| 886 |
+
|
| 887 |
+
# Builtin name in old_keys.
|
| 888 |
+
changes.clear()
|
| 889 |
+
d.builtinlist.SetMenu(item_list, 'IDLE Classic OSX')
|
| 890 |
+
eq(mainpage, {'Keys': {'name': 'IDLE Classic OSX', 'name2': ''}})
|
| 891 |
+
eq(d.keys_message['text'], '')
|
| 892 |
+
eq(d.load_keys_list.called, 3)
|
| 893 |
+
eq(d.load_keys_list.args, ('IDLE Classic OSX', ))
|
| 894 |
+
|
| 895 |
+
def test_custom_name(self):
|
| 896 |
+
d = self.page
|
| 897 |
+
|
| 898 |
+
# If no selections, doesn't get added.
|
| 899 |
+
d.customlist.SetMenu([], '- no custom keys -')
|
| 900 |
+
self.assertNotIn('Keys', mainpage)
|
| 901 |
+
self.assertEqual(d.load_keys_list.called, 0)
|
| 902 |
+
|
| 903 |
+
# Custom name selected.
|
| 904 |
+
changes.clear()
|
| 905 |
+
d.customlist.SetMenu(['a', 'b', 'c'], 'c')
|
| 906 |
+
self.assertEqual(mainpage, {'Keys': {'name': 'c'}})
|
| 907 |
+
self.assertEqual(d.load_keys_list.called, 1)
|
| 908 |
+
|
| 909 |
+
def test_keybinding(self):
|
| 910 |
+
idleConf.SetOption('extensions', 'ZzDummy', 'enable', 'True')
|
| 911 |
+
d = self.page
|
| 912 |
+
d.custom_name.set('my custom keys')
|
| 913 |
+
d.bindingslist.delete(0, 'end')
|
| 914 |
+
d.bindingslist.insert(0, 'copy')
|
| 915 |
+
d.bindingslist.insert(1, 'z-in')
|
| 916 |
+
d.bindingslist.selection_set(0)
|
| 917 |
+
d.bindingslist.selection_anchor(0)
|
| 918 |
+
# Core binding - adds to keys.
|
| 919 |
+
d.keybinding.set('<Key-F11>')
|
| 920 |
+
self.assertEqual(keyspage,
|
| 921 |
+
{'my custom keys': {'copy': '<Key-F11>'}})
|
| 922 |
+
|
| 923 |
+
# Not a core binding - adds to extensions.
|
| 924 |
+
d.bindingslist.selection_set(1)
|
| 925 |
+
d.bindingslist.selection_anchor(1)
|
| 926 |
+
d.keybinding.set('<Key-F11>')
|
| 927 |
+
self.assertEqual(extpage,
|
| 928 |
+
{'ZzDummy_cfgBindings': {'z-in': '<Key-F11>'}})
|
| 929 |
+
|
| 930 |
+
def test_set_keys_type(self):
|
| 931 |
+
eq = self.assertEqual
|
| 932 |
+
d = self.page
|
| 933 |
+
del d.set_keys_type
|
| 934 |
+
|
| 935 |
+
# Builtin keyset selected.
|
| 936 |
+
d.keyset_source.set(True)
|
| 937 |
+
d.set_keys_type()
|
| 938 |
+
eq(d.builtinlist['state'], NORMAL)
|
| 939 |
+
eq(d.customlist['state'], DISABLED)
|
| 940 |
+
eq(d.button_delete_custom_keys.state(), ('disabled',))
|
| 941 |
+
|
| 942 |
+
# Custom keyset selected.
|
| 943 |
+
d.keyset_source.set(False)
|
| 944 |
+
d.set_keys_type()
|
| 945 |
+
eq(d.builtinlist['state'], DISABLED)
|
| 946 |
+
eq(d.custom_keyset_on.state(), ('selected',))
|
| 947 |
+
eq(d.customlist['state'], NORMAL)
|
| 948 |
+
eq(d.button_delete_custom_keys.state(), ())
|
| 949 |
+
d.set_keys_type = Func()
|
| 950 |
+
|
| 951 |
+
def test_get_new_keys(self):
|
| 952 |
+
eq = self.assertEqual
|
| 953 |
+
d = self.page
|
| 954 |
+
orig_getkeysdialog = configdialog.GetKeysWindow
|
| 955 |
+
gkd = configdialog.GetKeysWindow = Func(return_self=True)
|
| 956 |
+
gnkn = d.get_new_keys_name = Func()
|
| 957 |
+
|
| 958 |
+
d.button_new_keys.state(('!disabled',))
|
| 959 |
+
d.bindingslist.delete(0, 'end')
|
| 960 |
+
d.bindingslist.insert(0, 'copy - <Control-Shift-Key-C>')
|
| 961 |
+
d.bindingslist.selection_set(0)
|
| 962 |
+
d.bindingslist.selection_anchor(0)
|
| 963 |
+
d.keybinding.set('Key-a')
|
| 964 |
+
d.keyset_source.set(True) # Default keyset.
|
| 965 |
+
|
| 966 |
+
# Default keyset; no change to binding.
|
| 967 |
+
gkd.result = ''
|
| 968 |
+
d.button_new_keys.invoke()
|
| 969 |
+
eq(d.bindingslist.get('anchor'), 'copy - <Control-Shift-Key-C>')
|
| 970 |
+
# Keybinding isn't changed when there isn't a change entered.
|
| 971 |
+
eq(d.keybinding.get(), 'Key-a')
|
| 972 |
+
|
| 973 |
+
# Default keyset; binding changed.
|
| 974 |
+
gkd.result = '<Key-F11>'
|
| 975 |
+
# No keyset name selected therefore binding not saved.
|
| 976 |
+
gnkn.result = ''
|
| 977 |
+
d.button_new_keys.invoke()
|
| 978 |
+
eq(gnkn.called, 1)
|
| 979 |
+
eq(d.bindingslist.get('anchor'), 'copy - <Control-Shift-Key-C>')
|
| 980 |
+
# Keyset name selected.
|
| 981 |
+
gnkn.result = 'My New Key Set'
|
| 982 |
+
d.button_new_keys.invoke()
|
| 983 |
+
eq(d.custom_name.get(), gnkn.result)
|
| 984 |
+
eq(d.bindingslist.get('anchor'), 'copy - <Key-F11>')
|
| 985 |
+
eq(d.keybinding.get(), '<Key-F11>')
|
| 986 |
+
|
| 987 |
+
# User keyset; binding changed.
|
| 988 |
+
d.keyset_source.set(False) # Custom keyset.
|
| 989 |
+
gnkn.called = 0
|
| 990 |
+
gkd.result = '<Key-p>'
|
| 991 |
+
d.button_new_keys.invoke()
|
| 992 |
+
eq(gnkn.called, 0)
|
| 993 |
+
eq(d.bindingslist.get('anchor'), 'copy - <Key-p>')
|
| 994 |
+
eq(d.keybinding.get(), '<Key-p>')
|
| 995 |
+
|
| 996 |
+
del d.get_new_keys_name
|
| 997 |
+
configdialog.GetKeysWindow = orig_getkeysdialog
|
| 998 |
+
|
| 999 |
+
def test_get_new_keys_name(self):
|
| 1000 |
+
orig_sectionname = configdialog.SectionName
|
| 1001 |
+
sn = configdialog.SectionName = Func(return_self=True)
|
| 1002 |
+
d = self.page
|
| 1003 |
+
|
| 1004 |
+
sn.result = 'New Keys'
|
| 1005 |
+
self.assertEqual(d.get_new_keys_name(''), 'New Keys')
|
| 1006 |
+
|
| 1007 |
+
configdialog.SectionName = orig_sectionname
|
| 1008 |
+
|
| 1009 |
+
def test_save_as_new_key_set(self):
|
| 1010 |
+
d = self.page
|
| 1011 |
+
gnkn = d.get_new_keys_name = Func()
|
| 1012 |
+
d.keyset_source.set(True)
|
| 1013 |
+
|
| 1014 |
+
# No name entered.
|
| 1015 |
+
gnkn.result = ''
|
| 1016 |
+
d.button_save_custom_keys.invoke()
|
| 1017 |
+
|
| 1018 |
+
# Name entered.
|
| 1019 |
+
gnkn.result = 'my new key set'
|
| 1020 |
+
gnkn.called = 0
|
| 1021 |
+
self.assertNotIn(gnkn.result, idleConf.userCfg['keys'])
|
| 1022 |
+
d.button_save_custom_keys.invoke()
|
| 1023 |
+
self.assertIn(gnkn.result, idleConf.userCfg['keys'])
|
| 1024 |
+
|
| 1025 |
+
del d.get_new_keys_name
|
| 1026 |
+
|
| 1027 |
+
def test_on_bindingslist_select(self):
|
| 1028 |
+
d = self.page
|
| 1029 |
+
b = d.bindingslist
|
| 1030 |
+
b.delete(0, 'end')
|
| 1031 |
+
b.insert(0, 'copy')
|
| 1032 |
+
b.insert(1, 'find')
|
| 1033 |
+
b.activate(0)
|
| 1034 |
+
|
| 1035 |
+
b.focus_force()
|
| 1036 |
+
b.see(1)
|
| 1037 |
+
b.update()
|
| 1038 |
+
x, y, dx, dy = b.bbox(1)
|
| 1039 |
+
x += dx // 2
|
| 1040 |
+
y += dy // 2
|
| 1041 |
+
b.event_generate('<Enter>', x=0, y=0)
|
| 1042 |
+
b.event_generate('<Motion>', x=x, y=y)
|
| 1043 |
+
b.event_generate('<Button-1>', x=x, y=y)
|
| 1044 |
+
b.event_generate('<ButtonRelease-1>', x=x, y=y)
|
| 1045 |
+
self.assertEqual(b.get('anchor'), 'find')
|
| 1046 |
+
self.assertEqual(d.button_new_keys.state(), ())
|
| 1047 |
+
|
| 1048 |
+
def test_create_new_key_set_and_save_new_key_set(self):
|
| 1049 |
+
eq = self.assertEqual
|
| 1050 |
+
d = self.page
|
| 1051 |
+
|
| 1052 |
+
# Use default as previously active keyset.
|
| 1053 |
+
d.keyset_source.set(True)
|
| 1054 |
+
d.builtin_name.set('IDLE Classic Windows')
|
| 1055 |
+
first_new = 'my new custom key set'
|
| 1056 |
+
second_new = 'my second custom keyset'
|
| 1057 |
+
|
| 1058 |
+
# No changes, so keysets are an exact copy.
|
| 1059 |
+
self.assertNotIn(first_new, idleConf.userCfg)
|
| 1060 |
+
d.create_new_key_set(first_new)
|
| 1061 |
+
eq(idleConf.GetSectionList('user', 'keys'), [first_new])
|
| 1062 |
+
eq(idleConf.GetKeySet('IDLE Classic Windows'),
|
| 1063 |
+
idleConf.GetKeySet(first_new))
|
| 1064 |
+
eq(d.custom_name.get(), first_new)
|
| 1065 |
+
self.assertFalse(d.keyset_source.get()) # Use custom set.
|
| 1066 |
+
eq(d.set_keys_type.called, 1)
|
| 1067 |
+
|
| 1068 |
+
# Test that changed keybindings are in new keyset.
|
| 1069 |
+
changes.add_option('keys', first_new, 'copy', '<Key-F11>')
|
| 1070 |
+
self.assertNotIn(second_new, idleConf.userCfg)
|
| 1071 |
+
d.create_new_key_set(second_new)
|
| 1072 |
+
eq(idleConf.GetSectionList('user', 'keys'), [first_new, second_new])
|
| 1073 |
+
self.assertNotEqual(idleConf.GetKeySet(first_new),
|
| 1074 |
+
idleConf.GetKeySet(second_new))
|
| 1075 |
+
# Check that difference in keysets was in option `copy` from `changes`.
|
| 1076 |
+
idleConf.SetOption('keys', first_new, 'copy', '<Key-F11>')
|
| 1077 |
+
eq(idleConf.GetKeySet(first_new), idleConf.GetKeySet(second_new))
|
| 1078 |
+
|
| 1079 |
+
def test_load_keys_list(self):
|
| 1080 |
+
eq = self.assertEqual
|
| 1081 |
+
d = self.page
|
| 1082 |
+
gks = idleConf.GetKeySet = Func()
|
| 1083 |
+
del d.load_keys_list
|
| 1084 |
+
b = d.bindingslist
|
| 1085 |
+
|
| 1086 |
+
b.delete(0, 'end')
|
| 1087 |
+
b.insert(0, '<<find>>')
|
| 1088 |
+
b.insert(1, '<<help>>')
|
| 1089 |
+
gks.result = {'<<copy>>': ['<Control-Key-c>', '<Control-Key-C>'],
|
| 1090 |
+
'<<force-open-completions>>': ['<Control-Key-space>'],
|
| 1091 |
+
'<<spam>>': ['<Key-F11>']}
|
| 1092 |
+
changes.add_option('keys', 'my keys', 'spam', '<Shift-Key-a>')
|
| 1093 |
+
expected = ('copy - <Control-Key-c> <Control-Key-C>',
|
| 1094 |
+
'force-open-completions - <Control-Key-space>',
|
| 1095 |
+
'spam - <Shift-Key-a>')
|
| 1096 |
+
|
| 1097 |
+
# No current selection.
|
| 1098 |
+
d.load_keys_list('my keys')
|
| 1099 |
+
eq(b.get(0, 'end'), expected)
|
| 1100 |
+
eq(b.get('anchor'), '')
|
| 1101 |
+
eq(b.curselection(), ())
|
| 1102 |
+
|
| 1103 |
+
# Check selection.
|
| 1104 |
+
b.selection_set(1)
|
| 1105 |
+
b.selection_anchor(1)
|
| 1106 |
+
d.load_keys_list('my keys')
|
| 1107 |
+
eq(b.get(0, 'end'), expected)
|
| 1108 |
+
eq(b.get('anchor'), 'force-open-completions - <Control-Key-space>')
|
| 1109 |
+
eq(b.curselection(), (1, ))
|
| 1110 |
+
|
| 1111 |
+
# Change selection.
|
| 1112 |
+
b.selection_set(2)
|
| 1113 |
+
b.selection_anchor(2)
|
| 1114 |
+
d.load_keys_list('my keys')
|
| 1115 |
+
eq(b.get(0, 'end'), expected)
|
| 1116 |
+
eq(b.get('anchor'), 'spam - <Shift-Key-a>')
|
| 1117 |
+
eq(b.curselection(), (2, ))
|
| 1118 |
+
d.load_keys_list = Func()
|
| 1119 |
+
|
| 1120 |
+
del idleConf.GetKeySet
|
| 1121 |
+
|
| 1122 |
+
def test_delete_custom_keys(self):
|
| 1123 |
+
eq = self.assertEqual
|
| 1124 |
+
d = self.page
|
| 1125 |
+
d.button_delete_custom_keys.state(('!disabled',))
|
| 1126 |
+
yesno = d.askyesno = Func()
|
| 1127 |
+
dialog.deactivate_current_config = Func()
|
| 1128 |
+
dialog.activate_config_changes = Func()
|
| 1129 |
+
|
| 1130 |
+
keyset_name = 'spam key set'
|
| 1131 |
+
idleConf.userCfg['keys'].SetOption(keyset_name, 'name', 'value')
|
| 1132 |
+
keyspage[keyset_name] = {'option': 'True'}
|
| 1133 |
+
|
| 1134 |
+
keyset_name2 = 'other key set'
|
| 1135 |
+
idleConf.userCfg['keys'].SetOption(keyset_name2, 'name', 'value')
|
| 1136 |
+
keyspage[keyset_name2] = {'option': 'False'}
|
| 1137 |
+
|
| 1138 |
+
# Force custom keyset.
|
| 1139 |
+
d.custom_keyset_on.state(('!disabled',))
|
| 1140 |
+
d.custom_keyset_on.invoke()
|
| 1141 |
+
d.custom_name.set(keyset_name)
|
| 1142 |
+
|
| 1143 |
+
# Cancel deletion.
|
| 1144 |
+
yesno.result = False
|
| 1145 |
+
d.button_delete_custom_keys.invoke()
|
| 1146 |
+
eq(yesno.called, 1)
|
| 1147 |
+
eq(keyspage[keyset_name], {'option': 'True'})
|
| 1148 |
+
eq(idleConf.GetSectionList('user', 'keys'), [keyset_name, keyset_name2])
|
| 1149 |
+
eq(dialog.deactivate_current_config.called, 0)
|
| 1150 |
+
eq(dialog.activate_config_changes.called, 0)
|
| 1151 |
+
eq(d.set_keys_type.called, 0)
|
| 1152 |
+
|
| 1153 |
+
# Confirm deletion.
|
| 1154 |
+
yesno.result = True
|
| 1155 |
+
d.button_delete_custom_keys.invoke()
|
| 1156 |
+
eq(yesno.called, 2)
|
| 1157 |
+
self.assertNotIn(keyset_name, keyspage)
|
| 1158 |
+
eq(idleConf.GetSectionList('user', 'keys'), [keyset_name2])
|
| 1159 |
+
eq(d.custom_keyset_on.state(), ())
|
| 1160 |
+
eq(d.custom_name.get(), keyset_name2)
|
| 1161 |
+
eq(dialog.deactivate_current_config.called, 1)
|
| 1162 |
+
eq(dialog.activate_config_changes.called, 1)
|
| 1163 |
+
eq(d.set_keys_type.called, 1)
|
| 1164 |
+
|
| 1165 |
+
# Confirm deletion of second keyset - empties list.
|
| 1166 |
+
d.custom_name.set(keyset_name2)
|
| 1167 |
+
yesno.result = True
|
| 1168 |
+
d.button_delete_custom_keys.invoke()
|
| 1169 |
+
eq(yesno.called, 3)
|
| 1170 |
+
self.assertNotIn(keyset_name, keyspage)
|
| 1171 |
+
eq(idleConf.GetSectionList('user', 'keys'), [])
|
| 1172 |
+
eq(d.custom_keyset_on.state(), ('disabled',))
|
| 1173 |
+
eq(d.custom_name.get(), '- no custom keys -')
|
| 1174 |
+
eq(dialog.deactivate_current_config.called, 2)
|
| 1175 |
+
eq(dialog.activate_config_changes.called, 2)
|
| 1176 |
+
eq(d.set_keys_type.called, 2)
|
| 1177 |
+
|
| 1178 |
+
del dialog.activate_config_changes, dialog.deactivate_current_config
|
| 1179 |
+
del d.askyesno
|
| 1180 |
+
|
| 1181 |
+
|
| 1182 |
+
class WinPageTest(unittest.TestCase):
|
| 1183 |
+
"""Test that general tab widgets enable users to make changes.
|
| 1184 |
+
|
| 1185 |
+
Test that widget actions set vars, that var changes add
|
| 1186 |
+
options to changes.
|
| 1187 |
+
"""
|
| 1188 |
+
@classmethod
|
| 1189 |
+
def setUpClass(cls):
|
| 1190 |
+
page = cls.page = dialog.winpage
|
| 1191 |
+
dialog.note.select(page)
|
| 1192 |
+
page.update()
|
| 1193 |
+
|
| 1194 |
+
def setUp(self):
|
| 1195 |
+
changes.clear()
|
| 1196 |
+
|
| 1197 |
+
def test_load_windows_cfg(self):
|
| 1198 |
+
# Set to wrong values, load, check right values.
|
| 1199 |
+
eq = self.assertEqual
|
| 1200 |
+
d = self.page
|
| 1201 |
+
d.startup_edit.set(1)
|
| 1202 |
+
d.win_width.set(1)
|
| 1203 |
+
d.win_height.set(1)
|
| 1204 |
+
d.load_windows_cfg()
|
| 1205 |
+
eq(d.startup_edit.get(), 0)
|
| 1206 |
+
eq(d.win_width.get(), '80')
|
| 1207 |
+
eq(d.win_height.get(), '40')
|
| 1208 |
+
|
| 1209 |
+
def test_startup(self):
|
| 1210 |
+
d = self.page
|
| 1211 |
+
d.startup_editor_on.invoke()
|
| 1212 |
+
self.assertEqual(mainpage,
|
| 1213 |
+
{'General': {'editor-on-startup': '1'}})
|
| 1214 |
+
changes.clear()
|
| 1215 |
+
d.startup_shell_on.invoke()
|
| 1216 |
+
self.assertEqual(mainpage,
|
| 1217 |
+
{'General': {'editor-on-startup': '0'}})
|
| 1218 |
+
|
| 1219 |
+
def test_editor_size(self):
|
| 1220 |
+
d = self.page
|
| 1221 |
+
d.win_height_int.delete(0, 'end')
|
| 1222 |
+
d.win_height_int.insert(0, '11')
|
| 1223 |
+
self.assertEqual(mainpage, {'EditorWindow': {'height': '11'}})
|
| 1224 |
+
changes.clear()
|
| 1225 |
+
d.win_width_int.delete(0, 'end')
|
| 1226 |
+
d.win_width_int.insert(0, '11')
|
| 1227 |
+
self.assertEqual(mainpage, {'EditorWindow': {'width': '11'}})
|
| 1228 |
+
|
| 1229 |
+
def test_indent_spaces(self):
|
| 1230 |
+
d = self.page
|
| 1231 |
+
d.indent_chooser.set(6)
|
| 1232 |
+
self.assertEqual(d.indent_spaces.get(), '6')
|
| 1233 |
+
self.assertEqual(mainpage, {'Indent': {'num-spaces': '6'}})
|
| 1234 |
+
|
| 1235 |
+
def test_cursor_blink(self):
|
| 1236 |
+
self.page.cursor_blink_bool.invoke()
|
| 1237 |
+
self.assertEqual(mainpage, {'EditorWindow': {'cursor-blink': 'False'}})
|
| 1238 |
+
|
| 1239 |
+
def test_autocomplete_wait(self):
|
| 1240 |
+
self.page.auto_wait_int.delete(0, 'end')
|
| 1241 |
+
self.page.auto_wait_int.insert(0, '11')
|
| 1242 |
+
self.assertEqual(extpage, {'AutoComplete': {'popupwait': '11'}})
|
| 1243 |
+
|
| 1244 |
+
def test_parenmatch(self):
|
| 1245 |
+
d = self.page
|
| 1246 |
+
eq = self.assertEqual
|
| 1247 |
+
d.paren_style_type['menu'].invoke(0)
|
| 1248 |
+
eq(extpage, {'ParenMatch': {'style': 'opener'}})
|
| 1249 |
+
changes.clear()
|
| 1250 |
+
d.paren_flash_time.delete(0, 'end')
|
| 1251 |
+
d.paren_flash_time.insert(0, '11')
|
| 1252 |
+
eq(extpage, {'ParenMatch': {'flash-delay': '11'}})
|
| 1253 |
+
changes.clear()
|
| 1254 |
+
d.bell_on.invoke()
|
| 1255 |
+
eq(extpage, {'ParenMatch': {'bell': 'False'}})
|
| 1256 |
+
|
| 1257 |
+
def test_paragraph(self):
|
| 1258 |
+
self.page.format_width_int.delete(0, 'end')
|
| 1259 |
+
self.page.format_width_int.insert(0, '11')
|
| 1260 |
+
self.assertEqual(extpage, {'FormatParagraph': {'max-width': '11'}})
|
| 1261 |
+
|
| 1262 |
+
|
| 1263 |
+
class ShedPageTest(unittest.TestCase):
|
| 1264 |
+
"""Test that shed tab widgets enable users to make changes.
|
| 1265 |
+
|
| 1266 |
+
Test that widget actions set vars, that var changes add
|
| 1267 |
+
options to changes.
|
| 1268 |
+
"""
|
| 1269 |
+
@classmethod
|
| 1270 |
+
def setUpClass(cls):
|
| 1271 |
+
page = cls.page = dialog.shedpage
|
| 1272 |
+
dialog.note.select(page)
|
| 1273 |
+
page.update()
|
| 1274 |
+
|
| 1275 |
+
def setUp(self):
|
| 1276 |
+
changes.clear()
|
| 1277 |
+
|
| 1278 |
+
def test_load_shelled_cfg(self):
|
| 1279 |
+
# Set to wrong values, load, check right values.
|
| 1280 |
+
eq = self.assertEqual
|
| 1281 |
+
d = self.page
|
| 1282 |
+
d.autosave.set(1)
|
| 1283 |
+
d.load_shelled_cfg()
|
| 1284 |
+
eq(d.autosave.get(), 0)
|
| 1285 |
+
|
| 1286 |
+
def test_autosave(self):
|
| 1287 |
+
d = self.page
|
| 1288 |
+
d.save_auto_on.invoke()
|
| 1289 |
+
self.assertEqual(mainpage, {'General': {'autosave': '1'}})
|
| 1290 |
+
d.save_ask_on.invoke()
|
| 1291 |
+
self.assertEqual(mainpage, {'General': {'autosave': '0'}})
|
| 1292 |
+
|
| 1293 |
+
def test_context(self):
|
| 1294 |
+
self.page.context_int.delete(0, 'end')
|
| 1295 |
+
self.page.context_int.insert(0, '1')
|
| 1296 |
+
self.assertEqual(extpage, {'CodeContext': {'maxlines': '1'}})
|
| 1297 |
+
|
| 1298 |
+
|
| 1299 |
+
#unittest.skip("Nothing here yet TODO")
|
| 1300 |
+
class ExtPageTest(unittest.TestCase):
|
| 1301 |
+
"""Test that the help source list works correctly."""
|
| 1302 |
+
@classmethod
|
| 1303 |
+
def setUpClass(cls):
|
| 1304 |
+
page = dialog.extpage
|
| 1305 |
+
dialog.note.select(page)
|
| 1306 |
+
|
| 1307 |
+
|
| 1308 |
+
class HelpSourceTest(unittest.TestCase):
|
| 1309 |
+
"""Test that the help source list works correctly."""
|
| 1310 |
+
@classmethod
|
| 1311 |
+
def setUpClass(cls):
|
| 1312 |
+
page = dialog.extpage
|
| 1313 |
+
dialog.note.select(page)
|
| 1314 |
+
frame = cls.frame = page.frame_help
|
| 1315 |
+
frame.set = frame.set_add_delete_state = Func()
|
| 1316 |
+
frame.upc = frame.update_help_changes = Func()
|
| 1317 |
+
frame.update()
|
| 1318 |
+
|
| 1319 |
+
@classmethod
|
| 1320 |
+
def tearDownClass(cls):
|
| 1321 |
+
frame = cls.frame
|
| 1322 |
+
del frame.set, frame.set_add_delete_state
|
| 1323 |
+
del frame.upc, frame.update_help_changes
|
| 1324 |
+
frame.helplist.delete(0, 'end')
|
| 1325 |
+
frame.user_helplist.clear()
|
| 1326 |
+
|
| 1327 |
+
def setUp(self):
|
| 1328 |
+
changes.clear()
|
| 1329 |
+
|
| 1330 |
+
def test_load_helplist(self):
|
| 1331 |
+
eq = self.assertEqual
|
| 1332 |
+
fr = self.frame
|
| 1333 |
+
fr.helplist.insert('end', 'bad')
|
| 1334 |
+
fr.user_helplist = ['bad', 'worse']
|
| 1335 |
+
idleConf.SetOption('main', 'HelpFiles', '1', 'name;file')
|
| 1336 |
+
fr.load_helplist()
|
| 1337 |
+
eq(fr.helplist.get(0, 'end'), ('name',))
|
| 1338 |
+
eq(fr.user_helplist, [('name', 'file', '1')])
|
| 1339 |
+
|
| 1340 |
+
def test_source_selected(self):
|
| 1341 |
+
fr = self.frame
|
| 1342 |
+
fr.set = fr.set_add_delete_state
|
| 1343 |
+
fr.upc = fr.update_help_changes
|
| 1344 |
+
helplist = fr.helplist
|
| 1345 |
+
dex = 'end'
|
| 1346 |
+
helplist.insert(dex, 'source')
|
| 1347 |
+
helplist.activate(dex)
|
| 1348 |
+
|
| 1349 |
+
helplist.focus_force()
|
| 1350 |
+
helplist.see(dex)
|
| 1351 |
+
helplist.update()
|
| 1352 |
+
x, y, dx, dy = helplist.bbox(dex)
|
| 1353 |
+
x += dx // 2
|
| 1354 |
+
y += dy // 2
|
| 1355 |
+
fr.set.called = fr.upc.called = 0
|
| 1356 |
+
helplist.event_generate('<Enter>', x=0, y=0)
|
| 1357 |
+
helplist.event_generate('<Motion>', x=x, y=y)
|
| 1358 |
+
helplist.event_generate('<Button-1>', x=x, y=y)
|
| 1359 |
+
helplist.event_generate('<ButtonRelease-1>', x=x, y=y)
|
| 1360 |
+
self.assertEqual(helplist.get('anchor'), 'source')
|
| 1361 |
+
self.assertTrue(fr.set.called)
|
| 1362 |
+
self.assertFalse(fr.upc.called)
|
| 1363 |
+
|
| 1364 |
+
def test_set_add_delete_state(self):
|
| 1365 |
+
# Call with 0 items, 1 unselected item, 1 selected item.
|
| 1366 |
+
eq = self.assertEqual
|
| 1367 |
+
fr = self.frame
|
| 1368 |
+
del fr.set_add_delete_state # Unmask method.
|
| 1369 |
+
sad = fr.set_add_delete_state
|
| 1370 |
+
h = fr.helplist
|
| 1371 |
+
|
| 1372 |
+
h.delete(0, 'end')
|
| 1373 |
+
sad()
|
| 1374 |
+
eq(fr.button_helplist_edit.state(), ('disabled',))
|
| 1375 |
+
eq(fr.button_helplist_remove.state(), ('disabled',))
|
| 1376 |
+
|
| 1377 |
+
h.insert(0, 'source')
|
| 1378 |
+
sad()
|
| 1379 |
+
eq(fr.button_helplist_edit.state(), ('disabled',))
|
| 1380 |
+
eq(fr.button_helplist_remove.state(), ('disabled',))
|
| 1381 |
+
|
| 1382 |
+
h.selection_set(0)
|
| 1383 |
+
sad()
|
| 1384 |
+
eq(fr.button_helplist_edit.state(), ())
|
| 1385 |
+
eq(fr.button_helplist_remove.state(), ())
|
| 1386 |
+
fr.set_add_delete_state = Func() # Mask method.
|
| 1387 |
+
|
| 1388 |
+
def test_helplist_item_add(self):
|
| 1389 |
+
# Call without and twice with HelpSource result.
|
| 1390 |
+
# Double call enables check on order.
|
| 1391 |
+
eq = self.assertEqual
|
| 1392 |
+
orig_helpsource = configdialog.HelpSource
|
| 1393 |
+
hs = configdialog.HelpSource = Func(return_self=True)
|
| 1394 |
+
fr = self.frame
|
| 1395 |
+
fr.helplist.delete(0, 'end')
|
| 1396 |
+
fr.user_helplist.clear()
|
| 1397 |
+
fr.set.called = fr.upc.called = 0
|
| 1398 |
+
|
| 1399 |
+
hs.result = ''
|
| 1400 |
+
fr.helplist_item_add()
|
| 1401 |
+
self.assertTrue(list(fr.helplist.get(0, 'end')) ==
|
| 1402 |
+
fr.user_helplist == [])
|
| 1403 |
+
self.assertFalse(fr.upc.called)
|
| 1404 |
+
|
| 1405 |
+
hs.result = ('name1', 'file1')
|
| 1406 |
+
fr.helplist_item_add()
|
| 1407 |
+
hs.result = ('name2', 'file2')
|
| 1408 |
+
fr.helplist_item_add()
|
| 1409 |
+
eq(fr.helplist.get(0, 'end'), ('name1', 'name2'))
|
| 1410 |
+
eq(fr.user_helplist, [('name1', 'file1'), ('name2', 'file2')])
|
| 1411 |
+
eq(fr.upc.called, 2)
|
| 1412 |
+
self.assertFalse(fr.set.called)
|
| 1413 |
+
|
| 1414 |
+
configdialog.HelpSource = orig_helpsource
|
| 1415 |
+
|
| 1416 |
+
def test_helplist_item_edit(self):
|
| 1417 |
+
# Call without and with HelpSource change.
|
| 1418 |
+
eq = self.assertEqual
|
| 1419 |
+
orig_helpsource = configdialog.HelpSource
|
| 1420 |
+
hs = configdialog.HelpSource = Func(return_self=True)
|
| 1421 |
+
fr = self.frame
|
| 1422 |
+
fr.helplist.delete(0, 'end')
|
| 1423 |
+
fr.helplist.insert(0, 'name1')
|
| 1424 |
+
fr.helplist.selection_set(0)
|
| 1425 |
+
fr.helplist.selection_anchor(0)
|
| 1426 |
+
fr.user_helplist.clear()
|
| 1427 |
+
fr.user_helplist.append(('name1', 'file1'))
|
| 1428 |
+
fr.set.called = fr.upc.called = 0
|
| 1429 |
+
|
| 1430 |
+
hs.result = ''
|
| 1431 |
+
fr.helplist_item_edit()
|
| 1432 |
+
hs.result = ('name1', 'file1')
|
| 1433 |
+
fr.helplist_item_edit()
|
| 1434 |
+
eq(fr.helplist.get(0, 'end'), ('name1',))
|
| 1435 |
+
eq(fr.user_helplist, [('name1', 'file1')])
|
| 1436 |
+
self.assertFalse(fr.upc.called)
|
| 1437 |
+
|
| 1438 |
+
hs.result = ('name2', 'file2')
|
| 1439 |
+
fr.helplist_item_edit()
|
| 1440 |
+
eq(fr.helplist.get(0, 'end'), ('name2',))
|
| 1441 |
+
eq(fr.user_helplist, [('name2', 'file2')])
|
| 1442 |
+
self.assertTrue(fr.upc.called == fr.set.called == 1)
|
| 1443 |
+
|
| 1444 |
+
configdialog.HelpSource = orig_helpsource
|
| 1445 |
+
|
| 1446 |
+
def test_helplist_item_remove(self):
|
| 1447 |
+
eq = self.assertEqual
|
| 1448 |
+
fr = self.frame
|
| 1449 |
+
fr.helplist.delete(0, 'end')
|
| 1450 |
+
fr.helplist.insert(0, 'name1')
|
| 1451 |
+
fr.helplist.selection_set(0)
|
| 1452 |
+
fr.helplist.selection_anchor(0)
|
| 1453 |
+
fr.user_helplist.clear()
|
| 1454 |
+
fr.user_helplist.append(('name1', 'file1'))
|
| 1455 |
+
fr.set.called = fr.upc.called = 0
|
| 1456 |
+
|
| 1457 |
+
fr.helplist_item_remove()
|
| 1458 |
+
eq(fr.helplist.get(0, 'end'), ())
|
| 1459 |
+
eq(fr.user_helplist, [])
|
| 1460 |
+
self.assertTrue(fr.upc.called == fr.set.called == 1)
|
| 1461 |
+
|
| 1462 |
+
def test_update_help_changes(self):
|
| 1463 |
+
fr = self.frame
|
| 1464 |
+
del fr.update_help_changes
|
| 1465 |
+
fr.user_helplist.clear()
|
| 1466 |
+
fr.user_helplist.append(('name1', 'file1'))
|
| 1467 |
+
fr.user_helplist.append(('name2', 'file2'))
|
| 1468 |
+
|
| 1469 |
+
fr.update_help_changes()
|
| 1470 |
+
self.assertEqual(mainpage['HelpFiles'],
|
| 1471 |
+
{'1': 'name1;file1', '2': 'name2;file2'})
|
| 1472 |
+
fr.update_help_changes = Func()
|
| 1473 |
+
|
| 1474 |
+
|
| 1475 |
+
class VarTraceTest(unittest.TestCase):
|
| 1476 |
+
|
| 1477 |
+
@classmethod
|
| 1478 |
+
def setUpClass(cls):
|
| 1479 |
+
cls.tracers = configdialog.VarTrace()
|
| 1480 |
+
cls.iv = IntVar(root)
|
| 1481 |
+
cls.bv = BooleanVar(root)
|
| 1482 |
+
|
| 1483 |
+
@classmethod
|
| 1484 |
+
def tearDownClass(cls):
|
| 1485 |
+
del cls.tracers, cls.iv, cls.bv
|
| 1486 |
+
|
| 1487 |
+
def setUp(self):
|
| 1488 |
+
self.tracers.clear()
|
| 1489 |
+
self.called = 0
|
| 1490 |
+
|
| 1491 |
+
def var_changed_increment(self, *params):
|
| 1492 |
+
self.called += 13
|
| 1493 |
+
|
| 1494 |
+
def var_changed_boolean(self, *params):
|
| 1495 |
+
pass
|
| 1496 |
+
|
| 1497 |
+
def test_init(self):
|
| 1498 |
+
tr = self.tracers
|
| 1499 |
+
tr.__init__()
|
| 1500 |
+
self.assertEqual(tr.untraced, [])
|
| 1501 |
+
self.assertEqual(tr.traced, [])
|
| 1502 |
+
|
| 1503 |
+
def test_clear(self):
|
| 1504 |
+
tr = self.tracers
|
| 1505 |
+
tr.untraced.append(0)
|
| 1506 |
+
tr.traced.append(1)
|
| 1507 |
+
tr.clear()
|
| 1508 |
+
self.assertEqual(tr.untraced, [])
|
| 1509 |
+
self.assertEqual(tr.traced, [])
|
| 1510 |
+
|
| 1511 |
+
def test_add(self):
|
| 1512 |
+
tr = self.tracers
|
| 1513 |
+
func = Func()
|
| 1514 |
+
cb = tr.make_callback = mock.Mock(return_value=func)
|
| 1515 |
+
|
| 1516 |
+
iv = tr.add(self.iv, self.var_changed_increment)
|
| 1517 |
+
self.assertIs(iv, self.iv)
|
| 1518 |
+
bv = tr.add(self.bv, self.var_changed_boolean)
|
| 1519 |
+
self.assertIs(bv, self.bv)
|
| 1520 |
+
|
| 1521 |
+
sv = StringVar(root)
|
| 1522 |
+
sv2 = tr.add(sv, ('main', 'section', 'option'))
|
| 1523 |
+
self.assertIs(sv2, sv)
|
| 1524 |
+
cb.assert_called_once()
|
| 1525 |
+
cb.assert_called_with(sv, ('main', 'section', 'option'))
|
| 1526 |
+
|
| 1527 |
+
expected = [(iv, self.var_changed_increment),
|
| 1528 |
+
(bv, self.var_changed_boolean),
|
| 1529 |
+
(sv, func)]
|
| 1530 |
+
self.assertEqual(tr.traced, [])
|
| 1531 |
+
self.assertEqual(tr.untraced, expected)
|
| 1532 |
+
|
| 1533 |
+
del tr.make_callback
|
| 1534 |
+
|
| 1535 |
+
def test_make_callback(self):
|
| 1536 |
+
cb = self.tracers.make_callback(self.iv, ('main', 'section', 'option'))
|
| 1537 |
+
self.assertTrue(callable(cb))
|
| 1538 |
+
self.iv.set(42)
|
| 1539 |
+
# Not attached, so set didn't invoke the callback.
|
| 1540 |
+
self.assertNotIn('section', changes['main'])
|
| 1541 |
+
# Invoke callback manually.
|
| 1542 |
+
cb()
|
| 1543 |
+
self.assertIn('section', changes['main'])
|
| 1544 |
+
self.assertEqual(changes['main']['section']['option'], '42')
|
| 1545 |
+
changes.clear()
|
| 1546 |
+
|
| 1547 |
+
def test_attach_detach(self):
|
| 1548 |
+
tr = self.tracers
|
| 1549 |
+
iv = tr.add(self.iv, self.var_changed_increment)
|
| 1550 |
+
bv = tr.add(self.bv, self.var_changed_boolean)
|
| 1551 |
+
expected = [(iv, self.var_changed_increment),
|
| 1552 |
+
(bv, self.var_changed_boolean)]
|
| 1553 |
+
|
| 1554 |
+
# Attach callbacks and test call increment.
|
| 1555 |
+
tr.attach()
|
| 1556 |
+
self.assertEqual(tr.untraced, [])
|
| 1557 |
+
self.assertCountEqual(tr.traced, expected)
|
| 1558 |
+
iv.set(1)
|
| 1559 |
+
self.assertEqual(iv.get(), 1)
|
| 1560 |
+
self.assertEqual(self.called, 13)
|
| 1561 |
+
|
| 1562 |
+
# Check that only one callback is attached to a variable.
|
| 1563 |
+
# If more than one callback were attached, then var_changed_increment
|
| 1564 |
+
# would be called twice and the counter would be 2.
|
| 1565 |
+
self.called = 0
|
| 1566 |
+
tr.attach()
|
| 1567 |
+
iv.set(1)
|
| 1568 |
+
self.assertEqual(self.called, 13)
|
| 1569 |
+
|
| 1570 |
+
# Detach callbacks.
|
| 1571 |
+
self.called = 0
|
| 1572 |
+
tr.detach()
|
| 1573 |
+
self.assertEqual(tr.traced, [])
|
| 1574 |
+
self.assertCountEqual(tr.untraced, expected)
|
| 1575 |
+
iv.set(1)
|
| 1576 |
+
self.assertEqual(self.called, 0)
|
| 1577 |
+
|
| 1578 |
+
|
| 1579 |
+
if __name__ == '__main__':
|
| 1580 |
+
unittest.main(verbosity=2)
|
micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_debugger.py
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Test debugger, coverage 66%
|
| 2 |
+
|
| 3 |
+
Try to make tests pass with draft bdbx, which may replace bdb in 3.13+.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
from idlelib import debugger
|
| 7 |
+
from collections import namedtuple
|
| 8 |
+
from textwrap import dedent
|
| 9 |
+
from tkinter import Tk
|
| 10 |
+
|
| 11 |
+
from test.support import requires
|
| 12 |
+
import unittest
|
| 13 |
+
from unittest import mock
|
| 14 |
+
from unittest.mock import Mock, patch
|
| 15 |
+
|
| 16 |
+
"""A test python script for the debug tests."""
|
| 17 |
+
TEST_CODE = dedent("""
|
| 18 |
+
i = 1
|
| 19 |
+
i += 2
|
| 20 |
+
if i == 3:
|
| 21 |
+
print(i)
|
| 22 |
+
""")
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
class MockFrame:
|
| 26 |
+
"Minimal mock frame."
|
| 27 |
+
|
| 28 |
+
def __init__(self, code, lineno):
|
| 29 |
+
self.f_code = code
|
| 30 |
+
self.f_lineno = lineno
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
class IdbTest(unittest.TestCase):
|
| 34 |
+
|
| 35 |
+
@classmethod
|
| 36 |
+
def setUpClass(cls):
|
| 37 |
+
cls.gui = Mock()
|
| 38 |
+
cls.idb = debugger.Idb(cls.gui)
|
| 39 |
+
|
| 40 |
+
# Create test and code objects to simulate a debug session.
|
| 41 |
+
code_obj = compile(TEST_CODE, 'idlelib/file.py', mode='exec')
|
| 42 |
+
frame1 = MockFrame(code_obj, 1)
|
| 43 |
+
frame1.f_back = None
|
| 44 |
+
frame2 = MockFrame(code_obj, 2)
|
| 45 |
+
frame2.f_back = frame1
|
| 46 |
+
cls.frame = frame2
|
| 47 |
+
cls.msg = 'file.py:2: <module>()'
|
| 48 |
+
|
| 49 |
+
def test_init(self):
|
| 50 |
+
self.assertIs(self.idb.gui, self.gui)
|
| 51 |
+
# Won't test super call since two Bdbs are very different.
|
| 52 |
+
|
| 53 |
+
def test_user_line(self):
|
| 54 |
+
# Test that .user_line() creates a string message for a frame.
|
| 55 |
+
self.gui.interaction = Mock()
|
| 56 |
+
self.idb.user_line(self.frame)
|
| 57 |
+
self.gui.interaction.assert_called_once_with(self.msg, self.frame)
|
| 58 |
+
|
| 59 |
+
def test_user_exception(self):
|
| 60 |
+
# Test that .user_exception() creates a string message for a frame.
|
| 61 |
+
exc_info = (type(ValueError), ValueError(), None)
|
| 62 |
+
self.gui.interaction = Mock()
|
| 63 |
+
self.idb.user_exception(self.frame, exc_info)
|
| 64 |
+
self.gui.interaction.assert_called_once_with(
|
| 65 |
+
self.msg, self.frame, exc_info)
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
class FunctionTest(unittest.TestCase):
|
| 69 |
+
# Test module functions together.
|
| 70 |
+
|
| 71 |
+
def test_functions(self):
|
| 72 |
+
rpc_obj = compile(TEST_CODE,'rpc.py', mode='exec')
|
| 73 |
+
rpc_frame = MockFrame(rpc_obj, 2)
|
| 74 |
+
rpc_frame.f_back = rpc_frame
|
| 75 |
+
self.assertTrue(debugger._in_rpc_code(rpc_frame))
|
| 76 |
+
self.assertEqual(debugger._frame2message(rpc_frame),
|
| 77 |
+
'rpc.py:2: <module>()')
|
| 78 |
+
|
| 79 |
+
code_obj = compile(TEST_CODE, 'idlelib/debugger.py', mode='exec')
|
| 80 |
+
code_frame = MockFrame(code_obj, 1)
|
| 81 |
+
code_frame.f_back = None
|
| 82 |
+
self.assertFalse(debugger._in_rpc_code(code_frame))
|
| 83 |
+
self.assertEqual(debugger._frame2message(code_frame),
|
| 84 |
+
'debugger.py:1: <module>()')
|
| 85 |
+
|
| 86 |
+
code_frame.f_back = code_frame
|
| 87 |
+
self.assertFalse(debugger._in_rpc_code(code_frame))
|
| 88 |
+
code_frame.f_back = rpc_frame
|
| 89 |
+
self.assertTrue(debugger._in_rpc_code(code_frame))
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
class DebuggerTest(unittest.TestCase):
|
| 93 |
+
"Tests for Debugger that do not need a real root."
|
| 94 |
+
|
| 95 |
+
@classmethod
|
| 96 |
+
def setUpClass(cls):
|
| 97 |
+
cls.pyshell = Mock()
|
| 98 |
+
cls.pyshell.root = Mock()
|
| 99 |
+
cls.idb = Mock()
|
| 100 |
+
with patch.object(debugger.Debugger, 'make_gui'):
|
| 101 |
+
cls.debugger = debugger.Debugger(cls.pyshell, cls.idb)
|
| 102 |
+
cls.debugger.root = Mock()
|
| 103 |
+
|
| 104 |
+
def test_cont(self):
|
| 105 |
+
self.debugger.cont()
|
| 106 |
+
self.idb.set_continue.assert_called_once()
|
| 107 |
+
|
| 108 |
+
def test_step(self):
|
| 109 |
+
self.debugger.step()
|
| 110 |
+
self.idb.set_step.assert_called_once()
|
| 111 |
+
|
| 112 |
+
def test_quit(self):
|
| 113 |
+
self.debugger.quit()
|
| 114 |
+
self.idb.set_quit.assert_called_once()
|
| 115 |
+
|
| 116 |
+
def test_next(self):
|
| 117 |
+
with patch.object(self.debugger, 'frame') as frame:
|
| 118 |
+
self.debugger.next()
|
| 119 |
+
self.idb.set_next.assert_called_once_with(frame)
|
| 120 |
+
|
| 121 |
+
def test_ret(self):
|
| 122 |
+
with patch.object(self.debugger, 'frame') as frame:
|
| 123 |
+
self.debugger.ret()
|
| 124 |
+
self.idb.set_return.assert_called_once_with(frame)
|
| 125 |
+
|
| 126 |
+
def test_clear_breakpoint(self):
|
| 127 |
+
self.debugger.clear_breakpoint('test.py', 4)
|
| 128 |
+
self.idb.clear_break.assert_called_once_with('test.py', 4)
|
| 129 |
+
|
| 130 |
+
def test_clear_file_breaks(self):
|
| 131 |
+
self.debugger.clear_file_breaks('test.py')
|
| 132 |
+
self.idb.clear_all_file_breaks.assert_called_once_with('test.py')
|
| 133 |
+
|
| 134 |
+
def test_set_load_breakpoints(self):
|
| 135 |
+
# Test the .load_breakpoints() method calls idb.
|
| 136 |
+
FileIO = namedtuple('FileIO', 'filename')
|
| 137 |
+
|
| 138 |
+
class MockEditWindow(object):
|
| 139 |
+
def __init__(self, fn, breakpoints):
|
| 140 |
+
self.io = FileIO(fn)
|
| 141 |
+
self.breakpoints = breakpoints
|
| 142 |
+
|
| 143 |
+
self.pyshell.flist = Mock()
|
| 144 |
+
self.pyshell.flist.inversedict = (
|
| 145 |
+
MockEditWindow('test1.py', [4, 4]),
|
| 146 |
+
MockEditWindow('test2.py', [13, 44, 45]),
|
| 147 |
+
)
|
| 148 |
+
self.debugger.set_breakpoint('test0.py', 1)
|
| 149 |
+
self.idb.set_break.assert_called_once_with('test0.py', 1)
|
| 150 |
+
self.debugger.load_breakpoints() # Call set_breakpoint 5 times.
|
| 151 |
+
self.idb.set_break.assert_has_calls(
|
| 152 |
+
[mock.call('test0.py', 1),
|
| 153 |
+
mock.call('test1.py', 4),
|
| 154 |
+
mock.call('test1.py', 4),
|
| 155 |
+
mock.call('test2.py', 13),
|
| 156 |
+
mock.call('test2.py', 44),
|
| 157 |
+
mock.call('test2.py', 45)])
|
| 158 |
+
|
| 159 |
+
def test_sync_source_line(self):
|
| 160 |
+
# Test that .sync_source_line() will set the flist.gotofileline with fixed frame.
|
| 161 |
+
test_code = compile(TEST_CODE, 'test_sync.py', 'exec')
|
| 162 |
+
test_frame = MockFrame(test_code, 1)
|
| 163 |
+
self.debugger.frame = test_frame
|
| 164 |
+
|
| 165 |
+
self.debugger.flist = Mock()
|
| 166 |
+
with patch('idlelib.debugger.os.path.exists', return_value=True):
|
| 167 |
+
self.debugger.sync_source_line()
|
| 168 |
+
self.debugger.flist.gotofileline.assert_called_once_with('test_sync.py', 1)
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
class DebuggerGuiTest(unittest.TestCase):
|
| 172 |
+
"""Tests for debugger.Debugger that need tk root.
|
| 173 |
+
|
| 174 |
+
close needs debugger.top set in make_gui.
|
| 175 |
+
"""
|
| 176 |
+
|
| 177 |
+
@classmethod
|
| 178 |
+
def setUpClass(cls):
|
| 179 |
+
requires('gui')
|
| 180 |
+
cls.root = root = Tk()
|
| 181 |
+
root.withdraw()
|
| 182 |
+
cls.pyshell = Mock()
|
| 183 |
+
cls.pyshell.root = root
|
| 184 |
+
cls.idb = Mock()
|
| 185 |
+
# stack tests fail with debugger here.
|
| 186 |
+
## cls.debugger = debugger.Debugger(cls.pyshell, cls.idb)
|
| 187 |
+
## cls.debugger.root = root
|
| 188 |
+
## # real root needed for real make_gui
|
| 189 |
+
## # run, interacting, abort_loop
|
| 190 |
+
|
| 191 |
+
@classmethod
|
| 192 |
+
def tearDownClass(cls):
|
| 193 |
+
cls.root.destroy()
|
| 194 |
+
del cls.root
|
| 195 |
+
|
| 196 |
+
def setUp(self):
|
| 197 |
+
self.debugger = debugger.Debugger(self.pyshell, self.idb)
|
| 198 |
+
self.debugger.root = self.root
|
| 199 |
+
# real root needed for real make_gui
|
| 200 |
+
# run, interacting, abort_loop
|
| 201 |
+
|
| 202 |
+
def test_run_debugger(self):
|
| 203 |
+
self.debugger.run(1, 'two')
|
| 204 |
+
self.idb.run.assert_called_once_with(1, 'two')
|
| 205 |
+
self.assertEqual(self.debugger.interacting, 0)
|
| 206 |
+
|
| 207 |
+
def test_close(self):
|
| 208 |
+
# Test closing the window in an idle state.
|
| 209 |
+
self.debugger.close()
|
| 210 |
+
self.pyshell.close_debugger.assert_called_once()
|
| 211 |
+
|
| 212 |
+
def test_show_stack(self):
|
| 213 |
+
self.debugger.show_stack()
|
| 214 |
+
self.assertEqual(self.debugger.stackviewer.gui, self.debugger)
|
| 215 |
+
|
| 216 |
+
def test_show_stack_with_frame(self):
|
| 217 |
+
test_frame = MockFrame(None, None)
|
| 218 |
+
self.debugger.frame = test_frame
|
| 219 |
+
|
| 220 |
+
# Reset the stackviewer to force it to be recreated.
|
| 221 |
+
self.debugger.stackviewer = None
|
| 222 |
+
self.idb.get_stack.return_value = ([], 0)
|
| 223 |
+
self.debugger.show_stack()
|
| 224 |
+
|
| 225 |
+
# Check that the newly created stackviewer has the test gui as a field.
|
| 226 |
+
self.assertEqual(self.debugger.stackviewer.gui, self.debugger)
|
| 227 |
+
self.idb.get_stack.assert_called_once_with(test_frame, None)
|
| 228 |
+
|
| 229 |
+
|
| 230 |
+
class StackViewerTest(unittest.TestCase):
|
| 231 |
+
|
| 232 |
+
@classmethod
|
| 233 |
+
def setUpClass(cls):
|
| 234 |
+
requires('gui')
|
| 235 |
+
cls.root = Tk()
|
| 236 |
+
cls.root.withdraw()
|
| 237 |
+
|
| 238 |
+
@classmethod
|
| 239 |
+
def tearDownClass(cls):
|
| 240 |
+
cls.root.destroy()
|
| 241 |
+
del cls.root
|
| 242 |
+
|
| 243 |
+
def setUp(self):
|
| 244 |
+
self.code = compile(TEST_CODE, 'test_stackviewer.py', 'exec')
|
| 245 |
+
self.stack = [
|
| 246 |
+
(MockFrame(self.code, 1), 1),
|
| 247 |
+
(MockFrame(self.code, 2), 2)
|
| 248 |
+
]
|
| 249 |
+
# Create a stackviewer and load the test stack.
|
| 250 |
+
self.sv = debugger.StackViewer(self.root, None, None)
|
| 251 |
+
self.sv.load_stack(self.stack)
|
| 252 |
+
|
| 253 |
+
def test_init(self):
|
| 254 |
+
# Test creation of StackViewer.
|
| 255 |
+
gui = None
|
| 256 |
+
flist = None
|
| 257 |
+
master_window = self.root
|
| 258 |
+
sv = debugger.StackViewer(master_window, flist, gui)
|
| 259 |
+
self.assertTrue(hasattr(sv, 'stack'))
|
| 260 |
+
|
| 261 |
+
def test_load_stack(self):
|
| 262 |
+
# Test the .load_stack() method against a fixed test stack.
|
| 263 |
+
# Check the test stack is assigned and the list contains the repr of them.
|
| 264 |
+
self.assertEqual(self.sv.stack, self.stack)
|
| 265 |
+
self.assertTrue('?.<module>(), line 1:' in self.sv.get(0))
|
| 266 |
+
self.assertEqual(self.sv.get(1), '?.<module>(), line 2: ')
|
| 267 |
+
|
| 268 |
+
def test_show_source(self):
|
| 269 |
+
# Test the .show_source() method against a fixed test stack.
|
| 270 |
+
# Patch out the file list to monitor it
|
| 271 |
+
self.sv.flist = Mock()
|
| 272 |
+
# Patch out isfile to pretend file exists.
|
| 273 |
+
with patch('idlelib.debugger.os.path.isfile', return_value=True) as isfile:
|
| 274 |
+
self.sv.show_source(1)
|
| 275 |
+
isfile.assert_called_once_with('test_stackviewer.py')
|
| 276 |
+
self.sv.flist.open.assert_called_once_with('test_stackviewer.py')
|
| 277 |
+
|
| 278 |
+
|
| 279 |
+
class NameSpaceTest(unittest.TestCase):
|
| 280 |
+
|
| 281 |
+
@classmethod
|
| 282 |
+
def setUpClass(cls):
|
| 283 |
+
requires('gui')
|
| 284 |
+
cls.root = Tk()
|
| 285 |
+
cls.root.withdraw()
|
| 286 |
+
|
| 287 |
+
@classmethod
|
| 288 |
+
def tearDownClass(cls):
|
| 289 |
+
cls.root.destroy()
|
| 290 |
+
del cls.root
|
| 291 |
+
|
| 292 |
+
def test_init(self):
|
| 293 |
+
debugger.NamespaceViewer(self.root, 'Test')
|
| 294 |
+
|
| 295 |
+
|
| 296 |
+
if __name__ == '__main__':
|
| 297 |
+
unittest.main(verbosity=2)
|
micromamba_root/envs/pytorch_env/Lib/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)
|
micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_debugobj.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"Test debugobj, coverage 40%."
|
| 2 |
+
|
| 3 |
+
from idlelib import debugobj
|
| 4 |
+
import unittest
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class ObjectTreeItemTest(unittest.TestCase):
|
| 8 |
+
|
| 9 |
+
def test_init(self):
|
| 10 |
+
ti = debugobj.ObjectTreeItem('label', 22)
|
| 11 |
+
self.assertEqual(ti.labeltext, 'label')
|
| 12 |
+
self.assertEqual(ti.object, 22)
|
| 13 |
+
self.assertEqual(ti.setfunction, None)
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class ClassTreeItemTest(unittest.TestCase):
|
| 17 |
+
|
| 18 |
+
def test_isexpandable(self):
|
| 19 |
+
ti = debugobj.ClassTreeItem('label', 0)
|
| 20 |
+
self.assertTrue(ti.IsExpandable())
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
class AtomicObjectTreeItemTest(unittest.TestCase):
|
| 24 |
+
|
| 25 |
+
def test_isexpandable(self):
|
| 26 |
+
ti = debugobj.AtomicObjectTreeItem('label', 0)
|
| 27 |
+
self.assertFalse(ti.IsExpandable())
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
class SequenceTreeItemTest(unittest.TestCase):
|
| 31 |
+
|
| 32 |
+
def test_isexpandable(self):
|
| 33 |
+
ti = debugobj.SequenceTreeItem('label', ())
|
| 34 |
+
self.assertFalse(ti.IsExpandable())
|
| 35 |
+
ti = debugobj.SequenceTreeItem('label', (1,))
|
| 36 |
+
self.assertTrue(ti.IsExpandable())
|
| 37 |
+
|
| 38 |
+
def test_keys(self):
|
| 39 |
+
ti = debugobj.SequenceTreeItem('label', 'abc')
|
| 40 |
+
self.assertEqual(list(ti.keys()), [0, 1, 2]) # keys() is a range.
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
class DictTreeItemTest(unittest.TestCase):
|
| 44 |
+
|
| 45 |
+
def test_isexpandable(self):
|
| 46 |
+
ti = debugobj.DictTreeItem('label', {})
|
| 47 |
+
self.assertFalse(ti.IsExpandable())
|
| 48 |
+
ti = debugobj.DictTreeItem('label', {1:1})
|
| 49 |
+
self.assertTrue(ti.IsExpandable())
|
| 50 |
+
|
| 51 |
+
def test_keys(self):
|
| 52 |
+
ti = debugobj.DictTreeItem('label', {1:1, 0:0, 2:2})
|
| 53 |
+
self.assertEqual(ti.keys(), [0, 1, 2]) # keys() is a sorted list.
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
if __name__ == '__main__':
|
| 57 |
+
unittest.main(verbosity=2)
|
micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_debugobj_r.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"Test debugobj_r, coverage 56%."
|
| 2 |
+
|
| 3 |
+
from idlelib import debugobj_r
|
| 4 |
+
import unittest
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class WrappedObjectTreeItemTest(unittest.TestCase):
|
| 8 |
+
|
| 9 |
+
def test_getattr(self):
|
| 10 |
+
ti = debugobj_r.WrappedObjectTreeItem(list)
|
| 11 |
+
self.assertEqual(ti.append, list.append)
|
| 12 |
+
|
| 13 |
+
class StubObjectTreeItemTest(unittest.TestCase):
|
| 14 |
+
|
| 15 |
+
def test_init(self):
|
| 16 |
+
ti = debugobj_r.StubObjectTreeItem('socket', 1111)
|
| 17 |
+
self.assertEqual(ti.sockio, 'socket')
|
| 18 |
+
self.assertEqual(ti.oid, 1111)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
if __name__ == '__main__':
|
| 22 |
+
unittest.main(verbosity=2)
|
micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_delegator.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"Test delegator, coverage 100%."
|
| 2 |
+
|
| 3 |
+
from idlelib.delegator import Delegator
|
| 4 |
+
import unittest
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class DelegatorTest(unittest.TestCase):
|
| 8 |
+
|
| 9 |
+
def test_mydel(self):
|
| 10 |
+
# Test a simple use scenario.
|
| 11 |
+
|
| 12 |
+
# Initialize an int delegator.
|
| 13 |
+
mydel = Delegator(int)
|
| 14 |
+
self.assertIs(mydel.delegate, int)
|
| 15 |
+
self.assertEqual(mydel._Delegator__cache, set())
|
| 16 |
+
# Trying to access a non-attribute of int fails.
|
| 17 |
+
self.assertRaises(AttributeError, mydel.__getattr__, 'xyz')
|
| 18 |
+
|
| 19 |
+
# Add real int attribute 'bit_length' by accessing it.
|
| 20 |
+
bl = mydel.bit_length
|
| 21 |
+
self.assertIs(bl, int.bit_length)
|
| 22 |
+
self.assertIs(mydel.__dict__['bit_length'], int.bit_length)
|
| 23 |
+
self.assertEqual(mydel._Delegator__cache, {'bit_length'})
|
| 24 |
+
|
| 25 |
+
# Add attribute 'numerator'.
|
| 26 |
+
mydel.numerator
|
| 27 |
+
self.assertEqual(mydel._Delegator__cache, {'bit_length', 'numerator'})
|
| 28 |
+
|
| 29 |
+
# Delete 'numerator'.
|
| 30 |
+
del mydel.numerator
|
| 31 |
+
self.assertNotIn('numerator', mydel.__dict__)
|
| 32 |
+
# The current implementation leaves it in the name cache.
|
| 33 |
+
# self.assertIn('numerator', mydel._Delegator__cache)
|
| 34 |
+
# However, this is not required and not part of the specification
|
| 35 |
+
|
| 36 |
+
# Change delegate to float, first resetting the attributes.
|
| 37 |
+
mydel.setdelegate(float) # calls resetcache
|
| 38 |
+
self.assertNotIn('bit_length', mydel.__dict__)
|
| 39 |
+
self.assertEqual(mydel._Delegator__cache, set())
|
| 40 |
+
self.assertIs(mydel.delegate, float)
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
if __name__ == '__main__':
|
| 44 |
+
unittest.main(verbosity=2, exit=2)
|
micromamba_root/envs/pytorch_env/Lib/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)
|
micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_editor.py
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"Test editor, coverage 53%."
|
| 2 |
+
|
| 3 |
+
from idlelib import editor
|
| 4 |
+
import unittest
|
| 5 |
+
from collections import namedtuple
|
| 6 |
+
from test.support import requires
|
| 7 |
+
from tkinter import Tk, Text
|
| 8 |
+
|
| 9 |
+
Editor = editor.EditorWindow
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class EditorWindowTest(unittest.TestCase):
|
| 13 |
+
|
| 14 |
+
@classmethod
|
| 15 |
+
def setUpClass(cls):
|
| 16 |
+
requires('gui')
|
| 17 |
+
cls.root = Tk()
|
| 18 |
+
cls.root.withdraw()
|
| 19 |
+
|
| 20 |
+
@classmethod
|
| 21 |
+
def tearDownClass(cls):
|
| 22 |
+
cls.root.update_idletasks()
|
| 23 |
+
for id in cls.root.tk.call('after', 'info'):
|
| 24 |
+
cls.root.after_cancel(id)
|
| 25 |
+
cls.root.destroy()
|
| 26 |
+
del cls.root
|
| 27 |
+
|
| 28 |
+
def test_init(self):
|
| 29 |
+
e = Editor(root=self.root)
|
| 30 |
+
self.assertEqual(e.root, self.root)
|
| 31 |
+
e._close()
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
class GetLineIndentTest(unittest.TestCase):
|
| 35 |
+
def test_empty_lines(self):
|
| 36 |
+
for tabwidth in [1, 2, 4, 6, 8]:
|
| 37 |
+
for line in ['', '\n']:
|
| 38 |
+
with self.subTest(line=line, tabwidth=tabwidth):
|
| 39 |
+
self.assertEqual(
|
| 40 |
+
editor.get_line_indent(line, tabwidth=tabwidth),
|
| 41 |
+
(0, 0),
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
def test_tabwidth_4(self):
|
| 45 |
+
# (line, (raw, effective))
|
| 46 |
+
tests = (('no spaces', (0, 0)),
|
| 47 |
+
# Internal space isn't counted.
|
| 48 |
+
(' space test', (4, 4)),
|
| 49 |
+
('\ttab test', (1, 4)),
|
| 50 |
+
('\t\tdouble tabs test', (2, 8)),
|
| 51 |
+
# Different results when mixing tabs and spaces.
|
| 52 |
+
(' \tmixed test', (5, 8)),
|
| 53 |
+
(' \t mixed test', (5, 6)),
|
| 54 |
+
('\t mixed test', (5, 8)),
|
| 55 |
+
# Spaces not divisible by tabwidth.
|
| 56 |
+
(' \tmixed test', (3, 4)),
|
| 57 |
+
(' \t mixed test', (3, 5)),
|
| 58 |
+
('\t mixed test', (3, 6)),
|
| 59 |
+
# Only checks spaces and tabs.
|
| 60 |
+
('\nnewline test', (0, 0)))
|
| 61 |
+
|
| 62 |
+
for line, expected in tests:
|
| 63 |
+
with self.subTest(line=line):
|
| 64 |
+
self.assertEqual(
|
| 65 |
+
editor.get_line_indent(line, tabwidth=4),
|
| 66 |
+
expected,
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
+
def test_tabwidth_8(self):
|
| 70 |
+
# (line, (raw, effective))
|
| 71 |
+
tests = (('no spaces', (0, 0)),
|
| 72 |
+
# Internal space isn't counted.
|
| 73 |
+
(' space test', (8, 8)),
|
| 74 |
+
('\ttab test', (1, 8)),
|
| 75 |
+
('\t\tdouble tabs test', (2, 16)),
|
| 76 |
+
# Different results when mixing tabs and spaces.
|
| 77 |
+
(' \tmixed test', (9, 16)),
|
| 78 |
+
(' \t mixed test', (9, 10)),
|
| 79 |
+
('\t mixed test', (9, 16)),
|
| 80 |
+
# Spaces not divisible by tabwidth.
|
| 81 |
+
(' \tmixed test', (3, 8)),
|
| 82 |
+
(' \t mixed test', (3, 9)),
|
| 83 |
+
('\t mixed test', (3, 10)),
|
| 84 |
+
# Only checks spaces and tabs.
|
| 85 |
+
('\nnewline test', (0, 0)))
|
| 86 |
+
|
| 87 |
+
for line, expected in tests:
|
| 88 |
+
with self.subTest(line=line):
|
| 89 |
+
self.assertEqual(
|
| 90 |
+
editor.get_line_indent(line, tabwidth=8),
|
| 91 |
+
expected,
|
| 92 |
+
)
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
def insert(text, string):
|
| 96 |
+
text.delete('1.0', 'end')
|
| 97 |
+
text.insert('end', string)
|
| 98 |
+
text.update_idletasks() # Force update for colorizer to finish.
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
class IndentAndNewlineTest(unittest.TestCase):
|
| 102 |
+
|
| 103 |
+
@classmethod
|
| 104 |
+
def setUpClass(cls):
|
| 105 |
+
requires('gui')
|
| 106 |
+
cls.root = Tk()
|
| 107 |
+
cls.root.withdraw()
|
| 108 |
+
cls.window = Editor(root=cls.root)
|
| 109 |
+
cls.window.indentwidth = 2
|
| 110 |
+
cls.window.tabwidth = 2
|
| 111 |
+
|
| 112 |
+
@classmethod
|
| 113 |
+
def tearDownClass(cls):
|
| 114 |
+
cls.window._close()
|
| 115 |
+
del cls.window
|
| 116 |
+
cls.root.update_idletasks()
|
| 117 |
+
for id in cls.root.tk.call('after', 'info'):
|
| 118 |
+
cls.root.after_cancel(id)
|
| 119 |
+
cls.root.destroy()
|
| 120 |
+
del cls.root
|
| 121 |
+
|
| 122 |
+
def test_indent_and_newline_event(self):
|
| 123 |
+
eq = self.assertEqual
|
| 124 |
+
w = self.window
|
| 125 |
+
text = w.text
|
| 126 |
+
get = text.get
|
| 127 |
+
nl = w.newline_and_indent_event
|
| 128 |
+
|
| 129 |
+
TestInfo = namedtuple('Tests', ['label', 'text', 'expected', 'mark'])
|
| 130 |
+
|
| 131 |
+
tests = (TestInfo('Empty line inserts with no indent.',
|
| 132 |
+
' \n def __init__(self):',
|
| 133 |
+
'\n \n def __init__(self):\n',
|
| 134 |
+
'1.end'),
|
| 135 |
+
TestInfo('Inside bracket before space, deletes space.',
|
| 136 |
+
' def f1(self, a, b):',
|
| 137 |
+
' def f1(self,\n a, b):\n',
|
| 138 |
+
'1.14'),
|
| 139 |
+
TestInfo('Inside bracket after space, deletes space.',
|
| 140 |
+
' def f1(self, a, b):',
|
| 141 |
+
' def f1(self,\n a, b):\n',
|
| 142 |
+
'1.15'),
|
| 143 |
+
TestInfo('Inside string with one line - no indent.',
|
| 144 |
+
' """Docstring."""',
|
| 145 |
+
' """Docstring.\n"""\n',
|
| 146 |
+
'1.15'),
|
| 147 |
+
TestInfo('Inside string with more than one line.',
|
| 148 |
+
' """Docstring.\n Docstring Line 2"""',
|
| 149 |
+
' """Docstring.\n Docstring Line 2\n """\n',
|
| 150 |
+
'2.18'),
|
| 151 |
+
TestInfo('Backslash with one line.',
|
| 152 |
+
'a =\\',
|
| 153 |
+
'a =\\\n \n',
|
| 154 |
+
'1.end'),
|
| 155 |
+
TestInfo('Backslash with more than one line.',
|
| 156 |
+
'a =\\\n multiline\\',
|
| 157 |
+
'a =\\\n multiline\\\n \n',
|
| 158 |
+
'2.end'),
|
| 159 |
+
TestInfo('Block opener - indents +1 level.',
|
| 160 |
+
' def f1(self):\n pass',
|
| 161 |
+
' def f1(self):\n \n pass\n',
|
| 162 |
+
'1.end'),
|
| 163 |
+
TestInfo('Block closer - dedents -1 level.',
|
| 164 |
+
' def f1(self):\n pass',
|
| 165 |
+
' def f1(self):\n pass\n \n',
|
| 166 |
+
'2.end'),
|
| 167 |
+
)
|
| 168 |
+
|
| 169 |
+
for test in tests:
|
| 170 |
+
with self.subTest(label=test.label):
|
| 171 |
+
insert(text, test.text)
|
| 172 |
+
text.mark_set('insert', test.mark)
|
| 173 |
+
nl(event=None)
|
| 174 |
+
eq(get('1.0', 'end'), test.expected)
|
| 175 |
+
|
| 176 |
+
# Selected text.
|
| 177 |
+
insert(text, ' def f1(self, a, b):\n return a + b')
|
| 178 |
+
text.tag_add('sel', '1.17', '1.end')
|
| 179 |
+
nl(None)
|
| 180 |
+
# Deletes selected text before adding new line.
|
| 181 |
+
eq(get('1.0', 'end'), ' def f1(self, a,\n \n return a + b\n')
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
class IndentSearcherTest(unittest.TestCase):
|
| 185 |
+
|
| 186 |
+
@classmethod
|
| 187 |
+
def setUpClass(cls):
|
| 188 |
+
requires('gui')
|
| 189 |
+
cls.root = Tk()
|
| 190 |
+
cls.root.withdraw()
|
| 191 |
+
cls.text = Text(cls.root)
|
| 192 |
+
|
| 193 |
+
@classmethod
|
| 194 |
+
def tearDownClass(cls):
|
| 195 |
+
cls.root.destroy()
|
| 196 |
+
del cls.root
|
| 197 |
+
|
| 198 |
+
def test_searcher(self):
|
| 199 |
+
text = self.text
|
| 200 |
+
searcher = (self.text)
|
| 201 |
+
test_info = (# text, (block, indent))
|
| 202 |
+
("", (None, None)),
|
| 203 |
+
("[1,", (None, None)), # TokenError
|
| 204 |
+
("if 1:\n", ('if 1:\n', None)),
|
| 205 |
+
("if 1:\n 2\n 3\n", ('if 1:\n', ' 2\n')),
|
| 206 |
+
)
|
| 207 |
+
for code, expected_pair in test_info:
|
| 208 |
+
with self.subTest(code=code):
|
| 209 |
+
insert(text, code)
|
| 210 |
+
actual_pair = editor.IndentSearcher(text).run()
|
| 211 |
+
self.assertEqual(actual_pair, expected_pair)
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
class RMenuTest(unittest.TestCase):
|
| 215 |
+
|
| 216 |
+
@classmethod
|
| 217 |
+
def setUpClass(cls):
|
| 218 |
+
requires('gui')
|
| 219 |
+
cls.root = Tk()
|
| 220 |
+
cls.root.withdraw()
|
| 221 |
+
cls.window = Editor(root=cls.root)
|
| 222 |
+
|
| 223 |
+
@classmethod
|
| 224 |
+
def tearDownClass(cls):
|
| 225 |
+
cls.window._close()
|
| 226 |
+
del cls.window
|
| 227 |
+
cls.root.update_idletasks()
|
| 228 |
+
for id in cls.root.tk.call('after', 'info'):
|
| 229 |
+
cls.root.after_cancel(id)
|
| 230 |
+
cls.root.destroy()
|
| 231 |
+
del cls.root
|
| 232 |
+
|
| 233 |
+
class DummyRMenu:
|
| 234 |
+
def tk_popup(x, y): pass
|
| 235 |
+
|
| 236 |
+
def test_rclick(self):
|
| 237 |
+
pass
|
| 238 |
+
|
| 239 |
+
|
| 240 |
+
if __name__ == '__main__':
|
| 241 |
+
unittest.main(verbosity=2)
|
micromamba_root/envs/pytorch_env/Lib/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 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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"Test format, coverage 99%."
|
| 2 |
+
|
| 3 |
+
from idlelib import format as ft
|
| 4 |
+
import unittest
|
| 5 |
+
from unittest import mock
|
| 6 |
+
from test.support import requires
|
| 7 |
+
from tkinter import Tk, Text
|
| 8 |
+
from idlelib.editor import EditorWindow
|
| 9 |
+
from idlelib.idle_test.mock_idle import Editor as MockEditor
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class Is_Get_Test(unittest.TestCase):
|
| 13 |
+
"""Test the is_ and get_ functions"""
|
| 14 |
+
test_comment = '# This is a comment'
|
| 15 |
+
test_nocomment = 'This is not a comment'
|
| 16 |
+
trailingws_comment = '# This is a comment '
|
| 17 |
+
leadingws_comment = ' # This is a comment'
|
| 18 |
+
leadingws_nocomment = ' This is not a comment'
|
| 19 |
+
|
| 20 |
+
def test_is_all_white(self):
|
| 21 |
+
self.assertTrue(ft.is_all_white(''))
|
| 22 |
+
self.assertTrue(ft.is_all_white('\t\n\r\f\v'))
|
| 23 |
+
self.assertFalse(ft.is_all_white(self.test_comment))
|
| 24 |
+
|
| 25 |
+
def test_get_indent(self):
|
| 26 |
+
Equal = self.assertEqual
|
| 27 |
+
Equal(ft.get_indent(self.test_comment), '')
|
| 28 |
+
Equal(ft.get_indent(self.trailingws_comment), '')
|
| 29 |
+
Equal(ft.get_indent(self.leadingws_comment), ' ')
|
| 30 |
+
Equal(ft.get_indent(self.leadingws_nocomment), ' ')
|
| 31 |
+
|
| 32 |
+
def test_get_comment_header(self):
|
| 33 |
+
Equal = self.assertEqual
|
| 34 |
+
# Test comment strings
|
| 35 |
+
Equal(ft.get_comment_header(self.test_comment), '#')
|
| 36 |
+
Equal(ft.get_comment_header(self.trailingws_comment), '#')
|
| 37 |
+
Equal(ft.get_comment_header(self.leadingws_comment), ' #')
|
| 38 |
+
# Test non-comment strings
|
| 39 |
+
Equal(ft.get_comment_header(self.leadingws_nocomment), ' ')
|
| 40 |
+
Equal(ft.get_comment_header(self.test_nocomment), '')
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
class FindTest(unittest.TestCase):
|
| 44 |
+
"""Test the find_paragraph function in paragraph module.
|
| 45 |
+
|
| 46 |
+
Using the runcase() function, find_paragraph() is called with 'mark' set at
|
| 47 |
+
multiple indexes before and inside the test paragraph.
|
| 48 |
+
|
| 49 |
+
It appears that code with the same indentation as a quoted string is grouped
|
| 50 |
+
as part of the same paragraph, which is probably incorrect behavior.
|
| 51 |
+
"""
|
| 52 |
+
|
| 53 |
+
@classmethod
|
| 54 |
+
def setUpClass(cls):
|
| 55 |
+
from idlelib.idle_test.mock_tk import Text
|
| 56 |
+
cls.text = Text()
|
| 57 |
+
|
| 58 |
+
def runcase(self, inserttext, stopline, expected):
|
| 59 |
+
# Check that find_paragraph returns the expected paragraph when
|
| 60 |
+
# the mark index is set to beginning, middle, end of each line
|
| 61 |
+
# up to but not including the stop line
|
| 62 |
+
text = self.text
|
| 63 |
+
text.insert('1.0', inserttext)
|
| 64 |
+
for line in range(1, stopline):
|
| 65 |
+
linelength = int(text.index("%d.end" % line).split('.')[1])
|
| 66 |
+
for col in (0, linelength//2, linelength):
|
| 67 |
+
tempindex = "%d.%d" % (line, col)
|
| 68 |
+
self.assertEqual(ft.find_paragraph(text, tempindex), expected)
|
| 69 |
+
text.delete('1.0', 'end')
|
| 70 |
+
|
| 71 |
+
def test_find_comment(self):
|
| 72 |
+
comment = (
|
| 73 |
+
"# Comment block with no blank lines before\n"
|
| 74 |
+
"# Comment line\n"
|
| 75 |
+
"\n")
|
| 76 |
+
self.runcase(comment, 3, ('1.0', '3.0', '#', comment[0:58]))
|
| 77 |
+
|
| 78 |
+
comment = (
|
| 79 |
+
"\n"
|
| 80 |
+
"# Comment block with whitespace line before and after\n"
|
| 81 |
+
"# Comment line\n"
|
| 82 |
+
"\n")
|
| 83 |
+
self.runcase(comment, 4, ('2.0', '4.0', '#', comment[1:70]))
|
| 84 |
+
|
| 85 |
+
comment = (
|
| 86 |
+
"\n"
|
| 87 |
+
" # Indented comment block with whitespace before and after\n"
|
| 88 |
+
" # Comment line\n"
|
| 89 |
+
"\n")
|
| 90 |
+
self.runcase(comment, 4, ('2.0', '4.0', ' #', comment[1:82]))
|
| 91 |
+
|
| 92 |
+
comment = (
|
| 93 |
+
"\n"
|
| 94 |
+
"# Single line comment\n"
|
| 95 |
+
"\n")
|
| 96 |
+
self.runcase(comment, 3, ('2.0', '3.0', '#', comment[1:23]))
|
| 97 |
+
|
| 98 |
+
comment = (
|
| 99 |
+
"\n"
|
| 100 |
+
" # Single line comment with leading whitespace\n"
|
| 101 |
+
"\n")
|
| 102 |
+
self.runcase(comment, 3, ('2.0', '3.0', ' #', comment[1:51]))
|
| 103 |
+
|
| 104 |
+
comment = (
|
| 105 |
+
"\n"
|
| 106 |
+
"# Comment immediately followed by code\n"
|
| 107 |
+
"x = 42\n"
|
| 108 |
+
"\n")
|
| 109 |
+
self.runcase(comment, 3, ('2.0', '3.0', '#', comment[1:40]))
|
| 110 |
+
|
| 111 |
+
comment = (
|
| 112 |
+
"\n"
|
| 113 |
+
" # Indented comment immediately followed by code\n"
|
| 114 |
+
"x = 42\n"
|
| 115 |
+
"\n")
|
| 116 |
+
self.runcase(comment, 3, ('2.0', '3.0', ' #', comment[1:53]))
|
| 117 |
+
|
| 118 |
+
comment = (
|
| 119 |
+
"\n"
|
| 120 |
+
"# Comment immediately followed by indented code\n"
|
| 121 |
+
" x = 42\n"
|
| 122 |
+
"\n")
|
| 123 |
+
self.runcase(comment, 3, ('2.0', '3.0', '#', comment[1:49]))
|
| 124 |
+
|
| 125 |
+
def test_find_paragraph(self):
|
| 126 |
+
teststring = (
|
| 127 |
+
'"""String with no blank lines before\n'
|
| 128 |
+
'String line\n'
|
| 129 |
+
'"""\n'
|
| 130 |
+
'\n')
|
| 131 |
+
self.runcase(teststring, 4, ('1.0', '4.0', '', teststring[0:53]))
|
| 132 |
+
|
| 133 |
+
teststring = (
|
| 134 |
+
"\n"
|
| 135 |
+
'"""String with whitespace line before and after\n'
|
| 136 |
+
'String line.\n'
|
| 137 |
+
'"""\n'
|
| 138 |
+
'\n')
|
| 139 |
+
self.runcase(teststring, 5, ('2.0', '5.0', '', teststring[1:66]))
|
| 140 |
+
|
| 141 |
+
teststring = (
|
| 142 |
+
'\n'
|
| 143 |
+
' """Indented string with whitespace before and after\n'
|
| 144 |
+
' Comment string.\n'
|
| 145 |
+
' """\n'
|
| 146 |
+
'\n')
|
| 147 |
+
self.runcase(teststring, 5, ('2.0', '5.0', ' ', teststring[1:85]))
|
| 148 |
+
|
| 149 |
+
teststring = (
|
| 150 |
+
'\n'
|
| 151 |
+
'"""Single line string."""\n'
|
| 152 |
+
'\n')
|
| 153 |
+
self.runcase(teststring, 3, ('2.0', '3.0', '', teststring[1:27]))
|
| 154 |
+
|
| 155 |
+
teststring = (
|
| 156 |
+
'\n'
|
| 157 |
+
' """Single line string with leading whitespace."""\n'
|
| 158 |
+
'\n')
|
| 159 |
+
self.runcase(teststring, 3, ('2.0', '3.0', ' ', teststring[1:55]))
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
class ReformatFunctionTest(unittest.TestCase):
|
| 163 |
+
"""Test the reformat_paragraph function without the editor window."""
|
| 164 |
+
|
| 165 |
+
def test_reformat_paragraph(self):
|
| 166 |
+
Equal = self.assertEqual
|
| 167 |
+
reform = ft.reformat_paragraph
|
| 168 |
+
hw = "O hello world"
|
| 169 |
+
Equal(reform(' ', 1), ' ')
|
| 170 |
+
Equal(reform("Hello world", 20), "Hello world")
|
| 171 |
+
|
| 172 |
+
# Test without leading newline
|
| 173 |
+
Equal(reform(hw, 1), "O\nhello\nworld")
|
| 174 |
+
Equal(reform(hw, 6), "O\nhello\nworld")
|
| 175 |
+
Equal(reform(hw, 7), "O hello\nworld")
|
| 176 |
+
Equal(reform(hw, 12), "O hello\nworld")
|
| 177 |
+
Equal(reform(hw, 13), "O hello world")
|
| 178 |
+
|
| 179 |
+
# Test with leading newline
|
| 180 |
+
hw = "\nO hello world"
|
| 181 |
+
Equal(reform(hw, 1), "\nO\nhello\nworld")
|
| 182 |
+
Equal(reform(hw, 6), "\nO\nhello\nworld")
|
| 183 |
+
Equal(reform(hw, 7), "\nO hello\nworld")
|
| 184 |
+
Equal(reform(hw, 12), "\nO hello\nworld")
|
| 185 |
+
Equal(reform(hw, 13), "\nO hello world")
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
class ReformatCommentTest(unittest.TestCase):
|
| 189 |
+
"""Test the reformat_comment function without the editor window."""
|
| 190 |
+
|
| 191 |
+
def test_reformat_comment(self):
|
| 192 |
+
Equal = self.assertEqual
|
| 193 |
+
|
| 194 |
+
# reformat_comment formats to a minimum of 20 characters
|
| 195 |
+
test_string = (
|
| 196 |
+
" \"\"\"this is a test of a reformat for a triple quoted string"
|
| 197 |
+
" will it reformat to less than 70 characters for me?\"\"\"")
|
| 198 |
+
result = ft.reformat_comment(test_string, 70, " ")
|
| 199 |
+
expected = (
|
| 200 |
+
" \"\"\"this is a test of a reformat for a triple quoted string will it\n"
|
| 201 |
+
" reformat to less than 70 characters for me?\"\"\"")
|
| 202 |
+
Equal(result, expected)
|
| 203 |
+
|
| 204 |
+
test_comment = (
|
| 205 |
+
"# this is a test of a reformat for a triple quoted string will "
|
| 206 |
+
"it reformat to less than 70 characters for me?")
|
| 207 |
+
result = ft.reformat_comment(test_comment, 70, "#")
|
| 208 |
+
expected = (
|
| 209 |
+
"# this is a test of a reformat for a triple quoted string will it\n"
|
| 210 |
+
"# reformat to less than 70 characters for me?")
|
| 211 |
+
Equal(result, expected)
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
class FormatClassTest(unittest.TestCase):
|
| 215 |
+
def test_init_close(self):
|
| 216 |
+
instance = ft.FormatParagraph('editor')
|
| 217 |
+
self.assertEqual(instance.editwin, 'editor')
|
| 218 |
+
instance.close()
|
| 219 |
+
self.assertEqual(instance.editwin, None)
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
# For testing format_paragraph_event, Initialize FormatParagraph with
|
| 223 |
+
# a mock Editor with .text and .get_selection_indices. The text must
|
| 224 |
+
# be a Text wrapper that adds two methods
|
| 225 |
+
|
| 226 |
+
# A real EditorWindow creates unneeded, time-consuming baggage and
|
| 227 |
+
# sometimes emits shutdown warnings like this:
|
| 228 |
+
# "warning: callback failed in WindowList <class '_tkinter.TclError'>
|
| 229 |
+
# : invalid command name ".55131368.windows".
|
| 230 |
+
# Calling EditorWindow._close in tearDownClass prevents this but causes
|
| 231 |
+
# other problems (windows left open).
|
| 232 |
+
|
| 233 |
+
class TextWrapper:
|
| 234 |
+
def __init__(self, master):
|
| 235 |
+
self.text = Text(master=master)
|
| 236 |
+
def __getattr__(self, name):
|
| 237 |
+
return getattr(self.text, name)
|
| 238 |
+
def undo_block_start(self): pass
|
| 239 |
+
def undo_block_stop(self): pass
|
| 240 |
+
|
| 241 |
+
class Editor:
|
| 242 |
+
def __init__(self, root):
|
| 243 |
+
self.text = TextWrapper(root)
|
| 244 |
+
get_selection_indices = EditorWindow. get_selection_indices
|
| 245 |
+
|
| 246 |
+
class FormatEventTest(unittest.TestCase):
|
| 247 |
+
"""Test the formatting of text inside a Text widget.
|
| 248 |
+
|
| 249 |
+
This is done with FormatParagraph.format.paragraph_event,
|
| 250 |
+
which calls functions in the module as appropriate.
|
| 251 |
+
"""
|
| 252 |
+
test_string = (
|
| 253 |
+
" '''this is a test of a reformat for a triple "
|
| 254 |
+
"quoted string will it reformat to less than 70 "
|
| 255 |
+
"characters for me?'''\n")
|
| 256 |
+
multiline_test_string = (
|
| 257 |
+
" '''The first line is under the max width.\n"
|
| 258 |
+
" The second line's length is way over the max width. It goes "
|
| 259 |
+
"on and on until it is over 100 characters long.\n"
|
| 260 |
+
" Same thing with the third line. It is also way over the max "
|
| 261 |
+
"width, but FormatParagraph will fix it.\n"
|
| 262 |
+
" '''\n")
|
| 263 |
+
multiline_test_comment = (
|
| 264 |
+
"# The first line is under the max width.\n"
|
| 265 |
+
"# The second line's length is way over the max width. It goes on "
|
| 266 |
+
"and on until it is over 100 characters long.\n"
|
| 267 |
+
"# Same thing with the third line. It is also way over the max "
|
| 268 |
+
"width, but FormatParagraph will fix it.\n"
|
| 269 |
+
"# The fourth line is short like the first line.")
|
| 270 |
+
|
| 271 |
+
@classmethod
|
| 272 |
+
def setUpClass(cls):
|
| 273 |
+
requires('gui')
|
| 274 |
+
cls.root = Tk()
|
| 275 |
+
cls.root.withdraw()
|
| 276 |
+
editor = Editor(root=cls.root)
|
| 277 |
+
cls.text = editor.text.text # Test code does not need the wrapper.
|
| 278 |
+
cls.formatter = ft.FormatParagraph(editor).format_paragraph_event
|
| 279 |
+
# Sets the insert mark just after the re-wrapped and inserted text.
|
| 280 |
+
|
| 281 |
+
@classmethod
|
| 282 |
+
def tearDownClass(cls):
|
| 283 |
+
del cls.text, cls.formatter
|
| 284 |
+
cls.root.update_idletasks()
|
| 285 |
+
cls.root.destroy()
|
| 286 |
+
del cls.root
|
| 287 |
+
|
| 288 |
+
def test_short_line(self):
|
| 289 |
+
self.text.insert('1.0', "Short line\n")
|
| 290 |
+
self.formatter("Dummy")
|
| 291 |
+
self.assertEqual(self.text.get('1.0', 'insert'), "Short line\n" )
|
| 292 |
+
self.text.delete('1.0', 'end')
|
| 293 |
+
|
| 294 |
+
def test_long_line(self):
|
| 295 |
+
text = self.text
|
| 296 |
+
|
| 297 |
+
# Set cursor ('insert' mark) to '1.0', within text.
|
| 298 |
+
text.insert('1.0', self.test_string)
|
| 299 |
+
text.mark_set('insert', '1.0')
|
| 300 |
+
self.formatter('ParameterDoesNothing', limit=70)
|
| 301 |
+
result = text.get('1.0', 'insert')
|
| 302 |
+
# find function includes \n
|
| 303 |
+
expected = (
|
| 304 |
+
" '''this is a test of a reformat for a triple quoted string will it\n"
|
| 305 |
+
" reformat to less than 70 characters for me?'''\n") # yes
|
| 306 |
+
self.assertEqual(result, expected)
|
| 307 |
+
text.delete('1.0', 'end')
|
| 308 |
+
|
| 309 |
+
# Select from 1.11 to line end.
|
| 310 |
+
text.insert('1.0', self.test_string)
|
| 311 |
+
text.tag_add('sel', '1.11', '1.end')
|
| 312 |
+
self.formatter('ParameterDoesNothing', limit=70)
|
| 313 |
+
result = text.get('1.0', 'insert')
|
| 314 |
+
# selection excludes \n
|
| 315 |
+
expected = (
|
| 316 |
+
" '''this is a test of a reformat for a triple quoted string will it reformat\n"
|
| 317 |
+
" to less than 70 characters for me?'''") # no
|
| 318 |
+
self.assertEqual(result, expected)
|
| 319 |
+
text.delete('1.0', 'end')
|
| 320 |
+
|
| 321 |
+
def test_multiple_lines(self):
|
| 322 |
+
text = self.text
|
| 323 |
+
# Select 2 long lines.
|
| 324 |
+
text.insert('1.0', self.multiline_test_string)
|
| 325 |
+
text.tag_add('sel', '2.0', '4.0')
|
| 326 |
+
self.formatter('ParameterDoesNothing', limit=70)
|
| 327 |
+
result = text.get('2.0', 'insert')
|
| 328 |
+
expected = (
|
| 329 |
+
" The second line's length is way over the max width. It goes on and\n"
|
| 330 |
+
" on until it is over 100 characters long. Same thing with the third\n"
|
| 331 |
+
" line. It is also way over the max width, but FormatParagraph will\n"
|
| 332 |
+
" fix it.\n")
|
| 333 |
+
self.assertEqual(result, expected)
|
| 334 |
+
text.delete('1.0', 'end')
|
| 335 |
+
|
| 336 |
+
def test_comment_block(self):
|
| 337 |
+
text = self.text
|
| 338 |
+
|
| 339 |
+
# Set cursor ('insert') to '1.0', within block.
|
| 340 |
+
text.insert('1.0', self.multiline_test_comment)
|
| 341 |
+
self.formatter('ParameterDoesNothing', limit=70)
|
| 342 |
+
result = text.get('1.0', 'insert')
|
| 343 |
+
expected = (
|
| 344 |
+
"# The first line is under the max width. The second line's length is\n"
|
| 345 |
+
"# way over the max width. It goes on and on until it is over 100\n"
|
| 346 |
+
"# characters long. Same thing with the third line. It is also way over\n"
|
| 347 |
+
"# the max width, but FormatParagraph will fix it. The fourth line is\n"
|
| 348 |
+
"# short like the first line.\n")
|
| 349 |
+
self.assertEqual(result, expected)
|
| 350 |
+
text.delete('1.0', 'end')
|
| 351 |
+
|
| 352 |
+
# Select line 2, verify line 1 unaffected.
|
| 353 |
+
text.insert('1.0', self.multiline_test_comment)
|
| 354 |
+
text.tag_add('sel', '2.0', '3.0')
|
| 355 |
+
self.formatter('ParameterDoesNothing', limit=70)
|
| 356 |
+
result = text.get('1.0', 'insert')
|
| 357 |
+
expected = (
|
| 358 |
+
"# The first line is under the max width.\n"
|
| 359 |
+
"# The second line's length is way over the max width. It goes on and\n"
|
| 360 |
+
"# on until it is over 100 characters long.\n")
|
| 361 |
+
self.assertEqual(result, expected)
|
| 362 |
+
text.delete('1.0', 'end')
|
| 363 |
+
|
| 364 |
+
# The following block worked with EditorWindow but fails with the mock.
|
| 365 |
+
# Lines 2 and 3 get pasted together even though the previous block left
|
| 366 |
+
# the previous line alone. More investigation is needed.
|
| 367 |
+
## # Select lines 3 and 4
|
| 368 |
+
## text.insert('1.0', self.multiline_test_comment)
|
| 369 |
+
## text.tag_add('sel', '3.0', '5.0')
|
| 370 |
+
## self.formatter('ParameterDoesNothing')
|
| 371 |
+
## result = text.get('3.0', 'insert')
|
| 372 |
+
## expected = (
|
| 373 |
+
##"# Same thing with the third line. It is also way over the max width,\n"
|
| 374 |
+
##"# but FormatParagraph will fix it. The fourth line is short like the\n"
|
| 375 |
+
##"# first line.\n")
|
| 376 |
+
## self.assertEqual(result, expected)
|
| 377 |
+
## text.delete('1.0', 'end')
|
| 378 |
+
|
| 379 |
+
|
| 380 |
+
class DummyEditwin:
|
| 381 |
+
def __init__(self, root, text):
|
| 382 |
+
self.root = root
|
| 383 |
+
self.text = text
|
| 384 |
+
self.indentwidth = 4
|
| 385 |
+
self.tabwidth = 4
|
| 386 |
+
self.usetabs = False
|
| 387 |
+
self.context_use_ps1 = True
|
| 388 |
+
|
| 389 |
+
_make_blanks = EditorWindow._make_blanks
|
| 390 |
+
get_selection_indices = EditorWindow.get_selection_indices
|
| 391 |
+
|
| 392 |
+
|
| 393 |
+
class FormatRegionTest(unittest.TestCase):
|
| 394 |
+
|
| 395 |
+
@classmethod
|
| 396 |
+
def setUpClass(cls):
|
| 397 |
+
requires('gui')
|
| 398 |
+
cls.root = Tk()
|
| 399 |
+
cls.root.withdraw()
|
| 400 |
+
cls.text = Text(cls.root)
|
| 401 |
+
cls.text.undo_block_start = mock.Mock()
|
| 402 |
+
cls.text.undo_block_stop = mock.Mock()
|
| 403 |
+
cls.editor = DummyEditwin(cls.root, cls.text)
|
| 404 |
+
cls.formatter = ft.FormatRegion(cls.editor)
|
| 405 |
+
|
| 406 |
+
@classmethod
|
| 407 |
+
def tearDownClass(cls):
|
| 408 |
+
del cls.text, cls.formatter, cls.editor
|
| 409 |
+
cls.root.update_idletasks()
|
| 410 |
+
cls.root.destroy()
|
| 411 |
+
del cls.root
|
| 412 |
+
|
| 413 |
+
def setUp(self):
|
| 414 |
+
self.text.insert('1.0', self.code_sample)
|
| 415 |
+
|
| 416 |
+
def tearDown(self):
|
| 417 |
+
self.text.delete('1.0', 'end')
|
| 418 |
+
|
| 419 |
+
code_sample = """\
|
| 420 |
+
# WS line needed for test.
|
| 421 |
+
class C1:
|
| 422 |
+
# Class comment.
|
| 423 |
+
def __init__(self, a, b):
|
| 424 |
+
self.a = a
|
| 425 |
+
self.b = b
|
| 426 |
+
|
| 427 |
+
def compare(self):
|
| 428 |
+
if a > b:
|
| 429 |
+
return a
|
| 430 |
+
elif a < b:
|
| 431 |
+
return b
|
| 432 |
+
else:
|
| 433 |
+
return None
|
| 434 |
+
"""
|
| 435 |
+
|
| 436 |
+
def test_get_region(self):
|
| 437 |
+
get = self.formatter.get_region
|
| 438 |
+
text = self.text
|
| 439 |
+
eq = self.assertEqual
|
| 440 |
+
|
| 441 |
+
# Add selection.
|
| 442 |
+
text.tag_add('sel', '7.0', '10.0')
|
| 443 |
+
expected_lines = ['',
|
| 444 |
+
' def compare(self):',
|
| 445 |
+
' if a > b:',
|
| 446 |
+
'']
|
| 447 |
+
eq(get(), ('7.0', '10.0', '\n'.join(expected_lines), expected_lines))
|
| 448 |
+
|
| 449 |
+
# Remove selection.
|
| 450 |
+
text.tag_remove('sel', '1.0', 'end')
|
| 451 |
+
eq(get(), ('15.0', '16.0', '\n', ['', '']))
|
| 452 |
+
|
| 453 |
+
def test_set_region(self):
|
| 454 |
+
set_ = self.formatter.set_region
|
| 455 |
+
text = self.text
|
| 456 |
+
eq = self.assertEqual
|
| 457 |
+
|
| 458 |
+
save_bell = text.bell
|
| 459 |
+
text.bell = mock.Mock()
|
| 460 |
+
line6 = self.code_sample.splitlines()[5]
|
| 461 |
+
line10 = self.code_sample.splitlines()[9]
|
| 462 |
+
|
| 463 |
+
text.tag_add('sel', '6.0', '11.0')
|
| 464 |
+
head, tail, chars, lines = self.formatter.get_region()
|
| 465 |
+
|
| 466 |
+
# No changes.
|
| 467 |
+
set_(head, tail, chars, lines)
|
| 468 |
+
text.bell.assert_called_once()
|
| 469 |
+
eq(text.get('6.0', '11.0'), chars)
|
| 470 |
+
eq(text.get('sel.first', 'sel.last'), chars)
|
| 471 |
+
text.tag_remove('sel', '1.0', 'end')
|
| 472 |
+
|
| 473 |
+
# Alter selected lines by changing lines and adding a newline.
|
| 474 |
+
newstring = 'added line 1\n\n\n\n'
|
| 475 |
+
newlines = newstring.split('\n')
|
| 476 |
+
set_('7.0', '10.0', chars, newlines)
|
| 477 |
+
# Selection changed.
|
| 478 |
+
eq(text.get('sel.first', 'sel.last'), newstring)
|
| 479 |
+
# Additional line added, so last index is changed.
|
| 480 |
+
eq(text.get('7.0', '11.0'), newstring)
|
| 481 |
+
# Before and after lines unchanged.
|
| 482 |
+
eq(text.get('6.0', '7.0-1c'), line6)
|
| 483 |
+
eq(text.get('11.0', '12.0-1c'), line10)
|
| 484 |
+
text.tag_remove('sel', '1.0', 'end')
|
| 485 |
+
|
| 486 |
+
text.bell = save_bell
|
| 487 |
+
|
| 488 |
+
def test_indent_region_event(self):
|
| 489 |
+
indent = self.formatter.indent_region_event
|
| 490 |
+
text = self.text
|
| 491 |
+
eq = self.assertEqual
|
| 492 |
+
|
| 493 |
+
text.tag_add('sel', '7.0', '10.0')
|
| 494 |
+
indent()
|
| 495 |
+
# Blank lines aren't affected by indent.
|
| 496 |
+
eq(text.get('7.0', '10.0'), ('\n def compare(self):\n if a > b:\n'))
|
| 497 |
+
|
| 498 |
+
def test_dedent_region_event(self):
|
| 499 |
+
dedent = self.formatter.dedent_region_event
|
| 500 |
+
text = self.text
|
| 501 |
+
eq = self.assertEqual
|
| 502 |
+
|
| 503 |
+
text.tag_add('sel', '7.0', '10.0')
|
| 504 |
+
dedent()
|
| 505 |
+
# Blank lines aren't affected by dedent.
|
| 506 |
+
eq(text.get('7.0', '10.0'), ('\ndef compare(self):\n if a > b:\n'))
|
| 507 |
+
|
| 508 |
+
def test_comment_region_event(self):
|
| 509 |
+
comment = self.formatter.comment_region_event
|
| 510 |
+
text = self.text
|
| 511 |
+
eq = self.assertEqual
|
| 512 |
+
|
| 513 |
+
text.tag_add('sel', '7.0', '10.0')
|
| 514 |
+
comment()
|
| 515 |
+
eq(text.get('7.0', '10.0'), ('##\n## def compare(self):\n## if a > b:\n'))
|
| 516 |
+
|
| 517 |
+
def test_uncomment_region_event(self):
|
| 518 |
+
comment = self.formatter.comment_region_event
|
| 519 |
+
uncomment = self.formatter.uncomment_region_event
|
| 520 |
+
text = self.text
|
| 521 |
+
eq = self.assertEqual
|
| 522 |
+
|
| 523 |
+
text.tag_add('sel', '7.0', '10.0')
|
| 524 |
+
comment()
|
| 525 |
+
uncomment()
|
| 526 |
+
eq(text.get('7.0', '10.0'), ('\n def compare(self):\n if a > b:\n'))
|
| 527 |
+
|
| 528 |
+
# Only remove comments at the beginning of a line.
|
| 529 |
+
text.tag_remove('sel', '1.0', 'end')
|
| 530 |
+
text.tag_add('sel', '3.0', '4.0')
|
| 531 |
+
uncomment()
|
| 532 |
+
eq(text.get('3.0', '3.end'), (' # Class comment.'))
|
| 533 |
+
|
| 534 |
+
self.formatter.set_region('3.0', '4.0', '', ['# Class comment.', ''])
|
| 535 |
+
uncomment()
|
| 536 |
+
eq(text.get('3.0', '3.end'), (' Class comment.'))
|
| 537 |
+
|
| 538 |
+
@mock.patch.object(ft.FormatRegion, "_asktabwidth")
|
| 539 |
+
def test_tabify_region_event(self, _asktabwidth):
|
| 540 |
+
tabify = self.formatter.tabify_region_event
|
| 541 |
+
text = self.text
|
| 542 |
+
eq = self.assertEqual
|
| 543 |
+
|
| 544 |
+
text.tag_add('sel', '7.0', '10.0')
|
| 545 |
+
# No tabwidth selected.
|
| 546 |
+
_asktabwidth.return_value = None
|
| 547 |
+
self.assertIsNone(tabify())
|
| 548 |
+
|
| 549 |
+
_asktabwidth.return_value = 3
|
| 550 |
+
self.assertIsNotNone(tabify())
|
| 551 |
+
eq(text.get('7.0', '10.0'), ('\n\t def compare(self):\n\t\t if a > b:\n'))
|
| 552 |
+
|
| 553 |
+
@mock.patch.object(ft.FormatRegion, "_asktabwidth")
|
| 554 |
+
def test_untabify_region_event(self, _asktabwidth):
|
| 555 |
+
untabify = self.formatter.untabify_region_event
|
| 556 |
+
text = self.text
|
| 557 |
+
eq = self.assertEqual
|
| 558 |
+
|
| 559 |
+
text.tag_add('sel', '7.0', '10.0')
|
| 560 |
+
# No tabwidth selected.
|
| 561 |
+
_asktabwidth.return_value = None
|
| 562 |
+
self.assertIsNone(untabify())
|
| 563 |
+
|
| 564 |
+
_asktabwidth.return_value = 2
|
| 565 |
+
self.formatter.tabify_region_event()
|
| 566 |
+
_asktabwidth.return_value = 3
|
| 567 |
+
self.assertIsNotNone(untabify())
|
| 568 |
+
eq(text.get('7.0', '10.0'), ('\n def compare(self):\n if a > b:\n'))
|
| 569 |
+
|
| 570 |
+
@mock.patch.object(ft, "askinteger")
|
| 571 |
+
def test_ask_tabwidth(self, askinteger):
|
| 572 |
+
ask = self.formatter._asktabwidth
|
| 573 |
+
askinteger.return_value = 10
|
| 574 |
+
self.assertEqual(ask(), 10)
|
| 575 |
+
|
| 576 |
+
|
| 577 |
+
class IndentsTest(unittest.TestCase):
|
| 578 |
+
|
| 579 |
+
@mock.patch.object(ft, "askyesno")
|
| 580 |
+
def test_toggle_tabs(self, askyesno):
|
| 581 |
+
editor = DummyEditwin(None, None) # usetabs == False.
|
| 582 |
+
indents = ft.Indents(editor)
|
| 583 |
+
askyesno.return_value = True
|
| 584 |
+
|
| 585 |
+
indents.toggle_tabs_event(None)
|
| 586 |
+
self.assertEqual(editor.usetabs, True)
|
| 587 |
+
self.assertEqual(editor.indentwidth, 8)
|
| 588 |
+
|
| 589 |
+
indents.toggle_tabs_event(None)
|
| 590 |
+
self.assertEqual(editor.usetabs, False)
|
| 591 |
+
self.assertEqual(editor.indentwidth, 8)
|
| 592 |
+
|
| 593 |
+
@mock.patch.object(ft, "askinteger")
|
| 594 |
+
def test_change_indentwidth(self, askinteger):
|
| 595 |
+
editor = DummyEditwin(None, None) # indentwidth == 4.
|
| 596 |
+
indents = ft.Indents(editor)
|
| 597 |
+
|
| 598 |
+
askinteger.return_value = None
|
| 599 |
+
indents.change_indentwidth_event(None)
|
| 600 |
+
self.assertEqual(editor.indentwidth, 4)
|
| 601 |
+
|
| 602 |
+
askinteger.return_value = 3
|
| 603 |
+
indents.change_indentwidth_event(None)
|
| 604 |
+
self.assertEqual(editor.indentwidth, 3)
|
| 605 |
+
|
| 606 |
+
askinteger.return_value = 5
|
| 607 |
+
editor.usetabs = True
|
| 608 |
+
indents.change_indentwidth_event(None)
|
| 609 |
+
self.assertEqual(editor.indentwidth, 3)
|
| 610 |
+
|
| 611 |
+
|
| 612 |
+
class RstripTest(unittest.TestCase):
|
| 613 |
+
|
| 614 |
+
@classmethod
|
| 615 |
+
def setUpClass(cls):
|
| 616 |
+
requires('gui')
|
| 617 |
+
cls.root = Tk()
|
| 618 |
+
cls.root.withdraw()
|
| 619 |
+
cls.text = Text(cls.root)
|
| 620 |
+
cls.editor = MockEditor(text=cls.text)
|
| 621 |
+
cls.do_rstrip = ft.Rstrip(cls.editor).do_rstrip
|
| 622 |
+
|
| 623 |
+
@classmethod
|
| 624 |
+
def tearDownClass(cls):
|
| 625 |
+
del cls.text, cls.do_rstrip, cls.editor
|
| 626 |
+
cls.root.update_idletasks()
|
| 627 |
+
cls.root.destroy()
|
| 628 |
+
del cls.root
|
| 629 |
+
|
| 630 |
+
def tearDown(self):
|
| 631 |
+
self.text.delete('1.0', 'end-1c')
|
| 632 |
+
|
| 633 |
+
def test_rstrip_lines(self):
|
| 634 |
+
original = (
|
| 635 |
+
"Line with an ending tab \n"
|
| 636 |
+
"Line ending in 5 spaces \n"
|
| 637 |
+
"Linewithnospaces\n"
|
| 638 |
+
" indented line\n"
|
| 639 |
+
" indented line with trailing space \n"
|
| 640 |
+
" \n")
|
| 641 |
+
stripped = (
|
| 642 |
+
"Line with an ending tab\n"
|
| 643 |
+
"Line ending in 5 spaces\n"
|
| 644 |
+
"Linewithnospaces\n"
|
| 645 |
+
" indented line\n"
|
| 646 |
+
" indented line with trailing space\n")
|
| 647 |
+
|
| 648 |
+
self.text.insert('1.0', original)
|
| 649 |
+
self.do_rstrip()
|
| 650 |
+
self.assertEqual(self.text.get('1.0', 'insert'), stripped)
|
| 651 |
+
|
| 652 |
+
def test_rstrip_end(self):
|
| 653 |
+
text = self.text
|
| 654 |
+
for code in ('', '\n', '\n\n\n'):
|
| 655 |
+
with self.subTest(code=code):
|
| 656 |
+
text.insert('1.0', code)
|
| 657 |
+
self.do_rstrip()
|
| 658 |
+
self.assertEqual(text.get('1.0','end-1c'), '')
|
| 659 |
+
for code in ('a\n', 'a\n\n', 'a\n\n\n'):
|
| 660 |
+
with self.subTest(code=code):
|
| 661 |
+
text.delete('1.0', 'end-1c')
|
| 662 |
+
text.insert('1.0', code)
|
| 663 |
+
self.do_rstrip()
|
| 664 |
+
self.assertEqual(text.get('1.0','end-1c'), 'a\n')
|
| 665 |
+
|
| 666 |
+
|
| 667 |
+
if __name__ == '__main__':
|
| 668 |
+
unittest.main(verbosity=2, exit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ing 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)
|
micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_help.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"Test help, coverage 94%."
|
| 2 |
+
|
| 3 |
+
from idlelib import help
|
| 4 |
+
import unittest
|
| 5 |
+
from test.support import requires
|
| 6 |
+
requires('gui')
|
| 7 |
+
from os.path import abspath, dirname, join
|
| 8 |
+
from tkinter import Tk
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class IdleDocTest(unittest.TestCase):
|
| 12 |
+
|
| 13 |
+
@classmethod
|
| 14 |
+
def setUpClass(cls):
|
| 15 |
+
"By itself, this tests that file parsed without exception."
|
| 16 |
+
cls.root = root = Tk()
|
| 17 |
+
root.withdraw()
|
| 18 |
+
cls.window = help.show_idlehelp(root)
|
| 19 |
+
|
| 20 |
+
@classmethod
|
| 21 |
+
def tearDownClass(cls):
|
| 22 |
+
del cls.window
|
| 23 |
+
cls.root.update_idletasks()
|
| 24 |
+
cls.root.destroy()
|
| 25 |
+
del cls.root
|
| 26 |
+
|
| 27 |
+
def test_1window(self):
|
| 28 |
+
self.assertIn('IDLE Doc', self.window.wm_title())
|
| 29 |
+
|
| 30 |
+
def test_4text(self):
|
| 31 |
+
text = self.window.frame.text
|
| 32 |
+
self.assertEqual(text.get('1.0', '1.end'), ' IDLE ')
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
if __name__ == '__main__':
|
| 36 |
+
unittest.main(verbosity=2)
|
micromamba_root/envs/pytorch_env/Lib/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.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, 'News3.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.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)
|
micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_history.py
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
" Test history, coverage 100%."
|
| 2 |
+
|
| 3 |
+
from idlelib.history import History
|
| 4 |
+
import unittest
|
| 5 |
+
from test.support import requires
|
| 6 |
+
|
| 7 |
+
import tkinter as tk
|
| 8 |
+
from tkinter import Text as tkText
|
| 9 |
+
from idlelib.idle_test.mock_tk import Text as mkText
|
| 10 |
+
from idlelib.config import idleConf
|
| 11 |
+
|
| 12 |
+
line1 = 'a = 7'
|
| 13 |
+
line2 = 'b = a'
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class StoreTest(unittest.TestCase):
|
| 17 |
+
'''Tests History.__init__ and History.store with mock Text'''
|
| 18 |
+
|
| 19 |
+
@classmethod
|
| 20 |
+
def setUpClass(cls):
|
| 21 |
+
cls.text = mkText()
|
| 22 |
+
cls.history = History(cls.text)
|
| 23 |
+
|
| 24 |
+
def tearDown(self):
|
| 25 |
+
self.text.delete('1.0', 'end')
|
| 26 |
+
self.history.history = []
|
| 27 |
+
|
| 28 |
+
def test_init(self):
|
| 29 |
+
self.assertIs(self.history.text, self.text)
|
| 30 |
+
self.assertEqual(self.history.history, [])
|
| 31 |
+
self.assertIsNone(self.history.prefix)
|
| 32 |
+
self.assertIsNone(self.history.pointer)
|
| 33 |
+
self.assertEqual(self.history.cyclic,
|
| 34 |
+
idleConf.GetOption("main", "History", "cyclic", 1, "bool"))
|
| 35 |
+
|
| 36 |
+
def test_store_short(self):
|
| 37 |
+
self.history.store('a')
|
| 38 |
+
self.assertEqual(self.history.history, [])
|
| 39 |
+
self.history.store(' a ')
|
| 40 |
+
self.assertEqual(self.history.history, [])
|
| 41 |
+
|
| 42 |
+
def test_store_dup(self):
|
| 43 |
+
self.history.store(line1)
|
| 44 |
+
self.assertEqual(self.history.history, [line1])
|
| 45 |
+
self.history.store(line2)
|
| 46 |
+
self.assertEqual(self.history.history, [line1, line2])
|
| 47 |
+
self.history.store(line1)
|
| 48 |
+
self.assertEqual(self.history.history, [line2, line1])
|
| 49 |
+
|
| 50 |
+
def test_store_reset(self):
|
| 51 |
+
self.history.prefix = line1
|
| 52 |
+
self.history.pointer = 0
|
| 53 |
+
self.history.store(line2)
|
| 54 |
+
self.assertIsNone(self.history.prefix)
|
| 55 |
+
self.assertIsNone(self.history.pointer)
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
class TextWrapper:
|
| 59 |
+
def __init__(self, master):
|
| 60 |
+
self.text = tkText(master=master)
|
| 61 |
+
self._bell = False
|
| 62 |
+
def __getattr__(self, name):
|
| 63 |
+
return getattr(self.text, name)
|
| 64 |
+
def bell(self):
|
| 65 |
+
self._bell = True
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
class FetchTest(unittest.TestCase):
|
| 69 |
+
'''Test History.fetch with wrapped tk.Text.
|
| 70 |
+
'''
|
| 71 |
+
@classmethod
|
| 72 |
+
def setUpClass(cls):
|
| 73 |
+
requires('gui')
|
| 74 |
+
cls.root = tk.Tk()
|
| 75 |
+
cls.root.withdraw()
|
| 76 |
+
|
| 77 |
+
def setUp(self):
|
| 78 |
+
self.text = text = TextWrapper(self.root)
|
| 79 |
+
text.insert('1.0', ">>> ")
|
| 80 |
+
text.mark_set('iomark', '1.4')
|
| 81 |
+
text.mark_gravity('iomark', 'left')
|
| 82 |
+
self.history = History(text)
|
| 83 |
+
self.history.history = [line1, line2]
|
| 84 |
+
|
| 85 |
+
@classmethod
|
| 86 |
+
def tearDownClass(cls):
|
| 87 |
+
cls.root.destroy()
|
| 88 |
+
del cls.root
|
| 89 |
+
|
| 90 |
+
def fetch_test(self, reverse, line, prefix, index, *, bell=False):
|
| 91 |
+
# Perform one fetch as invoked by Alt-N or Alt-P
|
| 92 |
+
# Test the result. The line test is the most important.
|
| 93 |
+
# The last two are diagnostic of fetch internals.
|
| 94 |
+
History = self.history
|
| 95 |
+
History.fetch(reverse)
|
| 96 |
+
|
| 97 |
+
Equal = self.assertEqual
|
| 98 |
+
Equal(self.text.get('iomark', 'end-1c'), line)
|
| 99 |
+
Equal(self.text._bell, bell)
|
| 100 |
+
if bell:
|
| 101 |
+
self.text._bell = False
|
| 102 |
+
Equal(History.prefix, prefix)
|
| 103 |
+
Equal(History.pointer, index)
|
| 104 |
+
Equal(self.text.compare("insert", '==', "end-1c"), 1)
|
| 105 |
+
|
| 106 |
+
def test_fetch_prev_cyclic(self):
|
| 107 |
+
prefix = ''
|
| 108 |
+
test = self.fetch_test
|
| 109 |
+
test(True, line2, prefix, 1)
|
| 110 |
+
test(True, line1, prefix, 0)
|
| 111 |
+
test(True, prefix, None, None, bell=True)
|
| 112 |
+
|
| 113 |
+
def test_fetch_next_cyclic(self):
|
| 114 |
+
prefix = ''
|
| 115 |
+
test = self.fetch_test
|
| 116 |
+
test(False, line1, prefix, 0)
|
| 117 |
+
test(False, line2, prefix, 1)
|
| 118 |
+
test(False, prefix, None, None, bell=True)
|
| 119 |
+
|
| 120 |
+
# Prefix 'a' tests skip line2, which starts with 'b'
|
| 121 |
+
def test_fetch_prev_prefix(self):
|
| 122 |
+
prefix = 'a'
|
| 123 |
+
self.text.insert('iomark', prefix)
|
| 124 |
+
self.fetch_test(True, line1, prefix, 0)
|
| 125 |
+
self.fetch_test(True, prefix, None, None, bell=True)
|
| 126 |
+
|
| 127 |
+
def test_fetch_next_prefix(self):
|
| 128 |
+
prefix = 'a'
|
| 129 |
+
self.text.insert('iomark', prefix)
|
| 130 |
+
self.fetch_test(False, line1, prefix, 0)
|
| 131 |
+
self.fetch_test(False, prefix, None, None, bell=True)
|
| 132 |
+
|
| 133 |
+
def test_fetch_prev_noncyclic(self):
|
| 134 |
+
prefix = ''
|
| 135 |
+
self.history.cyclic = False
|
| 136 |
+
test = self.fetch_test
|
| 137 |
+
test(True, line2, prefix, 1)
|
| 138 |
+
test(True, line1, prefix, 0)
|
| 139 |
+
test(True, line1, prefix, 0, bell=True)
|
| 140 |
+
|
| 141 |
+
def test_fetch_next_noncyclic(self):
|
| 142 |
+
prefix = ''
|
| 143 |
+
self.history.cyclic = False
|
| 144 |
+
test = self.fetch_test
|
| 145 |
+
test(False, prefix, None, None, bell=True)
|
| 146 |
+
test(True, line2, prefix, 1)
|
| 147 |
+
test(False, prefix, None, None, bell=True)
|
| 148 |
+
test(False, prefix, None, None, bell=True)
|
| 149 |
+
|
| 150 |
+
def test_fetch_cursor_move(self):
|
| 151 |
+
# Move cursor after fetch
|
| 152 |
+
self.history.fetch(reverse=True) # initialization
|
| 153 |
+
self.text.mark_set('insert', 'iomark')
|
| 154 |
+
self.fetch_test(True, line2, None, None, bell=True)
|
| 155 |
+
|
| 156 |
+
def test_fetch_edit(self):
|
| 157 |
+
# Edit after fetch
|
| 158 |
+
self.history.fetch(reverse=True) # initialization
|
| 159 |
+
self.text.delete('iomark', 'insert', )
|
| 160 |
+
self.text.insert('iomark', 'a =')
|
| 161 |
+
self.fetch_test(True, line1, 'a =', 0) # prefix is reset
|
| 162 |
+
|
| 163 |
+
def test_history_prev_next(self):
|
| 164 |
+
# Minimally test functions bound to events
|
| 165 |
+
self.history.history_prev('dummy event')
|
| 166 |
+
self.assertEqual(self.history.pointer, 1)
|
| 167 |
+
self.history.history_next('dummy event')
|
| 168 |
+
self.assertEqual(self.history.pointer, None)
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
if __name__ == '__main__':
|
| 172 |
+
unittest.main(verbosity=2, exit=2)
|
micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_hyperparser.py
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"Test hyperparser, 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)
|
micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_iomenu.py
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"Test , coverage 17%."
|
| 2 |
+
|
| 3 |
+
from idlelib import iomenu
|
| 4 |
+
import unittest
|
| 5 |
+
from test.support import requires
|
| 6 |
+
from tkinter import Tk
|
| 7 |
+
from idlelib.editor import EditorWindow
|
| 8 |
+
from idlelib import util
|
| 9 |
+
from idlelib.idle_test.mock_idle import Func
|
| 10 |
+
|
| 11 |
+
# Fail if either tokenize.open and t.detect_encoding does not exist.
|
| 12 |
+
# These are used in loadfile and encode.
|
| 13 |
+
# Also used in pyshell.MI.execfile and runscript.tabnanny.
|
| 14 |
+
from tokenize import open, detect_encoding
|
| 15 |
+
# Remove when we have proper tests that use both.
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class IOBindingTest(unittest.TestCase):
|
| 19 |
+
|
| 20 |
+
@classmethod
|
| 21 |
+
def setUpClass(cls):
|
| 22 |
+
requires('gui')
|
| 23 |
+
cls.root = Tk()
|
| 24 |
+
cls.root.withdraw()
|
| 25 |
+
cls.editwin = EditorWindow(root=cls.root)
|
| 26 |
+
cls.io = iomenu.IOBinding(cls.editwin)
|
| 27 |
+
|
| 28 |
+
@classmethod
|
| 29 |
+
def tearDownClass(cls):
|
| 30 |
+
cls.io.close()
|
| 31 |
+
cls.editwin._close()
|
| 32 |
+
del cls.editwin
|
| 33 |
+
cls.root.update_idletasks()
|
| 34 |
+
for id in cls.root.tk.call('after', 'info'):
|
| 35 |
+
cls.root.after_cancel(id) # Need for EditorWindow.
|
| 36 |
+
cls.root.destroy()
|
| 37 |
+
del cls.root
|
| 38 |
+
|
| 39 |
+
def test_init(self):
|
| 40 |
+
self.assertIs(self.io.editwin, self.editwin)
|
| 41 |
+
|
| 42 |
+
def test_fixnewlines_end(self):
|
| 43 |
+
eq = self.assertEqual
|
| 44 |
+
io = self.io
|
| 45 |
+
fix = io.fixnewlines
|
| 46 |
+
text = io.editwin.text
|
| 47 |
+
|
| 48 |
+
# Make the editor temporarily look like Shell.
|
| 49 |
+
self.editwin.interp = None
|
| 50 |
+
shelltext = '>>> if 1'
|
| 51 |
+
self.editwin.get_prompt_text = Func(result=shelltext)
|
| 52 |
+
eq(fix(), shelltext) # Get... call and '\n' not added.
|
| 53 |
+
del self.editwin.interp, self.editwin.get_prompt_text
|
| 54 |
+
|
| 55 |
+
text.insert(1.0, 'a')
|
| 56 |
+
eq(fix(), 'a'+io.eol_convention)
|
| 57 |
+
eq(text.get('1.0', 'end-1c'), 'a\n')
|
| 58 |
+
eq(fix(), 'a'+io.eol_convention)
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def _extension_in_filetypes(extension):
|
| 62 |
+
return any(
|
| 63 |
+
f'*{extension}' in filetype_tuple[1]
|
| 64 |
+
for filetype_tuple in iomenu.IOBinding.filetypes
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
class FiletypesTest(unittest.TestCase):
|
| 69 |
+
def test_python_source_files(self):
|
| 70 |
+
for extension in util.py_extensions:
|
| 71 |
+
with self.subTest(extension=extension):
|
| 72 |
+
self.assertTrue(
|
| 73 |
+
_extension_in_filetypes(extension)
|
| 74 |
+
)
|
| 75 |
+
|
| 76 |
+
def test_text_files(self):
|
| 77 |
+
self.assertTrue(_extension_in_filetypes('.txt'))
|
| 78 |
+
|
| 79 |
+
def test_all_files(self):
|
| 80 |
+
self.assertTrue(_extension_in_filetypes(''))
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
if __name__ == '__main__':
|
| 84 |
+
unittest.main(verbosity=2)
|
micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_macosx.py
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"Test macosx, coverage 45% on Windows."
|
| 2 |
+
|
| 3 |
+
from idlelib import macosx
|
| 4 |
+
import unittest
|
| 5 |
+
from test.support import requires
|
| 6 |
+
import tkinter as tk
|
| 7 |
+
import unittest.mock as mock
|
| 8 |
+
from idlelib.filelist import FileList
|
| 9 |
+
|
| 10 |
+
mactypes = {'carbon', 'cocoa', 'xquartz'}
|
| 11 |
+
nontypes = {'other'}
|
| 12 |
+
alltypes = mactypes | nontypes
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def setUpModule():
|
| 16 |
+
global orig_tktype
|
| 17 |
+
orig_tktype = macosx._tk_type
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def tearDownModule():
|
| 21 |
+
macosx._tk_type = orig_tktype
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class InitTktypeTest(unittest.TestCase):
|
| 25 |
+
"Test _init_tk_type."
|
| 26 |
+
|
| 27 |
+
@classmethod
|
| 28 |
+
def setUpClass(cls):
|
| 29 |
+
requires('gui')
|
| 30 |
+
cls.root = tk.Tk()
|
| 31 |
+
cls.root.withdraw()
|
| 32 |
+
cls.orig_platform = macosx.platform
|
| 33 |
+
|
| 34 |
+
@classmethod
|
| 35 |
+
def tearDownClass(cls):
|
| 36 |
+
cls.root.update_idletasks()
|
| 37 |
+
cls.root.destroy()
|
| 38 |
+
del cls.root
|
| 39 |
+
macosx.platform = cls.orig_platform
|
| 40 |
+
|
| 41 |
+
def test_init_sets_tktype(self):
|
| 42 |
+
"Test that _init_tk_type sets _tk_type according to platform."
|
| 43 |
+
for platform, types in ('darwin', alltypes), ('other', nontypes):
|
| 44 |
+
with self.subTest(platform=platform):
|
| 45 |
+
macosx.platform = platform
|
| 46 |
+
macosx._tk_type = None
|
| 47 |
+
macosx._init_tk_type()
|
| 48 |
+
self.assertIn(macosx._tk_type, types)
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
class IsTypeTkTest(unittest.TestCase):
|
| 52 |
+
"Test each of the four isTypeTk predecates."
|
| 53 |
+
isfuncs = ((macosx.isAquaTk, ('carbon', 'cocoa')),
|
| 54 |
+
(macosx.isCarbonTk, ('carbon')),
|
| 55 |
+
(macosx.isCocoaTk, ('cocoa')),
|
| 56 |
+
(macosx.isXQuartz, ('xquartz')),
|
| 57 |
+
)
|
| 58 |
+
|
| 59 |
+
@mock.patch('idlelib.macosx._init_tk_type')
|
| 60 |
+
def test_is_calls_init(self, mockinit):
|
| 61 |
+
"Test that each isTypeTk calls _init_tk_type when _tk_type is None."
|
| 62 |
+
macosx._tk_type = None
|
| 63 |
+
for func, whentrue in self.isfuncs:
|
| 64 |
+
with self.subTest(func=func):
|
| 65 |
+
func()
|
| 66 |
+
self.assertTrue(mockinit.called)
|
| 67 |
+
mockinit.reset_mock()
|
| 68 |
+
|
| 69 |
+
def test_isfuncs(self):
|
| 70 |
+
"Test that each isTypeTk return correct bool."
|
| 71 |
+
for func, whentrue in self.isfuncs:
|
| 72 |
+
for tktype in alltypes:
|
| 73 |
+
with self.subTest(func=func, whentrue=whentrue, tktype=tktype):
|
| 74 |
+
macosx._tk_type = tktype
|
| 75 |
+
(self.assertTrue if tktype in whentrue else self.assertFalse)\
|
| 76 |
+
(func())
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
class SetupTest(unittest.TestCase):
|
| 80 |
+
"Test setupApp."
|
| 81 |
+
|
| 82 |
+
@classmethod
|
| 83 |
+
def setUpClass(cls):
|
| 84 |
+
requires('gui')
|
| 85 |
+
cls.root = tk.Tk()
|
| 86 |
+
cls.root.withdraw()
|
| 87 |
+
def cmd(tkpath, func):
|
| 88 |
+
assert isinstance(tkpath, str)
|
| 89 |
+
assert isinstance(func, type(cmd))
|
| 90 |
+
cls.root.createcommand = cmd
|
| 91 |
+
|
| 92 |
+
@classmethod
|
| 93 |
+
def tearDownClass(cls):
|
| 94 |
+
cls.root.update_idletasks()
|
| 95 |
+
cls.root.destroy()
|
| 96 |
+
del cls.root
|
| 97 |
+
|
| 98 |
+
@mock.patch('idlelib.macosx.overrideRootMenu') #27312
|
| 99 |
+
def test_setupapp(self, overrideRootMenu):
|
| 100 |
+
"Call setupApp with each possible graphics type."
|
| 101 |
+
root = self.root
|
| 102 |
+
flist = FileList(root)
|
| 103 |
+
for tktype in alltypes:
|
| 104 |
+
with self.subTest(tktype=tktype):
|
| 105 |
+
macosx._tk_type = tktype
|
| 106 |
+
macosx.setupApp(root, flist)
|
| 107 |
+
if tktype in ('carbon', 'cocoa'):
|
| 108 |
+
self.assertTrue(overrideRootMenu.called)
|
| 109 |
+
overrideRootMenu.reset_mock()
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
if __name__ == '__main__':
|
| 113 |
+
unittest.main(verbosity=2)
|
micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_mainmenu.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"Test mainmenu, coverage 100%."
|
| 2 |
+
# Reported as 88%; mocking turtledemo absence would have no point.
|
| 3 |
+
|
| 4 |
+
from idlelib import mainmenu
|
| 5 |
+
import re
|
| 6 |
+
import unittest
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class MainMenuTest(unittest.TestCase):
|
| 10 |
+
|
| 11 |
+
def test_menudefs(self):
|
| 12 |
+
actual = [item[0] for item in mainmenu.menudefs]
|
| 13 |
+
expect = ['file', 'edit', 'format', 'run', 'shell',
|
| 14 |
+
'debug', 'options', 'window', 'help']
|
| 15 |
+
self.assertEqual(actual, expect)
|
| 16 |
+
|
| 17 |
+
def test_default_keydefs(self):
|
| 18 |
+
self.assertGreaterEqual(len(mainmenu.default_keydefs), 50)
|
| 19 |
+
|
| 20 |
+
def test_tcl_indexes(self):
|
| 21 |
+
# Test tcl patterns used to find menuitem to alter.
|
| 22 |
+
# On failure, change pattern here and in function(s).
|
| 23 |
+
# Patterns here have '.*' for re instead of '*' for tcl.
|
| 24 |
+
for menu, pattern in (
|
| 25 |
+
('debug', '.*tack.*iewer'), # PyShell.debug_menu_postcommand
|
| 26 |
+
('options', '.*ode.*ontext'), # EW.__init__, CodeContext.toggle...
|
| 27 |
+
('options', '.*ine.*umbers'), # EW.__init__, EW.toggle...event.
|
| 28 |
+
):
|
| 29 |
+
with self.subTest(menu=menu, pattern=pattern):
|
| 30 |
+
for menutup in mainmenu.menudefs:
|
| 31 |
+
if menutup[0] == menu:
|
| 32 |
+
break
|
| 33 |
+
else:
|
| 34 |
+
self.assertTrue(0, f"{menu} not in menudefs")
|
| 35 |
+
self.assertTrue(any(re.search(pattern, menuitem[0])
|
| 36 |
+
for menuitem in menutup[1]
|
| 37 |
+
if menuitem is not None), # Separator.
|
| 38 |
+
f"{pattern} not in {menu}")
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
if __name__ == '__main__':
|
| 42 |
+
unittest.main(verbosity=2)
|
micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_multicall.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"Test multicall, coverage 33%."
|
| 2 |
+
|
| 3 |
+
from idlelib import multicall
|
| 4 |
+
import unittest
|
| 5 |
+
from test.support import requires
|
| 6 |
+
from tkinter import Tk, Text
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class MultiCallTest(unittest.TestCase):
|
| 10 |
+
|
| 11 |
+
@classmethod
|
| 12 |
+
def setUpClass(cls):
|
| 13 |
+
requires('gui')
|
| 14 |
+
cls.root = Tk()
|
| 15 |
+
cls.root.withdraw()
|
| 16 |
+
cls.mc = multicall.MultiCallCreator(Text)
|
| 17 |
+
|
| 18 |
+
@classmethod
|
| 19 |
+
def tearDownClass(cls):
|
| 20 |
+
del cls.mc
|
| 21 |
+
cls.root.update_idletasks()
|
| 22 |
+
## for id in cls.root.tk.call('after', 'info'):
|
| 23 |
+
## cls.root.after_cancel(id) # Need for EditorWindow.
|
| 24 |
+
cls.root.destroy()
|
| 25 |
+
del cls.root
|
| 26 |
+
|
| 27 |
+
def test_creator(self):
|
| 28 |
+
mc = self.mc
|
| 29 |
+
self.assertIs(multicall._multicall_dict[Text], mc)
|
| 30 |
+
self.assertTrue(issubclass(mc, Text))
|
| 31 |
+
mc2 = multicall.MultiCallCreator(Text)
|
| 32 |
+
self.assertIs(mc, mc2)
|
| 33 |
+
|
| 34 |
+
def test_init(self):
|
| 35 |
+
mctext = self.mc(self.root)
|
| 36 |
+
self.assertIsInstance(mctext._MultiCall__binders, list)
|
| 37 |
+
|
| 38 |
+
def test_yview(self):
|
| 39 |
+
# Added for tree.wheel_event
|
| 40 |
+
# (it depends on yview to not be overridden)
|
| 41 |
+
mc = self.mc
|
| 42 |
+
self.assertIs(mc.yview, Text.yview)
|
| 43 |
+
mctext = self.mc(self.root)
|
| 44 |
+
self.assertIs(mctext.yview.__func__, Text.yview)
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
if __name__ == '__main__':
|
| 48 |
+
unittest.main(verbosity=2)
|
micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_outwin.py
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"Test outwin, coverage 76%."
|
| 2 |
+
|
| 3 |
+
from idlelib import outwin
|
| 4 |
+
import unittest
|
| 5 |
+
from test.support import requires
|
| 6 |
+
from tkinter import Tk, Text
|
| 7 |
+
from idlelib.idle_test.mock_tk import Mbox_func
|
| 8 |
+
from idlelib.idle_test.mock_idle import Func
|
| 9 |
+
from unittest import mock
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class OutputWindowTest(unittest.TestCase):
|
| 13 |
+
|
| 14 |
+
@classmethod
|
| 15 |
+
def setUpClass(cls):
|
| 16 |
+
requires('gui')
|
| 17 |
+
root = cls.root = Tk()
|
| 18 |
+
root.withdraw()
|
| 19 |
+
w = cls.window = outwin.OutputWindow(None, None, None, root)
|
| 20 |
+
cls.text = w.text = Text(root)
|
| 21 |
+
|
| 22 |
+
@classmethod
|
| 23 |
+
def tearDownClass(cls):
|
| 24 |
+
cls.window.close()
|
| 25 |
+
del cls.text, cls.window
|
| 26 |
+
cls.root.destroy()
|
| 27 |
+
del cls.root
|
| 28 |
+
|
| 29 |
+
def setUp(self):
|
| 30 |
+
self.text.delete('1.0', 'end')
|
| 31 |
+
|
| 32 |
+
def test_ispythonsource(self):
|
| 33 |
+
# OutputWindow overrides ispythonsource to always return False.
|
| 34 |
+
w = self.window
|
| 35 |
+
self.assertFalse(w.ispythonsource('test.txt'))
|
| 36 |
+
self.assertFalse(w.ispythonsource(__file__))
|
| 37 |
+
|
| 38 |
+
def test_window_title(self):
|
| 39 |
+
self.assertEqual(self.window.top.title(), 'Output')
|
| 40 |
+
|
| 41 |
+
def test_maybesave(self):
|
| 42 |
+
w = self.window
|
| 43 |
+
eq = self.assertEqual
|
| 44 |
+
w.get_saved = Func()
|
| 45 |
+
|
| 46 |
+
w.get_saved.result = False
|
| 47 |
+
eq(w.maybesave(), 'no')
|
| 48 |
+
eq(w.get_saved.called, 1)
|
| 49 |
+
|
| 50 |
+
w.get_saved.result = True
|
| 51 |
+
eq(w.maybesave(), 'yes')
|
| 52 |
+
eq(w.get_saved.called, 2)
|
| 53 |
+
del w.get_saved
|
| 54 |
+
|
| 55 |
+
def test_write(self):
|
| 56 |
+
eq = self.assertEqual
|
| 57 |
+
delete = self.text.delete
|
| 58 |
+
get = self.text.get
|
| 59 |
+
write = self.window.write
|
| 60 |
+
|
| 61 |
+
# No new line - insert stays on same line.
|
| 62 |
+
delete('1.0', 'end')
|
| 63 |
+
test_text = 'test text'
|
| 64 |
+
eq(write(test_text), len(test_text))
|
| 65 |
+
eq(get('1.0', '1.end'), 'test text')
|
| 66 |
+
eq(get('insert linestart', 'insert lineend'), 'test text')
|
| 67 |
+
|
| 68 |
+
# New line - insert moves to next line.
|
| 69 |
+
delete('1.0', 'end')
|
| 70 |
+
test_text = 'test text\n'
|
| 71 |
+
eq(write(test_text), len(test_text))
|
| 72 |
+
eq(get('1.0', '1.end'), 'test text')
|
| 73 |
+
eq(get('insert linestart', 'insert lineend'), '')
|
| 74 |
+
|
| 75 |
+
# Text after new line is tagged for second line of Text widget.
|
| 76 |
+
delete('1.0', 'end')
|
| 77 |
+
test_text = 'test text\nLine 2'
|
| 78 |
+
eq(write(test_text), len(test_text))
|
| 79 |
+
eq(get('1.0', '1.end'), 'test text')
|
| 80 |
+
eq(get('2.0', '2.end'), 'Line 2')
|
| 81 |
+
eq(get('insert linestart', 'insert lineend'), 'Line 2')
|
| 82 |
+
|
| 83 |
+
# Test tags.
|
| 84 |
+
delete('1.0', 'end')
|
| 85 |
+
test_text = 'test text\n'
|
| 86 |
+
test_text2 = 'Line 2\n'
|
| 87 |
+
eq(write(test_text, tags='mytag'), len(test_text))
|
| 88 |
+
eq(write(test_text2, tags='secondtag'), len(test_text2))
|
| 89 |
+
eq(get('mytag.first', 'mytag.last'), test_text)
|
| 90 |
+
eq(get('secondtag.first', 'secondtag.last'), test_text2)
|
| 91 |
+
eq(get('1.0', '1.end'), test_text.rstrip('\n'))
|
| 92 |
+
eq(get('2.0', '2.end'), test_text2.rstrip('\n'))
|
| 93 |
+
|
| 94 |
+
def test_writelines(self):
|
| 95 |
+
eq = self.assertEqual
|
| 96 |
+
get = self.text.get
|
| 97 |
+
writelines = self.window.writelines
|
| 98 |
+
|
| 99 |
+
writelines(('Line 1\n', 'Line 2\n', 'Line 3\n'))
|
| 100 |
+
eq(get('1.0', '1.end'), 'Line 1')
|
| 101 |
+
eq(get('2.0', '2.end'), 'Line 2')
|
| 102 |
+
eq(get('3.0', '3.end'), 'Line 3')
|
| 103 |
+
eq(get('insert linestart', 'insert lineend'), '')
|
| 104 |
+
|
| 105 |
+
def test_goto_file_line(self):
|
| 106 |
+
eq = self.assertEqual
|
| 107 |
+
w = self.window
|
| 108 |
+
text = self.text
|
| 109 |
+
|
| 110 |
+
w.flist = mock.Mock()
|
| 111 |
+
gfl = w.flist.gotofileline = Func()
|
| 112 |
+
showerror = w.showerror = Mbox_func()
|
| 113 |
+
|
| 114 |
+
# No file/line number.
|
| 115 |
+
w.write('Not a file line')
|
| 116 |
+
self.assertIsNone(w.goto_file_line())
|
| 117 |
+
eq(gfl.called, 0)
|
| 118 |
+
eq(showerror.title, 'No special line')
|
| 119 |
+
|
| 120 |
+
# Current file/line number.
|
| 121 |
+
w.write(f'{str(__file__)}: 42: spam\n')
|
| 122 |
+
w.write(f'{str(__file__)}: 21: spam')
|
| 123 |
+
self.assertIsNone(w.goto_file_line())
|
| 124 |
+
eq(gfl.args, (str(__file__), 21))
|
| 125 |
+
|
| 126 |
+
# Previous line has file/line number.
|
| 127 |
+
text.delete('1.0', 'end')
|
| 128 |
+
w.write(f'{str(__file__)}: 42: spam\n')
|
| 129 |
+
w.write('Not a file line')
|
| 130 |
+
self.assertIsNone(w.goto_file_line())
|
| 131 |
+
eq(gfl.args, (str(__file__), 42))
|
| 132 |
+
|
| 133 |
+
del w.flist.gotofileline, w.showerror
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
class ModuleFunctionTest(unittest.TestCase):
|
| 137 |
+
|
| 138 |
+
@classmethod
|
| 139 |
+
def setUp(cls):
|
| 140 |
+
outwin.file_line_progs = None
|
| 141 |
+
|
| 142 |
+
def test_compile_progs(self):
|
| 143 |
+
outwin.compile_progs()
|
| 144 |
+
for pat, regex in zip(outwin.file_line_pats, outwin.file_line_progs):
|
| 145 |
+
self.assertEqual(regex.pattern, pat)
|
| 146 |
+
|
| 147 |
+
@mock.patch('builtins.open')
|
| 148 |
+
def test_file_line_helper(self, mock_open):
|
| 149 |
+
flh = outwin.file_line_helper
|
| 150 |
+
test_lines = (
|
| 151 |
+
(r'foo file "testfile1", line 42, bar', ('testfile1', 42)),
|
| 152 |
+
(r'foo testfile2(21) bar', ('testfile2', 21)),
|
| 153 |
+
(r' testfile3 : 42: foo bar\n', (' testfile3 ', 42)),
|
| 154 |
+
(r'foo testfile4.py :1: ', ('foo testfile4.py ', 1)),
|
| 155 |
+
('testfile5: \u19D4\u19D2: ', ('testfile5', 42)),
|
| 156 |
+
(r'testfile6: 42', None), # only one `:`
|
| 157 |
+
(r'testfile7 42 text', None) # no separators
|
| 158 |
+
)
|
| 159 |
+
for line, expected_output in test_lines:
|
| 160 |
+
self.assertEqual(flh(line), expected_output)
|
| 161 |
+
if expected_output:
|
| 162 |
+
mock_open.assert_called_with(expected_output[0])
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
if __name__ == '__main__':
|
| 166 |
+
unittest.main(verbosity=2)
|
micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_parenmatch.py
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Test parenmatch, coverage 91%.
|
| 2 |
+
|
| 3 |
+
This must currently be a gui test because ParenMatch methods use
|
| 4 |
+
several text methods not defined on idlelib.idle_test.mock_tk.Text.
|
| 5 |
+
"""
|
| 6 |
+
from idlelib.parenmatch import ParenMatch
|
| 7 |
+
from test.support import requires
|
| 8 |
+
requires('gui')
|
| 9 |
+
|
| 10 |
+
import unittest
|
| 11 |
+
from unittest.mock import Mock
|
| 12 |
+
from tkinter import Tk, Text
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class DummyEditwin:
|
| 16 |
+
def __init__(self, text):
|
| 17 |
+
self.text = text
|
| 18 |
+
self.indentwidth = 8
|
| 19 |
+
self.tabwidth = 8
|
| 20 |
+
self.prompt_last_line = '>>>' # Currently not used by parenmatch.
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
class ParenMatchTest(unittest.TestCase):
|
| 24 |
+
|
| 25 |
+
@classmethod
|
| 26 |
+
def setUpClass(cls):
|
| 27 |
+
cls.root = Tk()
|
| 28 |
+
cls.root.withdraw()
|
| 29 |
+
cls.text = Text(cls.root)
|
| 30 |
+
cls.editwin = DummyEditwin(cls.text)
|
| 31 |
+
cls.editwin.text_frame = Mock()
|
| 32 |
+
|
| 33 |
+
@classmethod
|
| 34 |
+
def tearDownClass(cls):
|
| 35 |
+
del cls.text, cls.editwin
|
| 36 |
+
cls.root.update_idletasks()
|
| 37 |
+
cls.root.destroy()
|
| 38 |
+
del cls.root
|
| 39 |
+
|
| 40 |
+
def tearDown(self):
|
| 41 |
+
self.text.delete('1.0', 'end')
|
| 42 |
+
|
| 43 |
+
def get_parenmatch(self):
|
| 44 |
+
pm = ParenMatch(self.editwin)
|
| 45 |
+
pm.bell = lambda: None
|
| 46 |
+
return pm
|
| 47 |
+
|
| 48 |
+
def test_paren_styles(self):
|
| 49 |
+
"""
|
| 50 |
+
Test ParenMatch with each style.
|
| 51 |
+
"""
|
| 52 |
+
text = self.text
|
| 53 |
+
pm = self.get_parenmatch()
|
| 54 |
+
for style, range1, range2 in (
|
| 55 |
+
('opener', ('1.10', '1.11'), ('1.10', '1.11')),
|
| 56 |
+
('default',('1.10', '1.11'),('1.10', '1.11')),
|
| 57 |
+
('parens', ('1.14', '1.15'), ('1.15', '1.16')),
|
| 58 |
+
('expression', ('1.10', '1.15'), ('1.10', '1.16'))):
|
| 59 |
+
with self.subTest(style=style):
|
| 60 |
+
text.delete('1.0', 'end')
|
| 61 |
+
pm.STYLE = style
|
| 62 |
+
text.insert('insert', 'def foobar(a, b')
|
| 63 |
+
|
| 64 |
+
pm.flash_paren_event('event')
|
| 65 |
+
self.assertIn('<<parenmatch-check-restore>>', text.event_info())
|
| 66 |
+
if style == 'parens':
|
| 67 |
+
self.assertTupleEqual(text.tag_nextrange('paren', '1.0'),
|
| 68 |
+
('1.10', '1.11'))
|
| 69 |
+
self.assertTupleEqual(
|
| 70 |
+
text.tag_prevrange('paren', 'end'), range1)
|
| 71 |
+
|
| 72 |
+
text.insert('insert', ')')
|
| 73 |
+
pm.restore_event()
|
| 74 |
+
self.assertNotIn('<<parenmatch-check-restore>>',
|
| 75 |
+
text.event_info())
|
| 76 |
+
self.assertEqual(text.tag_prevrange('paren', 'end'), ())
|
| 77 |
+
|
| 78 |
+
pm.paren_closed_event('event')
|
| 79 |
+
self.assertTupleEqual(
|
| 80 |
+
text.tag_prevrange('paren', 'end'), range2)
|
| 81 |
+
|
| 82 |
+
def test_paren_corner(self):
|
| 83 |
+
"""
|
| 84 |
+
Test corner cases in flash_paren_event and paren_closed_event.
|
| 85 |
+
|
| 86 |
+
Force execution of conditional expressions and alternate paths.
|
| 87 |
+
"""
|
| 88 |
+
text = self.text
|
| 89 |
+
pm = self.get_parenmatch()
|
| 90 |
+
|
| 91 |
+
text.insert('insert', '# Comment.)')
|
| 92 |
+
pm.paren_closed_event('event')
|
| 93 |
+
|
| 94 |
+
text.insert('insert', '\ndef')
|
| 95 |
+
pm.flash_paren_event('event')
|
| 96 |
+
pm.paren_closed_event('event')
|
| 97 |
+
|
| 98 |
+
text.insert('insert', ' a, *arg)')
|
| 99 |
+
pm.paren_closed_event('event')
|
| 100 |
+
|
| 101 |
+
def test_handle_restore_timer(self):
|
| 102 |
+
pm = self.get_parenmatch()
|
| 103 |
+
pm.restore_event = Mock()
|
| 104 |
+
pm.handle_restore_timer(0)
|
| 105 |
+
self.assertTrue(pm.restore_event.called)
|
| 106 |
+
pm.restore_event.reset_mock()
|
| 107 |
+
pm.handle_restore_timer(1)
|
| 108 |
+
self.assertFalse(pm.restore_event.called)
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
if __name__ == '__main__':
|
| 112 |
+
unittest.main(verbosity=2)
|
micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_pathbrowser.py
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"Test pathbrowser, coverage 95%."
|
| 2 |
+
|
| 3 |
+
from idlelib import pathbrowser
|
| 4 |
+
import unittest
|
| 5 |
+
from test.support import requires
|
| 6 |
+
from tkinter import Tk
|
| 7 |
+
|
| 8 |
+
import os.path
|
| 9 |
+
import pyclbr # for _modules
|
| 10 |
+
import sys # for sys.path
|
| 11 |
+
|
| 12 |
+
from idlelib.idle_test.mock_idle import Func
|
| 13 |
+
import idlelib # for __file__
|
| 14 |
+
from idlelib import browser
|
| 15 |
+
from idlelib.tree import TreeNode
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class PathBrowserTest(unittest.TestCase):
|
| 19 |
+
|
| 20 |
+
@classmethod
|
| 21 |
+
def setUpClass(cls):
|
| 22 |
+
requires('gui')
|
| 23 |
+
cls.root = Tk()
|
| 24 |
+
cls.root.withdraw()
|
| 25 |
+
cls.pb = pathbrowser.PathBrowser(cls.root, _utest=True)
|
| 26 |
+
|
| 27 |
+
@classmethod
|
| 28 |
+
def tearDownClass(cls):
|
| 29 |
+
cls.pb.close()
|
| 30 |
+
cls.root.update_idletasks()
|
| 31 |
+
cls.root.destroy()
|
| 32 |
+
del cls.root, cls.pb
|
| 33 |
+
|
| 34 |
+
def test_init(self):
|
| 35 |
+
pb = self.pb
|
| 36 |
+
eq = self.assertEqual
|
| 37 |
+
eq(pb.master, self.root)
|
| 38 |
+
eq(pyclbr._modules, {})
|
| 39 |
+
self.assertIsInstance(pb.node, TreeNode)
|
| 40 |
+
self.assertIsNotNone(browser.file_open)
|
| 41 |
+
|
| 42 |
+
def test_settitle(self):
|
| 43 |
+
pb = self.pb
|
| 44 |
+
self.assertEqual(pb.top.title(), 'Path Browser')
|
| 45 |
+
self.assertEqual(pb.top.iconname(), 'Path Browser')
|
| 46 |
+
|
| 47 |
+
def test_rootnode(self):
|
| 48 |
+
pb = self.pb
|
| 49 |
+
rn = pb.rootnode()
|
| 50 |
+
self.assertIsInstance(rn, pathbrowser.PathBrowserTreeItem)
|
| 51 |
+
|
| 52 |
+
def test_close(self):
|
| 53 |
+
pb = self.pb
|
| 54 |
+
pb.top.destroy = Func()
|
| 55 |
+
pb.node.destroy = Func()
|
| 56 |
+
pb.close()
|
| 57 |
+
self.assertTrue(pb.top.destroy.called)
|
| 58 |
+
self.assertTrue(pb.node.destroy.called)
|
| 59 |
+
del pb.top.destroy, pb.node.destroy
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
class DirBrowserTreeItemTest(unittest.TestCase):
|
| 63 |
+
|
| 64 |
+
def test_DirBrowserTreeItem(self):
|
| 65 |
+
# Issue16226 - make sure that getting a sublist works
|
| 66 |
+
d = pathbrowser.DirBrowserTreeItem('')
|
| 67 |
+
d.GetSubList()
|
| 68 |
+
self.assertEqual('', d.GetText())
|
| 69 |
+
|
| 70 |
+
dir = os.path.split(os.path.abspath(idlelib.__file__))[0]
|
| 71 |
+
self.assertEqual(d.ispackagedir(dir), True)
|
| 72 |
+
self.assertEqual(d.ispackagedir(dir + '/Icons'), False)
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
class PathBrowserTreeItemTest(unittest.TestCase):
|
| 76 |
+
|
| 77 |
+
def test_PathBrowserTreeItem(self):
|
| 78 |
+
p = pathbrowser.PathBrowserTreeItem()
|
| 79 |
+
self.assertEqual(p.GetText(), 'sys.path')
|
| 80 |
+
sub = p.GetSubList()
|
| 81 |
+
self.assertEqual(len(sub), len(sys.path))
|
| 82 |
+
self.assertEqual(type(sub[0]), pathbrowser.DirBrowserTreeItem)
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
if __name__ == '__main__':
|
| 86 |
+
unittest.main(verbosity=2, exit=False)
|
micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_percolator.py
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"Test percolator, coverage 100%."
|
| 2 |
+
|
| 3 |
+
from idlelib.percolator import Percolator, Delegator
|
| 4 |
+
import unittest
|
| 5 |
+
from test.support import requires
|
| 6 |
+
requires('gui')
|
| 7 |
+
from tkinter import Text, Tk, END
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class MyFilter(Delegator):
|
| 11 |
+
def __init__(self):
|
| 12 |
+
Delegator.__init__(self, None)
|
| 13 |
+
|
| 14 |
+
def insert(self, *args):
|
| 15 |
+
self.insert_called_with = args
|
| 16 |
+
self.delegate.insert(*args)
|
| 17 |
+
|
| 18 |
+
def delete(self, *args):
|
| 19 |
+
self.delete_called_with = args
|
| 20 |
+
self.delegate.delete(*args)
|
| 21 |
+
|
| 22 |
+
def uppercase_insert(self, index, chars, tags=None):
|
| 23 |
+
chars = chars.upper()
|
| 24 |
+
self.delegate.insert(index, chars)
|
| 25 |
+
|
| 26 |
+
def lowercase_insert(self, index, chars, tags=None):
|
| 27 |
+
chars = chars.lower()
|
| 28 |
+
self.delegate.insert(index, chars)
|
| 29 |
+
|
| 30 |
+
def dont_insert(self, index, chars, tags=None):
|
| 31 |
+
pass
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
class PercolatorTest(unittest.TestCase):
|
| 35 |
+
|
| 36 |
+
@classmethod
|
| 37 |
+
def setUpClass(cls):
|
| 38 |
+
cls.root = Tk()
|
| 39 |
+
cls.text = Text(cls.root)
|
| 40 |
+
|
| 41 |
+
@classmethod
|
| 42 |
+
def tearDownClass(cls):
|
| 43 |
+
del cls.text
|
| 44 |
+
cls.root.destroy()
|
| 45 |
+
del cls.root
|
| 46 |
+
|
| 47 |
+
def setUp(self):
|
| 48 |
+
self.percolator = Percolator(self.text)
|
| 49 |
+
self.filter_one = MyFilter()
|
| 50 |
+
self.filter_two = MyFilter()
|
| 51 |
+
self.percolator.insertfilter(self.filter_one)
|
| 52 |
+
self.percolator.insertfilter(self.filter_two)
|
| 53 |
+
|
| 54 |
+
def tearDown(self):
|
| 55 |
+
self.percolator.close()
|
| 56 |
+
self.text.delete('1.0', END)
|
| 57 |
+
|
| 58 |
+
def test_insertfilter(self):
|
| 59 |
+
self.assertIsNotNone(self.filter_one.delegate)
|
| 60 |
+
self.assertEqual(self.percolator.top, self.filter_two)
|
| 61 |
+
self.assertEqual(self.filter_two.delegate, self.filter_one)
|
| 62 |
+
self.assertEqual(self.filter_one.delegate, self.percolator.bottom)
|
| 63 |
+
|
| 64 |
+
def test_removefilter(self):
|
| 65 |
+
filter_three = MyFilter()
|
| 66 |
+
self.percolator.removefilter(self.filter_two)
|
| 67 |
+
self.assertEqual(self.percolator.top, self.filter_one)
|
| 68 |
+
self.assertIsNone(self.filter_two.delegate)
|
| 69 |
+
|
| 70 |
+
filter_three = MyFilter()
|
| 71 |
+
self.percolator.insertfilter(self.filter_two)
|
| 72 |
+
self.percolator.insertfilter(filter_three)
|
| 73 |
+
self.percolator.removefilter(self.filter_one)
|
| 74 |
+
self.assertEqual(self.percolator.top, filter_three)
|
| 75 |
+
self.assertEqual(filter_three.delegate, self.filter_two)
|
| 76 |
+
self.assertEqual(self.filter_two.delegate, self.percolator.bottom)
|
| 77 |
+
self.assertIsNone(self.filter_one.delegate)
|
| 78 |
+
|
| 79 |
+
def test_insert(self):
|
| 80 |
+
self.text.insert('insert', 'foo')
|
| 81 |
+
self.assertEqual(self.text.get('1.0', END), 'foo\n')
|
| 82 |
+
self.assertTupleEqual(self.filter_one.insert_called_with,
|
| 83 |
+
('insert', 'foo', None))
|
| 84 |
+
|
| 85 |
+
def test_modify_insert(self):
|
| 86 |
+
self.filter_one.insert = self.filter_one.uppercase_insert
|
| 87 |
+
self.text.insert('insert', 'bAr')
|
| 88 |
+
self.assertEqual(self.text.get('1.0', END), 'BAR\n')
|
| 89 |
+
|
| 90 |
+
def test_modify_chain_insert(self):
|
| 91 |
+
filter_three = MyFilter()
|
| 92 |
+
self.percolator.insertfilter(filter_three)
|
| 93 |
+
self.filter_two.insert = self.filter_two.uppercase_insert
|
| 94 |
+
self.filter_one.insert = self.filter_one.lowercase_insert
|
| 95 |
+
self.text.insert('insert', 'BaR')
|
| 96 |
+
self.assertEqual(self.text.get('1.0', END), 'bar\n')
|
| 97 |
+
|
| 98 |
+
def test_dont_insert(self):
|
| 99 |
+
self.filter_one.insert = self.filter_one.dont_insert
|
| 100 |
+
self.text.insert('insert', 'foo bar')
|
| 101 |
+
self.assertEqual(self.text.get('1.0', END), '\n')
|
| 102 |
+
self.filter_one.insert = self.filter_one.dont_insert
|
| 103 |
+
self.text.insert('insert', 'foo bar')
|
| 104 |
+
self.assertEqual(self.text.get('1.0', END), '\n')
|
| 105 |
+
|
| 106 |
+
def test_without_filter(self):
|
| 107 |
+
self.text.insert('insert', 'hello')
|
| 108 |
+
self.assertEqual(self.text.get('1.0', 'end'), 'hello\n')
|
| 109 |
+
|
| 110 |
+
def test_delete(self):
|
| 111 |
+
self.text.insert('insert', 'foo')
|
| 112 |
+
self.text.delete('1.0', '1.2')
|
| 113 |
+
self.assertEqual(self.text.get('1.0', END), 'o\n')
|
| 114 |
+
self.assertTupleEqual(self.filter_one.delete_called_with,
|
| 115 |
+
('1.0', '1.2'))
|
| 116 |
+
|
| 117 |
+
if __name__ == '__main__':
|
| 118 |
+
unittest.main(verbosity=2)
|
micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_pyparse.py
ADDED
|
@@ -0,0 +1,483 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"Test pyparse, coverage 96%."
|
| 2 |
+
|
| 3 |
+
from idlelib import pyparse
|
| 4 |
+
import unittest
|
| 5 |
+
from collections import namedtuple
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class ParseMapTest(unittest.TestCase):
|
| 9 |
+
|
| 10 |
+
def test_parsemap(self):
|
| 11 |
+
keepwhite = {ord(c): ord(c) for c in ' \t\n\r'}
|
| 12 |
+
mapping = pyparse.ParseMap(keepwhite)
|
| 13 |
+
self.assertEqual(mapping[ord('\t')], ord('\t'))
|
| 14 |
+
self.assertEqual(mapping[ord('a')], ord('x'))
|
| 15 |
+
self.assertEqual(mapping[1000], ord('x'))
|
| 16 |
+
|
| 17 |
+
def test_trans(self):
|
| 18 |
+
# trans is the production instance of ParseMap, used in _study1
|
| 19 |
+
parser = pyparse.Parser(4, 4)
|
| 20 |
+
self.assertEqual('\t a([{b}])b"c\'d\n'.translate(pyparse.trans),
|
| 21 |
+
'xxx(((x)))x"x\'x\n')
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class PyParseTest(unittest.TestCase):
|
| 25 |
+
|
| 26 |
+
@classmethod
|
| 27 |
+
def setUpClass(cls):
|
| 28 |
+
cls.parser = pyparse.Parser(indentwidth=4, tabwidth=4)
|
| 29 |
+
|
| 30 |
+
@classmethod
|
| 31 |
+
def tearDownClass(cls):
|
| 32 |
+
del cls.parser
|
| 33 |
+
|
| 34 |
+
def test_init(self):
|
| 35 |
+
self.assertEqual(self.parser.indentwidth, 4)
|
| 36 |
+
self.assertEqual(self.parser.tabwidth, 4)
|
| 37 |
+
|
| 38 |
+
def test_set_code(self):
|
| 39 |
+
eq = self.assertEqual
|
| 40 |
+
p = self.parser
|
| 41 |
+
setcode = p.set_code
|
| 42 |
+
|
| 43 |
+
# Not empty and doesn't end with newline.
|
| 44 |
+
with self.assertRaises(AssertionError):
|
| 45 |
+
setcode('a')
|
| 46 |
+
|
| 47 |
+
tests = ('',
|
| 48 |
+
'a\n')
|
| 49 |
+
|
| 50 |
+
for string in tests:
|
| 51 |
+
with self.subTest(string=string):
|
| 52 |
+
setcode(string)
|
| 53 |
+
eq(p.code, string)
|
| 54 |
+
eq(p.study_level, 0)
|
| 55 |
+
|
| 56 |
+
def test_find_good_parse_start(self):
|
| 57 |
+
eq = self.assertEqual
|
| 58 |
+
p = self.parser
|
| 59 |
+
setcode = p.set_code
|
| 60 |
+
start = p.find_good_parse_start
|
| 61 |
+
def char_in_string_false(index): return False
|
| 62 |
+
|
| 63 |
+
# First line starts with 'def' and ends with ':', then 0 is the pos.
|
| 64 |
+
setcode('def spam():\n')
|
| 65 |
+
eq(start(char_in_string_false), 0)
|
| 66 |
+
|
| 67 |
+
# First line begins with a keyword in the list and ends
|
| 68 |
+
# with an open brace, then 0 is the pos. This is how
|
| 69 |
+
# hyperparser calls this function as the newline is not added
|
| 70 |
+
# in the editor, but rather on the call to setcode.
|
| 71 |
+
setcode('class spam( ' + ' \n')
|
| 72 |
+
eq(start(char_in_string_false), 0)
|
| 73 |
+
|
| 74 |
+
# Split def across lines.
|
| 75 |
+
setcode('"""This is a module docstring"""\n'
|
| 76 |
+
'class C:\n'
|
| 77 |
+
' def __init__(self, a,\n'
|
| 78 |
+
' b=True):\n'
|
| 79 |
+
' pass\n'
|
| 80 |
+
)
|
| 81 |
+
pos0, pos = 33, 42 # Start of 'class...', ' def' lines.
|
| 82 |
+
|
| 83 |
+
# Passing no value or non-callable should fail (issue 32989).
|
| 84 |
+
with self.assertRaises(TypeError):
|
| 85 |
+
start()
|
| 86 |
+
with self.assertRaises(TypeError):
|
| 87 |
+
start(False)
|
| 88 |
+
|
| 89 |
+
# Make text look like a string. This returns pos as the start
|
| 90 |
+
# position, but it's set to None.
|
| 91 |
+
self.assertIsNone(start(is_char_in_string=lambda index: True))
|
| 92 |
+
|
| 93 |
+
# Make all text look like it's not in a string. This means that it
|
| 94 |
+
# found a good start position.
|
| 95 |
+
eq(start(char_in_string_false), pos)
|
| 96 |
+
|
| 97 |
+
# If the beginning of the def line is not in a string, then it
|
| 98 |
+
# returns that as the index.
|
| 99 |
+
eq(start(is_char_in_string=lambda index: index > pos), pos)
|
| 100 |
+
# If the beginning of the def line is in a string, then it
|
| 101 |
+
# looks for a previous index.
|
| 102 |
+
eq(start(is_char_in_string=lambda index: index >= pos), pos0)
|
| 103 |
+
# If everything before the 'def' is in a string, then returns None.
|
| 104 |
+
# The non-continuation def line returns 44 (see below).
|
| 105 |
+
eq(start(is_char_in_string=lambda index: index < pos), None)
|
| 106 |
+
|
| 107 |
+
# Code without extra line break in def line - mostly returns the same
|
| 108 |
+
# values.
|
| 109 |
+
setcode('"""This is a module docstring"""\n'
|
| 110 |
+
'class C:\n'
|
| 111 |
+
' def __init__(self, a, b=True):\n'
|
| 112 |
+
' pass\n'
|
| 113 |
+
) # Does not affect class, def positions.
|
| 114 |
+
eq(start(char_in_string_false), pos)
|
| 115 |
+
eq(start(is_char_in_string=lambda index: index > pos), pos)
|
| 116 |
+
eq(start(is_char_in_string=lambda index: index >= pos), pos0)
|
| 117 |
+
# When the def line isn't split, this returns which doesn't match the
|
| 118 |
+
# split line test.
|
| 119 |
+
eq(start(is_char_in_string=lambda index: index < pos), pos)
|
| 120 |
+
|
| 121 |
+
def test_set_lo(self):
|
| 122 |
+
code = (
|
| 123 |
+
'"""This is a module docstring"""\n'
|
| 124 |
+
'class C:\n'
|
| 125 |
+
' def __init__(self, a,\n'
|
| 126 |
+
' b=True):\n'
|
| 127 |
+
' pass\n'
|
| 128 |
+
)
|
| 129 |
+
pos = 42
|
| 130 |
+
p = self.parser
|
| 131 |
+
p.set_code(code)
|
| 132 |
+
|
| 133 |
+
# Previous character is not a newline.
|
| 134 |
+
with self.assertRaises(AssertionError):
|
| 135 |
+
p.set_lo(5)
|
| 136 |
+
|
| 137 |
+
# A value of 0 doesn't change self.code.
|
| 138 |
+
p.set_lo(0)
|
| 139 |
+
self.assertEqual(p.code, code)
|
| 140 |
+
|
| 141 |
+
# An index that is preceded by a newline.
|
| 142 |
+
p.set_lo(pos)
|
| 143 |
+
self.assertEqual(p.code, code[pos:])
|
| 144 |
+
|
| 145 |
+
def test_study1(self):
|
| 146 |
+
eq = self.assertEqual
|
| 147 |
+
p = self.parser
|
| 148 |
+
setcode = p.set_code
|
| 149 |
+
study = p._study1
|
| 150 |
+
|
| 151 |
+
(NONE, BACKSLASH, FIRST, NEXT, BRACKET) = range(5)
|
| 152 |
+
TestInfo = namedtuple('TestInfo', ['string', 'goodlines',
|
| 153 |
+
'continuation'])
|
| 154 |
+
tests = (
|
| 155 |
+
TestInfo('', [0], NONE),
|
| 156 |
+
# Docstrings.
|
| 157 |
+
TestInfo('"""This is a complete docstring."""\n', [0, 1], NONE),
|
| 158 |
+
TestInfo("'''This is a complete docstring.'''\n", [0, 1], NONE),
|
| 159 |
+
TestInfo('"""This is a continued docstring.\n', [0, 1], FIRST),
|
| 160 |
+
TestInfo("'''This is a continued docstring.\n", [0, 1], FIRST),
|
| 161 |
+
TestInfo('"""Closing quote does not match."\n', [0, 1], FIRST),
|
| 162 |
+
TestInfo('"""Bracket in docstring [\n', [0, 1], FIRST),
|
| 163 |
+
TestInfo("'''Incomplete two line docstring.\n\n", [0, 2], NEXT),
|
| 164 |
+
# Single-quoted strings.
|
| 165 |
+
TestInfo('"This is a complete string."\n', [0, 1], NONE),
|
| 166 |
+
TestInfo('"This is an incomplete string.\n', [0, 1], NONE),
|
| 167 |
+
TestInfo("'This is more incomplete.\n\n", [0, 1, 2], NONE),
|
| 168 |
+
# Comment (backslash does not continue comments).
|
| 169 |
+
TestInfo('# Comment\\\n', [0, 1], NONE),
|
| 170 |
+
# Brackets.
|
| 171 |
+
TestInfo('("""Complete string in bracket"""\n', [0, 1], BRACKET),
|
| 172 |
+
TestInfo('("""Open string in bracket\n', [0, 1], FIRST),
|
| 173 |
+
TestInfo('a = (1 + 2) - 5 *\\\n', [0, 1], BACKSLASH), # No bracket.
|
| 174 |
+
TestInfo('\n def function1(self, a,\n b):\n',
|
| 175 |
+
[0, 1, 3], NONE),
|
| 176 |
+
TestInfo('\n def function1(self, a,\\\n', [0, 1, 2], BRACKET),
|
| 177 |
+
TestInfo('\n def function1(self, a,\n', [0, 1, 2], BRACKET),
|
| 178 |
+
TestInfo('())\n', [0, 1], NONE), # Extra closer.
|
| 179 |
+
TestInfo(')(\n', [0, 1], BRACKET), # Extra closer.
|
| 180 |
+
# For the mismatched example, it doesn't look like continuation.
|
| 181 |
+
TestInfo('{)(]\n', [0, 1], NONE), # Mismatched.
|
| 182 |
+
)
|
| 183 |
+
|
| 184 |
+
for test in tests:
|
| 185 |
+
with self.subTest(string=test.string):
|
| 186 |
+
setcode(test.string) # resets study_level
|
| 187 |
+
study()
|
| 188 |
+
eq(p.study_level, 1)
|
| 189 |
+
eq(p.goodlines, test.goodlines)
|
| 190 |
+
eq(p.continuation, test.continuation)
|
| 191 |
+
|
| 192 |
+
# Called again, just returns without reprocessing.
|
| 193 |
+
self.assertIsNone(study())
|
| 194 |
+
|
| 195 |
+
def test_get_continuation_type(self):
|
| 196 |
+
eq = self.assertEqual
|
| 197 |
+
p = self.parser
|
| 198 |
+
setcode = p.set_code
|
| 199 |
+
gettype = p.get_continuation_type
|
| 200 |
+
|
| 201 |
+
(NONE, BACKSLASH, FIRST, NEXT, BRACKET) = range(5)
|
| 202 |
+
TestInfo = namedtuple('TestInfo', ['string', 'continuation'])
|
| 203 |
+
tests = (
|
| 204 |
+
TestInfo('', NONE),
|
| 205 |
+
TestInfo('"""This is a continuation docstring.\n', FIRST),
|
| 206 |
+
TestInfo("'''This is a multiline-continued docstring.\n\n", NEXT),
|
| 207 |
+
TestInfo('a = (1 + 2) - 5 *\\\n', BACKSLASH),
|
| 208 |
+
TestInfo('\n def function1(self, a,\\\n', BRACKET)
|
| 209 |
+
)
|
| 210 |
+
|
| 211 |
+
for test in tests:
|
| 212 |
+
with self.subTest(string=test.string):
|
| 213 |
+
setcode(test.string)
|
| 214 |
+
eq(gettype(), test.continuation)
|
| 215 |
+
|
| 216 |
+
def test_study2(self):
|
| 217 |
+
eq = self.assertEqual
|
| 218 |
+
p = self.parser
|
| 219 |
+
setcode = p.set_code
|
| 220 |
+
study = p._study2
|
| 221 |
+
|
| 222 |
+
TestInfo = namedtuple('TestInfo', ['string', 'start', 'end', 'lastch',
|
| 223 |
+
'openbracket', 'bracketing'])
|
| 224 |
+
tests = (
|
| 225 |
+
TestInfo('', 0, 0, '', None, ((0, 0),)),
|
| 226 |
+
TestInfo("'''This is a multiline continuation docstring.\n\n",
|
| 227 |
+
0, 48, "'", None, ((0, 0), (0, 1), (48, 0))),
|
| 228 |
+
TestInfo(' # Comment\\\n',
|
| 229 |
+
0, 12, '', None, ((0, 0), (1, 1), (12, 0))),
|
| 230 |
+
# A comment without a space is a special case
|
| 231 |
+
TestInfo(' #Comment\\\n',
|
| 232 |
+
0, 0, '', None, ((0, 0),)),
|
| 233 |
+
# Backslash continuation.
|
| 234 |
+
TestInfo('a = (1 + 2) - 5 *\\\n',
|
| 235 |
+
0, 19, '*', None, ((0, 0), (4, 1), (11, 0))),
|
| 236 |
+
# Bracket continuation with close.
|
| 237 |
+
TestInfo('\n def function1(self, a,\n b):\n',
|
| 238 |
+
1, 48, ':', None, ((1, 0), (17, 1), (46, 0))),
|
| 239 |
+
# Bracket continuation with unneeded backslash.
|
| 240 |
+
TestInfo('\n def function1(self, a,\\\n',
|
| 241 |
+
1, 28, ',', 17, ((1, 0), (17, 1))),
|
| 242 |
+
# Bracket continuation.
|
| 243 |
+
TestInfo('\n def function1(self, a,\n',
|
| 244 |
+
1, 27, ',', 17, ((1, 0), (17, 1))),
|
| 245 |
+
# Bracket continuation with comment at end of line with text.
|
| 246 |
+
TestInfo('\n def function1(self, a, # End of line comment.\n',
|
| 247 |
+
1, 51, ',', 17, ((1, 0), (17, 1), (28, 2), (51, 1))),
|
| 248 |
+
# Multi-line statement with comment line in between code lines.
|
| 249 |
+
TestInfo(' a = ["first item",\n # Comment line\n "next item",\n',
|
| 250 |
+
0, 55, ',', 6, ((0, 0), (6, 1), (7, 2), (19, 1),
|
| 251 |
+
(23, 2), (38, 1), (42, 2), (53, 1))),
|
| 252 |
+
TestInfo('())\n',
|
| 253 |
+
0, 4, ')', None, ((0, 0), (0, 1), (2, 0), (3, 0))),
|
| 254 |
+
TestInfo(')(\n', 0, 3, '(', 1, ((0, 0), (1, 0), (1, 1))),
|
| 255 |
+
# Wrong closers still decrement stack level.
|
| 256 |
+
TestInfo('{)(]\n',
|
| 257 |
+
0, 5, ']', None, ((0, 0), (0, 1), (2, 0), (2, 1), (4, 0))),
|
| 258 |
+
# Character after backslash.
|
| 259 |
+
TestInfo(':\\a\n', 0, 4, '\\a', None, ((0, 0),)),
|
| 260 |
+
TestInfo('\n', 0, 0, '', None, ((0, 0),)),
|
| 261 |
+
)
|
| 262 |
+
|
| 263 |
+
for test in tests:
|
| 264 |
+
with self.subTest(string=test.string):
|
| 265 |
+
setcode(test.string)
|
| 266 |
+
study()
|
| 267 |
+
eq(p.study_level, 2)
|
| 268 |
+
eq(p.stmt_start, test.start)
|
| 269 |
+
eq(p.stmt_end, test.end)
|
| 270 |
+
eq(p.lastch, test.lastch)
|
| 271 |
+
eq(p.lastopenbracketpos, test.openbracket)
|
| 272 |
+
eq(p.stmt_bracketing, test.bracketing)
|
| 273 |
+
|
| 274 |
+
# Called again, just returns without reprocessing.
|
| 275 |
+
self.assertIsNone(study())
|
| 276 |
+
|
| 277 |
+
def test_get_num_lines_in_stmt(self):
|
| 278 |
+
eq = self.assertEqual
|
| 279 |
+
p = self.parser
|
| 280 |
+
setcode = p.set_code
|
| 281 |
+
getlines = p.get_num_lines_in_stmt
|
| 282 |
+
|
| 283 |
+
TestInfo = namedtuple('TestInfo', ['string', 'lines'])
|
| 284 |
+
tests = (
|
| 285 |
+
TestInfo('[x for x in a]\n', 1), # Closed on one line.
|
| 286 |
+
TestInfo('[x\nfor x in a\n', 2), # Not closed.
|
| 287 |
+
TestInfo('[x\\\nfor x in a\\\n', 2), # "", unneeded backslashes.
|
| 288 |
+
TestInfo('[x\nfor x in a\n]\n', 3), # Closed on multi-line.
|
| 289 |
+
TestInfo('\n"""Docstring comment L1"""\nL2\nL3\nL4\n', 1),
|
| 290 |
+
TestInfo('\n"""Docstring comment L1\nL2"""\nL3\nL4\n', 1),
|
| 291 |
+
TestInfo('\n"""Docstring comment L1\\\nL2\\\nL3\\\nL4\\\n', 4),
|
| 292 |
+
TestInfo('\n\n"""Docstring comment L1\\\nL2\\\nL3\\\nL4\\\n"""\n', 5)
|
| 293 |
+
)
|
| 294 |
+
|
| 295 |
+
# Blank string doesn't have enough elements in goodlines.
|
| 296 |
+
setcode('')
|
| 297 |
+
with self.assertRaises(IndexError):
|
| 298 |
+
getlines()
|
| 299 |
+
|
| 300 |
+
for test in tests:
|
| 301 |
+
with self.subTest(string=test.string):
|
| 302 |
+
setcode(test.string)
|
| 303 |
+
eq(getlines(), test.lines)
|
| 304 |
+
|
| 305 |
+
def test_compute_bracket_indent(self):
|
| 306 |
+
eq = self.assertEqual
|
| 307 |
+
p = self.parser
|
| 308 |
+
setcode = p.set_code
|
| 309 |
+
indent = p.compute_bracket_indent
|
| 310 |
+
|
| 311 |
+
TestInfo = namedtuple('TestInfo', ['string', 'spaces'])
|
| 312 |
+
tests = (
|
| 313 |
+
TestInfo('def function1(self, a,\n', 14),
|
| 314 |
+
# Characters after bracket.
|
| 315 |
+
TestInfo('\n def function1(self, a,\n', 18),
|
| 316 |
+
TestInfo('\n\tdef function1(self, a,\n', 18),
|
| 317 |
+
# No characters after bracket.
|
| 318 |
+
TestInfo('\n def function1(\n', 8),
|
| 319 |
+
TestInfo('\n\tdef function1(\n', 8),
|
| 320 |
+
TestInfo('\n def function1( \n', 8), # Ignore extra spaces.
|
| 321 |
+
TestInfo('[\n"first item",\n # Comment line\n "next item",\n', 0),
|
| 322 |
+
TestInfo('[\n "first item",\n # Comment line\n "next item",\n', 2),
|
| 323 |
+
TestInfo('["first item",\n # Comment line\n "next item",\n', 1),
|
| 324 |
+
TestInfo('(\n', 4),
|
| 325 |
+
TestInfo('(a\n', 1),
|
| 326 |
+
)
|
| 327 |
+
|
| 328 |
+
# Must be C_BRACKET continuation type.
|
| 329 |
+
setcode('def function1(self, a, b):\n')
|
| 330 |
+
with self.assertRaises(AssertionError):
|
| 331 |
+
indent()
|
| 332 |
+
|
| 333 |
+
for test in tests:
|
| 334 |
+
setcode(test.string)
|
| 335 |
+
eq(indent(), test.spaces)
|
| 336 |
+
|
| 337 |
+
def test_compute_backslash_indent(self):
|
| 338 |
+
eq = self.assertEqual
|
| 339 |
+
p = self.parser
|
| 340 |
+
setcode = p.set_code
|
| 341 |
+
indent = p.compute_backslash_indent
|
| 342 |
+
|
| 343 |
+
# Must be C_BACKSLASH continuation type.
|
| 344 |
+
errors = (('def function1(self, a, b\\\n'), # Bracket.
|
| 345 |
+
(' """ (\\\n'), # Docstring.
|
| 346 |
+
('a = #\\\n'), # Inline comment.
|
| 347 |
+
)
|
| 348 |
+
for string in errors:
|
| 349 |
+
with self.subTest(string=string):
|
| 350 |
+
setcode(string)
|
| 351 |
+
with self.assertRaises(AssertionError):
|
| 352 |
+
indent()
|
| 353 |
+
|
| 354 |
+
TestInfo = namedtuple('TestInfo', ('string', 'spaces'))
|
| 355 |
+
tests = (TestInfo('a = (1 + 2) - 5 *\\\n', 4),
|
| 356 |
+
TestInfo('a = 1 + 2 - 5 *\\\n', 4),
|
| 357 |
+
TestInfo(' a = 1 + 2 - 5 *\\\n', 8),
|
| 358 |
+
TestInfo(' a = "spam"\\\n', 6),
|
| 359 |
+
TestInfo(' a = \\\n"a"\\\n', 4),
|
| 360 |
+
TestInfo(' a = #\\\n"a"\\\n', 5),
|
| 361 |
+
TestInfo('a == \\\n', 2),
|
| 362 |
+
TestInfo('a != \\\n', 2),
|
| 363 |
+
# Difference between containing = and those not.
|
| 364 |
+
TestInfo('\\\n', 2),
|
| 365 |
+
TestInfo(' \\\n', 6),
|
| 366 |
+
TestInfo('\t\\\n', 6),
|
| 367 |
+
TestInfo('a\\\n', 3),
|
| 368 |
+
TestInfo('{}\\\n', 4),
|
| 369 |
+
TestInfo('(1 + 2) - 5 *\\\n', 3),
|
| 370 |
+
)
|
| 371 |
+
for test in tests:
|
| 372 |
+
with self.subTest(string=test.string):
|
| 373 |
+
setcode(test.string)
|
| 374 |
+
eq(indent(), test.spaces)
|
| 375 |
+
|
| 376 |
+
def test_get_base_indent_string(self):
|
| 377 |
+
eq = self.assertEqual
|
| 378 |
+
p = self.parser
|
| 379 |
+
setcode = p.set_code
|
| 380 |
+
baseindent = p.get_base_indent_string
|
| 381 |
+
|
| 382 |
+
TestInfo = namedtuple('TestInfo', ['string', 'indent'])
|
| 383 |
+
tests = (TestInfo('', ''),
|
| 384 |
+
TestInfo('def a():\n', ''),
|
| 385 |
+
TestInfo('\tdef a():\n', '\t'),
|
| 386 |
+
TestInfo(' def a():\n', ' '),
|
| 387 |
+
TestInfo(' def a(\n', ' '),
|
| 388 |
+
TestInfo('\t\n def a(\n', ' '),
|
| 389 |
+
TestInfo('\t\n # Comment.\n', ' '),
|
| 390 |
+
)
|
| 391 |
+
|
| 392 |
+
for test in tests:
|
| 393 |
+
with self.subTest(string=test.string):
|
| 394 |
+
setcode(test.string)
|
| 395 |
+
eq(baseindent(), test.indent)
|
| 396 |
+
|
| 397 |
+
def test_is_block_opener(self):
|
| 398 |
+
yes = self.assertTrue
|
| 399 |
+
no = self.assertFalse
|
| 400 |
+
p = self.parser
|
| 401 |
+
setcode = p.set_code
|
| 402 |
+
opener = p.is_block_opener
|
| 403 |
+
|
| 404 |
+
TestInfo = namedtuple('TestInfo', ['string', 'assert_'])
|
| 405 |
+
tests = (
|
| 406 |
+
TestInfo('def a():\n', yes),
|
| 407 |
+
TestInfo('\n def function1(self, a,\n b):\n', yes),
|
| 408 |
+
TestInfo(':\n', yes),
|
| 409 |
+
TestInfo('a:\n', yes),
|
| 410 |
+
TestInfo('):\n', yes),
|
| 411 |
+
TestInfo('(:\n', yes),
|
| 412 |
+
TestInfo('":\n', no),
|
| 413 |
+
TestInfo('\n def function1(self, a,\n', no),
|
| 414 |
+
TestInfo('def function1(self, a):\n pass\n', no),
|
| 415 |
+
TestInfo('# A comment:\n', no),
|
| 416 |
+
TestInfo('"""A docstring:\n', no),
|
| 417 |
+
TestInfo('"""A docstring:\n', no),
|
| 418 |
+
)
|
| 419 |
+
|
| 420 |
+
for test in tests:
|
| 421 |
+
with self.subTest(string=test.string):
|
| 422 |
+
setcode(test.string)
|
| 423 |
+
test.assert_(opener())
|
| 424 |
+
|
| 425 |
+
def test_is_block_closer(self):
|
| 426 |
+
yes = self.assertTrue
|
| 427 |
+
no = self.assertFalse
|
| 428 |
+
p = self.parser
|
| 429 |
+
setcode = p.set_code
|
| 430 |
+
closer = p.is_block_closer
|
| 431 |
+
|
| 432 |
+
TestInfo = namedtuple('TestInfo', ['string', 'assert_'])
|
| 433 |
+
tests = (
|
| 434 |
+
TestInfo('return\n', yes),
|
| 435 |
+
TestInfo('\tbreak\n', yes),
|
| 436 |
+
TestInfo(' continue\n', yes),
|
| 437 |
+
TestInfo(' raise\n', yes),
|
| 438 |
+
TestInfo('pass \n', yes),
|
| 439 |
+
TestInfo('pass\t\n', yes),
|
| 440 |
+
TestInfo('return #\n', yes),
|
| 441 |
+
TestInfo('raised\n', no),
|
| 442 |
+
TestInfo('returning\n', no),
|
| 443 |
+
TestInfo('# return\n', no),
|
| 444 |
+
TestInfo('"""break\n', no),
|
| 445 |
+
TestInfo('"continue\n', no),
|
| 446 |
+
TestInfo('def function1(self, a):\n pass\n', yes),
|
| 447 |
+
)
|
| 448 |
+
|
| 449 |
+
for test in tests:
|
| 450 |
+
with self.subTest(string=test.string):
|
| 451 |
+
setcode(test.string)
|
| 452 |
+
test.assert_(closer())
|
| 453 |
+
|
| 454 |
+
def test_get_last_stmt_bracketing(self):
|
| 455 |
+
eq = self.assertEqual
|
| 456 |
+
p = self.parser
|
| 457 |
+
setcode = p.set_code
|
| 458 |
+
bracketing = p.get_last_stmt_bracketing
|
| 459 |
+
|
| 460 |
+
TestInfo = namedtuple('TestInfo', ['string', 'bracket'])
|
| 461 |
+
tests = (
|
| 462 |
+
TestInfo('', ((0, 0),)),
|
| 463 |
+
TestInfo('a\n', ((0, 0),)),
|
| 464 |
+
TestInfo('()()\n', ((0, 0), (0, 1), (2, 0), (2, 1), (4, 0))),
|
| 465 |
+
TestInfo('(\n)()\n', ((0, 0), (0, 1), (3, 0), (3, 1), (5, 0))),
|
| 466 |
+
TestInfo('()\n()\n', ((3, 0), (3, 1), (5, 0))),
|
| 467 |
+
TestInfo('()(\n)\n', ((0, 0), (0, 1), (2, 0), (2, 1), (5, 0))),
|
| 468 |
+
TestInfo('(())\n', ((0, 0), (0, 1), (1, 2), (3, 1), (4, 0))),
|
| 469 |
+
TestInfo('(\n())\n', ((0, 0), (0, 1), (2, 2), (4, 1), (5, 0))),
|
| 470 |
+
# Same as matched test.
|
| 471 |
+
TestInfo('{)(]\n', ((0, 0), (0, 1), (2, 0), (2, 1), (4, 0))),
|
| 472 |
+
TestInfo('(((())\n',
|
| 473 |
+
((0, 0), (0, 1), (1, 2), (2, 3), (3, 4), (5, 3), (6, 2))),
|
| 474 |
+
)
|
| 475 |
+
|
| 476 |
+
for test in tests:
|
| 477 |
+
with self.subTest(string=test.string):
|
| 478 |
+
setcode(test.string)
|
| 479 |
+
eq(bracketing(), test.bracket)
|
| 480 |
+
|
| 481 |
+
|
| 482 |
+
if __name__ == '__main__':
|
| 483 |
+
unittest.main(verbos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.
|
| 3 |
+
|
| 4 |
+
from idlelib import pyshell
|
| 5 |
+
import unittest
|
| 6 |
+
from test.support import requires
|
| 7 |
+
from tkinter import Tk
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class FunctionTest(unittest.TestCase):
|
| 11 |
+
# Test stand-alone module level non-gui functions.
|
| 12 |
+
|
| 13 |
+
def test_restart_line_wide(self):
|
| 14 |
+
eq = self.assertEqual
|
| 15 |
+
for file, mul, extra in (('', 22, ''), ('finame', 21, '=')):
|
| 16 |
+
width = 60
|
| 17 |
+
bar = mul * '='
|
| 18 |
+
with self.subTest(file=file, bar=bar):
|
| 19 |
+
file = file or 'Shell'
|
| 20 |
+
line = pyshell.restart_line(width, file)
|
| 21 |
+
eq(len(line), width)
|
| 22 |
+
eq(line, f"{bar+extra} RESTART: {file} {bar}")
|
| 23 |
+
|
| 24 |
+
def test_restart_line_narrow(self):
|
| 25 |
+
expect, taglen = "= RESTART: Shell", 16
|
| 26 |
+
for width in (taglen-1, taglen, taglen+1):
|
| 27 |
+
with self.subTest(width=width):
|
| 28 |
+
self.assertEqual(pyshell.restart_line(width, ''), expect)
|
| 29 |
+
self.assertEqual(pyshell.restart_line(taglen+2, ''), expect+' =')
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
class PyShellFileListTest(unittest.TestCase):
|
| 33 |
+
|
| 34 |
+
@classmethod
|
| 35 |
+
def setUpClass(cls):
|
| 36 |
+
requires('gui')
|
| 37 |
+
cls.root = Tk()
|
| 38 |
+
cls.root.withdraw()
|
| 39 |
+
|
| 40 |
+
@classmethod
|
| 41 |
+
def tearDownClass(cls):
|
| 42 |
+
#cls.root.update_idletasks()
|
| 43 |
+
## for id in cls.root.tk.call('after', 'info'):
|
| 44 |
+
## cls.root.after_cancel(id) # Need for EditorWindow.
|
| 45 |
+
cls.root.destroy()
|
| 46 |
+
del cls.root
|
| 47 |
+
|
| 48 |
+
def test_init(self):
|
| 49 |
+
psfl = pyshell.PyShellFileList(self.root)
|
| 50 |
+
self.assertEqual(psfl.EditorWindow, pyshell.PyShellEditorWindow)
|
| 51 |
+
self.assertIsNone(psfl.pyshell)
|
| 52 |
+
|
| 53 |
+
# The following sometimes causes 'invalid command name "109734456recolorize"'.
|
| 54 |
+
# Uncommenting after_cancel above prevents this, but results in
|
| 55 |
+
# TclError: bad window path name ".!listedtoplevel.!frame.text"
|
| 56 |
+
# which is normally prevented by after_cancel.
|
| 57 |
+
## def test_openshell(self):
|
| 58 |
+
## pyshell.use_subprocess = False
|
| 59 |
+
## ps = pyshell.PyShellFileList(self.root).open_shell()
|
| 60 |
+
## self.assertIsInstance(ps, pyshell.PyShell)
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
class PyShellRemoveLastNewlineAndSurroundingWhitespaceTest(unittest.TestCase):
|
| 64 |
+
regexp = pyshell.PyShell._last_newline_re
|
| 65 |
+
|
| 66 |
+
def all_removed(self, text):
|
| 67 |
+
self.assertEqual('', self.regexp.sub('', text))
|
| 68 |
+
|
| 69 |
+
def none_removed(self, text):
|
| 70 |
+
self.assertEqual(text, self.regexp.sub('', text))
|
| 71 |
+
|
| 72 |
+
def check_result(self, text, expected):
|
| 73 |
+
self.assertEqual(expected, self.regexp.sub('', text))
|
| 74 |
+
|
| 75 |
+
def test_empty(self):
|
| 76 |
+
self.all_removed('')
|
| 77 |
+
|
| 78 |
+
def test_newline(self):
|
| 79 |
+
self.all_removed('\n')
|
| 80 |
+
|
| 81 |
+
def test_whitespace_no_newline(self):
|
| 82 |
+
self.all_removed(' ')
|
| 83 |
+
self.all_removed(' ')
|
| 84 |
+
self.all_removed(' ')
|
| 85 |
+
self.all_removed(' ' * 20)
|
| 86 |
+
self.all_removed('\t')
|
| 87 |
+
self.all_removed('\t\t')
|
| 88 |
+
self.all_removed('\t\t\t')
|
| 89 |
+
self.all_removed('\t' * 20)
|
| 90 |
+
self.all_removed('\t ')
|
| 91 |
+
self.all_removed(' \t')
|
| 92 |
+
self.all_removed(' \t \t ')
|
| 93 |
+
self.all_removed('\t \t \t')
|
| 94 |
+
|
| 95 |
+
def test_newline_with_whitespace(self):
|
| 96 |
+
self.all_removed(' \n')
|
| 97 |
+
self.all_removed('\t\n')
|
| 98 |
+
self.all_removed(' \t\n')
|
| 99 |
+
self.all_removed('\t \n')
|
| 100 |
+
self.all_removed('\n ')
|
| 101 |
+
self.all_removed('\n\t')
|
| 102 |
+
self.all_removed('\n \t')
|
| 103 |
+
self.all_removed('\n\t ')
|
| 104 |
+
self.all_removed(' \n ')
|
| 105 |
+
self.all_removed('\t\n ')
|
| 106 |
+
self.all_removed(' \n\t')
|
| 107 |
+
self.all_removed('\t\n\t')
|
| 108 |
+
self.all_removed('\t \t \t\n')
|
| 109 |
+
self.all_removed(' \t \t \n')
|
| 110 |
+
self.all_removed('\n\t \t \t')
|
| 111 |
+
self.all_removed('\n \t \t ')
|
| 112 |
+
|
| 113 |
+
def test_multiple_newlines(self):
|
| 114 |
+
self.check_result('\n\n', '\n')
|
| 115 |
+
self.check_result('\n' * 5, '\n' * 4)
|
| 116 |
+
self.check_result('\n' * 5 + '\t', '\n' * 4)
|
| 117 |
+
self.check_result('\n' * 20, '\n' * 19)
|
| 118 |
+
self.check_result('\n' * 20 + ' ', '\n' * 19)
|
| 119 |
+
self.check_result(' \n \n ', ' \n')
|
| 120 |
+
self.check_result(' \n\n ', ' \n')
|
| 121 |
+
self.check_result(' \n\n', ' \n')
|
| 122 |
+
self.check_result('\t\n\n', '\t\n')
|
| 123 |
+
self.check_result('\n\n ', '\n')
|
| 124 |
+
self.check_result('\n\n\t', '\n')
|
| 125 |
+
self.check_result(' \n \n ', ' \n')
|
| 126 |
+
self.check_result('\t\n\t\n\t', '\t\n')
|
| 127 |
+
|
| 128 |
+
def test_non_whitespace(self):
|
| 129 |
+
self.none_removed('a')
|
| 130 |
+
self.check_result('a\n', 'a')
|
| 131 |
+
self.check_result('a\n ', 'a')
|
| 132 |
+
self.check_result('a \n ', 'a')
|
| 133 |
+
self.check_result('a \n\t', 'a')
|
| 134 |
+
self.none_removed('-')
|
| 135 |
+
self.check_result('-\n', '-')
|
| 136 |
+
self.none_removed('.')
|
| 137 |
+
self.check_result('.\n', '.')
|
| 138 |
+
|
| 139 |
+
def test_unsupported_whitespace(self):
|
| 140 |
+
self.none_removed('\v')
|
| 141 |
+
self.none_removed('\n\v')
|
| 142 |
+
self.check_result('\v\n', '\v')
|
| 143 |
+
self.none_removed(' \n\v')
|
| 144 |
+
self.check_result('\v\n ', '\v')
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
if __name__ == '__main__':
|
| 148 |
+
unittest.main(verbosity=2)
|
micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_query.py
ADDED
|
@@ -0,0 +1,451 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
| 1 |
+
"""Test query, coverage 93%.
|
| 2 |
+
|
| 3 |
+
Non-gui tests for Query, SectionName, ModuleName, and HelpSource use
|
| 4 |
+
dummy versions that extract the non-gui methods and add other needed
|
| 5 |
+
attributes. GUI tests create an instance of each class and simulate
|
| 6 |
+
entries and button clicks. Subclass tests only target the new code in
|
| 7 |
+
the subclass definition.
|
| 8 |
+
|
| 9 |
+
The appearance of the widgets is checked by the Query and
|
| 10 |
+
HelpSource htests. These are run by running query.py.
|
| 11 |
+
"""
|
| 12 |
+
from idlelib import query
|
| 13 |
+
import unittest
|
| 14 |
+
from test.support import requires
|
| 15 |
+
from tkinter import Tk, END
|
| 16 |
+
|
| 17 |
+
import sys
|
| 18 |
+
from unittest import mock
|
| 19 |
+
from idlelib.idle_test.mock_tk import Var
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
# NON-GUI TESTS
|
| 23 |
+
|
| 24 |
+
class QueryTest(unittest.TestCase):
|
| 25 |
+
"Test Query base class."
|
| 26 |
+
|
| 27 |
+
class Dummy_Query:
|
| 28 |
+
# Test the following Query methods.
|
| 29 |
+
entry_ok = query.Query.entry_ok
|
| 30 |
+
ok = query.Query.ok
|
| 31 |
+
cancel = query.Query.cancel
|
| 32 |
+
# Add attributes and initialization needed for tests.
|
| 33 |
+
def __init__(self, dummy_entry):
|
| 34 |
+
self.entry = Var(value=dummy_entry)
|
| 35 |
+
self.entry_error = {'text': ''}
|
| 36 |
+
self.result = None
|
| 37 |
+
self.destroyed = False
|
| 38 |
+
def showerror(self, message):
|
| 39 |
+
self.entry_error['text'] = message
|
| 40 |
+
def destroy(self):
|
| 41 |
+
self.destroyed = True
|
| 42 |
+
|
| 43 |
+
def test_entry_ok_blank(self):
|
| 44 |
+
dialog = self.Dummy_Query(' ')
|
| 45 |
+
self.assertEqual(dialog.entry_ok(), None)
|
| 46 |
+
self.assertEqual((dialog.result, dialog.destroyed), (None, False))
|
| 47 |
+
self.assertIn('blank line', dialog.entry_error['text'])
|
| 48 |
+
|
| 49 |
+
def test_entry_ok_good(self):
|
| 50 |
+
dialog = self.Dummy_Query(' good ')
|
| 51 |
+
Equal = self.assertEqual
|
| 52 |
+
Equal(dialog.entry_ok(), 'good')
|
| 53 |
+
Equal((dialog.result, dialog.destroyed), (None, False))
|
| 54 |
+
Equal(dialog.entry_error['text'], '')
|
| 55 |
+
|
| 56 |
+
def test_ok_blank(self):
|
| 57 |
+
dialog = self.Dummy_Query('')
|
| 58 |
+
dialog.entry.focus_set = mock.Mock()
|
| 59 |
+
self.assertEqual(dialog.ok(), None)
|
| 60 |
+
self.assertTrue(dialog.entry.focus_set.called)
|
| 61 |
+
del dialog.entry.focus_set
|
| 62 |
+
self.assertEqual((dialog.result, dialog.destroyed), (None, False))
|
| 63 |
+
|
| 64 |
+
def test_ok_good(self):
|
| 65 |
+
dialog = self.Dummy_Query('good')
|
| 66 |
+
self.assertEqual(dialog.ok(), None)
|
| 67 |
+
self.assertEqual((dialog.result, dialog.destroyed), ('good', True))
|
| 68 |
+
|
| 69 |
+
def test_cancel(self):
|
| 70 |
+
dialog = self.Dummy_Query('does not matter')
|
| 71 |
+
self.assertEqual(dialog.cancel(), None)
|
| 72 |
+
self.assertEqual((dialog.result, dialog.destroyed), (None, True))
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
class SectionNameTest(unittest.TestCase):
|
| 76 |
+
"Test SectionName subclass of Query."
|
| 77 |
+
|
| 78 |
+
class Dummy_SectionName:
|
| 79 |
+
entry_ok = query.SectionName.entry_ok # Function being tested.
|
| 80 |
+
used_names = ['used']
|
| 81 |
+
def __init__(self, dummy_entry):
|
| 82 |
+
self.entry = Var(value=dummy_entry)
|
| 83 |
+
self.entry_error = {'text': ''}
|
| 84 |
+
def showerror(self, message):
|
| 85 |
+
self.entry_error['text'] = message
|
| 86 |
+
|
| 87 |
+
def test_blank_section_name(self):
|
| 88 |
+
dialog = self.Dummy_SectionName(' ')
|
| 89 |
+
self.assertEqual(dialog.entry_ok(), None)
|
| 90 |
+
self.assertIn('no name', dialog.entry_error['text'])
|
| 91 |
+
|
| 92 |
+
def test_used_section_name(self):
|
| 93 |
+
dialog = self.Dummy_SectionName('used')
|
| 94 |
+
self.assertEqual(dialog.entry_ok(), None)
|
| 95 |
+
self.assertIn('use', dialog.entry_error['text'])
|
| 96 |
+
|
| 97 |
+
def test_long_section_name(self):
|
| 98 |
+
dialog = self.Dummy_SectionName('good'*8)
|
| 99 |
+
self.assertEqual(dialog.entry_ok(), None)
|
| 100 |
+
self.assertIn('longer than 30', dialog.entry_error['text'])
|
| 101 |
+
|
| 102 |
+
def test_good_section_name(self):
|
| 103 |
+
dialog = self.Dummy_SectionName(' good ')
|
| 104 |
+
self.assertEqual(dialog.entry_ok(), 'good')
|
| 105 |
+
self.assertEqual(dialog.entry_error['text'], '')
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
class ModuleNameTest(unittest.TestCase):
|
| 109 |
+
"Test ModuleName subclass of Query."
|
| 110 |
+
|
| 111 |
+
class Dummy_ModuleName:
|
| 112 |
+
entry_ok = query.ModuleName.entry_ok # Function being tested.
|
| 113 |
+
text0 = ''
|
| 114 |
+
def __init__(self, dummy_entry):
|
| 115 |
+
self.entry = Var(value=dummy_entry)
|
| 116 |
+
self.entry_error = {'text': ''}
|
| 117 |
+
def showerror(self, message):
|
| 118 |
+
self.entry_error['text'] = message
|
| 119 |
+
|
| 120 |
+
def test_blank_module_name(self):
|
| 121 |
+
dialog = self.Dummy_ModuleName(' ')
|
| 122 |
+
self.assertEqual(dialog.entry_ok(), None)
|
| 123 |
+
self.assertIn('no name', dialog.entry_error['text'])
|
| 124 |
+
|
| 125 |
+
def test_bogus_module_name(self):
|
| 126 |
+
dialog = self.Dummy_ModuleName('__name_xyz123_should_not_exist__')
|
| 127 |
+
self.assertEqual(dialog.entry_ok(), None)
|
| 128 |
+
self.assertIn('not found', dialog.entry_error['text'])
|
| 129 |
+
|
| 130 |
+
def test_c_source_name(self):
|
| 131 |
+
dialog = self.Dummy_ModuleName('itertools')
|
| 132 |
+
self.assertEqual(dialog.entry_ok(), None)
|
| 133 |
+
self.assertIn('source-based', dialog.entry_error['text'])
|
| 134 |
+
|
| 135 |
+
def test_good_module_name(self):
|
| 136 |
+
dialog = self.Dummy_ModuleName('idlelib')
|
| 137 |
+
self.assertTrue(dialog.entry_ok().endswith('__init__.py'))
|
| 138 |
+
self.assertEqual(dialog.entry_error['text'], '')
|
| 139 |
+
dialog = self.Dummy_ModuleName('idlelib.idle')
|
| 140 |
+
self.assertTrue(dialog.entry_ok().endswith('idle.py'))
|
| 141 |
+
self.assertEqual(dialog.entry_error['text'], '')
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
class GotoTest(unittest.TestCase):
|
| 145 |
+
"Test Goto subclass of Query."
|
| 146 |
+
|
| 147 |
+
class Dummy_ModuleName:
|
| 148 |
+
entry_ok = query.Goto.entry_ok # Function being tested.
|
| 149 |
+
def __init__(self, dummy_entry):
|
| 150 |
+
self.entry = Var(value=dummy_entry)
|
| 151 |
+
self.entry_error = {'text': ''}
|
| 152 |
+
def showerror(self, message):
|
| 153 |
+
self.entry_error['text'] = message
|
| 154 |
+
|
| 155 |
+
def test_bogus_goto(self):
|
| 156 |
+
dialog = self.Dummy_ModuleName('a')
|
| 157 |
+
self.assertEqual(dialog.entry_ok(), None)
|
| 158 |
+
self.assertIn('not a base 10 integer', dialog.entry_error['text'])
|
| 159 |
+
|
| 160 |
+
def test_bad_goto(self):
|
| 161 |
+
dialog = self.Dummy_ModuleName('0')
|
| 162 |
+
self.assertEqual(dialog.entry_ok(), None)
|
| 163 |
+
self.assertIn('not a positive integer', dialog.entry_error['text'])
|
| 164 |
+
|
| 165 |
+
def test_good_goto(self):
|
| 166 |
+
dialog = self.Dummy_ModuleName('1')
|
| 167 |
+
self.assertEqual(dialog.entry_ok(), 1)
|
| 168 |
+
self.assertEqual(dialog.entry_error['text'], '')
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
# 3 HelpSource test classes each test one method.
|
| 172 |
+
|
| 173 |
+
class HelpsourceBrowsefileTest(unittest.TestCase):
|
| 174 |
+
"Test browse_file method of ModuleName subclass of Query."
|
| 175 |
+
|
| 176 |
+
class Dummy_HelpSource:
|
| 177 |
+
browse_file = query.HelpSource.browse_file
|
| 178 |
+
pathvar = Var()
|
| 179 |
+
|
| 180 |
+
def test_file_replaces_path(self):
|
| 181 |
+
dialog = self.Dummy_HelpSource()
|
| 182 |
+
# Path is widget entry, either '' or something.
|
| 183 |
+
# Func return is file dialog return, either '' or something.
|
| 184 |
+
# Func return should override widget entry.
|
| 185 |
+
# We need all 4 combinations to test all (most) code paths.
|
| 186 |
+
for path, func, result in (
|
| 187 |
+
('', lambda a,b,c:'', ''),
|
| 188 |
+
('', lambda a,b,c: __file__, __file__),
|
| 189 |
+
('htest', lambda a,b,c:'', 'htest'),
|
| 190 |
+
('htest', lambda a,b,c: __file__, __file__)):
|
| 191 |
+
with self.subTest():
|
| 192 |
+
dialog.pathvar.set(path)
|
| 193 |
+
dialog.askfilename = func
|
| 194 |
+
dialog.browse_file()
|
| 195 |
+
self.assertEqual(dialog.pathvar.get(), result)
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
class HelpsourcePathokTest(unittest.TestCase):
|
| 199 |
+
"Test path_ok method of HelpSource subclass of Query."
|
| 200 |
+
|
| 201 |
+
class Dummy_HelpSource:
|
| 202 |
+
path_ok = query.HelpSource.path_ok
|
| 203 |
+
def __init__(self, dummy_path):
|
| 204 |
+
self.path = Var(value=dummy_path)
|
| 205 |
+
self.path_error = {'text': ''}
|
| 206 |
+
def showerror(self, message, widget=None):
|
| 207 |
+
self.path_error['text'] = message
|
| 208 |
+
|
| 209 |
+
orig_platform = query.platform # Set in test_path_ok_file.
|
| 210 |
+
@classmethod
|
| 211 |
+
def tearDownClass(cls):
|
| 212 |
+
query.platform = cls.orig_platform
|
| 213 |
+
|
| 214 |
+
def test_path_ok_blank(self):
|
| 215 |
+
dialog = self.Dummy_HelpSource(' ')
|
| 216 |
+
self.assertEqual(dialog.path_ok(), None)
|
| 217 |
+
self.assertIn('no help file', dialog.path_error['text'])
|
| 218 |
+
|
| 219 |
+
def test_path_ok_bad(self):
|
| 220 |
+
dialog = self.Dummy_HelpSource(__file__ + 'bad-bad-bad')
|
| 221 |
+
self.assertEqual(dialog.path_ok(), None)
|
| 222 |
+
self.assertIn('not exist', dialog.path_error['text'])
|
| 223 |
+
|
| 224 |
+
def test_path_ok_web(self):
|
| 225 |
+
dialog = self.Dummy_HelpSource('')
|
| 226 |
+
Equal = self.assertEqual
|
| 227 |
+
for url in 'www.py.org', 'http://py.org':
|
| 228 |
+
with self.subTest():
|
| 229 |
+
dialog.path.set(url)
|
| 230 |
+
self.assertEqual(dialog.path_ok(), url)
|
| 231 |
+
self.assertEqual(dialog.path_error['text'], '')
|
| 232 |
+
|
| 233 |
+
def test_path_ok_file(self):
|
| 234 |
+
dialog = self.Dummy_HelpSource('')
|
| 235 |
+
for platform, prefix in ('darwin', 'file://'), ('other', ''):
|
| 236 |
+
with self.subTest():
|
| 237 |
+
query.platform = platform
|
| 238 |
+
dialog.path.set(__file__)
|
| 239 |
+
self.assertEqual(dialog.path_ok(), prefix + __file__)
|
| 240 |
+
self.assertEqual(dialog.path_error['text'], '')
|
| 241 |
+
|
| 242 |
+
|
| 243 |
+
class HelpsourceEntryokTest(unittest.TestCase):
|
| 244 |
+
"Test entry_ok method of HelpSource subclass of Query."
|
| 245 |
+
|
| 246 |
+
class Dummy_HelpSource:
|
| 247 |
+
entry_ok = query.HelpSource.entry_ok
|
| 248 |
+
entry_error = {}
|
| 249 |
+
path_error = {}
|
| 250 |
+
def item_ok(self):
|
| 251 |
+
return self.name
|
| 252 |
+
def path_ok(self):
|
| 253 |
+
return self.path
|
| 254 |
+
|
| 255 |
+
def test_entry_ok_helpsource(self):
|
| 256 |
+
dialog = self.Dummy_HelpSource()
|
| 257 |
+
for name, path, result in ((None, None, None),
|
| 258 |
+
(None, 'doc.txt', None),
|
| 259 |
+
('doc', None, None),
|
| 260 |
+
('doc', 'doc.txt', ('doc', 'doc.txt'))):
|
| 261 |
+
with self.subTest():
|
| 262 |
+
dialog.name, dialog.path = name, path
|
| 263 |
+
self.assertEqual(dialog.entry_ok(), result)
|
| 264 |
+
|
| 265 |
+
|
| 266 |
+
# 2 CustomRun test classes each test one method.
|
| 267 |
+
|
| 268 |
+
class CustomRunCLIargsokTest(unittest.TestCase):
|
| 269 |
+
"Test cli_ok method of the CustomRun subclass of Query."
|
| 270 |
+
|
| 271 |
+
class Dummy_CustomRun:
|
| 272 |
+
cli_args_ok = query.CustomRun.cli_args_ok
|
| 273 |
+
def __init__(self, dummy_entry):
|
| 274 |
+
self.entry = Var(value=dummy_entry)
|
| 275 |
+
self.entry_error = {'text': ''}
|
| 276 |
+
def showerror(self, message):
|
| 277 |
+
self.entry_error['text'] = message
|
| 278 |
+
|
| 279 |
+
def test_blank_args(self):
|
| 280 |
+
dialog = self.Dummy_CustomRun(' ')
|
| 281 |
+
self.assertEqual(dialog.cli_args_ok(), [])
|
| 282 |
+
|
| 283 |
+
def test_invalid_args(self):
|
| 284 |
+
dialog = self.Dummy_CustomRun("'no-closing-quote")
|
| 285 |
+
self.assertEqual(dialog.cli_args_ok(), None)
|
| 286 |
+
self.assertIn('No closing', dialog.entry_error['text'])
|
| 287 |
+
|
| 288 |
+
def test_good_args(self):
|
| 289 |
+
args = ['-n', '10', '--verbose', '-p', '/path', '--name']
|
| 290 |
+
dialog = self.Dummy_CustomRun(' '.join(args) + ' "my name"')
|
| 291 |
+
self.assertEqual(dialog.cli_args_ok(), args + ["my name"])
|
| 292 |
+
self.assertEqual(dialog.entry_error['text'], '')
|
| 293 |
+
|
| 294 |
+
|
| 295 |
+
class CustomRunEntryokTest(unittest.TestCase):
|
| 296 |
+
"Test entry_ok method of the CustomRun subclass of Query."
|
| 297 |
+
|
| 298 |
+
class Dummy_CustomRun:
|
| 299 |
+
entry_ok = query.CustomRun.entry_ok
|
| 300 |
+
entry_error = {}
|
| 301 |
+
restartvar = Var()
|
| 302 |
+
def cli_args_ok(self):
|
| 303 |
+
return self.cli_args
|
| 304 |
+
|
| 305 |
+
def test_entry_ok_customrun(self):
|
| 306 |
+
dialog = self.Dummy_CustomRun()
|
| 307 |
+
for restart in {True, False}:
|
| 308 |
+
dialog.restartvar.set(restart)
|
| 309 |
+
for cli_args, result in ((None, None),
|
| 310 |
+
(['my arg'], (['my arg'], restart))):
|
| 311 |
+
with self.subTest(restart=restart, cli_args=cli_args):
|
| 312 |
+
dialog.cli_args = cli_args
|
| 313 |
+
self.assertEqual(dialog.entry_ok(), result)
|
| 314 |
+
|
| 315 |
+
|
| 316 |
+
# GUI TESTS
|
| 317 |
+
|
| 318 |
+
class QueryGuiTest(unittest.TestCase):
|
| 319 |
+
|
| 320 |
+
@classmethod
|
| 321 |
+
def setUpClass(cls):
|
| 322 |
+
requires('gui')
|
| 323 |
+
cls.root = root = Tk()
|
| 324 |
+
cls.root.withdraw()
|
| 325 |
+
cls.dialog = query.Query(root, 'TEST', 'test', _utest=True)
|
| 326 |
+
cls.dialog.destroy = mock.Mock()
|
| 327 |
+
|
| 328 |
+
@classmethod
|
| 329 |
+
def tearDownClass(cls):
|
| 330 |
+
del cls.dialog.destroy
|
| 331 |
+
del cls.dialog
|
| 332 |
+
cls.root.destroy()
|
| 333 |
+
del cls.root
|
| 334 |
+
|
| 335 |
+
def setUp(self):
|
| 336 |
+
self.dialog.entry.delete(0, 'end')
|
| 337 |
+
self.dialog.result = None
|
| 338 |
+
self.dialog.destroy.reset_mock()
|
| 339 |
+
|
| 340 |
+
def test_click_ok(self):
|
| 341 |
+
dialog = self.dialog
|
| 342 |
+
dialog.entry.insert(0, 'abc')
|
| 343 |
+
dialog.button_ok.invoke()
|
| 344 |
+
self.assertEqual(dialog.result, 'abc')
|
| 345 |
+
self.assertTrue(dialog.destroy.called)
|
| 346 |
+
|
| 347 |
+
def test_click_blank(self):
|
| 348 |
+
dialog = self.dialog
|
| 349 |
+
dialog.button_ok.invoke()
|
| 350 |
+
self.assertEqual(dialog.result, None)
|
| 351 |
+
self.assertFalse(dialog.destroy.called)
|
| 352 |
+
|
| 353 |
+
def test_click_cancel(self):
|
| 354 |
+
dialog = self.dialog
|
| 355 |
+
dialog.entry.insert(0, 'abc')
|
| 356 |
+
dialog.button_cancel.invoke()
|
| 357 |
+
self.assertEqual(dialog.result, None)
|
| 358 |
+
self.assertTrue(dialog.destroy.called)
|
| 359 |
+
|
| 360 |
+
|
| 361 |
+
class SectionnameGuiTest(unittest.TestCase):
|
| 362 |
+
|
| 363 |
+
@classmethod
|
| 364 |
+
def setUpClass(cls):
|
| 365 |
+
requires('gui')
|
| 366 |
+
|
| 367 |
+
def test_click_section_name(self):
|
| 368 |
+
root = Tk()
|
| 369 |
+
root.withdraw()
|
| 370 |
+
dialog = query.SectionName(root, 'T', 't', {'abc'}, _utest=True)
|
| 371 |
+
Equal = self.assertEqual
|
| 372 |
+
self.assertEqual(dialog.used_names, {'abc'})
|
| 373 |
+
dialog.entry.insert(0, 'okay')
|
| 374 |
+
dialog.button_ok.invoke()
|
| 375 |
+
self.assertEqual(dialog.result, 'okay')
|
| 376 |
+
root.destroy()
|
| 377 |
+
|
| 378 |
+
|
| 379 |
+
class ModulenameGuiTest(unittest.TestCase):
|
| 380 |
+
|
| 381 |
+
@classmethod
|
| 382 |
+
def setUpClass(cls):
|
| 383 |
+
requires('gui')
|
| 384 |
+
|
| 385 |
+
def test_click_module_name(self):
|
| 386 |
+
root = Tk()
|
| 387 |
+
root.withdraw()
|
| 388 |
+
dialog = query.ModuleName(root, 'T', 't', 'idlelib', _utest=True)
|
| 389 |
+
self.assertEqual(dialog.text0, 'idlelib')
|
| 390 |
+
self.assertEqual(dialog.entry.get(), 'idlelib')
|
| 391 |
+
dialog.button_ok.invoke()
|
| 392 |
+
self.assertTrue(dialog.result.endswith('__init__.py'))
|
| 393 |
+
root.destroy()
|
| 394 |
+
|
| 395 |
+
|
| 396 |
+
class GotoGuiTest(unittest.TestCase):
|
| 397 |
+
|
| 398 |
+
@classmethod
|
| 399 |
+
def setUpClass(cls):
|
| 400 |
+
requires('gui')
|
| 401 |
+
|
| 402 |
+
def test_click_module_name(self):
|
| 403 |
+
root = Tk()
|
| 404 |
+
root.withdraw()
|
| 405 |
+
dialog = query.Goto(root, 'T', 't', _utest=True)
|
| 406 |
+
dialog.entry.insert(0, '22')
|
| 407 |
+
dialog.button_ok.invoke()
|
| 408 |
+
self.assertEqual(dialog.result, 22)
|
| 409 |
+
root.destroy()
|
| 410 |
+
|
| 411 |
+
|
| 412 |
+
class HelpsourceGuiTest(unittest.TestCase):
|
| 413 |
+
|
| 414 |
+
@classmethod
|
| 415 |
+
def setUpClass(cls):
|
| 416 |
+
requires('gui')
|
| 417 |
+
|
| 418 |
+
def test_click_help_source(self):
|
| 419 |
+
root = Tk()
|
| 420 |
+
root.withdraw()
|
| 421 |
+
dialog = query.HelpSource(root, 'T', menuitem='__test__',
|
| 422 |
+
filepath=__file__, _utest=True)
|
| 423 |
+
Equal = self.assertEqual
|
| 424 |
+
Equal(dialog.entry.get(), '__test__')
|
| 425 |
+
Equal(dialog.path.get(), __file__)
|
| 426 |
+
dialog.button_ok.invoke()
|
| 427 |
+
prefix = "file://" if sys.platform == 'darwin' else ''
|
| 428 |
+
Equal(dialog.result, ('__test__', prefix + __file__))
|
| 429 |
+
root.destroy()
|
| 430 |
+
|
| 431 |
+
|
| 432 |
+
class CustomRunGuiTest(unittest.TestCase):
|
| 433 |
+
|
| 434 |
+
@classmethod
|
| 435 |
+
def setUpClass(cls):
|
| 436 |
+
requires('gui')
|
| 437 |
+
|
| 438 |
+
def test_click_args(self):
|
| 439 |
+
root = Tk()
|
| 440 |
+
root.withdraw()
|
| 441 |
+
dialog = query.CustomRun(root, 'Title',
|
| 442 |
+
cli_args=['a', 'b=1'], _utest=True)
|
| 443 |
+
self.assertEqual(dialog.entry.get(), 'a b=1')
|
| 444 |
+
dialog.entry.insert(END, ' c')
|
| 445 |
+
dialog.button_ok.invoke()
|
| 446 |
+
self.assertEqual(dialog.result, (['a', 'b=1', 'c'], True))
|
| 447 |
+
root.destroy()
|
| 448 |
+
|
| 449 |
+
|
| 450 |
+
if __name__ == '__main__':
|
| 451 |
+
unittest.main(verbosity=2, exit=False)
|
micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_redirector.py
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"Test redirector, coverage 100%."
|
| 2 |
+
|
| 3 |
+
from idlelib.redirector import WidgetRedirector
|
| 4 |
+
import unittest
|
| 5 |
+
from test.support import requires
|
| 6 |
+
from tkinter import Tk, Text, TclError
|
| 7 |
+
from idlelib.idle_test.mock_idle import Func
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class InitCloseTest(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 |
+
|
| 19 |
+
@classmethod
|
| 20 |
+
def tearDownClass(cls):
|
| 21 |
+
del cls.text
|
| 22 |
+
cls.root.destroy()
|
| 23 |
+
del cls.root
|
| 24 |
+
|
| 25 |
+
def test_init(self):
|
| 26 |
+
redir = WidgetRedirector(self.text)
|
| 27 |
+
self.assertEqual(redir.widget, self.text)
|
| 28 |
+
self.assertEqual(redir.tk, self.text.tk)
|
| 29 |
+
self.assertRaises(TclError, WidgetRedirector, self.text)
|
| 30 |
+
redir.close() # restore self.tk, self.text
|
| 31 |
+
|
| 32 |
+
def test_close(self):
|
| 33 |
+
redir = WidgetRedirector(self.text)
|
| 34 |
+
redir.register('insert', Func)
|
| 35 |
+
redir.close()
|
| 36 |
+
self.assertEqual(redir._operations, {})
|
| 37 |
+
self.assertFalse(hasattr(self.text, 'widget'))
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
class WidgetRedirectorTest(unittest.TestCase):
|
| 41 |
+
|
| 42 |
+
@classmethod
|
| 43 |
+
def setUpClass(cls):
|
| 44 |
+
requires('gui')
|
| 45 |
+
cls.root = Tk()
|
| 46 |
+
cls.root.withdraw()
|
| 47 |
+
cls.text = Text(cls.root)
|
| 48 |
+
|
| 49 |
+
@classmethod
|
| 50 |
+
def tearDownClass(cls):
|
| 51 |
+
del cls.text
|
| 52 |
+
cls.root.update_idletasks()
|
| 53 |
+
cls.root.destroy()
|
| 54 |
+
del cls.root
|
| 55 |
+
|
| 56 |
+
def setUp(self):
|
| 57 |
+
self.redir = WidgetRedirector(self.text)
|
| 58 |
+
self.func = Func()
|
| 59 |
+
self.orig_insert = self.redir.register('insert', self.func)
|
| 60 |
+
self.text.insert('insert', 'asdf') # leaves self.text empty
|
| 61 |
+
|
| 62 |
+
def tearDown(self):
|
| 63 |
+
self.text.delete('1.0', 'end')
|
| 64 |
+
self.redir.close()
|
| 65 |
+
|
| 66 |
+
def test_repr(self): # partly for 100% coverage
|
| 67 |
+
self.assertIn('Redirector', repr(self.redir))
|
| 68 |
+
self.assertIn('Original', repr(self.orig_insert))
|
| 69 |
+
|
| 70 |
+
def test_register(self):
|
| 71 |
+
self.assertEqual(self.text.get('1.0', 'end'), '\n')
|
| 72 |
+
self.assertEqual(self.func.args, ('insert', 'asdf'))
|
| 73 |
+
self.assertIn('insert', self.redir._operations)
|
| 74 |
+
self.assertIn('insert', self.text.__dict__)
|
| 75 |
+
self.assertEqual(self.text.insert, self.func)
|
| 76 |
+
|
| 77 |
+
def test_original_command(self):
|
| 78 |
+
self.assertEqual(self.orig_insert.operation, 'insert')
|
| 79 |
+
self.assertEqual(self.orig_insert.tk_call, self.text.tk.call)
|
| 80 |
+
self.orig_insert('insert', 'asdf')
|
| 81 |
+
self.assertEqual(self.text.get('1.0', 'end'), 'asdf\n')
|
| 82 |
+
|
| 83 |
+
def test_unregister(self):
|
| 84 |
+
self.assertIsNone(self.redir.unregister('invalid operation name'))
|
| 85 |
+
self.assertEqual(self.redir.unregister('insert'), self.func)
|
| 86 |
+
self.assertNotIn('insert', self.redir._operations)
|
| 87 |
+
self.assertNotIn('insert', self.text.__dict__)
|
| 88 |
+
|
| 89 |
+
def test_unregister_no_attribute(self):
|
| 90 |
+
del self.text.insert
|
| 91 |
+
self.assertEqual(self.redir.unregister('insert'), self.func)
|
| 92 |
+
|
| 93 |
+
def test_dispatch_intercept(self):
|
| 94 |
+
self.func.__init__(True)
|
| 95 |
+
self.assertTrue(self.redir.dispatch('insert', False))
|
| 96 |
+
self.assertFalse(self.func.args[0])
|
| 97 |
+
|
| 98 |
+
def test_dispatch_bypass(self):
|
| 99 |
+
self.orig_insert('insert', 'asdf')
|
| 100 |
+
# tk.call returns '' where Python would return None
|
| 101 |
+
self.assertEqual(self.redir.dispatch('delete', '1.0', 'end'), '')
|
| 102 |
+
self.assertEqual(self.text.get('1.0', 'end'), '\n')
|
| 103 |
+
|
| 104 |
+
def test_dispatch_error(self):
|
| 105 |
+
self.func.__init__(TclError())
|
| 106 |
+
self.assertEqual(self.redir.dispatch('insert', False), '')
|
| 107 |
+
self.assertEqual(self.redir.dispatch('invalid'), '')
|
| 108 |
+
|
| 109 |
+
def test_command_dispatch(self):
|
| 110 |
+
# Test that .__init__ causes redirection of tk calls
|
| 111 |
+
# through redir.dispatch
|
| 112 |
+
self.root.call(self.text._w, 'insert', 'hello')
|
| 113 |
+
self.assertEqual(self.func.args, ('hello',))
|
| 114 |
+
self.assertEqual(self.text.get('1.0', 'end'), '\n')
|
| 115 |
+
# Ensure that called through redir .dispatch and not through
|
| 116 |
+
# self.text.insert by having mock raise TclError.
|
| 117 |
+
self.func.__init__(TclError())
|
| 118 |
+
self.assertEqual(self.root.call(self.text._w, 'insert', 'boo'), '')
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
if __name__ == '__main__':
|
| 122 |
+
unittest.main(verbosity=2)
|
micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_replace.py
ADDED
|
@@ -0,0 +1,294 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"Test replace, coverage 78%."
|
| 2 |
+
|
| 3 |
+
from idlelib.replace import ReplaceDialog
|
| 4 |
+
import unittest
|
| 5 |
+
from test.support import requires
|
| 6 |
+
requires('gui')
|
| 7 |
+
from tkinter import Tk, Text
|
| 8 |
+
|
| 9 |
+
from unittest.mock import Mock
|
| 10 |
+
from idlelib.idle_test.mock_tk import Mbox
|
| 11 |
+
import idlelib.searchengine as se
|
| 12 |
+
|
| 13 |
+
orig_mbox = se.messagebox
|
| 14 |
+
showerror = Mbox.showerror
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
class ReplaceDialogTest(unittest.TestCase):
|
| 18 |
+
|
| 19 |
+
@classmethod
|
| 20 |
+
def setUpClass(cls):
|
| 21 |
+
cls.root = Tk()
|
| 22 |
+
cls.root.withdraw()
|
| 23 |
+
se.messagebox = Mbox
|
| 24 |
+
cls.engine = se.SearchEngine(cls.root)
|
| 25 |
+
cls.dialog = ReplaceDialog(cls.root, cls.engine)
|
| 26 |
+
cls.dialog.bell = lambda: None
|
| 27 |
+
cls.dialog.ok = Mock()
|
| 28 |
+
cls.text = Text(cls.root)
|
| 29 |
+
cls.text.undo_block_start = Mock()
|
| 30 |
+
cls.text.undo_block_stop = Mock()
|
| 31 |
+
cls.dialog.text = cls.text
|
| 32 |
+
|
| 33 |
+
@classmethod
|
| 34 |
+
def tearDownClass(cls):
|
| 35 |
+
se.messagebox = orig_mbox
|
| 36 |
+
del cls.text, cls.dialog, cls.engine
|
| 37 |
+
cls.root.destroy()
|
| 38 |
+
del cls.root
|
| 39 |
+
|
| 40 |
+
def setUp(self):
|
| 41 |
+
self.text.insert('insert', 'This is a sample sTring')
|
| 42 |
+
|
| 43 |
+
def tearDown(self):
|
| 44 |
+
self.engine.patvar.set('')
|
| 45 |
+
self.dialog.replvar.set('')
|
| 46 |
+
self.engine.wordvar.set(False)
|
| 47 |
+
self.engine.casevar.set(False)
|
| 48 |
+
self.engine.revar.set(False)
|
| 49 |
+
self.engine.wrapvar.set(True)
|
| 50 |
+
self.engine.backvar.set(False)
|
| 51 |
+
showerror.title = ''
|
| 52 |
+
showerror.message = ''
|
| 53 |
+
self.text.delete('1.0', 'end')
|
| 54 |
+
|
| 55 |
+
def test_replace_simple(self):
|
| 56 |
+
# Test replace function with all options at default setting.
|
| 57 |
+
# Wrap around - True
|
| 58 |
+
# Regular Expression - False
|
| 59 |
+
# Match case - False
|
| 60 |
+
# Match word - False
|
| 61 |
+
# Direction - Forwards
|
| 62 |
+
text = self.text
|
| 63 |
+
equal = self.assertEqual
|
| 64 |
+
pv = self.engine.patvar
|
| 65 |
+
rv = self.dialog.replvar
|
| 66 |
+
replace = self.dialog.replace_it
|
| 67 |
+
|
| 68 |
+
# test accessor method
|
| 69 |
+
self.engine.setpat('asdf')
|
| 70 |
+
equal(self.engine.getpat(), pv.get())
|
| 71 |
+
|
| 72 |
+
# text found and replaced
|
| 73 |
+
pv.set('a')
|
| 74 |
+
rv.set('asdf')
|
| 75 |
+
replace()
|
| 76 |
+
equal(text.get('1.8', '1.12'), 'asdf')
|
| 77 |
+
|
| 78 |
+
# don't "match word" case
|
| 79 |
+
text.mark_set('insert', '1.0')
|
| 80 |
+
pv.set('is')
|
| 81 |
+
rv.set('hello')
|
| 82 |
+
replace()
|
| 83 |
+
equal(text.get('1.2', '1.7'), 'hello')
|
| 84 |
+
|
| 85 |
+
# don't "match case" case
|
| 86 |
+
pv.set('string')
|
| 87 |
+
rv.set('world')
|
| 88 |
+
replace()
|
| 89 |
+
equal(text.get('1.23', '1.28'), 'world')
|
| 90 |
+
|
| 91 |
+
# without "regular expression" case
|
| 92 |
+
text.mark_set('insert', 'end')
|
| 93 |
+
text.insert('insert', '\nline42:')
|
| 94 |
+
before_text = text.get('1.0', 'end')
|
| 95 |
+
pv.set(r'[a-z][\d]+')
|
| 96 |
+
replace()
|
| 97 |
+
after_text = text.get('1.0', 'end')
|
| 98 |
+
equal(before_text, after_text)
|
| 99 |
+
|
| 100 |
+
# test with wrap around selected and complete a cycle
|
| 101 |
+
text.mark_set('insert', '1.9')
|
| 102 |
+
pv.set('i')
|
| 103 |
+
rv.set('j')
|
| 104 |
+
replace()
|
| 105 |
+
equal(text.get('1.8'), 'i')
|
| 106 |
+
equal(text.get('2.1'), 'j')
|
| 107 |
+
replace()
|
| 108 |
+
equal(text.get('2.1'), 'j')
|
| 109 |
+
equal(text.get('1.8'), 'j')
|
| 110 |
+
before_text = text.get('1.0', 'end')
|
| 111 |
+
replace()
|
| 112 |
+
after_text = text.get('1.0', 'end')
|
| 113 |
+
equal(before_text, after_text)
|
| 114 |
+
|
| 115 |
+
# text not found
|
| 116 |
+
before_text = text.get('1.0', 'end')
|
| 117 |
+
pv.set('foobar')
|
| 118 |
+
replace()
|
| 119 |
+
after_text = text.get('1.0', 'end')
|
| 120 |
+
equal(before_text, after_text)
|
| 121 |
+
|
| 122 |
+
# test access method
|
| 123 |
+
self.dialog.find_it(0)
|
| 124 |
+
|
| 125 |
+
def test_replace_wrap_around(self):
|
| 126 |
+
text = self.text
|
| 127 |
+
equal = self.assertEqual
|
| 128 |
+
pv = self.engine.patvar
|
| 129 |
+
rv = self.dialog.replvar
|
| 130 |
+
replace = self.dialog.replace_it
|
| 131 |
+
self.engine.wrapvar.set(False)
|
| 132 |
+
|
| 133 |
+
# replace candidate found both after and before 'insert'
|
| 134 |
+
text.mark_set('insert', '1.4')
|
| 135 |
+
pv.set('i')
|
| 136 |
+
rv.set('j')
|
| 137 |
+
replace()
|
| 138 |
+
equal(text.get('1.2'), 'i')
|
| 139 |
+
equal(text.get('1.5'), 'j')
|
| 140 |
+
replace()
|
| 141 |
+
equal(text.get('1.2'), 'i')
|
| 142 |
+
equal(text.get('1.20'), 'j')
|
| 143 |
+
replace()
|
| 144 |
+
equal(text.get('1.2'), 'i')
|
| 145 |
+
|
| 146 |
+
# replace candidate found only before 'insert'
|
| 147 |
+
text.mark_set('insert', '1.8')
|
| 148 |
+
pv.set('is')
|
| 149 |
+
before_text = text.get('1.0', 'end')
|
| 150 |
+
replace()
|
| 151 |
+
after_text = text.get('1.0', 'end')
|
| 152 |
+
equal(before_text, after_text)
|
| 153 |
+
|
| 154 |
+
def test_replace_whole_word(self):
|
| 155 |
+
text = self.text
|
| 156 |
+
equal = self.assertEqual
|
| 157 |
+
pv = self.engine.patvar
|
| 158 |
+
rv = self.dialog.replvar
|
| 159 |
+
replace = self.dialog.replace_it
|
| 160 |
+
self.engine.wordvar.set(True)
|
| 161 |
+
|
| 162 |
+
pv.set('is')
|
| 163 |
+
rv.set('hello')
|
| 164 |
+
replace()
|
| 165 |
+
equal(text.get('1.0', '1.4'), 'This')
|
| 166 |
+
equal(text.get('1.5', '1.10'), 'hello')
|
| 167 |
+
|
| 168 |
+
def test_replace_match_case(self):
|
| 169 |
+
equal = self.assertEqual
|
| 170 |
+
text = self.text
|
| 171 |
+
pv = self.engine.patvar
|
| 172 |
+
rv = self.dialog.replvar
|
| 173 |
+
replace = self.dialog.replace_it
|
| 174 |
+
self.engine.casevar.set(True)
|
| 175 |
+
|
| 176 |
+
before_text = self.text.get('1.0', 'end')
|
| 177 |
+
pv.set('this')
|
| 178 |
+
rv.set('that')
|
| 179 |
+
replace()
|
| 180 |
+
after_text = self.text.get('1.0', 'end')
|
| 181 |
+
equal(before_text, after_text)
|
| 182 |
+
|
| 183 |
+
pv.set('This')
|
| 184 |
+
replace()
|
| 185 |
+
equal(text.get('1.0', '1.4'), 'that')
|
| 186 |
+
|
| 187 |
+
def test_replace_regex(self):
|
| 188 |
+
equal = self.assertEqual
|
| 189 |
+
text = self.text
|
| 190 |
+
pv = self.engine.patvar
|
| 191 |
+
rv = self.dialog.replvar
|
| 192 |
+
replace = self.dialog.replace_it
|
| 193 |
+
self.engine.revar.set(True)
|
| 194 |
+
|
| 195 |
+
before_text = text.get('1.0', 'end')
|
| 196 |
+
pv.set(r'[a-z][\d]+')
|
| 197 |
+
rv.set('hello')
|
| 198 |
+
replace()
|
| 199 |
+
after_text = text.get('1.0', 'end')
|
| 200 |
+
equal(before_text, after_text)
|
| 201 |
+
|
| 202 |
+
text.insert('insert', '\nline42')
|
| 203 |
+
replace()
|
| 204 |
+
equal(text.get('2.0', '2.8'), 'linhello')
|
| 205 |
+
|
| 206 |
+
pv.set('')
|
| 207 |
+
replace()
|
| 208 |
+
self.assertIn('error', showerror.title)
|
| 209 |
+
self.assertIn('Empty', showerror.message)
|
| 210 |
+
|
| 211 |
+
pv.set(r'[\d')
|
| 212 |
+
replace()
|
| 213 |
+
self.assertIn('error', showerror.title)
|
| 214 |
+
self.assertIn('Pattern', showerror.message)
|
| 215 |
+
|
| 216 |
+
showerror.title = ''
|
| 217 |
+
showerror.message = ''
|
| 218 |
+
pv.set('[a]')
|
| 219 |
+
rv.set('test\\')
|
| 220 |
+
replace()
|
| 221 |
+
self.assertIn('error', showerror.title)
|
| 222 |
+
self.assertIn('Invalid Replace Expression', showerror.message)
|
| 223 |
+
|
| 224 |
+
# test access method
|
| 225 |
+
self.engine.setcookedpat("?")
|
| 226 |
+
equal(pv.get(), "\\?")
|
| 227 |
+
|
| 228 |
+
def test_replace_backwards(self):
|
| 229 |
+
equal = self.assertEqual
|
| 230 |
+
text = self.text
|
| 231 |
+
pv = self.engine.patvar
|
| 232 |
+
rv = self.dialog.replvar
|
| 233 |
+
replace = self.dialog.replace_it
|
| 234 |
+
self.engine.backvar.set(True)
|
| 235 |
+
|
| 236 |
+
text.insert('insert', '\nis as ')
|
| 237 |
+
|
| 238 |
+
pv.set('is')
|
| 239 |
+
rv.set('was')
|
| 240 |
+
replace()
|
| 241 |
+
equal(text.get('1.2', '1.4'), 'is')
|
| 242 |
+
equal(text.get('2.0', '2.3'), 'was')
|
| 243 |
+
replace()
|
| 244 |
+
equal(text.get('1.5', '1.8'), 'was')
|
| 245 |
+
replace()
|
| 246 |
+
equal(text.get('1.2', '1.5'), 'was')
|
| 247 |
+
|
| 248 |
+
def test_replace_all(self):
|
| 249 |
+
text = self.text
|
| 250 |
+
pv = self.engine.patvar
|
| 251 |
+
rv = self.dialog.replvar
|
| 252 |
+
replace_all = self.dialog.replace_all
|
| 253 |
+
|
| 254 |
+
text.insert('insert', '\n')
|
| 255 |
+
text.insert('insert', text.get('1.0', 'end')*100)
|
| 256 |
+
pv.set('is')
|
| 257 |
+
rv.set('was')
|
| 258 |
+
replace_all()
|
| 259 |
+
self.assertNotIn('is', text.get('1.0', 'end'))
|
| 260 |
+
|
| 261 |
+
self.engine.revar.set(True)
|
| 262 |
+
pv.set('')
|
| 263 |
+
replace_all()
|
| 264 |
+
self.assertIn('error', showerror.title)
|
| 265 |
+
self.assertIn('Empty', showerror.message)
|
| 266 |
+
|
| 267 |
+
pv.set('[s][T]')
|
| 268 |
+
rv.set('\\')
|
| 269 |
+
replace_all()
|
| 270 |
+
|
| 271 |
+
self.engine.revar.set(False)
|
| 272 |
+
pv.set('text which is not present')
|
| 273 |
+
rv.set('foobar')
|
| 274 |
+
replace_all()
|
| 275 |
+
|
| 276 |
+
def test_default_command(self):
|
| 277 |
+
text = self.text
|
| 278 |
+
pv = self.engine.patvar
|
| 279 |
+
rv = self.dialog.replvar
|
| 280 |
+
replace_find = self.dialog.default_command
|
| 281 |
+
equal = self.assertEqual
|
| 282 |
+
|
| 283 |
+
pv.set('This')
|
| 284 |
+
rv.set('was')
|
| 285 |
+
replace_find()
|
| 286 |
+
equal(text.get('sel.first', 'sel.last'), 'was')
|
| 287 |
+
|
| 288 |
+
self.engine.revar.set(True)
|
| 289 |
+
pv.set('')
|
| 290 |
+
replace_find()
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
if __name__ == '__main__':
|
| 294 |
+
unittest.main(verbosity=2)
|
micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_rpc.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"Test rpc, coverage 20%."
|
| 2 |
+
|
| 3 |
+
from idlelib import rpc
|
| 4 |
+
import unittest
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class CodePicklerTest(unittest.TestCase):
|
| 9 |
+
|
| 10 |
+
def test_pickle_unpickle(self):
|
| 11 |
+
def f(): return a + b + c
|
| 12 |
+
func, (cbytes,) = rpc.pickle_code(f.__code__)
|
| 13 |
+
self.assertIs(func, rpc.unpickle_code)
|
| 14 |
+
self.assertIn(b'test_rpc.py', cbytes)
|
| 15 |
+
code = rpc.unpickle_code(cbytes)
|
| 16 |
+
self.assertEqual(code.co_names, ('a', 'b', 'c'))
|
| 17 |
+
|
| 18 |
+
def test_code_pickler(self):
|
| 19 |
+
self.assertIn(type((lambda:None).__code__),
|
| 20 |
+
rpc.CodePickler.dispatch_table)
|
| 21 |
+
|
| 22 |
+
def test_dumps(self):
|
| 23 |
+
def f(): pass
|
| 24 |
+
# The main test here is that pickling code does not raise.
|
| 25 |
+
self.assertIn(b'test_rpc.py', rpc.dumps(f.__code__))
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
if __name__ == '__main__':
|
| 29 |
+
unittest.main(verbosity=2)
|
micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_run.py
ADDED
|
@@ -0,0 +1,429 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"Test run, coverage 54%."
|
| 2 |
+
|
| 3 |
+
from idlelib import run
|
| 4 |
+
import io
|
| 5 |
+
import sys
|
| 6 |
+
from test.support import captured_output, captured_stderr
|
| 7 |
+
import unittest
|
| 8 |
+
from unittest import mock
|
| 9 |
+
import idlelib
|
| 10 |
+
from idlelib.idle_test.mock_idle import Func
|
| 11 |
+
|
| 12 |
+
idlelib.testing = True # Use {} for executing test user code.
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class ExceptionTest(unittest.TestCase):
|
| 16 |
+
|
| 17 |
+
def test_print_exception_unhashable(self):
|
| 18 |
+
class UnhashableException(Exception):
|
| 19 |
+
def __eq__(self, other):
|
| 20 |
+
return True
|
| 21 |
+
|
| 22 |
+
ex1 = UnhashableException('ex1')
|
| 23 |
+
ex2 = UnhashableException('ex2')
|
| 24 |
+
try:
|
| 25 |
+
raise ex2 from ex1
|
| 26 |
+
except UnhashableException:
|
| 27 |
+
try:
|
| 28 |
+
raise ex1
|
| 29 |
+
except UnhashableException:
|
| 30 |
+
with captured_stderr() as output:
|
| 31 |
+
with mock.patch.object(run, 'cleanup_traceback') as ct:
|
| 32 |
+
ct.side_effect = lambda t, e: t
|
| 33 |
+
run.print_exception()
|
| 34 |
+
|
| 35 |
+
tb = output.getvalue().strip().splitlines()
|
| 36 |
+
self.assertEqual(11, len(tb))
|
| 37 |
+
self.assertIn('UnhashableException: ex2', tb[3])
|
| 38 |
+
self.assertIn('UnhashableException: ex1', tb[10])
|
| 39 |
+
|
| 40 |
+
data = (('1/0', ZeroDivisionError, "division by zero\n"),
|
| 41 |
+
('abc', NameError, "name 'abc' is not defined. "
|
| 42 |
+
"Did you mean: 'abs'?\n"),
|
| 43 |
+
('int.reel', AttributeError,
|
| 44 |
+
"type object 'int' has no attribute 'reel'. "
|
| 45 |
+
"Did you mean: 'real'?\n"),
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
def test_get_message(self):
|
| 49 |
+
for code, exc, msg in self.data:
|
| 50 |
+
with self.subTest(code=code):
|
| 51 |
+
try:
|
| 52 |
+
eval(compile(code, '', 'eval'))
|
| 53 |
+
except exc:
|
| 54 |
+
typ, val, tb = sys.exc_info()
|
| 55 |
+
actual = run.get_message_lines(typ, val, tb)[0]
|
| 56 |
+
expect = f'{exc.__name__}: {msg}'
|
| 57 |
+
self.assertEqual(actual, expect)
|
| 58 |
+
|
| 59 |
+
@mock.patch.object(run, 'cleanup_traceback',
|
| 60 |
+
new_callable=lambda: (lambda t, e: None))
|
| 61 |
+
def test_get_multiple_message(self, mock):
|
| 62 |
+
d = self.data
|
| 63 |
+
data2 = ((d[0], d[1]), (d[1], d[2]), (d[2], d[0]))
|
| 64 |
+
subtests = 0
|
| 65 |
+
for (code1, exc1, msg1), (code2, exc2, msg2) in data2:
|
| 66 |
+
with self.subTest(codes=(code1,code2)):
|
| 67 |
+
try:
|
| 68 |
+
eval(compile(code1, '', 'eval'))
|
| 69 |
+
except exc1:
|
| 70 |
+
try:
|
| 71 |
+
eval(compile(code2, '', 'eval'))
|
| 72 |
+
except exc2:
|
| 73 |
+
with captured_stderr() as output:
|
| 74 |
+
run.print_exception()
|
| 75 |
+
actual = output.getvalue()
|
| 76 |
+
self.assertIn(msg1, actual)
|
| 77 |
+
self.assertIn(msg2, actual)
|
| 78 |
+
subtests += 1
|
| 79 |
+
self.assertEqual(subtests, len(data2)) # All subtests ran?
|
| 80 |
+
|
| 81 |
+
# StdioFile tests.
|
| 82 |
+
|
| 83 |
+
class S(str):
|
| 84 |
+
def __str__(self):
|
| 85 |
+
return '%s:str' % type(self).__name__
|
| 86 |
+
def __unicode__(self):
|
| 87 |
+
return '%s:unicode' % type(self).__name__
|
| 88 |
+
def __len__(self):
|
| 89 |
+
return 3
|
| 90 |
+
def __iter__(self):
|
| 91 |
+
return iter('abc')
|
| 92 |
+
def __getitem__(self, *args):
|
| 93 |
+
return '%s:item' % type(self).__name__
|
| 94 |
+
def __getslice__(self, *args):
|
| 95 |
+
return '%s:slice' % type(self).__name__
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
class MockShell:
|
| 99 |
+
def __init__(self):
|
| 100 |
+
self.reset()
|
| 101 |
+
def write(self, *args):
|
| 102 |
+
self.written.append(args)
|
| 103 |
+
def readline(self):
|
| 104 |
+
return self.lines.pop()
|
| 105 |
+
def close(self):
|
| 106 |
+
pass
|
| 107 |
+
def reset(self):
|
| 108 |
+
self.written = []
|
| 109 |
+
def push(self, lines):
|
| 110 |
+
self.lines = list(lines)[::-1]
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
class StdInputFilesTest(unittest.TestCase):
|
| 114 |
+
|
| 115 |
+
def test_misc(self):
|
| 116 |
+
shell = MockShell()
|
| 117 |
+
f = run.StdInputFile(shell, 'stdin')
|
| 118 |
+
self.assertIsInstance(f, io.TextIOBase)
|
| 119 |
+
self.assertEqual(f.encoding, 'utf-8')
|
| 120 |
+
self.assertEqual(f.errors, 'strict')
|
| 121 |
+
self.assertIsNone(f.newlines)
|
| 122 |
+
self.assertEqual(f.name, '<stdin>')
|
| 123 |
+
self.assertFalse(f.closed)
|
| 124 |
+
self.assertTrue(f.isatty())
|
| 125 |
+
self.assertTrue(f.readable())
|
| 126 |
+
self.assertFalse(f.writable())
|
| 127 |
+
self.assertFalse(f.seekable())
|
| 128 |
+
|
| 129 |
+
def test_unsupported(self):
|
| 130 |
+
shell = MockShell()
|
| 131 |
+
f = run.StdInputFile(shell, 'stdin')
|
| 132 |
+
self.assertRaises(OSError, f.fileno)
|
| 133 |
+
self.assertRaises(OSError, f.tell)
|
| 134 |
+
self.assertRaises(OSError, f.seek, 0)
|
| 135 |
+
self.assertRaises(OSError, f.write, 'x')
|
| 136 |
+
self.assertRaises(OSError, f.writelines, ['x'])
|
| 137 |
+
|
| 138 |
+
def test_read(self):
|
| 139 |
+
shell = MockShell()
|
| 140 |
+
f = run.StdInputFile(shell, 'stdin')
|
| 141 |
+
shell.push(['one\n', 'two\n', ''])
|
| 142 |
+
self.assertEqual(f.read(), 'one\ntwo\n')
|
| 143 |
+
shell.push(['one\n', 'two\n', ''])
|
| 144 |
+
self.assertEqual(f.read(-1), 'one\ntwo\n')
|
| 145 |
+
shell.push(['one\n', 'two\n', ''])
|
| 146 |
+
self.assertEqual(f.read(None), 'one\ntwo\n')
|
| 147 |
+
shell.push(['one\n', 'two\n', 'three\n', ''])
|
| 148 |
+
self.assertEqual(f.read(2), 'on')
|
| 149 |
+
self.assertEqual(f.read(3), 'e\nt')
|
| 150 |
+
self.assertEqual(f.read(10), 'wo\nthree\n')
|
| 151 |
+
|
| 152 |
+
shell.push(['one\n', 'two\n'])
|
| 153 |
+
self.assertEqual(f.read(0), '')
|
| 154 |
+
self.assertRaises(TypeError, f.read, 1.5)
|
| 155 |
+
self.assertRaises(TypeError, f.read, '1')
|
| 156 |
+
self.assertRaises(TypeError, f.read, 1, 1)
|
| 157 |
+
|
| 158 |
+
def test_readline(self):
|
| 159 |
+
shell = MockShell()
|
| 160 |
+
f = run.StdInputFile(shell, 'stdin')
|
| 161 |
+
shell.push(['one\n', 'two\n', 'three\n', 'four\n'])
|
| 162 |
+
self.assertEqual(f.readline(), 'one\n')
|
| 163 |
+
self.assertEqual(f.readline(-1), 'two\n')
|
| 164 |
+
self.assertEqual(f.readline(None), 'three\n')
|
| 165 |
+
shell.push(['one\ntwo\n'])
|
| 166 |
+
self.assertEqual(f.readline(), 'one\n')
|
| 167 |
+
self.assertEqual(f.readline(), 'two\n')
|
| 168 |
+
shell.push(['one', 'two', 'three'])
|
| 169 |
+
self.assertEqual(f.readline(), 'one')
|
| 170 |
+
self.assertEqual(f.readline(), 'two')
|
| 171 |
+
shell.push(['one\n', 'two\n', 'three\n'])
|
| 172 |
+
self.assertEqual(f.readline(2), 'on')
|
| 173 |
+
self.assertEqual(f.readline(1), 'e')
|
| 174 |
+
self.assertEqual(f.readline(1), '\n')
|
| 175 |
+
self.assertEqual(f.readline(10), 'two\n')
|
| 176 |
+
|
| 177 |
+
shell.push(['one\n', 'two\n'])
|
| 178 |
+
self.assertEqual(f.readline(0), '')
|
| 179 |
+
self.assertRaises(TypeError, f.readlines, 1.5)
|
| 180 |
+
self.assertRaises(TypeError, f.readlines, '1')
|
| 181 |
+
self.assertRaises(TypeError, f.readlines, 1, 1)
|
| 182 |
+
|
| 183 |
+
def test_readlines(self):
|
| 184 |
+
shell = MockShell()
|
| 185 |
+
f = run.StdInputFile(shell, 'stdin')
|
| 186 |
+
shell.push(['one\n', 'two\n', ''])
|
| 187 |
+
self.assertEqual(f.readlines(), ['one\n', 'two\n'])
|
| 188 |
+
shell.push(['one\n', 'two\n', ''])
|
| 189 |
+
self.assertEqual(f.readlines(-1), ['one\n', 'two\n'])
|
| 190 |
+
shell.push(['one\n', 'two\n', ''])
|
| 191 |
+
self.assertEqual(f.readlines(None), ['one\n', 'two\n'])
|
| 192 |
+
shell.push(['one\n', 'two\n', ''])
|
| 193 |
+
self.assertEqual(f.readlines(0), ['one\n', 'two\n'])
|
| 194 |
+
shell.push(['one\n', 'two\n', ''])
|
| 195 |
+
self.assertEqual(f.readlines(3), ['one\n'])
|
| 196 |
+
shell.push(['one\n', 'two\n', ''])
|
| 197 |
+
self.assertEqual(f.readlines(4), ['one\n', 'two\n'])
|
| 198 |
+
|
| 199 |
+
shell.push(['one\n', 'two\n', ''])
|
| 200 |
+
self.assertRaises(TypeError, f.readlines, 1.5)
|
| 201 |
+
self.assertRaises(TypeError, f.readlines, '1')
|
| 202 |
+
self.assertRaises(TypeError, f.readlines, 1, 1)
|
| 203 |
+
|
| 204 |
+
def test_close(self):
|
| 205 |
+
shell = MockShell()
|
| 206 |
+
f = run.StdInputFile(shell, 'stdin')
|
| 207 |
+
shell.push(['one\n', 'two\n', ''])
|
| 208 |
+
self.assertFalse(f.closed)
|
| 209 |
+
self.assertEqual(f.readline(), 'one\n')
|
| 210 |
+
f.close()
|
| 211 |
+
self.assertFalse(f.closed)
|
| 212 |
+
self.assertEqual(f.readline(), 'two\n')
|
| 213 |
+
self.assertRaises(TypeError, f.close, 1)
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
class StdOutputFilesTest(unittest.TestCase):
|
| 217 |
+
|
| 218 |
+
def test_misc(self):
|
| 219 |
+
shell = MockShell()
|
| 220 |
+
f = run.StdOutputFile(shell, 'stdout')
|
| 221 |
+
self.assertIsInstance(f, io.TextIOBase)
|
| 222 |
+
self.assertEqual(f.encoding, 'utf-8')
|
| 223 |
+
self.assertEqual(f.errors, 'strict')
|
| 224 |
+
self.assertIsNone(f.newlines)
|
| 225 |
+
self.assertEqual(f.name, '<stdout>')
|
| 226 |
+
self.assertFalse(f.closed)
|
| 227 |
+
self.assertTrue(f.isatty())
|
| 228 |
+
self.assertFalse(f.readable())
|
| 229 |
+
self.assertTrue(f.writable())
|
| 230 |
+
self.assertFalse(f.seekable())
|
| 231 |
+
|
| 232 |
+
def test_unsupported(self):
|
| 233 |
+
shell = MockShell()
|
| 234 |
+
f = run.StdOutputFile(shell, 'stdout')
|
| 235 |
+
self.assertRaises(OSError, f.fileno)
|
| 236 |
+
self.assertRaises(OSError, f.tell)
|
| 237 |
+
self.assertRaises(OSError, f.seek, 0)
|
| 238 |
+
self.assertRaises(OSError, f.read, 0)
|
| 239 |
+
self.assertRaises(OSError, f.readline, 0)
|
| 240 |
+
|
| 241 |
+
def test_write(self):
|
| 242 |
+
shell = MockShell()
|
| 243 |
+
f = run.StdOutputFile(shell, 'stdout')
|
| 244 |
+
f.write('test')
|
| 245 |
+
self.assertEqual(shell.written, [('test', 'stdout')])
|
| 246 |
+
shell.reset()
|
| 247 |
+
f.write('t\xe8\u015b\U0001d599')
|
| 248 |
+
self.assertEqual(shell.written, [('t\xe8\u015b\U0001d599', 'stdout')])
|
| 249 |
+
shell.reset()
|
| 250 |
+
|
| 251 |
+
f.write(S('t\xe8\u015b\U0001d599'))
|
| 252 |
+
self.assertEqual(shell.written, [('t\xe8\u015b\U0001d599', 'stdout')])
|
| 253 |
+
self.assertEqual(type(shell.written[0][0]), str)
|
| 254 |
+
shell.reset()
|
| 255 |
+
|
| 256 |
+
self.assertRaises(TypeError, f.write)
|
| 257 |
+
self.assertEqual(shell.written, [])
|
| 258 |
+
self.assertRaises(TypeError, f.write, b'test')
|
| 259 |
+
self.assertRaises(TypeError, f.write, 123)
|
| 260 |
+
self.assertEqual(shell.written, [])
|
| 261 |
+
self.assertRaises(TypeError, f.write, 'test', 'spam')
|
| 262 |
+
self.assertEqual(shell.written, [])
|
| 263 |
+
|
| 264 |
+
def test_write_stderr_nonencodable(self):
|
| 265 |
+
shell = MockShell()
|
| 266 |
+
f = run.StdOutputFile(shell, 'stderr', 'iso-8859-15', 'backslashreplace')
|
| 267 |
+
f.write('t\xe8\u015b\U0001d599\xa4')
|
| 268 |
+
self.assertEqual(shell.written, [('t\xe8\\u015b\\U0001d599\\xa4', 'stderr')])
|
| 269 |
+
shell.reset()
|
| 270 |
+
|
| 271 |
+
f.write(S('t\xe8\u015b\U0001d599\xa4'))
|
| 272 |
+
self.assertEqual(shell.written, [('t\xe8\\u015b\\U0001d599\\xa4', 'stderr')])
|
| 273 |
+
self.assertEqual(type(shell.written[0][0]), str)
|
| 274 |
+
shell.reset()
|
| 275 |
+
|
| 276 |
+
self.assertRaises(TypeError, f.write)
|
| 277 |
+
self.assertEqual(shell.written, [])
|
| 278 |
+
self.assertRaises(TypeError, f.write, b'test')
|
| 279 |
+
self.assertRaises(TypeError, f.write, 123)
|
| 280 |
+
self.assertEqual(shell.written, [])
|
| 281 |
+
self.assertRaises(TypeError, f.write, 'test', 'spam')
|
| 282 |
+
self.assertEqual(shell.written, [])
|
| 283 |
+
|
| 284 |
+
def test_writelines(self):
|
| 285 |
+
shell = MockShell()
|
| 286 |
+
f = run.StdOutputFile(shell, 'stdout')
|
| 287 |
+
f.writelines([])
|
| 288 |
+
self.assertEqual(shell.written, [])
|
| 289 |
+
shell.reset()
|
| 290 |
+
f.writelines(['one\n', 'two'])
|
| 291 |
+
self.assertEqual(shell.written,
|
| 292 |
+
[('one\n', 'stdout'), ('two', 'stdout')])
|
| 293 |
+
shell.reset()
|
| 294 |
+
f.writelines(['on\xe8\n', 'tw\xf2'])
|
| 295 |
+
self.assertEqual(shell.written,
|
| 296 |
+
[('on\xe8\n', 'stdout'), ('tw\xf2', 'stdout')])
|
| 297 |
+
shell.reset()
|
| 298 |
+
|
| 299 |
+
f.writelines([S('t\xe8st')])
|
| 300 |
+
self.assertEqual(shell.written, [('t\xe8st', 'stdout')])
|
| 301 |
+
self.assertEqual(type(shell.written[0][0]), str)
|
| 302 |
+
shell.reset()
|
| 303 |
+
|
| 304 |
+
self.assertRaises(TypeError, f.writelines)
|
| 305 |
+
self.assertEqual(shell.written, [])
|
| 306 |
+
self.assertRaises(TypeError, f.writelines, 123)
|
| 307 |
+
self.assertEqual(shell.written, [])
|
| 308 |
+
self.assertRaises(TypeError, f.writelines, [b'test'])
|
| 309 |
+
self.assertRaises(TypeError, f.writelines, [123])
|
| 310 |
+
self.assertEqual(shell.written, [])
|
| 311 |
+
self.assertRaises(TypeError, f.writelines, [], [])
|
| 312 |
+
self.assertEqual(shell.written, [])
|
| 313 |
+
|
| 314 |
+
def test_close(self):
|
| 315 |
+
shell = MockShell()
|
| 316 |
+
f = run.StdOutputFile(shell, 'stdout')
|
| 317 |
+
self.assertFalse(f.closed)
|
| 318 |
+
f.write('test')
|
| 319 |
+
f.close()
|
| 320 |
+
self.assertTrue(f.closed)
|
| 321 |
+
self.assertRaises(ValueError, f.write, 'x')
|
| 322 |
+
self.assertEqual(shell.written, [('test', 'stdout')])
|
| 323 |
+
f.close()
|
| 324 |
+
self.assertRaises(TypeError, f.close, 1)
|
| 325 |
+
|
| 326 |
+
|
| 327 |
+
class RecursionLimitTest(unittest.TestCase):
|
| 328 |
+
# Test (un)install_recursionlimit_wrappers and fixdoc.
|
| 329 |
+
|
| 330 |
+
def test_bad_setrecursionlimit_calls(self):
|
| 331 |
+
run.install_recursionlimit_wrappers()
|
| 332 |
+
self.addCleanup(run.uninstall_recursionlimit_wrappers)
|
| 333 |
+
f = sys.setrecursionlimit
|
| 334 |
+
self.assertRaises(TypeError, f, limit=100)
|
| 335 |
+
self.assertRaises(TypeError, f, 100, 1000)
|
| 336 |
+
self.assertRaises(ValueError, f, 0)
|
| 337 |
+
|
| 338 |
+
def test_roundtrip(self):
|
| 339 |
+
run.install_recursionlimit_wrappers()
|
| 340 |
+
self.addCleanup(run.uninstall_recursionlimit_wrappers)
|
| 341 |
+
|
| 342 |
+
# Check that setting the recursion limit works.
|
| 343 |
+
orig_reclimit = sys.getrecursionlimit()
|
| 344 |
+
self.addCleanup(sys.setrecursionlimit, orig_reclimit)
|
| 345 |
+
sys.setrecursionlimit(orig_reclimit + 3)
|
| 346 |
+
|
| 347 |
+
# Check that the new limit is returned by sys.getrecursionlimit().
|
| 348 |
+
new_reclimit = sys.getrecursionlimit()
|
| 349 |
+
self.assertEqual(new_reclimit, orig_reclimit + 3)
|
| 350 |
+
|
| 351 |
+
def test_default_recursion_limit_preserved(self):
|
| 352 |
+
orig_reclimit = sys.getrecursionlimit()
|
| 353 |
+
run.install_recursionlimit_wrappers()
|
| 354 |
+
self.addCleanup(run.uninstall_recursionlimit_wrappers)
|
| 355 |
+
new_reclimit = sys.getrecursionlimit()
|
| 356 |
+
self.assertEqual(new_reclimit, orig_reclimit)
|
| 357 |
+
|
| 358 |
+
def test_fixdoc(self):
|
| 359 |
+
# Put here until better place for miscellaneous test.
|
| 360 |
+
def func(): "docstring"
|
| 361 |
+
run.fixdoc(func, "more")
|
| 362 |
+
self.assertEqual(func.__doc__, "docstring\n\nmore")
|
| 363 |
+
func.__doc__ = None
|
| 364 |
+
run.fixdoc(func, "more")
|
| 365 |
+
self.assertEqual(func.__doc__, "more")
|
| 366 |
+
|
| 367 |
+
|
| 368 |
+
class HandleErrorTest(unittest.TestCase):
|
| 369 |
+
# Method of MyRPCServer
|
| 370 |
+
def test_fatal_error(self):
|
| 371 |
+
eq = self.assertEqual
|
| 372 |
+
with captured_output('__stderr__') as err,\
|
| 373 |
+
mock.patch('idlelib.run.thread.interrupt_main',
|
| 374 |
+
new_callable=Func) as func:
|
| 375 |
+
try:
|
| 376 |
+
raise EOFError
|
| 377 |
+
except EOFError:
|
| 378 |
+
run.MyRPCServer.handle_error(None, 'abc', '123')
|
| 379 |
+
eq(run.exit_now, True)
|
| 380 |
+
run.exit_now = False
|
| 381 |
+
eq(err.getvalue(), '')
|
| 382 |
+
|
| 383 |
+
try:
|
| 384 |
+
raise IndexError
|
| 385 |
+
except IndexError:
|
| 386 |
+
run.MyRPCServer.handle_error(None, 'abc', '123')
|
| 387 |
+
eq(run.quitting, True)
|
| 388 |
+
run.quitting = False
|
| 389 |
+
msg = err.getvalue()
|
| 390 |
+
self.assertIn('abc', msg)
|
| 391 |
+
self.assertIn('123', msg)
|
| 392 |
+
self.assertIn('IndexError', msg)
|
| 393 |
+
eq(func.called, 2)
|
| 394 |
+
|
| 395 |
+
|
| 396 |
+
class ExecRuncodeTest(unittest.TestCase):
|
| 397 |
+
|
| 398 |
+
@classmethod
|
| 399 |
+
def setUpClass(cls):
|
| 400 |
+
cls.addClassCleanup(setattr,run,'print_exception',run.print_exception)
|
| 401 |
+
cls.prt = Func() # Need reference.
|
| 402 |
+
run.print_exception = cls.prt
|
| 403 |
+
mockrpc = mock.Mock()
|
| 404 |
+
mockrpc.console.getvar = Func(result=False)
|
| 405 |
+
cls.ex = run.Executive(mockrpc)
|
| 406 |
+
|
| 407 |
+
@classmethod
|
| 408 |
+
def tearDownClass(cls):
|
| 409 |
+
assert sys.excepthook == sys.__excepthook__
|
| 410 |
+
|
| 411 |
+
def test_exceptions(self):
|
| 412 |
+
ex = self.ex
|
| 413 |
+
ex.runcode('1/0')
|
| 414 |
+
self.assertIs(ex.user_exc_info[0], ZeroDivisionError)
|
| 415 |
+
|
| 416 |
+
self.addCleanup(setattr, sys, 'excepthook', sys.__excepthook__)
|
| 417 |
+
sys.excepthook = lambda t, e, tb: run.print_exception(t)
|
| 418 |
+
ex.runcode('1/0')
|
| 419 |
+
self.assertIs(self.prt.args[0], ZeroDivisionError)
|
| 420 |
+
|
| 421 |
+
sys.excepthook = lambda: None
|
| 422 |
+
ex.runcode('1/0')
|
| 423 |
+
t, e, tb = ex.user_exc_info
|
| 424 |
+
self.assertIs(t, TypeError)
|
| 425 |
+
self.assertTrue(isinstance(e.__context__, ZeroDivisionError))
|
| 426 |
+
|
| 427 |
+
|
| 428 |
+
if __name__ == '__main__':
|
| 429 |
+
unittest.main(verbosity=2)
|
micromamba_root/envs/pytorch_env/Lib/idlelib/idle_test/test_runscript.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"Test runscript, coverage 16%."
|
| 2 |
+
|
| 3 |
+
from idlelib import runscript
|
| 4 |
+
import unittest
|
| 5 |
+
from test.support import requires
|
| 6 |
+
from tkinter import Tk
|
| 7 |
+
from idlelib.editor import EditorWindow
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class ScriptBindingTest(unittest.TestCase):
|
| 11 |
+
|
| 12 |
+
@classmethod
|
| 13 |
+
def setUpClass(cls):
|
| 14 |
+
requires('gui')
|
| 15 |
+
cls.root = Tk()
|
| 16 |
+
cls.root.withdraw()
|
| 17 |
+
|
| 18 |
+
@classmethod
|
| 19 |
+
def tearDownClass(cls):
|
| 20 |
+
cls.root.update_idletasks()
|
| 21 |
+
for id in cls.root.tk.call('after', 'info'):
|
| 22 |
+
cls.root.after_cancel(id) # Need for EditorWindow.
|
| 23 |
+
cls.root.destroy()
|
| 24 |
+
del cls.root
|
| 25 |
+
|
| 26 |
+
def test_init(self):
|
| 27 |
+
ew = EditorWindow(root=self.root)
|
| 28 |
+
sb = runscript.ScriptBinding(ew)
|
| 29 |
+
ew._close()
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
if __name__ == '__main__':
|
| 33 |
+
unittest.main(verbosity=2)
|