Exemplo n.º 1
0
def test_cache(mocker, temp_repo_func, cache_backend, arguments):
    base_dir = Path(BASE_DIR)

    backend = VenvBackend(verbosity=2)

    base_dir.mkdir(parents=True, exist_ok=True)

    arca = Arca(backend=backend,
                base_dir=BASE_DIR,
                single_pull=True,
                settings={
                    "ARCA_CACHE_BACKEND": cache_backend,
                    "ARCA_CACHE_BACKEND_ARGUMENTS": arguments
                })

    requirements_path = temp_repo_func.repo_path / "requirements.txt"
    requirements_path.write_text("colorama==0.3.9")
    temp_repo_func.repo.index.add([str(requirements_path)])

    temp_repo_func.file_path.write_text(RETURN_COLORAMA_VERSION_FUNCTION)
    temp_repo_func.repo.index.add([str(temp_repo_func.file_path)])
    temp_repo_func.repo.index.commit("Added requirements")

    colorama_task = Task("test_file:return_str_function")

    repo = arca.get_repo(temp_repo_func.url, temp_repo_func.branch)
    cache_key = arca.cache_key(temp_repo_func.url, temp_repo_func.branch,
                               colorama_task, repo)

    # delete from previous tests
    arca.region.delete(cache_key)
    assert arca.region.get(cache_key) is NO_VALUE

    mocker.spy(arca.backend, "run")

    # run the first time, check it actually cached
    assert arca.run(temp_repo_func.url, temp_repo_func.branch,
                    colorama_task).output == "0.3.9"
    assert arca.backend.run.call_count == 1

    repo = arca.get_repo(temp_repo_func.url, temp_repo_func.branch)

    assert arca.region.get(
        arca.cache_key(temp_repo_func.url, temp_repo_func.branch,
                       colorama_task, repo)) is not NO_VALUE

    assert arca.run(temp_repo_func.url, temp_repo_func.branch,
                    colorama_task).output == "0.3.9"
    # check that the result was actually from cache, that run wasn't called again
    assert arca.backend.run.call_count == 1

    arca.pull_again(temp_repo_func.url, temp_repo_func.branch)

    mocker.spy(arca, "get_files")

    assert arca.run(temp_repo_func.url, temp_repo_func.branch,
                    colorama_task).output == "0.3.9"
    assert arca.get_files.call_count == 1  # check that the repo was pulled
Exemplo n.º 2
0
def test_get_repo(temp_repo_static):
    arca = Arca(base_dir=BASE_DIR)

    pulled_repo = arca.get_repo(temp_repo_static.url, temp_repo_static.branch)

    assert pulled_repo.head.object.hexsha == temp_repo_static.repo.head.object.hexsha