| 1 | n/a | '''Test idlelib.macosx.py. |
|---|
| 2 | n/a | |
|---|
| 3 | n/a | Coverage: 71% on Windows. |
|---|
| 4 | n/a | ''' |
|---|
| 5 | n/a | from idlelib import macosx |
|---|
| 6 | n/a | from test.support import requires |
|---|
| 7 | n/a | import tkinter as tk |
|---|
| 8 | n/a | import unittest |
|---|
| 9 | n/a | import unittest.mock as mock |
|---|
| 10 | n/a | from idlelib.filelist import FileList |
|---|
| 11 | n/a | |
|---|
| 12 | n/a | mactypes = {'carbon', 'cocoa', 'xquartz'} |
|---|
| 13 | n/a | nontypes = {'other'} |
|---|
| 14 | n/a | alltypes = mactypes | nontypes |
|---|
| 15 | n/a | |
|---|
| 16 | n/a | |
|---|
| 17 | n/a | class InitTktypeTest(unittest.TestCase): |
|---|
| 18 | n/a | "Test _init_tk_type." |
|---|
| 19 | n/a | |
|---|
| 20 | n/a | @classmethod |
|---|
| 21 | n/a | def setUpClass(cls): |
|---|
| 22 | n/a | requires('gui') |
|---|
| 23 | n/a | cls.root = tk.Tk() |
|---|
| 24 | n/a | cls.root.withdraw() |
|---|
| 25 | n/a | cls.orig_platform = macosx.platform |
|---|
| 26 | n/a | |
|---|
| 27 | n/a | @classmethod |
|---|
| 28 | n/a | def tearDownClass(cls): |
|---|
| 29 | n/a | cls.root.update_idletasks() |
|---|
| 30 | n/a | cls.root.destroy() |
|---|
| 31 | n/a | del cls.root |
|---|
| 32 | n/a | macosx.platform = cls.orig_platform |
|---|
| 33 | n/a | |
|---|
| 34 | n/a | def test_init_sets_tktype(self): |
|---|
| 35 | n/a | "Test that _init_tk_type sets _tk_type according to platform." |
|---|
| 36 | n/a | for platform, types in ('darwin', alltypes), ('other', nontypes): |
|---|
| 37 | n/a | with self.subTest(platform=platform): |
|---|
| 38 | n/a | macosx.platform = platform |
|---|
| 39 | n/a | macosx._tk_type == None |
|---|
| 40 | n/a | macosx._init_tk_type() |
|---|
| 41 | n/a | self.assertIn(macosx._tk_type, types) |
|---|
| 42 | n/a | |
|---|
| 43 | n/a | |
|---|
| 44 | n/a | class IsTypeTkTest(unittest.TestCase): |
|---|
| 45 | n/a | "Test each of the four isTypeTk predecates." |
|---|
| 46 | n/a | isfuncs = ((macosx.isAquaTk, ('carbon', 'cocoa')), |
|---|
| 47 | n/a | (macosx.isCarbonTk, ('carbon')), |
|---|
| 48 | n/a | (macosx.isCocoaTk, ('cocoa')), |
|---|
| 49 | n/a | (macosx.isXQuartz, ('xquartz')), |
|---|
| 50 | n/a | ) |
|---|
| 51 | n/a | |
|---|
| 52 | n/a | @mock.patch('idlelib.macosx._init_tk_type') |
|---|
| 53 | n/a | def test_is_calls_init(self, mockinit): |
|---|
| 54 | n/a | "Test that each isTypeTk calls _init_tk_type when _tk_type is None." |
|---|
| 55 | n/a | macosx._tk_type = None |
|---|
| 56 | n/a | for func, whentrue in self.isfuncs: |
|---|
| 57 | n/a | with self.subTest(func=func): |
|---|
| 58 | n/a | func() |
|---|
| 59 | n/a | self.assertTrue(mockinit.called) |
|---|
| 60 | n/a | mockinit.reset_mock() |
|---|
| 61 | n/a | |
|---|
| 62 | n/a | def test_isfuncs(self): |
|---|
| 63 | n/a | "Test that each isTypeTk return correct bool." |
|---|
| 64 | n/a | for func, whentrue in self.isfuncs: |
|---|
| 65 | n/a | for tktype in alltypes: |
|---|
| 66 | n/a | with self.subTest(func=func, whentrue=whentrue, tktype=tktype): |
|---|
| 67 | n/a | macosx._tk_type = tktype |
|---|
| 68 | n/a | (self.assertTrue if tktype in whentrue else self.assertFalse)\ |
|---|
| 69 | n/a | (func()) |
|---|
| 70 | n/a | |
|---|
| 71 | n/a | |
|---|
| 72 | n/a | class SetupTest(unittest.TestCase): |
|---|
| 73 | n/a | "Test setupApp." |
|---|
| 74 | n/a | |
|---|
| 75 | n/a | @classmethod |
|---|
| 76 | n/a | def setUpClass(cls): |
|---|
| 77 | n/a | requires('gui') |
|---|
| 78 | n/a | cls.root = tk.Tk() |
|---|
| 79 | n/a | cls.root.withdraw() |
|---|
| 80 | n/a | |
|---|
| 81 | n/a | @classmethod |
|---|
| 82 | n/a | def tearDownClass(cls): |
|---|
| 83 | n/a | cls.root.update_idletasks() |
|---|
| 84 | n/a | cls.root.destroy() |
|---|
| 85 | n/a | del cls.root |
|---|
| 86 | n/a | |
|---|
| 87 | n/a | @mock.patch('idlelib.macosx.overrideRootMenu') #27312 |
|---|
| 88 | n/a | def test_setupapp(self, overrideRootMenu): |
|---|
| 89 | n/a | "Call setupApp with each possible graphics type." |
|---|
| 90 | n/a | root = self.root |
|---|
| 91 | n/a | flist = FileList(root) |
|---|
| 92 | n/a | for tktype in alltypes: |
|---|
| 93 | n/a | with self.subTest(tktype=tktype): |
|---|
| 94 | n/a | macosx._tk_type = tktype |
|---|
| 95 | n/a | macosx.setupApp(root, flist) |
|---|
| 96 | n/a | if tktype in ('carbon', 'cocoa'): |
|---|
| 97 | n/a | self.assertTrue(overrideRootMenu.called) |
|---|
| 98 | n/a | overrideRootMenu.reset_mock() |
|---|
| 99 | n/a | |
|---|
| 100 | n/a | |
|---|
| 101 | n/a | if __name__ == '__main__': |
|---|
| 102 | n/a | unittest.main(verbosity=2) |
|---|