def test_fuse(token_restore): mountpath = tempfile.mkdtemp() with gcs_maker() as gcs: th = threading.Thread( target=lambda: run(gcs, TEST_BUCKET + "/", mountpath)) th.daemon = True th.start() time.sleep(5) timeout = 20 while True: try: open(os.path.join(mountpath, "lock"), "w").close() os.remove(os.path.join(mountpath, "lock")) break except: # noqa: E722 time.sleep(0.5) timeout -= 0.5 assert timeout > 0 with open(os.path.join(mountpath, "hello"), "w") as f: # NB this is in TEXT mode f.write("hello") files = os.listdir(mountpath) assert "hello" in files with open(os.path.join(mountpath, "hello"), "r") as f: # NB this is in TEXT mode assert f.read() == "hello"
def test_fuse(token_restore): mountpath = tempfile.mkdtemp() with gcs_maker() as gcs: th = threading.Thread( target=lambda: run(gcs, TEST_BUCKET + '/', mountpath)) th.daemon = True th.start() time.sleep(5) timeout = 20 while True: try: open(os.path.join(mountpath, 'lock'), 'w').close() os.remove(os.path.join(mountpath, 'lock')) break except: time.sleep(0.5) timeout -= 0.5 assert timeout > 0 with open(os.path.join(mountpath, 'hello'), 'w') as f: # NB this is in TEXT mode f.write('hello') files = os.listdir(mountpath) assert 'hello' in files with open(os.path.join(mountpath, 'hello'), 'r') as f: # NB this is in TEXT mode assert f.read() == 'hello'
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()
def host_fuse(mountdir): fs = MemoryFileSystem() fs.touch("/mounted/testfile") run(fs, "/mounted/", mountdir)