Exemple #1
0
async def _push_async(pt: Push):
    """Asynchronous call to git push, pushing directly to the repo_url and branch.

    Args:
        pt: A Push namedtuple.
    """
    command = ["git", "push", pt.repo_url, pt.branch]
    proc = await asyncio.create_subprocess_exec(
        *command,
        cwd=os.path.abspath(pt.local_path),
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
    )
    _, stderr = await proc.communicate()

    if proc.returncode != 0:
        raise exception.PushFailedError(
            f"Failed to push to {pt.repo_url}",
            proc.returncode or -sys.maxsize,
            stderr,
            pt.repo_url,
        )
    elif b"Everything up-to-date" in stderr:
        plug.log.info(f"{pt.repo_url} is up-to-date")
    else:
        plug.log.info(f"Pushed files to {pt.repo_url} {pt.branch}")
Exemple #2
0
 async def raise_(pt):
     raise exception.PushFailedError("Push failed", 128, b"some error",
                                     pt.repo_url)
Exemple #3
0
    return mocker.patch("_repobee.git", autospec=True)


@pytest.fixture(scope="function", params=iter(repobee_plug.cli.CoreCommand))
def parsed_args_all_subparsers(request):
    """Parametrized fixture which returns a namespace for each of the
    subparsers. These arguments are valid for all subparsers, even though
    many will only use some of the arguments.
    """
    return argparse.Namespace(**request.param.asdict(), **VALID_PARSED_ARGS)


@pytest.fixture(
    scope="function",
    params=[
        exception.PushFailedError("some message", 128, b"error", "someurl"),
        exception.CloneFailedError("some message", 128, b"error", "someurl"),
        exception.GitError("some message", 128, b"error"),
        plug.PlatformError("some message"),
    ],
)
def command_all_raise_mock(command_mock, dummyapi_instance, request):
    """Mock of _repobee.command where all functions raise expected exceptions
    (i.e. those caught in _sys_exit_on_expected_error)
    """

    def raise_(*args, **kwargs):
        raise request.param

    command_mock.setup_student_repos.side_effect = raise_
    command_mock.update_student_repos.side_effect = raise_
Exemple #4
0
 async def raise_once(pt):
     nonlocal tried
     if not tried and pt == fail_pt:
         tried = True
         raise exception.PushFailedError("Push failed", 128,
                                         b"some error", pt.repo_url)