def test_delete(repo: RemoteFileRepo, expected_file):
    model_file_path = repo.get(expected_file)
    repo.delete(expected_file)

    assert not repo.is_local(expected_file)
    assert repo.list_local() == []
    assert not os.path.exists(model_file_path)
def test_download(repo: RemoteFileRepo, expected_file):
    assert not repo.is_local(expected_file)

    model_file_path = repo.download(expected_file)
    assert repo.is_local(expected_file)
    assert os.path.isfile(model_file_path)
    assert repo.list_local() == [expected_file]
    assert repo.get(expected_file) == model_file_path
def test_clean(repo: RemoteFileRepo, expected_files):
    for file in expected_files:
        repo.get(file)

    assert set(repo.list_local()) == set(expected_files)

    local_paths = [repo.get(file) for file in expected_files]
    for path in local_paths:
        assert os.path.isfile(path)

    repo.clean()
    assert repo.list_local() == []
    for path in local_paths:
        assert not os.path.exists(path)
def test_autoload(repo: RemoteFileRepo, expected_file):
    assert not repo.is_local(expected_file)

    file_path = repo.get(expected_file)
    assert repo.is_local(expected_file)
    assert os.path.exists(file_path)
def test_empty(repo: RemoteFileRepo):
    assert repo.list_local() == []
def repo(remote):
    """Create a new empty file repo in a temporary directory."""
    with tempfile.TemporaryDirectory(prefix="remote-repo-") as directory:
        yield RemoteFileRepo(directory=directory, remote=remote)
def test_content(repo: RemoteFileRepo, expected_file, expected_content):
    file_path = repo.get(expected_file)
    with open(file_path, 'r') as file:
        assert file.read() == expected_content
示例#8
0
def pretrained_models(directory=None, base_url=None):
    """Get remote file repository containing pretrained models."""
    directory = directory or DEFAULT_DIRECTORY
    base_url = base_url or DEFAULT_URL
    return RemoteFileRepo(directory=directory, remote=BaseUrl(base_url))