diff options
author | Cheryl Sabella <cheryl.sabella@gmail.com> | 2019-06-18 02:24:10 (GMT) |
---|---|---|
committer | Terry Jan Reedy <tjreedy@udel.edu> | 2019-06-18 02:24:10 (GMT) |
commit | 201bc2d18b60adb05810d2a6ab396047bc527088 (patch) | |
tree | 1514619817f5282089691111547166b16cd4af56 /Lib/idlelib/idle_test | |
parent | 7fb3190bcf9872dca3d83a7f9e3e65cbce8be9ed (diff) | |
download | cpython-201bc2d18b60adb05810d2a6ab396047bc527088.zip cpython-201bc2d18b60adb05810d2a6ab396047bc527088.tar.gz cpython-201bc2d18b60adb05810d2a6ab396047bc527088.tar.bz2 |
bpo-5680: IDLE: Customize running a module (GH-13763)
The initialize options are 1) add command line options, which are appended to sys.argv as if passed on a real command line, and 2) skip the shell restart. The customization dialog is accessed by a new entry on the Run menu.
Diffstat (limited to 'Lib/idlelib/idle_test')
-rw-r--r-- | Lib/idlelib/idle_test/htest.py | 9 | ||||
-rw-r--r-- | Lib/idlelib/idle_test/test_query.py | 105 |
2 files changed, 87 insertions, 27 deletions
diff --git a/Lib/idlelib/idle_test/htest.py b/Lib/idlelib/idle_test/htest.py index 6e3398e..6ce8cc8 100644 --- a/Lib/idlelib/idle_test/htest.py +++ b/Lib/idlelib/idle_test/htest.py @@ -108,6 +108,15 @@ _color_delegator_spec = { "The default color scheme is in idlelib/config-highlight.def" } +CustomRun_spec = { + 'file': 'query', + 'kwds': {'title': 'Custom Run Args', + '_htest': True}, + 'msg': "Enter with <Return> or [Ok]. Print valid entry to Shell\n" + "Arguments are parsed into a list\n" + "Close dialog with valid entry, <Escape>, [Cancel], [X]" + } + ConfigDialog_spec = { 'file': 'configdialog', 'kwds': {'title': 'ConfigDialogTest', diff --git a/Lib/idlelib/idle_test/test_query.py b/Lib/idlelib/idle_test/test_query.py index c1c4a25..3b444de 100644 --- a/Lib/idlelib/idle_test/test_query.py +++ b/Lib/idlelib/idle_test/test_query.py @@ -1,4 +1,4 @@ -"""Test query, coverage 91%). +"""Test query, coverage 93%). Non-gui tests for Query, SectionName, ModuleName, and HelpSource use dummy versions that extract the non-gui methods and add other needed @@ -30,11 +30,9 @@ class QueryTest(unittest.TestCase): ok = query.Query.ok cancel = query.Query.cancel # Add attributes and initialization needed for tests. - entry = Var() - entry_error = {} def __init__(self, dummy_entry): - self.entry.set(dummy_entry) - self.entry_error['text'] = '' + self.entry = Var(value=dummy_entry) + self.entry_error = {'text': ''} self.result = None self.destroyed = False def showerror(self, message): @@ -80,11 +78,9 @@ class SectionNameTest(unittest.TestCase): class Dummy_SectionName: entry_ok = query.SectionName.entry_ok # Function being tested. used_names = ['used'] - entry = Var() - entry_error = {} def __init__(self, dummy_entry): - self.entry.set(dummy_entry) - self.entry_error['text'] = '' + self.entry = Var(value=dummy_entry) + self.entry_error = {'text': ''} def showerror(self, message): self.entry_error['text'] = message @@ -115,11 +111,9 @@ class ModuleNameTest(unittest.TestCase): class Dummy_ModuleName: entry_ok = query.ModuleName.entry_ok # Function being tested. text0 = '' - entry = Var() - entry_error = {} def __init__(self, dummy_entry): - self.entry.set(dummy_entry) - self.entry_error['text'] = '' + self.entry = Var(value=dummy_entry) + self.entry_error = {'text': ''} def showerror(self, message): self.entry_error['text'] = message @@ -144,9 +138,7 @@ class ModuleNameTest(unittest.TestCase): self.assertEqual(dialog.entry_error['text'], '') -# 3 HelpSource test classes each test one function. - -orig_platform = query.platform +# 3 HelpSource test classes each test one method. class HelpsourceBrowsefileTest(unittest.TestCase): "Test browse_file method of ModuleName subclass of Query." @@ -178,17 +170,16 @@ class HelpsourcePathokTest(unittest.TestCase): class Dummy_HelpSource: path_ok = query.HelpSource.path_ok - path = Var() - path_error = {} def __init__(self, dummy_path): - self.path.set(dummy_path) - self.path_error['text'] = '' + self.path = Var(value=dummy_path) + self.path_error = {'text': ''} def showerror(self, message, widget=None): self.path_error['text'] = message + orig_platform = query.platform # Set in test_path_ok_file. @classmethod def tearDownClass(cls): - query.platform = orig_platform + query.platform = cls.orig_platform def test_path_ok_blank(self): dialog = self.Dummy_HelpSource(' ') @@ -242,6 +233,56 @@ class HelpsourceEntryokTest(unittest.TestCase): self.assertEqual(dialog.entry_ok(), result) +# 2 CustomRun test classes each test one method. + +class CustomRunCLIargsokTest(unittest.TestCase): + "Test cli_ok method of the CustomRun subclass of Query." + + class Dummy_CustomRun: + cli_args_ok = query.CustomRun.cli_args_ok + def __init__(self, dummy_entry): + self.entry = Var(value=dummy_entry) + self.entry_error = {'text': ''} + def showerror(self, message): + self.entry_error['text'] = message + + def test_blank_args(self): + dialog = self.Dummy_CustomRun(' ') + self.assertEqual(dialog.cli_args_ok(), []) + + def test_invalid_args(self): + dialog = self.Dummy_CustomRun("'no-closing-quote") + self.assertEqual(dialog.cli_args_ok(), None) + self.assertIn('No closing', dialog.entry_error['text']) + + def test_good_args(self): + args = ['-n', '10', '--verbose', '-p', '/path', '--name'] + dialog = self.Dummy_CustomRun(' '.join(args) + ' "my name"') + self.assertEqual(dialog.cli_args_ok(), args + ["my name"]) + self.assertEqual(dialog.entry_error['text'], '') + + +class CustomRunEntryokTest(unittest.TestCase): + "Test entry_ok method of the CustomRun subclass of Query." + + class Dummy_CustomRun: + entry_ok = query.CustomRun.entry_ok + entry_error = {} + restartvar = Var() + def cli_args_ok(self): + return self.cli_args + + def test_entry_ok_customrun(self): + dialog = self.Dummy_CustomRun() + for restart in {True, False}: + dialog.restartvar.set(restart) + for cli_args, result in ((None, None), + (['my arg'], (['my arg'], restart))): + with self.subTest(restart=restart, cli_args=cli_args): + dialog.cli_args = cli_args + self.assertEqual(dialog.entry_ok(), result) + + # GUI TESTS class QueryGuiTest(unittest.TestCase): @@ -302,9 +343,7 @@ class SectionnameGuiTest(unittest.TestCase): dialog.entry.insert(0, 'okay') dialog.button_ok.invoke() self.assertEqual(dialog.result, 'okay') - del dialog root.destroy() - del root class ModulenameGuiTest(unittest.TestCase): @@ -321,9 +360,7 @@ class ModulenameGuiTest(unittest.TestCase): self.assertEqual(dialog.entry.get(), 'idlelib') dialog.button_ok.invoke() self.assertTrue(dialog.result.endswith('__init__.py')) - del dialog root.destroy() - del root class HelpsourceGuiTest(unittest.TestCase): @@ -343,9 +380,23 @@ class HelpsourceGuiTest(unittest.TestCase): dialog.button_ok.invoke() prefix = "file://" if sys.platform == 'darwin' else '' Equal(dialog.result, ('__test__', prefix + __file__)) - del dialog root.destroy() - del root + + +class CustomRunGuiTest(unittest.TestCase): + + @classmethod + def setUpClass(cls): + requires('gui') + + def test_click_args(self): + root = Tk() + root.withdraw() + dialog = query.CustomRun(root, 'Title', _utest=True) + dialog.entry.insert(0, 'okay') + dialog.button_ok.invoke() + self.assertEqual(dialog.result, (['okay'], True)) + root.destroy() if __name__ == '__main__': |