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_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)