'Test that it gives a readable error when trying to update an hdulist
to a full disk.'

def test_flush_full_disk(self, monkeypatch):

    filename = self.temp('test.fits')
    hdul = [fits.PrimaryHDU(), fits.ImageHDU()]
    hdul = fits.HDUList(hdul)
    hdul[0].data = np.arange(0, 1000, dtype='int64')
    hdul.writeto(filename)
    def _writedata(self, fileobj):
        raise OSError('Fake    error    raised    when    writing    file.')
    def get_free_space_in_dir(path):
        return 0
    monkeypatch.setattr(fits.hdu.base._BaseHDU, '_writedata', _writedata)
    monkeypatch.setattr(data, 'get_free_space_in_dir', get_free_space_in_dir)
    with pytest.raises(OSError) as exc:
        with fits.open(filename, mode='update') as hdul:
            hdul[0].data = np.arange(0, 1000, dtype='int64')
            hdul.insert(1, fits.ImageHDU())
            hdul.flush()
    assert ('Not    enough    space    on    disk:    requested    8000,    available    0.    Fake    error    raised    when    writing    file.' == exc.value.args[0])
