summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib/idle_test
diff options
context:
space:
mode:
authorTerry Jan Reedy <tjreedy@udel.edu>2016-06-27 02:05:10 (GMT)
committerTerry Jan Reedy <tjreedy@udel.edu>2016-06-27 02:05:10 (GMT)
commit68a53c5d3964ae2f4658491822f83cf36510f39b (patch)
tree6124e372ec80523d1718af3882c1b811febf67c5 /Lib/idlelib/idle_test
parent754a5c1a1d8cf0b3d61fb4552c57350b0d849089 (diff)
downloadcpython-68a53c5d3964ae2f4658491822f83cf36510f39b.zip
cpython-68a53c5d3964ae2f4658491822f83cf36510f39b.tar.gz
cpython-68a53c5d3964ae2f4658491822f83cf36510f39b.tar.bz2
Issue #27380: IDLE: add base Query dialog, with ttk widgets and subclass
SectionName. These split class GetCfgSectionNameDialog from configSectionNameDialog.py, temporarily renamed config_sec.py in 3.7.9a2. More Query subclasses are planned.
Diffstat (limited to 'Lib/idlelib/idle_test')
-rw-r--r--Lib/idlelib/idle_test/htest.py23
-rw-r--r--Lib/idlelib/idle_test/test_config_sec.py75
-rw-r--r--Lib/idlelib/idle_test/test_query.py164
3 files changed, 175 insertions, 87 deletions
diff --git a/Lib/idlelib/idle_test/htest.py b/Lib/idlelib/idle_test/htest.py
index 701f4d9..d809d30 100644
--- a/Lib/idlelib/idle_test/htest.py
+++ b/Lib/idlelib/idle_test/htest.py
@@ -137,18 +137,6 @@ _editor_window_spec = {
"Best to close editor first."
}
-GetCfgSectionNameDialog_spec = {
- 'file': 'config_sec',
- 'kwds': {'title':'Get Name',
- 'message':'Enter something',
- 'used_names': {'abc'},
- '_htest': True},
- 'msg': "After the text entered with [Ok] is stripped, <nothing>, "
- "'abc', or more that 30 chars are errors.\n"
- "Close 'Get Name' with a valid entry (printed to Shell), "
- "[Cancel], or [X]",
- }
-
GetHelpSourceDialog_spec = {
'file': 'config_help',
'kwds': {'title': 'Get helpsource',
@@ -245,6 +233,17 @@ _percolator_spec = {
"Test for actions like text entry, and removal."
}
+Query_spec = {
+ 'file': 'query',
+ 'kwds': {'title':'Query',
+ 'message':'Enter something',
+ '_htest': True},
+ 'msg': "Enter with <Return> or [Ok]. Print valid entry to Shell\n"
+ "Blank line, after stripping, is ignored\n"
+ "Close dialog with valid entry, [Cancel] or [X]",
+ }
+
+
_replace_dialog_spec = {
'file': 'replace',
'kwds': {},
diff --git a/Lib/idlelib/idle_test/test_config_sec.py b/Lib/idlelib/idle_test/test_config_sec.py
deleted file mode 100644
index a98b484..0000000
--- a/Lib/idlelib/idle_test/test_config_sec.py
+++ /dev/null
@@ -1,75 +0,0 @@
-"""Unit tests for idlelib.config_sec"""
-import unittest
-from idlelib.idle_test.mock_tk import Var, Mbox
-from idlelib import config_sec as name_dialog_module
-
-name_dialog = name_dialog_module.GetCfgSectionNameDialog
-
-class Dummy_name_dialog:
- # Mock for testing the following methods of name_dialog
- name_ok = name_dialog.name_ok
- Ok = name_dialog.Ok
- Cancel = name_dialog.Cancel
- # Attributes, constant or variable, needed for tests
- used_names = ['used']
- name = Var()
- result = None
- destroyed = False
- def destroy(self):
- self.destroyed = True
-
-# name_ok calls Mbox.showerror if name is not ok
-orig_mbox = name_dialog_module.tkMessageBox
-showerror = Mbox.showerror
-
-class ConfigNameTest(unittest.TestCase):
- dialog = Dummy_name_dialog()
-
- @classmethod
- def setUpClass(cls):
- name_dialog_module.tkMessageBox = Mbox
-
- @classmethod
- def tearDownClass(cls):
- name_dialog_module.tkMessageBox = orig_mbox
-
- def test_blank_name(self):
- self.dialog.name.set(' ')
- self.assertEqual(self.dialog.name_ok(), '')
- self.assertEqual(showerror.title, 'Name Error')
- self.assertIn('No', showerror.message)
-
- def test_used_name(self):
- self.dialog.name.set('used')
- self.assertEqual(self.dialog.name_ok(), '')
- self.assertEqual(showerror.title, 'Name Error')
- self.assertIn('use', showerror.message)
-
- def test_long_name(self):
- self.dialog.name.set('good'*8)
- self.assertEqual(self.dialog.name_ok(), '')
- self.assertEqual(showerror.title, 'Name Error')
- self.assertIn('too long', showerror.message)
-
- def test_good_name(self):
- self.dialog.name.set(' good ')
- showerror.title = 'No Error' # should not be called
- self.assertEqual(self.dialog.name_ok(), 'good')
- self.assertEqual(showerror.title, 'No Error')
-
- def test_ok(self):
- self.dialog.destroyed = False
- self.dialog.name.set('good')
- self.dialog.Ok()
- self.assertEqual(self.dialog.result, 'good')
- self.assertTrue(self.dialog.destroyed)
-
- def test_cancel(self):
- self.dialog.destroyed = False
- self.dialog.Cancel()
- self.assertEqual(self.dialog.result, '')
- self.assertTrue(self.dialog.destroyed)
-
-
-if __name__ == '__main__':
- unittest.main(verbosity=2, exit=False)
diff --git a/Lib/idlelib/idle_test/test_query.py b/Lib/idlelib/idle_test/test_query.py
new file mode 100644
index 0000000..e9c4bd4
--- /dev/null
+++ b/Lib/idlelib/idle_test/test_query.py
@@ -0,0 +1,164 @@
+"""Test idlelib.query.
+
+Coverage: 100%.
+"""
+from test.support import requires
+from tkinter import Tk
+import unittest
+from unittest import mock
+from idlelib.idle_test.mock_tk import Var, Mbox_func
+from idlelib import query
+Query, SectionName = query.Query, query.SectionName
+
+class Dummy_Query:
+ # Mock for testing the following methods Query
+ entry_ok = Query.entry_ok
+ ok = Query.ok
+ cancel = Query.cancel
+ # Attributes, constant or variable, needed for tests
+ entry = Var()
+ result = None
+ destroyed = False
+ def destroy(self):
+ self.destroyed = True
+
+# entry_ok calls modal messagebox.showerror if entry is not ok.
+# Mock showerrer returns, so don't need to click to continue.
+orig_showerror = query.showerror
+showerror = Mbox_func() # Instance has __call__ method.
+
+def setUpModule():
+ query.showerror = showerror
+
+def tearDownModule():
+ query.showerror = orig_showerror
+
+
+class QueryTest(unittest.TestCase):
+ dialog = Dummy_Query()
+
+ def setUp(self):
+ showerror.title = None
+ self.dialog.result = None
+ self.dialog.destroyed = False
+
+ def test_blank_entry(self):
+ dialog = self.dialog
+ Equal = self.assertEqual
+ dialog.entry.set(' ')
+ Equal(dialog.entry_ok(), '')
+ Equal((dialog.result, dialog.destroyed), (None, False))
+ Equal(showerror.title, 'Entry Error')
+ self.assertIn('Blank', showerror.message)
+
+ def test_good_entry(self):
+ dialog = self.dialog
+ Equal = self.assertEqual
+ dialog.entry.set(' good ')
+ Equal(dialog.entry_ok(), 'good')
+ Equal((dialog.result, dialog.destroyed), (None, False))
+ Equal(showerror.title, None)
+
+ def test_ok(self):
+ dialog = self.dialog
+ Equal = self.assertEqual
+ dialog.entry.set('good')
+ Equal(dialog.ok(), None)
+ Equal((dialog.result, dialog.destroyed), ('good', True))
+
+ def test_cancel(self):
+ dialog = self.dialog
+ Equal = self.assertEqual
+ Equal(self.dialog.cancel(), None)
+ Equal((dialog.result, dialog.destroyed), (None, True))
+
+
+class Dummy_SectionName:
+ # Mock for testing the following method of Section_Name
+ entry_ok = SectionName.entry_ok
+ # Attributes, constant or variable, needed for tests
+ used_names = ['used']
+ entry = Var()
+
+class SectionNameTest(unittest.TestCase):
+ dialog = Dummy_SectionName()
+
+
+ def setUp(self):
+ showerror.title = None
+
+ def test_blank_name(self):
+ dialog = self.dialog
+ Equal = self.assertEqual
+ dialog.entry.set(' ')
+ Equal(dialog.entry_ok(), '')
+ Equal(showerror.title, 'Name Error')
+ self.assertIn('No', showerror.message)
+
+ def test_used_name(self):
+ dialog = self.dialog
+ Equal = self.assertEqual
+ dialog.entry.set('used')
+ Equal(self.dialog.entry_ok(), '')
+ Equal(showerror.title, 'Name Error')
+ self.assertIn('use', showerror.message)
+
+ def test_long_name(self):
+ dialog = self.dialog
+ Equal = self.assertEqual
+ dialog.entry.set('good'*8)
+ Equal(self.dialog.entry_ok(), '')
+ Equal(showerror.title, 'Name Error')
+ self.assertIn('too long', showerror.message)
+
+ def test_good_entry(self):
+ dialog = self.dialog
+ Equal = self.assertEqual
+ dialog.entry.set(' good ')
+ Equal(dialog.entry_ok(), 'good')
+ Equal(showerror.title, None)
+
+
+class QueryGuiTest(unittest.TestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ requires('gui')
+ cls.root = Tk()
+ cls.dialog = Query(cls.root, 'TEST', 'test', _utest=True)
+ cls.dialog.destroy = mock.Mock()
+
+ @classmethod
+ def tearDownClass(cls):
+ del cls.dialog
+ cls.root.destroy()
+ del cls.root
+
+ def setUp(self):
+ self.dialog.entry.delete(0, 'end')
+ self.dialog.result = None
+ self.dialog.destroy.reset_mock()
+
+ def test_click_ok(self):
+ dialog = self.dialog
+ dialog.entry.insert(0, 'abc')
+ dialog.button_ok.invoke()
+ self.assertEqual(dialog.result, 'abc')
+ self.assertTrue(dialog.destroy.called)
+
+ def test_click_blank(self):
+ dialog = self.dialog
+ dialog.button_ok.invoke()
+ self.assertEqual(dialog.result, None)
+ self.assertFalse(dialog.destroy.called)
+
+ def test_click_cancel(self):
+ dialog = self.dialog
+ dialog.entry.insert(0, 'abc')
+ dialog.button_cancel.invoke()
+ self.assertEqual(dialog.result, None)
+ self.assertTrue(dialog.destroy.called)
+
+
+if __name__ == '__main__':
+ unittest.main(verbosity=2, exit=False)