diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2020-03-09 23:45:19 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-09 23:45:19 (GMT) |
commit | cadfe52a006abb46ea0948c6ae2e006064b4a091 (patch) | |
tree | 046e81a90a6663a3eb3ae4612a9825464077e6a8 /Lib/idlelib/idle_test/test_query.py | |
parent | 5854d451cb35ac38bc07b95afeb077e8a35d5c7d (diff) | |
download | cpython-cadfe52a006abb46ea0948c6ae2e006064b4a091.zip cpython-cadfe52a006abb46ea0948c6ae2e006064b4a091.tar.gz cpython-cadfe52a006abb46ea0948c6ae2e006064b4a091.tar.bz2 |
bpo-27115: Use Query subclass for IDLE editor Goto (GH-18871)
Replace tkinter tkSimpleDialog.askinteger with a standard IDLE query dialog.
The new box checks for positivity before returning.
(cherry picked from commit 363fab83b8a0e6d924c7a7c577feec6a2812bb8c)
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Diffstat (limited to 'Lib/idlelib/idle_test/test_query.py')
-rw-r--r-- | Lib/idlelib/idle_test/test_query.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/Lib/idlelib/idle_test/test_query.py b/Lib/idlelib/idle_test/test_query.py index f957585..6d026cb 100644 --- a/Lib/idlelib/idle_test/test_query.py +++ b/Lib/idlelib/idle_test/test_query.py @@ -138,6 +138,33 @@ class ModuleNameTest(unittest.TestCase): self.assertEqual(dialog.entry_error['text'], '') +class GotoTest(unittest.TestCase): + "Test Goto subclass of Query." + + class Dummy_ModuleName: + entry_ok = query.Goto.entry_ok # Function being tested. + 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_bogus_goto(self): + dialog = self.Dummy_ModuleName('a') + self.assertEqual(dialog.entry_ok(), None) + self.assertIn('not a base 10 integer', dialog.entry_error['text']) + + def test_bad_goto(self): + dialog = self.Dummy_ModuleName('0') + self.assertEqual(dialog.entry_ok(), None) + self.assertIn('not a positive integer', dialog.entry_error['text']) + + def test_good_goto(self): + dialog = self.Dummy_ModuleName('1') + self.assertEqual(dialog.entry_ok(), 1) + self.assertEqual(dialog.entry_error['text'], '') + + # 3 HelpSource test classes each test one method. class HelpsourceBrowsefileTest(unittest.TestCase): @@ -363,6 +390,22 @@ class ModulenameGuiTest(unittest.TestCase): root.destroy() +class GotoGuiTest(unittest.TestCase): + + @classmethod + def setUpClass(cls): + requires('gui') + + def test_click_module_name(self): + root = Tk() + root.withdraw() + dialog = query.Goto(root, 'T', 't', _utest=True) + dialog.entry.insert(0, '22') + dialog.button_ok.invoke() + self.assertEqual(dialog.result, 22) + root.destroy() + + class HelpsourceGuiTest(unittest.TestCase): @classmethod |