[Python-checkins] cpython: Issue #27239: Continue refactoring idlelib.macosx and adding macosx tests.

terry.reedy python-checkins at python.org
Sun Jun 12 15:49:42 EDT 2016


https://hg.python.org/cpython/rev/d8a2b6efdd4a
changeset:   101959:d8a2b6efdd4a
user:        Terry Jan Reedy <tjreedy at udel.edu>
date:        Sun Jun 12 15:49:20 2016 -0400
summary:
  Issue #27239: Continue refactoring idlelib.macosx and adding macosx tests.

files:
  Lib/idlelib/idle_test/htest.py       |   2 -
  Lib/idlelib/idle_test/test_macosx.py |  42 +++++++++++++--
  Lib/idlelib/macosx.py                |  25 ++++++--
  3 files changed, 53 insertions(+), 16 deletions(-)


diff --git a/Lib/idlelib/idle_test/htest.py b/Lib/idlelib/idle_test/htest.py
--- a/Lib/idlelib/idle_test/htest.py
+++ b/Lib/idlelib/idle_test/htest.py
@@ -66,7 +66,6 @@
 '''
 
 from importlib import import_module
-from idlelib.macosx import _init_tk_type
 import tkinter as tk
 from tkinter.ttk import Scrollbar
 
@@ -338,7 +337,6 @@
     root = tk.Tk()
     root.title('IDLE htest')
     root.resizable(0, 0)
-    _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_macosx.py b/Lib/idlelib/idle_test/test_macosx.py
--- a/Lib/idlelib/idle_test/test_macosx.py
+++ b/Lib/idlelib/idle_test/test_macosx.py
@@ -1,4 +1,6 @@
-'''Test idlelib.macosx.py
+'''Test idlelib.macosx.py.
+
+Coverage: 71% on Windows.
 '''
 from idlelib import macosx
 from test.support import requires
@@ -6,8 +8,8 @@
 import tkinter as tk
 import unittest
 import unittest.mock as mock
+from idlelib.filelist import FileList
 
-MAC = sys.platform == 'darwin'
 mactypes = {'carbon', 'cocoa', 'xquartz'}
 nontypes = {'other'}
 alltypes = mactypes | nontypes
@@ -20,21 +22,23 @@
     def setUpClass(cls):
         requires('gui')
         cls.root = tk.Tk()
+        cls.orig_platform = macosx.platform
 
     @classmethod
     def tearDownClass(cls):
         cls.root.update_idletasks()
         cls.root.destroy()
         del cls.root
+        macosx.platform = cls.orig_platform
 
     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):
+        for platform, types in ('darwin', alltypes), ('other', nontypes):
+            with self.subTest(platform=platform):
+                macosx.platform = platform
                 macosx._tk_type == None
-                macosx._init_tk_type(root)
-                self.assertIn(macosx._tk_type,
-                              mactypes if MAC else nontypes)
+                macosx._init_tk_type()
+                self.assertIn(macosx._tk_type, types)
 
 
 class IsTypeTkTest(unittest.TestCase):
@@ -65,5 +69,29 @@
                                      (func())
 
 
+class SetupTest(unittest.TestCase):
+    "Test setupApp."
+
+    @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_setupapp(self):
+        "Call setupApp with each possible graphics type."
+        root = self.root
+        flist = FileList(root)
+        for tktype in alltypes:
+            with self.subTest(tktype=tktype):
+                macosx._tk_type = tktype
+                macosx.setupApp(root, flist)
+
+
 if __name__ == '__main__':
     unittest.main(verbosity=2)
diff --git a/Lib/idlelib/macosx.py b/Lib/idlelib/macosx.py
--- a/Lib/idlelib/macosx.py
+++ b/Lib/idlelib/macosx.py
@@ -1,20 +1,24 @@
 """
 A number of functions that enhance IDLE on Mac OSX.
 """
-import sys
+from sys import platform  # Used in _init_tk_type, changed by test.
 import tkinter
 import warnings
 
+
+## Define functions that query the Mac graphics type.
+## _tk_type and its initializer are private to this section.
+
 _tk_type = None
 
-def _init_tk_type(idleroot=None):
+def _init_tk_type():
     """
     Initializes OS X Tk variant values for
     isAquaTk(), isCarbonTk(), isCocoaTk(), and isXQuartz().
     """
     global _tk_type
-    if sys.platform == 'darwin':
-        root = idleroot or tkinter.Tk()
+    if platform == 'darwin':
+        root = tkinter.Tk()
         ws = root.tk.call('tk', 'windowingsystem')
         if 'x11' in ws:
             _tk_type = "xquartz"
@@ -24,8 +28,7 @@
             _tk_type = "cocoa"
         else:
             _tk_type = "carbon"
-        if not idleroot:
-            root.destroy
+        root.destroy()
     else:
         _tk_type = "other"
 
@@ -62,6 +65,7 @@
         _init_tk_type()
     return _tk_type == "xquartz"
 
+
 def tkVersionWarning(root):
     """
     Returns a string warning message if the Tk version in use appears to
@@ -82,6 +86,9 @@
     else:
         return False
 
+
+## Fix the menu and related functions.
+
 def addOpenEventSupport(root, flist):
     """
     This ensures that the application will respond to open AppleEvents, which
@@ -233,9 +240,13 @@
     isAquaTk(), isCarbonTk(), isCocoaTk(), isXQuartz() functions which
     are initialized here as well.
     """
-    _init_tk_type(root)
     if isAquaTk():
         hideTkConsole(root)
         overrideRootMenu(root, flist)
         addOpenEventSupport(root, flist)
         fixb2context(root)
+
+
+if __name__ == '__main__':
+    from unittest import main
+    main('idlelib.idle_test.test_macosx', verbosity=2)

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list