def test_sync_checkpoint_previous(tmpdir: py.path.local): inputs, input_file, outputs = create_folder_write_file(tmpdir) cp = SyncCheckpoint(checkpoint_dest=str(outputs), checkpoint_src=str(inputs)) scratch = tmpdir.mkdir("user_scratch") assert cp.restore(str(scratch)) == scratch assert scratch.listdir() == [scratch.join(CHECKPOINT_FILE)] # ensure download is not performed again assert cp.restore("x") == scratch
def test_sync_checkpoint_write(tmpdir): td_path = Path(tmpdir) cp = SyncCheckpoint(checkpoint_dest=tmpdir) assert cp.read() is None assert cp.restore() is None dst_path = td_path.joinpath(SyncCheckpoint.TMP_DST_PATH) assert not dst_path.exists() cp.write(b"bytes") assert dst_path.exists()
def test_sync_checkpoint_restore(tmpdir): td_path = Path(tmpdir) dest = td_path.joinpath("dest") dest.mkdir() src = td_path.joinpath("src") src.mkdir() prev = src.joinpath("prev") p = b"prev-bytes" with prev.open("wb") as f: f.write(p) cp = SyncCheckpoint(checkpoint_dest=str(dest), checkpoint_src=str(src)) user_dest = td_path.joinpath("user_dest") with pytest.raises(ValueError): cp.restore(user_dest) user_dest.mkdir() assert cp.restore(user_dest) == user_dest assert cp.restore("other_path") == user_dest
def test_sync_checkpoint_folder(tmpdir: py.path.local): inputs, input_file, outputs = create_folder_write_file(tmpdir) cp = SyncCheckpoint(checkpoint_dest=str(outputs)) # Lets try to restore - should not work! assert not cp.restore("/tmp") # Now save cp.save(Path(str(inputs))) # Expect file in tmpdir expected_dst = outputs.join(CHECKPOINT_FILE) assert outputs.listdir() == [expected_dst]
def test_sync_checkpoint_reader(tmpdir: py.path.local): inputs, input_file, outputs = create_folder_write_file(tmpdir) cp = SyncCheckpoint(checkpoint_dest=str(outputs)) # Lets try to restore - should not work! assert not cp.restore("/tmp") # Now save with input_file.open(mode="rb") as b: cp.save(b) # Expect file in tmpdir expected_dst = outputs.join(SyncCheckpoint.TMP_DST_PATH) assert outputs.listdir() == [expected_dst]
def test_sync_checkpoint_restore_default_path(tmpdir): td_path = Path(tmpdir) dest = td_path.joinpath("dest") dest.mkdir() src = td_path.joinpath("src") src.mkdir() prev = src.joinpath("prev") p = b"prev-bytes" with prev.open("wb") as f: f.write(p) cp = SyncCheckpoint(checkpoint_dest=str(dest), checkpoint_src=str(src)) assert cp.read() == p assert cp._prev_download_path is not None assert cp.restore() == cp._prev_download_path