'Tests that mmap, and specifically mmap.flush works.  This may
be the case on some uncommon platforms (see
https://github.com/astropy/astropy/issues/968).
If mmap.flush is found not to work, ``self.memmap = False`` is
set and a warning is issued.'

@classproperty(lazy=True)
def _mmap_available(cls):

    (tmpfd, tmpname) = tempfile.mkstemp()
    try:
        os.write(tmpfd, '    ')
        os.fsync(tmpfd)
        try:
            mm = mmap.mmap(tmpfd, 1, access=mmap.ACCESS_WRITE)
        except mmap.error as exc:
            warnings.warn('Failed    to    create    mmap:    {};    mmap    use    will    be    disabled'.format(str(exc)), AstropyUserWarning)
            del exc
            return False
        try:
            mm.flush()
        except mmap.error:
            warnings.warn('mmap.flush    is    unavailable    on    this    platform;    using    mmap    in    writeable    mode    will    be    disabled', AstropyUserWarning)
            return False
        finally:
            mm.close()
    finally:
        os.close(tmpfd)
        os.remove(tmpname)
    return True
