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