summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib/idle_test
diff options
context:
space:
mode:
authorTerry Jan Reedy <tjreedy@udel.edu>2016-06-08 22:09:22 (GMT)
committerTerry Jan Reedy <tjreedy@udel.edu>2016-06-08 22:09:22 (GMT)
commitfb51e6528947f86f4c64a409966deb8cb1267083 (patch)
tree4b7575beb0980703a87d1a609a42e4c26e08d69e /Lib/idlelib/idle_test
parent47791df97cb36d5abf4ef7e465e7e654690f1cbd (diff)
downloadcpython-fb51e6528947f86f4c64a409966deb8cb1267083.zip
cpython-fb51e6528947f86f4c64a409966deb8cb1267083.tar.gz
cpython-fb51e6528947f86f4c64a409966deb8cb1267083.tar.bz2
Issue #27239: idlelib.macosx.isXyzTk functions initialize as needed.
Diffstat (limited to 'Lib/idlelib/idle_test')
-rw-r--r--Lib/idlelib/idle_test/htest.py4
-rw-r--r--Lib/idlelib/idle_test/test_configdialog.py2
-rw-r--r--Lib/idlelib/idle_test/test_macosx.py69
3 files changed, 71 insertions, 4 deletions
diff --git a/Lib/idlelib/idle_test/htest.py b/Lib/idlelib/idle_test/htest.py
index 4675645..686ccc5 100644
--- a/Lib/idlelib/idle_test/htest.py
+++ b/Lib/idlelib/idle_test/htest.py
@@ -66,7 +66,7 @@ outwin.OutputWindow (indirectly being tested with grep test)
'''
from importlib import import_module
-from idlelib.macosx import _initializeTkVariantTests
+from idlelib.macosx import _init_tk_type
import tkinter as tk
AboutDialog_spec = {
@@ -337,7 +337,7 @@ def run(*tests):
root = tk.Tk()
root.title('IDLE htest')
root.resizable(0, 0)
- _initializeTkVariantTests(root)
+ _init_tk_type(root)
# a scrollable Label like constant width text widget.
frameLabel = tk.Frame(root, padx=10)
diff --git a/Lib/idlelib/idle_test/test_configdialog.py b/Lib/idlelib/idle_test/test_configdialog.py
index 4f5d216..1801a7d 100644
--- a/Lib/idlelib/idle_test/test_configdialog.py
+++ b/Lib/idlelib/idle_test/test_configdialog.py
@@ -8,14 +8,12 @@ from test.support import requires
requires('gui')
from tkinter import Tk
import unittest
-from idlelib import macosx
class ConfigDialogTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.root = Tk()
- macosx._initializeTkVariantTests(cls.root)
@classmethod
def tearDownClass(cls):
diff --git a/Lib/idlelib/idle_test/test_macosx.py b/Lib/idlelib/idle_test/test_macosx.py
new file mode 100644
index 0000000..0f90fb6
--- /dev/null
+++ b/Lib/idlelib/idle_test/test_macosx.py
@@ -0,0 +1,69 @@
+'''Test idlelib.macosx.py
+'''
+from idlelib import macosx
+from test.support import requires
+import sys
+import tkinter as tk
+import unittest
+import unittest.mock as mock
+
+MAC = sys.platform == 'darwin'
+mactypes = {'carbon', 'cocoa', 'xquartz'}
+nontypes = {'other'}
+alltypes = mactypes | nontypes
+
+
+class InitTktypeTest(unittest.TestCase):
+ "Test _init_tk_type."
+
+ @classmethod
+ def setUpClass(cls):
+ requires('gui')
+ cls.root = tk.Tk()
+
+ @classmethod
+ def tearDownClass(cls):
+ cls.root.update_idletasks()
+ cls.root.destroy()
+ del cls.root
+
+ def test_init_sets_tktype(self):
+ "Test that _init_tk_type sets _tk_type according to platform."
+ for root in (None, self.root):
+ with self.subTest(root=root):
+ macosx._tk_type == None
+ macosx._init_tk_type(root)
+ self.assertIn(macosx._tk_type,
+ mactypes if MAC else nontypes)
+
+
+class IsTypeTkTest(unittest.TestCase):
+ "Test each of the four isTypeTk predecates."
+ isfuncs = ((macosx.isAquaTk, ('carbon', 'cocoa')),
+ (macosx.isCarbonTk, ('carbon')),
+ (macosx.isCocoaTk, ('cocoa')),
+ (macosx.isXQuartz, ('xquartz')),
+ )
+
+ @mock.patch('idlelib.macosx._init_tk_type')
+ def test_is_calls_init(self, mockinit):
+ "Test that each isTypeTk calls _init_tk_type when _tk_type is None."
+ macosx._tk_type = None
+ for func, whentrue in self.isfuncs:
+ with self.subTest(func=func):
+ func()
+ self.assertTrue(mockinit.called)
+ mockinit.reset_mock()
+
+ def test_isfuncs(self):
+ "Test that each isTypeTk return correct bool."
+ for func, whentrue in self.isfuncs:
+ for tktype in alltypes:
+ with self.subTest(func=func, whentrue=whentrue, tktype=tktype):
+ macosx._tk_type = tktype
+ (self.assertTrue if tktype in whentrue else self.assertFalse)\
+ (func())
+
+
+if __name__ == '__main__':
+ unittest.main(verbosity=2)