Terry J. Reedy added the comment:
This issue began with #27173 which added test_config with CurrentColorKeysTest
to test the new IdleConf.current_colors_and_keys. Those tests never called any
user parser.Save, but I knew I had to remove the possibility that any future
test would touch anyone's working .idlerc. I thought of at least some of the
following:
1. Directly replace config.IdleUserConfParser.Save. Since 4 instances are
created during import, this would require recreating idleCong.userCfg after
import. Restore the status quo by saving the original userCfg and restoring it
after tests. The same applies to 3. and 4.
2. Give instances a Save function, as Cheryl did in PR2610,
test_config.ConfigChangesTest.test_save_all, to mask the instance method.
idleConf.userCfg['main'].Save = Func()
Restore the status quo by removing the instance function.
3. Subclass IdleUserConfigParser with a new Save and recreate userCfg, as
Cheryl did in configdialog_tests_v1.py on #30868. But instead of a dummy
function, the replacement should be a mock.
class DummyUserConfParser(config.IdleUserConfParser):
Save = Func() # or other Mock.
This is essentially 1. with subclassing being an alternate way to replace the
original Save.
4. It turns out the initializing IdleUserConfParser with file name '' works to
disable both Load and Save without raising an exception. (Plain open('') gives
me FileNotFoundError.) So, recreate userCfg with instances initialized with ''.
When I opened this issue, I forgot about the no load part. But it is in the
comment near the top of test_config, and it is essential. This suggests
combining 3. and 4. by initializing a subclass with ''.
A. Testing ConfigChanges.save_all requires a count of calls. Func can easily
be upgraded to do that.
B. The real save function does not just save a page. Instead, it removes empty
sections and if the result is an empty page, the corresponding file is deleted,
not just emptied. Testing the function requires a fairly functional substitute.
I am not sure yet how the solution for this should relate to A and its
solution.
In #8231, I tried and failed to get IDLE to run with a temporary directory as
the home directory, so people without a writeable home directory can still run
IDLE. Having to run with 2.7 is no more, for me, an issue. Running in 2
processes, and having config indirectly inported into the run process is. As I
noted there, #27534 could result in this issue going away.
I also want to look into a simulated in-memory 'directory', class IdleRC,
contains StringIO instances, with a simulated open and any needed os functions.
(For instance, mock-open('.idlerc/config-main.cfg') returns the StringIO for
'main'.) This would be fast and instrumented for testing as we please.
C. 'Other tests' at the top of this post include both other tests in
test_config and other test files. If Solutions 1. to 4. have to include
restoration, then they should be repeated in every test_file that imports
config. So why bother restoring, only to repatch? This suggests that when
testing, usefCfg should be created in an alternate state.
However, ... the current mechanism is that test.test_idle sets
idlelib.__init__.testing to True. This is fine for buildbots, which only run
idle test by running test_idle. So an IdelConf.set_testing, called from
test_xyz would be needed.
D. Other modules write other configuration files into .idlerc. When a file is
opened, it is added or moved to the top of recent-files.lst. When the debugger
is on and a file with breakpoints is run, the filename and breakpoint lines are
supposed to be saved to breakpoints.lst. (Withoug tests, this could have stop
working without me noticing.)
So disabling parser saves during tests is not enough. The other .idlerc saves
must also be blocked. Some sort of temporary directory is needed.
E. On the next issue after this, #30869, Victor Stinner requested that IDLE not
even create $HOME/.idlerc on buildbots.
F. There systems on which IDLE does not find a place to write .idlerc. IDLE
now quits. Any temporary directory would be better, at least as a choice. See
#8231 and #15862.
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue30868>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com