Exemplo n.º 1
0
    def test_writelines(self):
        shell = MockShell()
        f = PseudoOutputFile(shell, 'stdout', 'utf-8')
        f.writelines([])
        self.assertEqual(shell.written, [])
        shell.reset()
        f.writelines(['one\n', 'two'])
        self.assertEqual(shell.written,
                         [('one\n', 'stdout'), ('two', 'stdout')])
        shell.reset()
        f.writelines(['on\xe8\n', 'tw\xf2'])
        self.assertEqual(shell.written,
                         [('on\xe8\n', 'stdout'), ('tw\xf2', 'stdout')])
        shell.reset()

        f.writelines([S('t\xe8st')])
        self.assertEqual(shell.written, [('t\xe8st', 'stdout')])
        self.assertEqual(type(shell.written[0][0]), str)
        shell.reset()

        self.assertRaises(TypeError, f.writelines)
        self.assertEqual(shell.written, [])
        self.assertRaises(TypeError, f.writelines, 123)
        self.assertEqual(shell.written, [])
        self.assertRaises(TypeError, f.writelines, [b'test'])
        self.assertRaises(TypeError, f.writelines, [123])
        self.assertEqual(shell.written, [])
        self.assertRaises(TypeError, f.writelines, [], [])
        self.assertEqual(shell.written, [])
Exemplo n.º 2
0
 def test_misc(self):
     shell = MockShell()
     f = PseudoOutputFile(shell, 'stdout', '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, '<stdout>')
     self.assertFalse(f.closed)
     self.assertTrue(f.isatty())
     self.assertFalse(f.readable())
     self.assertTrue(f.writable())
     self.assertFalse(f.seekable())
Exemplo n.º 3
0
 def test_unsupported(self):
     shell = MockShell()
     f = PseudoOutputFile(shell, 'stdout', 'utf-8')
     self.assertRaises(IOError, f.fileno)
     self.assertRaises(IOError, f.tell)
     self.assertRaises(IOError, f.seek, 0)
     self.assertRaises(IOError, f.read, 0)
     self.assertRaises(IOError, f.readline, 0)
Exemplo n.º 4
0
 def test_close(self):
     shell = MockShell()
     f = PseudoOutputFile(shell, 'stdout', 'utf-8')
     self.assertFalse(f.closed)
     f.write('test')
     f.close()
     self.assertTrue(f.closed)
     self.assertRaises(ValueError, f.write, 'x')
     self.assertEqual(shell.written, [('test', 'stdout')])
     f.close()
     self.assertRaises(TypeError, f.close, 1)
Exemplo n.º 5
0
 def test_close(self):
     shell = MockShell()
     f = PseudoOutputFile(shell, 'stdout', 'utf-8')
     self.assertFalse(f.closed)
     f.write('test')
     f.close()
     self.assertTrue(f.closed)
     self.assertRaises(ValueError, f.write, 'x')
     self.assertEqual(shell.written, [('test', 'stdout')])
     f.close()
     self.assertRaises(TypeError, f.close, 1)
Exemplo n.º 6
0
 def test_misc(self):
     shell = MockShell()
     f = PseudoOutputFile(shell, 'stdout', '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, '<stdout>')
     self.assertFalse(f.closed)
     self.assertTrue(f.isatty())
     self.assertFalse(f.readable())
     self.assertTrue(f.writable())
     self.assertFalse(f.seekable())
Exemplo n.º 7
0
    def test_write(self):
        shell = MockShell()
        f = PseudoOutputFile(shell, 'stdout', 'utf-8')
        f.write('test')
        self.assertEqual(shell.written, [('test', 'stdout')])
        shell.reset()
        f.write('t\xe8st')
        self.assertEqual(shell.written, [('t\xe8st', 'stdout')])
        shell.reset()

        f.write(S('t\xe8st'))
        self.assertEqual(shell.written, [('t\xe8st', 'stdout')])
        self.assertEqual(type(shell.written[0][0]), str)
        shell.reset()

        self.assertRaises(TypeError, f.write)
        self.assertEqual(shell.written, [])
        self.assertRaises(TypeError, f.write, b'test')
        self.assertRaises(TypeError, f.write, 123)
        self.assertEqual(shell.written, [])
        self.assertRaises(TypeError, f.write, 'test', 'spam')
        self.assertEqual(shell.written, [])