@known_failure_githubci_win
@with_tempfile
def test_link_file_load(tempfile=None):
    tempfile2 = (tempfile + '_')
    with open(tempfile, 'w') as f:
        f.write('LOAD')
    link_file_load(tempfile, tempfile2)
    ok_(os.path.exists(tempfile2))
    with open(tempfile2, 'r') as f:
        assert_equal(f.read(), 'LOAD')

    def inode(fname):
        with open(fname) as fd:
            return os.fstat(fd.fileno()).st_ino

    def stats(fname, times=True):
        'Return stats on the file which should have been preserved'
        with open(fname) as fd:
            st = os.fstat(fd.fileno())
            stats = (st.st_mode, st.st_uid, st.st_gid, st.st_size)
            if times:
                return (stats + (st.st_atime, st.st_mtime))
            else:
                return stats
    if True:
        assert_equal(inode(tempfile), inode(tempfile2))
        assert_equal(stats(tempfile), stats(tempfile2))

        def raise_AttributeError(*args):
            raise AttributeError('TEST')
        with patch('os.link', raise_AttributeError):
            with swallow_logs(logging.WARNING) as cm:
                link_file_load(tempfile, tempfile2)
                ok_(('failed (TEST), copying file' in cm.out))
        assert_not_equal(inode(tempfile), inode(tempfile2))
    with open(tempfile2, 'r') as f:
        assert_equal(f.read(), 'LOAD')
    assert_equal(stats(tempfile, times=False), stats(tempfile2, times=False))
    unlink(tempfile2)
@known_failure_githubci_win
@with_tempfile
def test_link_file_load(tempfile=None):
    tempfile2 = (tempfile + '_')
    with open(tempfile, 'w') as f:
        f.write('LOAD')
    link_file_load(tempfile, tempfile2)
    ok_(os.path.exists(tempfile2))
    with open(tempfile2, 'r') as f:
        assert_equal(f.read(), 'LOAD')

    def inode(fname):
        with open(fname) as fd:
            return os.fstat(fd.fileno()).st_ino

    def stats(fname, times=True):
        'Return stats on the file which should have been preserved'
        with open(fname) as fd:
            st = os.fstat(fd.fileno())
            stats = (st.st_mode, st.st_uid, st.st_gid, st.st_size)
            if times:
                return (stats + (st.st_atime, st.st_mtime))
            else:
                return stats
    if True:
        assert_equal(inode(tempfile), inode(tempfile2))
        assert_equal(stats(tempfile), stats(tempfile2))

        def raise_AttributeError(*args):
            raise AttributeError('TEST')
        with patch('os.link', raise_AttributeError):
            with swallow_logs(logging.WARNING) as cm:
                link_file_load(tempfile, tempfile2)
                ok_(('failed (TEST), copying file' in cm.out))
        assert_not_equal(inode(tempfile), inode(tempfile2))
    with open(tempfile2, 'r') as f:
        assert_equal(f.read(), 'LOAD')
    assert_equal(stats(tempfile, times=False), stats(tempfile2, times=False))
    unlink(tempfile2)