summaryrefslogtreecommitdiff
path: root/Lib/idlelib/idle_test/test_query.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/idlelib/idle_test/test_query.py')
-rw-r--r--Lib/idlelib/idle_test/test_query.py105
1 files changed, 78 insertions, 27 deletions
diff --git a/Lib/idlelib/idle_test/test_query.py b/Lib/idlelib/idle_test/test_query.py
index c1c4a25cc5..3b444de15d 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__':