test_pyshell.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. "Test pyshell, coverage 12%."
  2. # Plus coverage of test_warning. Was 20% with test_openshell.
  3. from idlelib import pyshell
  4. import unittest
  5. from test.support import requires
  6. from tkinter import Tk
  7. class FunctionTest(unittest.TestCase):
  8. # Test stand-alone module level non-gui functions.
  9. def test_restart_line_wide(self):
  10. eq = self.assertEqual
  11. for file, mul, extra in (('', 22, ''), ('finame', 21, '=')):
  12. width = 60
  13. bar = mul * '='
  14. with self.subTest(file=file, bar=bar):
  15. file = file or 'Shell'
  16. line = pyshell.restart_line(width, file)
  17. eq(len(line), width)
  18. eq(line, f"{bar+extra} RESTART: {file} {bar}")
  19. def test_restart_line_narrow(self):
  20. expect, taglen = "= RESTART: Shell", 16
  21. for width in (taglen-1, taglen, taglen+1):
  22. with self.subTest(width=width):
  23. self.assertEqual(pyshell.restart_line(width, ''), expect)
  24. self.assertEqual(pyshell.restart_line(taglen+2, ''), expect+' =')
  25. class PyShellFileListTest(unittest.TestCase):
  26. @classmethod
  27. def setUpClass(cls):
  28. requires('gui')
  29. cls.root = Tk()
  30. cls.root.withdraw()
  31. @classmethod
  32. def tearDownClass(cls):
  33. #cls.root.update_idletasks()
  34. ## for id in cls.root.tk.call('after', 'info'):
  35. ## cls.root.after_cancel(id) # Need for EditorWindow.
  36. cls.root.destroy()
  37. del cls.root
  38. def test_init(self):
  39. psfl = pyshell.PyShellFileList(self.root)
  40. self.assertEqual(psfl.EditorWindow, pyshell.PyShellEditorWindow)
  41. self.assertIsNone(psfl.pyshell)
  42. # The following sometimes causes 'invalid command name "109734456recolorize"'.
  43. # Uncommenting after_cancel above prevents this, but results in
  44. # TclError: bad window path name ".!listedtoplevel.!frame.text"
  45. # which is normally prevented by after_cancel.
  46. ## def test_openshell(self):
  47. ## pyshell.use_subprocess = False
  48. ## ps = pyshell.PyShellFileList(self.root).open_shell()
  49. ## self.assertIsInstance(ps, pyshell.PyShell)
  50. if __name__ == '__main__':
  51. unittest.main(verbosity=2)