'Confirm that FTP uploads (i.e. ftp_STOR) correctly call and wait
upon the IWriteFile object\'s close() method'

def test_write(self):

    f = ftp.FTP()
    f.workingDirectory = ['root']
    f.shell = CloseTestShell()
    f.shell.writer = CloseTestWriter()
    f.shell.writer.d = defer.Deferred()
    f.factory = ftp.FTPFactory()
    f.factory.timeOut = None
    f.makeConnection(BytesIO())
    di = ftp.DTP()
    di.factory = ftp.DTPFactory(f)
    f.dtpInstance = di
    di.makeConnection(None)
    stor_done = []
    d = f.ftp_STOR('path')
    d.addCallback(stor_done.append)
    self.assertFalse(f.shell.writer.closeStarted, 'close()    called    early')
    di.dataReceived('some    data    here')
    self.assertFalse(f.shell.writer.closeStarted, 'close()    called    early')
    di.connectionLost('reason    is    ignored')
    self.assertTrue(f.shell.writer.closeStarted, 'close()    not    called')
    self.assertFalse(stor_done)
    f.shell.writer.d.callback('allow    close()    to    finish')
    self.assertTrue(stor_done)
    return d
