def test_fail(self, mock_git_repo):
        # setup
        step_implementer = GitMixin()

        # set up mocks
        mock_get_value = MagicMock()
        step_implementer.get_value = mock_get_value

        def mock_get_value_side_effect(key):
            if 'git-commit-message' in key:
                return 'mock commit message'

        mock_get_value.side_effect = mock_get_value_side_effect
        mock_git_repo.git.commit.side_effect = GitCommandError('mock error')
        type(mock_git_repo.active_branch).name = PropertyMock(
            return_value='mock-branch')

        # run test
        with self.assertRaisesRegex(
                StepRunnerException,
                r"Error committing changes to current branch \(mock-branch\): Cmd\('mock'\)"
                r" failed!\s*cmdline: mock error"):
            step_implementer.git_commit_changes()

        # validate
        mock_git_repo.git.commit.assert_called_with('-am',
                                                    'mock commit message')
Esempio n. 2
0
def test_push_should_not_print_gh_token(mock_git):
    mock_git.configure_mock(
        **{
            'push.side_effect':
            GitCommandError('gh--token', 1, b'gh--token', b'gh--token')
        })
    with pytest.raises(GitError) as excinfo:
        push_new_version(gh_token='gh--token')
    assert 'gh--token' not in str(excinfo)
Esempio n. 3
0
 def describe(rev=None, **kwargs):
     print("call to describe(%r, %r)" % (rev, kwargs))
     if rev is None:
         return CURRENT_TAG
     if rev.endswith("^"):
         if rev.startswith(CURRENT_TAG):
             return PREVIOUS_TAG
         raise GitCommandError("describe", "failed")
     raise AssertionError("Test wants to describe something unexpected: rev=%r, kwargs=%r" % (rev, kwargs))
def test_push_should_not_print_auth_token(mock_gitlab, mock_git):
    mock_git.configure_mock(
        **{
            "push.side_effect":
            GitCommandError("auth--token", 1, b"auth--token", b"auth--token")
        })
    with pytest.raises(GitError) as excinfo:
        push_new_version(auth_token="auth--token")
    assert "auth--token" not in str(excinfo)
Esempio n. 5
0
    def test_clone_failure(self, mock_repo, mock_rmtree):
        """
        Tests failing to merge a branch.
        """
        mock_repo.clone_from.side_effect = GitCommandError('cmd', 1)

        with self.assertRaises(GitCommandError):
            LocalGitAPI.clone('[email protected]:edx/tubular.git', 'bar')
        self.assertEqual(mock_rmtree.call_count, 0)
Esempio n. 6
0
    def test_fetch_git_clone_error(self, git_dependency, mocker):
        """Error when fetching a Git repository."""
        mocked_exists = mocker.patch.object(Path, "exists", autospec=True)
        mocked_exists.return_value = False
        mocker.patch.object(Path, "mkdir_p", autospec=True)
        mocked_repo = mocker.patch("dependencmake.dependency.Repo")
        mocked_repo.clone_from.side_effect = GitCommandError("error message", "000")

        with pytest.raises(
            GitRepoFetchError,
            match=r"Cannot fetch My Git dep at http://example.com/dependency.git",
        ):
            git_dependency.fetch_git()
Esempio n. 7
0
    def test_cleanup(self, failing_mock, mock_repo, mock_rmtree):
        """
        Tests failing to merge a branch.
        """
        mock_repo.configure_mock(autospec=True,
                                 **{
                                     '{}.side_effect'.format(failing_mock):
                                     GitCommandError('cmd', 1)
                                 })

        with self.assertRaises(GitCommandError):
            LocalGitAPI.clone('[email protected]:edx/tubular.git',
                              'bar').merge_branch('foo', 'bar')
            mock_rmtree.assert_called_once_with('tubular')
def test_push_should_not_print_auth_token(mock_git, mocker):
    mock_git.configure_mock(
        **{
            "push.side_effect": GitCommandError(
                "auth--token", 1, b"auth--token", b"auth--token"
            )
        }
    )
    mocker.patch(
        "semantic_release.vcs_helpers.config.get",
        wrapped_config_get(**{"hvcs": "gitlab"}),
    )
    with pytest.raises(GitError) as excinfo:
        push_new_version(auth_token="auth--token")
    assert "auth--token" not in str(excinfo)
    def test_fail(self, mock_git_repo):
        # setup
        step_implementer = GitMixin()

        # setup mock
        mock_git_repo.create_tag.side_effect = GitCommandError('mock error')

        # run test
        with self.assertRaisesRegex(
                StepRunnerException,
                r"Error creating git tag \(v0.42.0-mock\): Cmd\('mock'\) failed!\s*cmdline: mock error"
        ):
            step_implementer.git_tag(git_tag_value='v0.42.0-mock')

        # validate
        mock_git_repo.create_tag.assert_called_once_with('v0.42.0-mock',
                                                         force=True)
    def test_fail(self, mock_git_url, mock_git_repo):
        # setup
        step_implementer = GitMixin()

        # set up mocks
        mock_git_url.return_value = 'mock-url'
        type(mock_git_repo.active_branch).name = PropertyMock(
            return_value='mock-branch')
        mock_git_repo.git.push.side_effect = GitCommandError('mock error')

        # run test
        with self.assertRaisesRegex(
                StepRunnerException,
                r"Error pushing tags to remote \(mock-url\) on current branch \(mock-branch\):"
                r" Cmd\('mock'\) failed!\s*cmdline: mock error"):
            step_implementer.git_push_tags()

        # validate
        mock_git_repo.git.push.assert_called_with('mock-url', '--tag')
Esempio n. 11
0
def test_error_while_cloning_skip(display, clone_from):
    error = GitCommandError(command='git clone etc ....', status=218)

    def raise_error_only_for_hierachy_project(*args, url=None, **kwargs):
        if 'Hierarchy' in url:
            raise error

    hierarchy = MOCK_HIERARCHY
    clone_from.side_effect = raise_error_only_for_hierachy_project

    cloner.clone_all(hierarchy)

    # THEN
    # - Error message was displayed
    display.assert_any_call(Contains('Hierarchy'),
                            variant='ERROR',
                            reason=error)
    # - But next repo is still processed
    clone_from.assert_called_with(
        url='[email protected]:FlorianKempenich/kata.git', to_path=mock.ANY)
Esempio n. 12
0
 def show(self, var):
     raise GitCommandError("A", "B")
Esempio n. 13
0
 def pull_plugin(plugin_name, branch_name='dev'):
     """stub method to raise error on pull."""
     raise GitCommandError('test', None)
Esempio n. 14
0
    kwargs = {"recursive": True, "depth": 1, "shallow-submodules": True}
    if branch:
        kwargs["branch"] = branch

    clone_from.assert_called_once_with(
        REPO_URL,
        str(tmp_path),
        **kwargs,
    )


@pytest.mark.parametrize(
    "git_error",
    [InvalidGitRepositoryError(),
     NoSuchPathError(),
     GitCommandError("clone")],
)
async def test_git_clone_error(coresys: CoreSys, tmp_path: Path,
                               clone_from: AsyncMock, git_error: GitError):
    """Test git clone error."""
    repo = GitRepo(coresys, tmp_path, REPO_URL)

    clone_from.side_effect = git_error
    with pytest.raises(StoreGitCloneError):
        await repo.clone.__wrapped__(repo)

    assert len(coresys.resolution.suggestions) == 0


async def test_git_load(coresys: CoreSys, tmp_path: Path):
    """Test git load."""