def test_close(self): shell = MockShell() f = PseudoInputFile(shell, 'stdin', 'utf-8') shell.push(['one\n', 'two\n', '']) self.assertFalse(f.closed) self.assertEqual(f.readline(), 'one\n') f.close() self.assertFalse(f.closed) self.assertEqual(f.readline(), 'two\n') self.assertRaises(TypeError, f.close, 1)
def test_misc(self): shell = MockShell() f = PseudoInputFile(shell, 'stdin', 'utf-8') self.assertIsInstance(f, io.TextIOBase) self.assertEqual(f.encoding, 'utf-8') self.assertIsNone(f.errors) self.assertIsNone(f.newlines) self.assertEqual(f.name, '<stdin>') self.assertFalse(f.closed) self.assertTrue(f.isatty()) self.assertTrue(f.readable()) self.assertFalse(f.writable()) self.assertFalse(f.seekable())
def test_unsupported(self): shell = MockShell() f = PseudoInputFile(shell, 'stdin', 'utf-8') self.assertRaises(OSError, f.fileno) self.assertRaises(OSError, f.tell) self.assertRaises(OSError, f.seek, 0) self.assertRaises(OSError, f.write, 'x') self.assertRaises(OSError, f.writelines, ['x'])
def test_readline(self): shell = MockShell() f = PseudoInputFile(shell, 'stdin', 'utf-8') shell.push(['one\n', 'two\n', 'three\n', 'four\n']) self.assertEqual(f.readline(), 'one\n') self.assertEqual(f.readline(-1), 'two\n') self.assertEqual(f.readline(None), 'three\n') shell.push(['one\ntwo\n']) self.assertEqual(f.readline(), 'one\n') self.assertEqual(f.readline(), 'two\n') shell.push(['one', 'two', 'three']) self.assertEqual(f.readline(), 'one') self.assertEqual(f.readline(), 'two') shell.push(['one\n', 'two\n', 'three\n']) self.assertEqual(f.readline(2), 'on') self.assertEqual(f.readline(1), 'e') self.assertEqual(f.readline(1), '\n') self.assertEqual(f.readline(10), 'two\n') shell.push(['one\n', 'two\n']) self.assertEqual(f.readline(0), '') self.assertRaises(TypeError, f.readlines, 1.5) self.assertRaises(TypeError, f.readlines, '1') self.assertRaises(TypeError, f.readlines, 1, 1)
def test_read(self): shell = MockShell() f = PseudoInputFile(shell, 'stdin', 'utf-8') shell.push(['one\n', 'two\n', '']) self.assertEqual(f.read(), 'one\ntwo\n') shell.push(['one\n', 'two\n', '']) self.assertEqual(f.read(-1), 'one\ntwo\n') shell.push(['one\n', 'two\n', '']) self.assertEqual(f.read(None), 'one\ntwo\n') shell.push(['one\n', 'two\n', 'three\n', '']) self.assertEqual(f.read(2), 'on') self.assertEqual(f.read(3), 'e\nt') self.assertEqual(f.read(10), 'wo\nthree\n') shell.push(['one\n', 'two\n']) self.assertEqual(f.read(0), '') self.assertRaises(TypeError, f.read, 1.5) self.assertRaises(TypeError, f.read, '1') self.assertRaises(TypeError, f.read, 1, 1)
def __init__(self, flist=None): if use_subprocess: ms = self.menu_specs if ms[2][0] != 'shell': ms.insert(2, ('shell', 'She_ll')) self.interp = ModifiedInterpreter(self) if flist is None: root = Tk() fixwordbreaks(root) root.withdraw() flist = PyShellFileList(root) OutputWindow.__init__(self, flist, None, None) self.usetabs = True self.indentwidth = 8 self.context_use_ps1 = True text = self.text text.configure(wrap='char') text.bind('<<newline-and-indent>>', self.enter_callback) text.bind('<<plain-newline-and-indent>>', self.linefeed_callback) text.bind('<<interrupt-execution>>', self.cancel_callback) text.bind('<<end-of-file>>', self.eof_callback) text.bind('<<open-stack-viewer>>', self.open_stack_viewer) text.bind('<<toggle-debugger>>', self.toggle_debugger) text.bind('<<toggle-jit-stack-viewer>>', self.toggle_jit_stack_viewer) if use_subprocess: text.bind('<<view-restart>>', self.view_restart_mark) text.bind('<<restart-shell>>', self.restart_shell) self.save_stdout = sys.stdout self.save_stderr = sys.stderr self.save_stdin = sys.stdin from idlelib import iomenu self.stdin = PseudoInputFile(self, 'stdin', iomenu.encoding) self.stdout = PseudoOutputFile(self, 'stdout', iomenu.encoding) self.stderr = PseudoOutputFile(self, 'stderr', iomenu.encoding) self.console = PseudoOutputFile(self, 'console', iomenu.encoding) if not use_subprocess: sys.stdout = self.stdout sys.stderr = self.stderr sys.stdin = self.stdin try: import pydoc pydoc.pager = pydoc.plainpager except: sys.stderr = sys.__stderr__ raise self.history = self.History(self.text) self.pollinterval = 50
def test_readlines(self): shell = MockShell() f = PseudoInputFile(shell, 'stdin', 'utf-8') shell.push(['one\n', 'two\n', '']) self.assertEqual(f.readlines(), ['one\n', 'two\n']) shell.push(['one\n', 'two\n', '']) self.assertEqual(f.readlines(-1), ['one\n', 'two\n']) shell.push(['one\n', 'two\n', '']) self.assertEqual(f.readlines(None), ['one\n', 'two\n']) shell.push(['one\n', 'two\n', '']) self.assertEqual(f.readlines(0), ['one\n', 'two\n']) shell.push(['one\n', 'two\n', '']) self.assertEqual(f.readlines(3), ['one\n']) shell.push(['one\n', 'two\n', '']) self.assertEqual(f.readlines(4), ['one\n', 'two\n']) shell.push(['one\n', 'two\n', '']) self.assertRaises(TypeError, f.readlines, 1.5) self.assertRaises(TypeError, f.readlines, '1') self.assertRaises(TypeError, f.readlines, 1, 1)