- Notifications
You must be signed in to change notification settings - Fork 31.8k
/
Copy pathtest_macosx.py
113 lines (91 loc) · 3.36 KB
/
test_macosx.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
"Test macosx, coverage 45% on Windows."
fromidlelibimportmacosx
importunittest
fromtest.supportimportrequires
importtkinterastk
importunittest.mockasmock
fromidlelib.filelistimportFileList
mactypes= {'carbon', 'cocoa', 'xquartz'}
nontypes= {'other'}
alltypes=mactypes|nontypes
defsetUpModule():
globalorig_tktype
orig_tktype=macosx._tk_type
deftearDownModule():
macosx._tk_type=orig_tktype
classInitTktypeTest(unittest.TestCase):
"Test _init_tk_type."
@classmethod
defsetUpClass(cls):
requires('gui')
cls.root=tk.Tk()
cls.root.withdraw()
cls.orig_platform=macosx.platform
@classmethod
deftearDownClass(cls):
cls.root.update_idletasks()
cls.root.destroy()
delcls.root
macosx.platform=cls.orig_platform
deftest_init_sets_tktype(self):
"Test that _init_tk_type sets _tk_type according to platform."
forplatform, typesin ('darwin', alltypes), ('other', nontypes):
withself.subTest(platform=platform):
macosx.platform=platform
macosx._tk_type=None
macosx._init_tk_type()
self.assertIn(macosx._tk_type, types)
classIsTypeTkTest(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')
deftest_is_calls_init(self, mockinit):
"Test that each isTypeTk calls _init_tk_type when _tk_type is None."
macosx._tk_type=None
forfunc, whentrueinself.isfuncs:
withself.subTest(func=func):
func()
self.assertTrue(mockinit.called)
mockinit.reset_mock()
deftest_isfuncs(self):
"Test that each isTypeTk return correct bool."
forfunc, whentrueinself.isfuncs:
fortktypeinalltypes:
withself.subTest(func=func, whentrue=whentrue, tktype=tktype):
macosx._tk_type=tktype
(self.assertTrueiftktypeinwhentrueelseself.assertFalse)\
(func())
classSetupTest(unittest.TestCase):
"Test setupApp."
@classmethod
defsetUpClass(cls):
requires('gui')
cls.root=tk.Tk()
cls.root.withdraw()
defcmd(tkpath, func):
assertisinstance(tkpath, str)
assertisinstance(func, type(cmd))
cls.root.createcommand=cmd
@classmethod
deftearDownClass(cls):
cls.root.update_idletasks()
cls.root.destroy()
delcls.root
@mock.patch('idlelib.macosx.overrideRootMenu') #27312
deftest_setupapp(self, overrideRootMenu):
"Call setupApp with each possible graphics type."
root=self.root
flist=FileList(root)
fortktypeinalltypes:
withself.subTest(tktype=tktype):
macosx._tk_type=tktype
macosx.setupApp(root, flist)
iftktypein ('carbon', 'cocoa'):
self.assertTrue(overrideRootMenu.called)
overrideRootMenu.reset_mock()
if__name__=='__main__':
unittest.main(verbosity=2)