mirror of
https://github.com/python/cpython.git
synced 2025-12-04 08:34:25 +00:00
Issue #27239: idlelib.macosx.isXyzTk functions initialize as needed.
This commit is contained in:
parent
47791df97c
commit
fb51e65289
4 changed files with 84 additions and 10 deletions
|
|
@ -66,7 +66,7 @@ outwin.OutputWindow (indirectly being tested with grep test)
|
||||||
'''
|
'''
|
||||||
|
|
||||||
from importlib import import_module
|
from importlib import import_module
|
||||||
from idlelib.macosx import _initializeTkVariantTests
|
from idlelib.macosx import _init_tk_type
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
|
|
||||||
AboutDialog_spec = {
|
AboutDialog_spec = {
|
||||||
|
|
@ -337,7 +337,7 @@ def run(*tests):
|
||||||
root = tk.Tk()
|
root = tk.Tk()
|
||||||
root.title('IDLE htest')
|
root.title('IDLE htest')
|
||||||
root.resizable(0, 0)
|
root.resizable(0, 0)
|
||||||
_initializeTkVariantTests(root)
|
_init_tk_type(root)
|
||||||
|
|
||||||
# a scrollable Label like constant width text widget.
|
# a scrollable Label like constant width text widget.
|
||||||
frameLabel = tk.Frame(root, padx=10)
|
frameLabel = tk.Frame(root, padx=10)
|
||||||
|
|
|
||||||
|
|
@ -8,14 +8,12 @@ from test.support import requires
|
||||||
requires('gui')
|
requires('gui')
|
||||||
from tkinter import Tk
|
from tkinter import Tk
|
||||||
import unittest
|
import unittest
|
||||||
from idlelib import macosx
|
|
||||||
|
|
||||||
class ConfigDialogTest(unittest.TestCase):
|
class ConfigDialogTest(unittest.TestCase):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
cls.root = Tk()
|
cls.root = Tk()
|
||||||
macosx._initializeTkVariantTests(cls.root)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
||||||
|
|
|
||||||
69
Lib/idlelib/idle_test/test_macosx.py
Normal file
69
Lib/idlelib/idle_test/test_macosx.py
Normal file
|
|
@ -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)
|
||||||
|
|
@ -7,13 +7,14 @@ import warnings
|
||||||
|
|
||||||
_tk_type = None
|
_tk_type = None
|
||||||
|
|
||||||
def _initializeTkVariantTests(root):
|
def _init_tk_type(idleroot=None):
|
||||||
"""
|
"""
|
||||||
Initializes OS X Tk variant values for
|
Initializes OS X Tk variant values for
|
||||||
isAquaTk(), isCarbonTk(), isCocoaTk(), and isXQuartz().
|
isAquaTk(), isCarbonTk(), isCocoaTk(), and isXQuartz().
|
||||||
"""
|
"""
|
||||||
global _tk_type
|
global _tk_type
|
||||||
if sys.platform == 'darwin':
|
if sys.platform == 'darwin':
|
||||||
|
root = idleroot or tkinter.Tk()
|
||||||
ws = root.tk.call('tk', 'windowingsystem')
|
ws = root.tk.call('tk', 'windowingsystem')
|
||||||
if 'x11' in ws:
|
if 'x11' in ws:
|
||||||
_tk_type = "xquartz"
|
_tk_type = "xquartz"
|
||||||
|
|
@ -23,6 +24,8 @@ def _initializeTkVariantTests(root):
|
||||||
_tk_type = "cocoa"
|
_tk_type = "cocoa"
|
||||||
else:
|
else:
|
||||||
_tk_type = "carbon"
|
_tk_type = "carbon"
|
||||||
|
if not idleroot:
|
||||||
|
root.destroy
|
||||||
else:
|
else:
|
||||||
_tk_type = "other"
|
_tk_type = "other"
|
||||||
|
|
||||||
|
|
@ -30,7 +33,8 @@ def isAquaTk():
|
||||||
"""
|
"""
|
||||||
Returns True if IDLE is using a native OS X Tk (Cocoa or Carbon).
|
Returns True if IDLE is using a native OS X Tk (Cocoa or Carbon).
|
||||||
"""
|
"""
|
||||||
assert _tk_type is not None
|
if not _tk_type:
|
||||||
|
_init_tk_type()
|
||||||
return _tk_type == "cocoa" or _tk_type == "carbon"
|
return _tk_type == "cocoa" or _tk_type == "carbon"
|
||||||
|
|
||||||
def isCarbonTk():
|
def isCarbonTk():
|
||||||
|
|
@ -38,21 +42,24 @@ def isCarbonTk():
|
||||||
Returns True if IDLE is using a Carbon Aqua Tk (instead of the
|
Returns True if IDLE is using a Carbon Aqua Tk (instead of the
|
||||||
newer Cocoa Aqua Tk).
|
newer Cocoa Aqua Tk).
|
||||||
"""
|
"""
|
||||||
assert _tk_type is not None
|
if not _tk_type:
|
||||||
|
_init_tk_type()
|
||||||
return _tk_type == "carbon"
|
return _tk_type == "carbon"
|
||||||
|
|
||||||
def isCocoaTk():
|
def isCocoaTk():
|
||||||
"""
|
"""
|
||||||
Returns True if IDLE is using a Cocoa Aqua Tk.
|
Returns True if IDLE is using a Cocoa Aqua Tk.
|
||||||
"""
|
"""
|
||||||
assert _tk_type is not None
|
if not _tk_type:
|
||||||
|
_init_tk_type()
|
||||||
return _tk_type == "cocoa"
|
return _tk_type == "cocoa"
|
||||||
|
|
||||||
def isXQuartz():
|
def isXQuartz():
|
||||||
"""
|
"""
|
||||||
Returns True if IDLE is using an OS X X11 Tk.
|
Returns True if IDLE is using an OS X X11 Tk.
|
||||||
"""
|
"""
|
||||||
assert _tk_type is not None
|
if not _tk_type:
|
||||||
|
_init_tk_type()
|
||||||
return _tk_type == "xquartz"
|
return _tk_type == "xquartz"
|
||||||
|
|
||||||
def tkVersionWarning(root):
|
def tkVersionWarning(root):
|
||||||
|
|
@ -232,7 +239,7 @@ def setupApp(root, flist):
|
||||||
isAquaTk(), isCarbonTk(), isCocoaTk(), isXQuartz() functions which
|
isAquaTk(), isCarbonTk(), isCocoaTk(), isXQuartz() functions which
|
||||||
are initialized here as well.
|
are initialized here as well.
|
||||||
"""
|
"""
|
||||||
_initializeTkVariantTests(root)
|
_init_tk_type(root)
|
||||||
if isAquaTk():
|
if isAquaTk():
|
||||||
hideTkConsole(root)
|
hideTkConsole(root)
|
||||||
overrideRootMenu(root, flist)
|
overrideRootMenu(root, flist)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue