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(IOError, f.fileno) self.assertRaises(IOError, f.tell) self.assertRaises(IOError, f.seek, 0) self.assertRaises(IOError, f.write, 'x') self.assertRaises(IOError, 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 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)