예제 #1
0
파일: memory.py 프로젝트: ush98/dvc
class MemoryFileSystem(BaseFileSystem):
    scheme = "local"
    PARAM_CHECKSUM = "md5"

    def __init__(self, **kwargs):
        from fsspec.implementations.memory import MemoryFileSystem as MemFS

        super().__init__(**kwargs)

        self.fs = MemFS()

    def exists(self, path_info) -> bool:
        return self.fs.exists(path_info.fspath)

    def open(self, path_info, mode="r", encoding=None, **kwargs):
        return self.fs.open(path_info.fspath,
                            mode=mode,
                            encoding=encoding,
                            **kwargs)

    def info(self, path_info):
        return self.fs.info(path_info.fspath)

    def stat(self, path_info):
        import os

        info = self.fs.info(path_info.fspath)

        return os.stat_result((0, 0, 0, 0, 0, 0, info["size"], 0, 0, 0))

    def walk_files(self, path_info, **kwargs):
        raise NotImplementedError
예제 #2
0
def test_move():
    fs = MemoryFileSystem()
    with fs.open("/myfile", "wb") as f:
        f.write(b"I had a nice big cabbage")
    fs.move("/myfile", "/otherfile")
    assert not fs.exists("/myfile")
    assert fs.info("/otherfile")
    assert isinstance(fs.ukey("/otherfile"), str)
예제 #3
0
def test_move():
    fs = MemoryFileSystem()
    with fs.open('/myfile', 'wb') as f:
        f.write(b'I had a nice big cabbage')
    fs.move('/myfile', '/otherfile')
    assert not fs.exists('/myfile')
    assert fs.info('/otherfile')
    assert isinstance(fs.ukey('/otherfile'), str)
예제 #4
0
def test_basic(tmpdir):
    tmpdir = str(tmpdir)
    fs = MemoryFileSystem()
    fs.touch('/mounted/testfile')
    th = run(fs, '/mounted/', tmpdir, False)
    timeout = 10
    while True:
        try:
            # can fail with device not ready while waiting for fuse
            if 'testfile' in os.listdir(tmpdir):
                break
        except:
            pass
        timeout -= 1
        time.sleep(1)
        assert timeout > 0, "Timeout"

    fn = os.path.join(tmpdir, 'test')
    with open(fn, 'wb') as f:
        f.write(b'data')
    assert fs.info("/mounted/test")['size'] == 4

    assert open(fn).read() == "data"
    os.remove(fn)

    os.mkdir(fn)
    assert os.listdir(fn) == []

    os.mkdir(fn + '/inner')

    with pytest.raises(OSError):
        os.rmdir(fn)

    os.rmdir(fn + '/inner')
    os.rmdir(fn)
    assert not fs.pseudo_dirs

    # should not normally kill a thread like this, but FUSE blocks, so we
    # cannot have thread listen for event. Alternative may be to .join() but
    # send a SIGINT
    th._tstate_lock.release()
    th._stop()
    th.join()
    fs.store.clear()