Beispiel #1
0
def test_message_1():
    """test that commit message is read"""
    repo = GitRepo(FIXTURES / "git01", "main", "FETCH_HEAD")
    try:
        assert "Test commit message" in repo.message("FETCH_HEAD")
    finally:
        repo.cleanup()
Beispiel #2
0
def test_message_2():
    """test that commit messages from a range are read"""
    repo = GitRepo(FIXTURES / "git03", "main", "FETCH_HEAD")
    try:
        message = repo.message("9ee55a5b8723e2dd762421ebdc4faf5a349052d7.."
                               "f52af064b7d715ea87595e9b21f1ae6323064f88")
    finally:
        repo.cleanup()
    assert "Another commit" in message
    assert "/force-rebuild" in message
    assert "Initial commit" not in message
Beispiel #3
0
def test_github_changed(mocker):
    """test github lists changed files in commit range"""
    repo = GitRepo(FIXTURES / "git02", "main", "FETCH_HEAD")
    try:
        evt = GithubEvent()
        evt.repo = repo
        evt.commit_range = "HEAD^..HEAD"
        changed_paths = set(evt.list_changed_paths())
        assert changed_paths == {repo.path / "a.txt"}
    finally:
        repo.cleanup()
Beispiel #4
0
def test_cleanup():
    """test that repo is checked out in a temp folder and removed by cleanup"""
    repo = GitRepo(FIXTURES / "git01", "main", "FETCH_HEAD")
    try:
        repo_path = repo.path
        assert repo_path.is_dir()
        assert (repo_path / ".git").is_dir()
        assert Path(gettempdir()) in repo_path.parents
    finally:
        repo.cleanup()
    assert not repo_path.exists()
    assert repo.path is None
Beispiel #5
0
def test_existing():
    """test that existing repo can be accessed and is not cleaned up"""
    root = FIXTURES / "git01"
    repo = GitRepo.from_existing(root)
    try:
        assert "Test commit message" in repo.message("HEAD")
    finally:
        repo.cleanup()
    assert root.is_dir()  # test fixture wasn't cleaned up :sweat_smile:
Beispiel #6
0
def test_retry(mocker):
    sleep = mocker.patch("orion_decision.git.sleep", autospec=True)
    with pytest.raises(CalledProcessError):
        GitRepo(FIXTURES / "git-noexist", "main", "FETCH_HEAD")
    assert sleep.call_count == 9