forked from datalad/git-lad
42 lines
985 B
Python
42 lines
985 B
Python
import pytest
|
|
from click.testing import (
|
|
CliRunner,
|
|
Result,
|
|
)
|
|
from datalad_core.tests import AuditProgressHandler
|
|
|
|
from git_lad.__main__ import git_lad as gitlad_main
|
|
|
|
|
|
class GitLadTestCLIRunnerResult(Result):
|
|
def __init__(
|
|
self,
|
|
result: Result,
|
|
progress: AuditProgressHandler,
|
|
) -> None:
|
|
self.click = result
|
|
self.progress = progress
|
|
|
|
|
|
class GitLadTestCLIRunner:
|
|
def run(
|
|
self,
|
|
cmd: list[str],
|
|
*,
|
|
raise_exception: bool = True,
|
|
) -> GitLadTestCLIRunnerResult:
|
|
ph = AuditProgressHandler()
|
|
res = CliRunner().invoke(
|
|
gitlad_main,
|
|
cmd,
|
|
obj={'progress_handler': ph},
|
|
)
|
|
if raise_exception and res.exception:
|
|
raise res.exception
|
|
|
|
return GitLadTestCLIRunnerResult(res, ph)
|
|
|
|
|
|
@pytest.fixture(autouse=False, scope='function') # noqa: PT003
|
|
def gitlad() -> GitLadTestCLIRunner:
|
|
return GitLadTestCLIRunner()
|