AutoGPT

Форк
0
/
test_git_commands.py 
44 строки · 1.5 Кб
1
import pytest
2
from git.exc import GitCommandError
3
from git.repo.base import Repo
4

5
from autogpt.agents.agent import Agent
6
from autogpt.agents.utils.exceptions import CommandExecutionError
7
from autogpt.commands.git_operations import clone_repository
8
from autogpt.file_storage.base import FileStorage
9

10

11
@pytest.fixture
12
def mock_clone_from(mocker):
13
    return mocker.patch.object(Repo, "clone_from")
14

15

16
def test_clone_auto_gpt_repository(storage: FileStorage, mock_clone_from, agent: Agent):
17
    mock_clone_from.return_value = None
18

19
    repo = "github.com/Significant-Gravitas/Auto-GPT.git"
20
    scheme = "https://"
21
    url = scheme + repo
22
    clone_path = storage.get_path("auto-gpt-repo")
23

24
    expected_output = f"Cloned {url} to {clone_path}"
25

26
    clone_result = clone_repository(url=url, clone_path=clone_path, agent=agent)
27

28
    assert clone_result == expected_output
29
    mock_clone_from.assert_called_once_with(
30
        url=f"{scheme}{agent.legacy_config.github_username}:{agent.legacy_config.github_api_key}@{repo}",  # noqa: E501
31
        to_path=clone_path,
32
    )
33

34

35
def test_clone_repository_error(storage: FileStorage, mock_clone_from, agent: Agent):
36
    url = "https://github.com/this-repository/does-not-exist.git"
37
    clone_path = storage.get_path("does-not-exist")
38

39
    mock_clone_from.side_effect = GitCommandError(
40
        "clone", "fatal: repository not found", ""
41
    )
42

43
    with pytest.raises(CommandExecutionError):
44
        clone_repository(url=url, clone_path=clone_path, agent=agent)
45

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.