2018-06-18 06:10:38 -03:00
|
|
|
"Test macosx, coverage 45% on Windows."
|
2016-06-12 16:49:20 -03:00
|
|
|
|
2016-06-08 19:09:22 -03:00
|
|
|
from idlelib import macosx
|
2018-06-18 06:10:38 -03:00
|
|
|
import unittest
|
2016-06-08 19:09:22 -03:00
|
|
|
from test.support import requires
|
|
|
|
import tkinter as tk
|
|
|
|
import unittest.mock as mock
|
2016-06-12 16:49:20 -03:00
|
|
|
from idlelib.filelist import FileList
|
2016-06-08 19:09:22 -03:00
|
|
|
|
|
|
|
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()
|
2016-08-31 22:09:02 -03:00
|
|
|
cls.root.withdraw()
|
2016-06-12 16:49:20 -03:00
|
|
|
cls.orig_platform = macosx.platform
|
2016-06-08 19:09:22 -03:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
|
|
|
cls.root.update_idletasks()
|
|
|
|
cls.root.destroy()
|
|
|
|
del cls.root
|
2016-06-12 16:49:20 -03:00
|
|
|
macosx.platform = cls.orig_platform
|
2016-06-08 19:09:22 -03:00
|
|
|
|
|
|
|
def test_init_sets_tktype(self):
|
|
|
|
"Test that _init_tk_type sets _tk_type according to platform."
|
2016-06-12 16:49:20 -03:00
|
|
|
for platform, types in ('darwin', alltypes), ('other', nontypes):
|
|
|
|
with self.subTest(platform=platform):
|
|
|
|
macosx.platform = platform
|
2016-06-08 19:09:22 -03:00
|
|
|
macosx._tk_type == None
|
2016-06-12 16:49:20 -03:00
|
|
|
macosx._init_tk_type()
|
|
|
|
self.assertIn(macosx._tk_type, types)
|
2016-06-08 19:09:22 -03:00
|
|
|
|
|
|
|
|
|
|
|
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())
|
|
|
|
|
|
|
|
|
2016-06-12 16:49:20 -03:00
|
|
|
class SetupTest(unittest.TestCase):
|
|
|
|
"Test setupApp."
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
|
|
|
requires('gui')
|
|
|
|
cls.root = tk.Tk()
|
2016-08-31 22:09:02 -03:00
|
|
|
cls.root.withdraw()
|
2017-06-13 11:52:29 -03:00
|
|
|
def cmd(tkpath, func):
|
|
|
|
assert isinstance(tkpath, str)
|
|
|
|
assert isinstance(func, type(cmd))
|
|
|
|
cls.root.createcommand = cmd
|
2016-06-12 16:49:20 -03:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
|
|
|
cls.root.update_idletasks()
|
|
|
|
cls.root.destroy()
|
|
|
|
del cls.root
|
|
|
|
|
2016-06-17 20:55:46 -03:00
|
|
|
@mock.patch('idlelib.macosx.overrideRootMenu') #27312
|
2016-06-17 22:18:24 -03:00
|
|
|
def test_setupapp(self, overrideRootMenu):
|
2016-06-12 16:49:20 -03:00
|
|
|
"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)
|
2016-06-17 22:18:24 -03:00
|
|
|
if tktype in ('carbon', 'cocoa'):
|
|
|
|
self.assertTrue(overrideRootMenu.called)
|
|
|
|
overrideRootMenu.reset_mock()
|
2016-06-12 16:49:20 -03:00
|
|
|
|
|
|
|
|
2016-06-08 19:09:22 -03:00
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main(verbosity=2)
|