summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib
diff options
context:
space:
mode:
authorTerry Jan Reedy <tjreedy@udel.edu>2016-06-04 02:28:05 (GMT)
committerTerry Jan Reedy <tjreedy@udel.edu>2016-06-04 02:28:05 (GMT)
commit3d7281d2bdf0bbea105d73a12555366f29d6830e (patch)
tree804d939f00db48fb2fd64731a30da221aa518ef6 /Lib/idlelib
parent622b2f6ec90e071e9fe0e34a49a7b1218d4a7121 (diff)
parent75cbeb5dac8f4f57777f053eee257dbba5553d98 (diff)
downloadcpython-3d7281d2bdf0bbea105d73a12555366f29d6830e.zip
cpython-3d7281d2bdf0bbea105d73a12555366f29d6830e.tar.gz
cpython-3d7281d2bdf0bbea105d73a12555366f29d6830e.tar.bz2
Issue 20567: Revise idle_test/README.txt and some tests to match new advice.
Diffstat (limited to 'Lib/idlelib')
-rw-r--r--Lib/idlelib/idle_test/README.txt28
-rw-r--r--Lib/idlelib/idle_test/test_autocomplete.py3
-rw-r--r--Lib/idlelib/idle_test/test_autoexpand.py2
-rw-r--r--Lib/idlelib/idle_test/test_paragraph.py3
-rw-r--r--Lib/idlelib/idle_test/test_percolator.py4
-rw-r--r--Lib/idlelib/idle_test/test_redirector.py24
-rw-r--r--Lib/idlelib/idle_test/test_replace.py3
-rw-r--r--Lib/idlelib/idle_test/test_textview.py3
-rw-r--r--Lib/idlelib/idle_test/test_undo.py3
9 files changed, 39 insertions, 34 deletions
diff --git a/Lib/idlelib/idle_test/README.txt b/Lib/idlelib/idle_test/README.txt
index f74affc..39a19d0 100644
--- a/Lib/idlelib/idle_test/README.txt
+++ b/Lib/idlelib/idle_test/README.txt
@@ -56,40 +56,44 @@ requires('gui')
To guard a test class, put "requires('gui')" in its setUpClass function.
-To avoid interfering with other GUI tests, all GUI objects must be
-destroyed and deleted by the end of the test. Widgets, such as a Tk
-root, created in a setUpX function, should be destroyed in the
-corresponding tearDownX. Module and class widget attributes should also
-be deleted.
+To avoid interfering with other gui tests, all gui objects must be destroyed and
+deleted by the end of the test. The Tk root created in a setUpX function should
+be destroyed in the corresponding tearDownX and the module or class attribute
+deleted. Others widgets should descend from the single root and the attributes
+deleted BEFORE root is destroyed. See https://bugs.python.org/issue20567.
@classmethod
def setUpClass(cls):
requires('gui')
cls.root = tk.Tk()
+ cls.text = tk.Text(root)
@classmethod
def tearDownClass(cls):
+ del cls.text
cls.root.destroy()
del cls.root
Requires('gui') causes the test(s) it guards to be skipped if any of
-a few conditions are met:
-
+these conditions are met:
+
- The tests are being run by regrtest.py, and it was started without
enabling the "gui" resource with the "-u" command line option.
-
+
- The tests are being run on Windows by a service that is not allowed
to interact with the graphical environment.
-
+
+ - The tests are being run on Linux and X Windows is not available.
+
- The tests are being run on Mac OSX in a process that cannot make a
window manager connection.
-
+
- tkinter.Tk cannot be successfully instantiated for some reason.
-
+
- test.support.use_resources has been set by something other than
regrtest.py and does not contain "gui".
-
+
Tests of non-GUI operations should avoid creating tk widgets. Incidental
uses of tk variables and messageboxes can be replaced by the mock
classes in idle_test/mock_tk.py. The mock text handles some uses of the
diff --git a/Lib/idlelib/idle_test/test_autocomplete.py b/Lib/idlelib/idle_test/test_autocomplete.py
index 833737e..496a41d 100644
--- a/Lib/idlelib/idle_test/test_autocomplete.py
+++ b/Lib/idlelib/idle_test/test_autocomplete.py
@@ -33,9 +33,8 @@ class AutoCompleteTest(unittest.TestCase):
@classmethod
def tearDownClass(cls):
+ del cls.editor, cls.text
cls.root.destroy()
- del cls.text
- del cls.editor
del cls.root
def setUp(self):
diff --git a/Lib/idlelib/idle_test/test_autoexpand.py b/Lib/idlelib/idle_test/test_autoexpand.py
index 801976a..5d234dd 100644
--- a/Lib/idlelib/idle_test/test_autoexpand.py
+++ b/Lib/idlelib/idle_test/test_autoexpand.py
@@ -25,10 +25,10 @@ class AutoExpandTest(unittest.TestCase):
@classmethod
def tearDownClass(cls):
+ del cls.text, cls.auto_expand
if hasattr(cls, 'tk'):
cls.tk.destroy()
del cls.tk
- del cls.text, cls.auto_expand
def tearDown(self):
self.text.delete('1.0', 'end')
diff --git a/Lib/idlelib/idle_test/test_paragraph.py b/Lib/idlelib/idle_test/test_paragraph.py
index 6949bbb..4741eb8 100644
--- a/Lib/idlelib/idle_test/test_paragraph.py
+++ b/Lib/idlelib/idle_test/test_paragraph.py
@@ -276,10 +276,9 @@ class FormatEventTest(unittest.TestCase):
@classmethod
def tearDownClass(cls):
+ del cls.text, cls.formatter
cls.root.destroy()
del cls.root
- del cls.text
- del cls.formatter
def test_short_line(self):
self.text.insert('1.0', "Short line\n")
diff --git a/Lib/idlelib/idle_test/test_percolator.py b/Lib/idlelib/idle_test/test_percolator.py
index dc3ed49..573b9a1 100644
--- a/Lib/idlelib/idle_test/test_percolator.py
+++ b/Lib/idlelib/idle_test/test_percolator.py
@@ -40,9 +40,9 @@ class PercolatorTest(unittest.TestCase):
@classmethod
def tearDownClass(cls):
- cls.text.destroy()
+ del cls.text
cls.root.destroy()
- del cls.text, cls.root
+ del cls.root
def setUp(self):
self.percolator = Percolator(self.text)
diff --git a/Lib/idlelib/idle_test/test_redirector.py b/Lib/idlelib/idle_test/test_redirector.py
index 998fd65..df2b618 100644
--- a/Lib/idlelib/idle_test/test_redirector.py
+++ b/Lib/idlelib/idle_test/test_redirector.py
@@ -14,14 +14,14 @@ class InitCloseTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
requires('gui')
- cls.tk = Tk()
- cls.text = Text(cls.tk)
+ cls.root = Tk()
+ cls.text = Text(cls.root)
@classmethod
def tearDownClass(cls):
- cls.text.destroy()
- cls.tk.destroy()
- del cls.text, cls.tk
+ del cls.text
+ cls.root.destroy()
+ del cls.root
def test_init(self):
redir = WidgetRedirector(self.text)
@@ -43,14 +43,15 @@ class WidgetRedirectorTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
requires('gui')
- cls.tk = Tk()
- cls.text = Text(cls.tk)
+ cls.root = Tk()
+ cls.text = Text(cls.root)
@classmethod
def tearDownClass(cls):
cls.text.destroy()
- cls.tk.destroy()
- del cls.text, cls.tk
+ del cls.text
+ cls.root.destroy()
+ del cls.root
def setUp(self):
self.redir = WidgetRedirector(self.text)
@@ -108,14 +109,13 @@ class WidgetRedirectorTest(unittest.TestCase):
def test_command_dispatch(self):
# Test that .__init__ causes redirection of tk calls
# through redir.dispatch
- self.tk.call(self.text._w, 'insert', 'hello')
+ self.root.call(self.text._w, 'insert', 'hello')
self.assertEqual(self.func.args, ('hello',))
self.assertEqual(self.text.get('1.0', 'end'), '\n')
# Ensure that called through redir .dispatch and not through
# self.text.insert by having mock raise TclError.
self.func.__init__(TclError())
- self.assertEqual(self.tk.call(self.text._w, 'insert', 'boo'), '')
-
+ self.assertEqual(self.root.call(self.text._w, 'insert', 'boo'), '')
if __name__ == '__main__':
diff --git a/Lib/idlelib/idle_test/test_replace.py b/Lib/idlelib/idle_test/test_replace.py
index acaae84..a9f3e15 100644
--- a/Lib/idlelib/idle_test/test_replace.py
+++ b/Lib/idlelib/idle_test/test_replace.py
@@ -31,8 +31,9 @@ class ReplaceDialogTest(unittest.TestCase):
@classmethod
def tearDownClass(cls):
se.tkMessageBox = orig_mbox
+ del cls.text, cls.dialog, cls.engine
cls.root.destroy()
- del cls.text, cls.dialog, cls.engine, cls.root
+ del cls.root
def setUp(self):
self.text.insert('insert', 'This is a sample sTring')
diff --git a/Lib/idlelib/idle_test/test_textview.py b/Lib/idlelib/idle_test/test_textview.py
index bd0a46c..084928f 100644
--- a/Lib/idlelib/idle_test/test_textview.py
+++ b/Lib/idlelib/idle_test/test_textview.py
@@ -22,7 +22,8 @@ def setUpModule():
root = Tk()
def tearDownModule():
- global root
+ global root, TV
+ del TV
root.destroy() # pyflakes falsely sees root as undefined
del root
diff --git a/Lib/idlelib/idle_test/test_undo.py b/Lib/idlelib/idle_test/test_undo.py
index 9a167c9..80f1b80 100644
--- a/Lib/idlelib/idle_test/test_undo.py
+++ b/Lib/idlelib/idle_test/test_undo.py
@@ -23,8 +23,9 @@ class UndoDelegatorTest(unittest.TestCase):
@classmethod
def tearDownClass(cls):
cls.percolator.redir.close()
+ del cls.percolator, cls.text
cls.root.destroy()
- del cls.percolator, cls.text, cls.root
+ del cls.root
def setUp(self):
self.delegator = UndoDelegator()