-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
bpo-5680: IDLE: Customize running a module. #13763
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ffc22b8
36f7771
69cf1b6
dbdd580
f1e7c61
286e4c6
03e0f59
22bb3a2
35f0379
09f37d7
8d98622
8c8bb4d
845178b
31416fd
fbfca23
4da67c3
307ac6a
4a64274
18177da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 Dummy_Query: | |
| 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 @@ def test_good_module_name(self): | |
| 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 @@ def test_entry_ok_helpsource(self): | |
| 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 @@ def test_click_section_name(self): | |
| 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 @@ def test_click_module_name(self): | |
| 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 @@ def test_click_help_source(self): | |
| 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)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The should probably be a call to
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe invoke blocks until done. I have run this test at least 20 times without issue. event_generate is different (and flakey). There are 55 invokes in idle tests and my spot check of nearly 10 showed none followed by update. And I know of no resulting failures. |
||
| root.destroy() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest cleaning up using root = Tk()
def cleanup():
root.update()
root.destroy()
self.addCleanup(cleanup)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I far prefer explicit calls. Update is not generally needed. update_idletasks is more often needed. I have not seen any of the tclerror messages that so indicate. |
||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.