1"Test mainmenu, coverage 100%." 2# Reported as 88%; mocking turtledemo absence would have no point. 3 4from idlelib import mainmenu 5import re 6import unittest 7 8 9class MainMenuTest(unittest.TestCase): 10 11 def test_menudefs(self): 12 actual = [item[0] for item in mainmenu.menudefs] 13 expect = ['file', 'edit', 'format', 'run', 'shell', 14 'debug', 'options', 'window', 'help'] 15 self.assertEqual(actual, expect) 16 17 def test_default_keydefs(self): 18 self.assertGreaterEqual(len(mainmenu.default_keydefs), 50) 19 20 def test_tcl_indexes(self): 21 # Test tcl patterns used to find menuitem to alter. 22 # On failure, change pattern here and in function(s). 23 # Patterns here have '.*' for re instead of '*' for tcl. 24 for menu, pattern in ( 25 ('debug', '.*tack.*iewer'), # PyShell.debug_menu_postcommand 26 ('options', '.*ode.*ontext'), # EW.__init__, CodeContext.toggle... 27 ('options', '.*ine.*umbers'), # EW.__init__, EW.toggle...event. 28 ): 29 with self.subTest(menu=menu, pattern=pattern): 30 for menutup in mainmenu.menudefs: 31 if menutup[0] == menu: 32 break 33 else: 34 self.assertTrue(0, f"{menu} not in menudefs") 35 self.assertTrue(any(re.search(pattern, menuitem[0]) 36 for menuitem in menutup[1] 37 if menuitem is not None), # Separator. 38 f"{pattern} not in {menu}") 39 40 41if __name__ == '__main__': 42 unittest.main(verbosity=2) 43