Ejemplo n.º 1
0
def ftp_writable(tmpdir):
    """
    Fixture providing a writable FTP filesystem.
    """
    pytest.importorskip("pyftpdlib")
    from fsspec.implementations.ftp import FTPFileSystem

    FTPFileSystem.clear_instance_cache()  # remove lingering connections
    CachingFileSystem.clear_instance_cache()
    d = str(tmpdir)
    with open(os.path.join(d, "out"), "wb") as f:
        f.write(b"hello" * 10000)
    P = subprocess.Popen([
        sys.executable, "-m", "pyftpdlib", "-d", d, "-u", "user", "-P", "pass",
        "-w"
    ])
    try:
        time.sleep(1)
        yield "localhost", 2121, "user", "pass"
    finally:
        P.terminate()
        P.wait()
        try:
            shutil.rmtree(tmpdir)
        except Exception:
            pass
Ejemplo n.º 2
0
def test_equality():
    """Test sane behaviour for equality and hashing.

    Make sure that different CachingFileSystem only test equal to each other
    when they should, and do not test equal to the filesystem they rely upon.
    Similarly, make sure their hashes differ when they should and are equal
    when they should not.

    Related: GitHub#577, GitHub#578
    """
    from fsspec.implementations.local import LocalFileSystem

    lfs = LocalFileSystem()
    cfs1 = CachingFileSystem(fs=lfs, cache_storage="raspberry")
    cfs2 = CachingFileSystem(fs=lfs, cache_storage="banana")
    cfs3 = CachingFileSystem(fs=lfs, cache_storage="banana")
    assert cfs1 == cfs1
    assert cfs1 != cfs2
    assert cfs1 != cfs3
    assert cfs2 == cfs3
    assert cfs1 != lfs
    assert cfs2 != lfs
    assert cfs3 != lfs
    assert hash(lfs) != hash(cfs1)
    assert hash(lfs) != hash(cfs2)
    assert hash(lfs) != hash(cfs3)
    assert hash(cfs1) != hash(cfs2)
    assert hash(cfs1) != hash(cfs2)
    assert hash(cfs2) == hash(cfs3)
Ejemplo n.º 3
0
def test_json():
    """Test that the JSON representation refers to correct class.

    Make sure that the JSON representation of a CachingFileSystem refers to the
    CachingFileSystem, not to the underlying filesystem.
    """
    import json

    from fsspec.implementations.local import LocalFileSystem

    lfs = LocalFileSystem()
    cfs = CachingFileSystem(fs=lfs, cache_storage="raspberry")
    D = json.loads(cfs.to_json())
    assert D["cls"].endswith("CachingFileSystem")
Ejemplo n.º 4
0
    def test_hash(self):
        """Test that FSFile hashing behaves sanely."""
        from fsspec.implementations.cached import CachingFileSystem
        from fsspec.implementations.local import LocalFileSystem
        from fsspec.implementations.zip import ZipFileSystem

        from satpy.readers import FSFile

        lfs = LocalFileSystem()
        zfs = ZipFileSystem(self.zip_name)
        cfs = CachingFileSystem(fs=lfs)
        # make sure each name/fs-combi has its own hash
        assert len({hash(FSFile(fn, fs))
                    for fn in {self.local_filename, self.local_filename2}
                    for fs in [None, lfs, zfs, cfs]}) == 2*4
Ejemplo n.º 5
0
def test_idempotent():
    fs = CachingFileSystem("file")
    fs2 = CachingFileSystem("file")
    assert fs2 is fs
    fs3 = pickle.loads(pickle.dumps(fs))
    assert fs3.storage == fs.storage