'Test that write handles data correctly.  Send data up to the size
of the remote window, splitting the data into packets of length
remoteMaxPacket.'

def test_write(self):

    cb = [False]
    def stubStopWriting():
        cb[0] = True
    self.channel.stopWriting = stubStopWriting
    self.channel.write('d')
    self.channel.write('a')
    self.assertFalse(self.channel.areWriting)
    self.assertTrue(cb[0])
    self.channel.addWindowBytes(20)
    self.channel.write('ta')
    data = self.conn.data[self.channel]
    self.assertEqual(data, ['da', 'ta'])
    self.assertEqual(self.channel.remoteWindowLeft, 16)
    self.channel.write('12345678901')
    self.assertEqual(data, ['da', 'ta', '1234567890', '1'])
    self.assertEqual(self.channel.remoteWindowLeft, 5)
    cb[0] = False
    self.channel.write('123456')
    self.assertFalse(self.channel.areWriting)
    self.assertTrue(cb[0])
    self.assertEqual(data, ['da', 'ta', '1234567890', '1', '12345'])
    self.assertEqual(self.channel.buf, '6')
    self.assertEqual(self.channel.remoteWindowLeft, 0)
