Пример #1
0
def test_readinto_with_multibyte(ftp_writable, tmpdir, dt):
    host, port, user, pw = ftp_writable
    ftp = FTPFileSystem(host=host, port=port, username=user, password=pw)

    with ftp.open("/out", "wb") as fp:
        arr = np.arange(10, dtype=dt)
        fp.write(arr.tobytes())

    with ftp.open("/out", "rb") as fp:
        arr2 = np.empty_like(arr)
        fp.readinto(arr2)

    assert np.array_equal(arr, arr2)
Пример #2
0
def test_transaction(ftp_writable):
    host, port, user, pw = ftp_writable
    fs = FTPFileSystem(host, port, user, pw)
    fs.mkdir('/tmp')
    fn = '/tr'
    with fs.transaction:
        with fs.open(fn, 'wb') as f:
            f.write(b'not')
        assert not fs.exists(fn)
    assert fs.exists(fn)
    assert fs.cat(fn) == b'not'
Пример #3
0
def test_transaction(ftp_writable):
    host, port, user, pw = ftp_writable
    fs = FTPFileSystem(host, port, user, pw)
    fs.mkdir("/tmp")
    fn = "/tr"
    with fs.transaction:
        with fs.open(fn, "wb") as f:
            f.write(b"not")
        assert not fs.exists(fn)
    assert fs.exists(fn)
    assert fs.cat(fn) == b"not"

    fs.rm(fn)
    assert not fs.exists(fn)
Пример #4
0
def test_write_big(ftp_writable):
    host, port, user, pw = ftp_writable
    fs = FTPFileSystem(host, port, user, pw, block_size=1000)
    fn = '/bigger'
    with fs.open(fn, 'wb') as f:
        f.write(b'o' * 500)
        assert not fs.exists(fn)
        f.write(b'o' * 1000)
        fs.invalidate_cache()
        assert fs.exists(fn)
        f.write(b'o' * 200)
        f.flush()
        assert f.buffer.tell() == 0

    assert fs.cat(fn) == b'o' * 1700
Пример #5
0
def test_write_big(ftp_writable, cache_type):
    host, port, user, pw = ftp_writable
    fs = FTPFileSystem(host,
                       port,
                       user,
                       pw,
                       block_size=1000,
                       cache_type=cache_type)
    fn = "/bigger"
    with fs.open(fn, "wb") as f:
        f.write(b"o" * 500)
        assert not fs.exists(fn)
        f.write(b"o" * 1000)
        fs.invalidate_cache()
        assert fs.exists(fn)
        f.write(b"o" * 200)
        f.flush()

    assert fs.info(fn)["size"] == 1700
    assert fs.cat(fn) == b"o" * 1700
Пример #6
0
def test_write_small(ftp_writable):
    host, port, user, pw = ftp_writable
    fs = FTPFileSystem(host, port, user, pw)
    with fs.open("/out2", "wb") as f:
        f.write(b"oi")
    assert fs.cat("/out2") == b"oi"
Пример #7
0
def test_write_small(ftp_writable):
    host, port, user, pw = ftp_writable
    fs = FTPFileSystem(host, port, user, pw)
    with fs.open('/out2', 'wb') as f:
        f.write(b'oi')
    assert fs.cat('/out2') == b'oi'