diff options
author | Terry Jan Reedy <tjreedy@udel.edu> | 2016-07-10 17:46:34 (GMT) |
---|---|---|
committer | Terry Jan Reedy <tjreedy@udel.edu> | 2016-07-10 17:46:34 (GMT) |
commit | 9bdb1edf35a5ee96f89973f55c52bb7da86dbd9e (patch) | |
tree | c1d21422fff3227e6737fc69c67593905a62da17 /Lib/idlelib/idle_test/test_config.py | |
parent | ce85acff3a28cd4c3ded487bfbc8c8ac5462d4e4 (diff) | |
download | cpython-9bdb1edf35a5ee96f89973f55c52bb7da86dbd9e.zip cpython-9bdb1edf35a5ee96f89973f55c52bb7da86dbd9e.tar.gz cpython-9bdb1edf35a5ee96f89973f55c52bb7da86dbd9e.tar.bz2 |
Issue #27173: Add 'IDLE Modern Unix' to the built-in key sets.
Make the default key set depend on the platform.
Add tests for changes to the config module.
Diffstat (limited to 'Lib/idlelib/idle_test/test_config.py')
-rw-r--r-- | Lib/idlelib/idle_test/test_config.py | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/Lib/idlelib/idle_test/test_config.py b/Lib/idlelib/idle_test/test_config.py new file mode 100644 index 0000000..bb7732c --- /dev/null +++ b/Lib/idlelib/idle_test/test_config.py @@ -0,0 +1,98 @@ +'''Test idlelib.config. + +Much is tested by opening config dialog live or in test_configdialog. +Coverage: 27% +''' +from sys import modules +from test.support import captured_stderr +from tkinter import Tk +import unittest +from idlelib import config + +# Tests should not depend on fortuitous user configurations. +# They must not affect actual user .cfg files. +# Replace user parsers with empty parsers that cannot be saved. + +idleConf = config.idleConf +usercfg = idleConf.userCfg +testcfg = {} +usermain = testcfg['main'] = config.IdleUserConfParser('') # filename +userhigh = testcfg['highlight'] = config.IdleUserConfParser('') +userkeys = testcfg['keys'] = config.IdleUserConfParser('') + +def setUpModule(): + idleConf.userCfg = testcfg + +def tearDownModule(): + idleConf.userCfg = testcfg + + +class CurrentColorKeysTest(unittest.TestCase): + """Test correct scenarios for colorkeys and wrap functions. + + The 5 correct patterns are possible results of config dialog. + """ + colorkeys = idleConf.current_colors_and_keys + + def test_old_default(self): + # name2 must be blank + usermain.read_string(''' + [Theme] + default= 1 + ''') + self.assertEqual(self.colorkeys('Theme'), 'IDLE Classic') + usermain['Theme']['name'] = 'IDLE New' + self.assertEqual(self.colorkeys('Theme'), 'IDLE New') + usermain['Theme']['name'] = 'non-default' # error + self.assertEqual(self.colorkeys('Theme'), 'IDLE Classic') + usermain.remove_section('Theme') + + def test_new_default(self): + # name2 overrides name + usermain.read_string(''' + [Theme] + default= 1 + name= IDLE New + name2= IDLE Dark + ''') + self.assertEqual(self.colorkeys('Theme'), 'IDLE Dark') + usermain['Theme']['name2'] = 'non-default' # error + self.assertEqual(self.colorkeys('Theme'), 'IDLE Classic') + usermain.remove_section('Theme') + + def test_user_override(self): + # name2 does not matter + usermain.read_string(''' + [Theme] + default= 0 + name= Custom Dark + ''') # error until set userhigh + self.assertEqual(self.colorkeys('Theme'), 'IDLE Classic') + userhigh.read_string('[Custom Dark]\na=b') + self.assertEqual(self.colorkeys('Theme'), 'Custom Dark') + usermain['Theme']['name2'] = 'IDLE Dark' + self.assertEqual(self.colorkeys('Theme'), 'Custom Dark') + usermain.remove_section('Theme') + userhigh.remove_section('Custom Dark') + + +class WarningTest(unittest.TestCase): + + def test_warn(self): + Equal = self.assertEqual + config._warned = set() + with captured_stderr() as stderr: + config._warn('warning', 'key') + Equal(config._warned, {('warning','key')}) + Equal(stderr.getvalue(), 'warning'+'\n') + with captured_stderr() as stderr: + config._warn('warning', 'key') + Equal(stderr.getvalue(), '') + with captured_stderr() as stderr: + config._warn('warn2', 'yek') + Equal(config._warned, {('warning','key'), ('warn2','yek')}) + Equal(stderr.getvalue(), 'warn2'+'\n') + + +if __name__ == '__main__': + unittest.main(verbosity=2) |