test_mainmenu.py 1.6 KB

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