mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-06-28 06:41:43 +00:00
make exception optional argument for check_output method
This commit is contained in:
@ -55,12 +55,10 @@ def test_fetch_existing(remote_source: RemoteSource, mocker: MockerFixture) -> N
|
||||
local = Path("local")
|
||||
Sources.fetch(local, remote_source)
|
||||
check_output_mock.assert_has_calls([
|
||||
MockCall("git", "fetch", "origin", remote_source.branch,
|
||||
exception=None, cwd=local, logger=pytest.helpers.anyvar(int)),
|
||||
MockCall("git", "checkout", "--force", remote_source.branch,
|
||||
exception=None, cwd=local, logger=pytest.helpers.anyvar(int)),
|
||||
MockCall("git", "fetch", "origin", remote_source.branch, cwd=local, logger=pytest.helpers.anyvar(int)),
|
||||
MockCall("git", "checkout", "--force", remote_source.branch, cwd=local, logger=pytest.helpers.anyvar(int)),
|
||||
MockCall("git", "reset", "--hard", f"origin/{remote_source.branch}",
|
||||
exception=None, cwd=local, logger=pytest.helpers.anyvar(int))
|
||||
cwd=local, logger=pytest.helpers.anyvar(int)),
|
||||
])
|
||||
move_mock.assert_called_once_with(local.resolve(), local)
|
||||
|
||||
@ -77,11 +75,10 @@ def test_fetch_new(remote_source: RemoteSource, mocker: MockerFixture) -> None:
|
||||
Sources.fetch(local, remote_source)
|
||||
check_output_mock.assert_has_calls([
|
||||
MockCall("git", "clone", "--branch", remote_source.branch, "--single-branch",
|
||||
remote_source.git_url, str(local), exception=None, cwd=local, logger=pytest.helpers.anyvar(int)),
|
||||
MockCall("git", "checkout", "--force", remote_source.branch,
|
||||
exception=None, cwd=local, logger=pytest.helpers.anyvar(int)),
|
||||
remote_source.git_url, str(local), cwd=local, logger=pytest.helpers.anyvar(int)),
|
||||
MockCall("git", "checkout", "--force", remote_source.branch, cwd=local, logger=pytest.helpers.anyvar(int)),
|
||||
MockCall("git", "reset", "--hard", f"origin/{remote_source.branch}",
|
||||
exception=None, cwd=local, logger=pytest.helpers.anyvar(int))
|
||||
cwd=local, logger=pytest.helpers.anyvar(int))
|
||||
])
|
||||
move_mock.assert_called_once_with(local.resolve(), local)
|
||||
|
||||
@ -97,10 +94,9 @@ def test_fetch_new_without_remote(mocker: MockerFixture) -> None:
|
||||
local = Path("local")
|
||||
Sources.fetch(local, None)
|
||||
check_output_mock.assert_has_calls([
|
||||
MockCall("git", "checkout", "--force", Sources.DEFAULT_BRANCH,
|
||||
exception=None, cwd=local, logger=pytest.helpers.anyvar(int)),
|
||||
MockCall("git", "checkout", "--force", Sources.DEFAULT_BRANCH, cwd=local, logger=pytest.helpers.anyvar(int)),
|
||||
MockCall("git", "reset", "--hard", f"origin/{Sources.DEFAULT_BRANCH}",
|
||||
exception=None, cwd=local, logger=pytest.helpers.anyvar(int))
|
||||
cwd=local, logger=pytest.helpers.anyvar(int))
|
||||
])
|
||||
move_mock.assert_called_once_with(local.resolve(), local)
|
||||
|
||||
@ -124,8 +120,7 @@ def test_has_remotes(mocker: MockerFixture) -> None:
|
||||
|
||||
local = Path("local")
|
||||
assert Sources.has_remotes(local)
|
||||
check_output_mock.assert_called_once_with(
|
||||
"git", "remote", exception=None, cwd=local, logger=pytest.helpers.anyvar(int))
|
||||
check_output_mock.assert_called_once_with("git", "remote", cwd=local, logger=pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
def test_has_remotes_empty(mocker: MockerFixture) -> None:
|
||||
@ -145,7 +140,7 @@ def test_init(mocker: MockerFixture) -> None:
|
||||
local = Path("local")
|
||||
Sources.init(local)
|
||||
check_output_mock.assert_called_once_with("git", "init", "--initial-branch", Sources.DEFAULT_BRANCH,
|
||||
exception=None, cwd=local, logger=pytest.helpers.anyvar(int))
|
||||
cwd=local, logger=pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
def test_load(package_ahriman: Package, repository_paths: RepositoryPaths, mocker: MockerFixture) -> None:
|
||||
@ -225,7 +220,7 @@ def test_push(package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
commit_mock.assert_called_once_with(local)
|
||||
check_output_mock.assert_called_once_with(
|
||||
"git", "push", package_ahriman.remote.git_url, package_ahriman.remote.branch,
|
||||
exception=None, cwd=local, logger=pytest.helpers.anyvar(int))
|
||||
cwd=local, logger=pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
def test_add(sources: Sources, mocker: MockerFixture) -> None:
|
||||
@ -239,8 +234,8 @@ def test_add(sources: Sources, mocker: MockerFixture) -> None:
|
||||
sources.add(local, "pattern1", "pattern2")
|
||||
glob_mock.assert_has_calls([MockCall("pattern1"), MockCall("pattern2")])
|
||||
check_output_mock.assert_called_once_with(
|
||||
"git", "add", "--intent-to-add", "1", "2", "1", "2",
|
||||
exception=None, cwd=local, logger=pytest.helpers.anyvar(int))
|
||||
"git", "add", "--intent-to-add", "1", "2", "1", "2", cwd=local, logger=pytest.helpers.anyvar(int)
|
||||
)
|
||||
|
||||
|
||||
def test_add_skip(sources: Sources, mocker: MockerFixture) -> None:
|
||||
@ -264,8 +259,7 @@ def test_commit(sources: Sources, mocker: MockerFixture) -> None:
|
||||
commit_message = "Commit message"
|
||||
sources.commit(local, commit_message=commit_message)
|
||||
check_output_mock.assert_called_once_with(
|
||||
"git", "commit", "--allow-empty", "--message", commit_message,
|
||||
exception=None, cwd=local, logger=pytest.helpers.anyvar(int)
|
||||
"git", "commit", "--allow-empty", "--message", commit_message, cwd=local, logger=pytest.helpers.anyvar(int)
|
||||
)
|
||||
|
||||
|
||||
@ -279,7 +273,7 @@ def test_commit_autogenerated(sources: Sources, mocker: MockerFixture) -> None:
|
||||
sources.commit(Path("local"))
|
||||
check_output_mock.assert_called_once_with(
|
||||
"git", "commit", "--allow-empty", "--message", pytest.helpers.anyvar(str, strict=True),
|
||||
exception=None, cwd=local, logger=pytest.helpers.anyvar(int)
|
||||
cwd=local, logger=pytest.helpers.anyvar(int)
|
||||
)
|
||||
|
||||
|
||||
@ -291,8 +285,7 @@ def test_diff(sources: Sources, mocker: MockerFixture) -> None:
|
||||
|
||||
local = Path("local")
|
||||
assert sources.diff(local)
|
||||
check_output_mock.assert_called_once_with(
|
||||
"git", "diff", exception=None, cwd=local, logger=pytest.helpers.anyvar(int))
|
||||
check_output_mock.assert_called_once_with("git", "diff", cwd=local, logger=pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
def test_move(sources: Sources, mocker: MockerFixture) -> None:
|
||||
@ -326,7 +319,7 @@ def test_patch_apply(sources: Sources, mocker: MockerFixture) -> None:
|
||||
sources.patch_apply(local, patch)
|
||||
check_output_mock.assert_called_once_with(
|
||||
"git", "apply", "--ignore-space-change", "--ignore-whitespace",
|
||||
exception=None, cwd=local, input_data=patch.value, logger=pytest.helpers.anyvar(int)
|
||||
cwd=local, input_data=patch.value, logger=pytest.helpers.anyvar(int)
|
||||
)
|
||||
|
||||
|
||||
|
@ -105,8 +105,7 @@ def test_key_import(gpg: GPG, mocker: MockerFixture) -> None:
|
||||
check_output_mock = mocker.patch("ahriman.core.sign.gpg.GPG._check_output")
|
||||
|
||||
gpg.key_import("pgp.mit.edu", "0xE989490C")
|
||||
check_output_mock.assert_called_once_with(
|
||||
"gpg", "--import", input_data="key", exception=None, logger=pytest.helpers.anyvar(int))
|
||||
check_output_mock.assert_called_once_with("gpg", "--import", input_data="key", logger=pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
def test_process(gpg_with_key: GPG, mocker: MockerFixture) -> None:
|
||||
|
@ -22,10 +22,10 @@ def test_check_output(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
logger_mock = mocker.patch("logging.Logger.debug")
|
||||
|
||||
assert check_output("echo", "hello", exception=None) == "hello"
|
||||
assert check_output("echo", "hello") == "hello"
|
||||
logger_mock.assert_not_called()
|
||||
|
||||
assert check_output("echo", "hello", exception=None, logger=logging.getLogger("")) == "hello"
|
||||
assert check_output("echo", "hello", logger=logging.getLogger("")) == "hello"
|
||||
logger_mock.assert_called_once_with("hello")
|
||||
|
||||
|
||||
@ -35,11 +35,11 @@ def test_check_output_stderr(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
logger_mock = mocker.patch("logging.Logger.debug")
|
||||
|
||||
assert check_output("python", "-c", """import sys; print("hello", file=sys.stderr)""", exception=None) == ""
|
||||
assert check_output("python", "-c", """import sys; print("hello", file=sys.stderr)""") == ""
|
||||
logger_mock.assert_not_called()
|
||||
|
||||
assert check_output("python", "-c", """import sys; print("hello", file=sys.stderr)""",
|
||||
exception=None, logger=logging.getLogger("")) == ""
|
||||
logger=logging.getLogger("")) == ""
|
||||
logger_mock.assert_called_once_with("hello")
|
||||
|
||||
|
||||
@ -48,7 +48,7 @@ def test_check_output_with_stdin() -> None:
|
||||
must run command and put string to stdin
|
||||
"""
|
||||
assert check_output("python", "-c", "import sys; value = sys.stdin.read(); print(value)",
|
||||
exception=None, input_data="single line") == "single line"
|
||||
input_data="single line") == "single line"
|
||||
|
||||
|
||||
def test_check_output_with_stdin_newline() -> None:
|
||||
@ -56,7 +56,7 @@ def test_check_output_with_stdin_newline() -> None:
|
||||
must run command and put string to stdin ending with new line
|
||||
"""
|
||||
assert check_output("python", "-c", "import sys; value = sys.stdin.read(); print(value)",
|
||||
exception=None, input_data="single line\n") == "single line"
|
||||
input_data="single line\n") == "single line"
|
||||
|
||||
|
||||
def test_check_output_multiple_with_stdin() -> None:
|
||||
@ -64,7 +64,7 @@ def test_check_output_multiple_with_stdin() -> None:
|
||||
must run command and put multiple lines to stdin
|
||||
"""
|
||||
assert check_output("python", "-c", "import sys; value = sys.stdin.read(); print(value)",
|
||||
exception=None, input_data="multiple\nlines") == "multiple\nlines"
|
||||
input_data="multiple\nlines") == "multiple\nlines"
|
||||
|
||||
|
||||
def test_check_output_multiple_with_stdin_newline() -> None:
|
||||
@ -72,7 +72,7 @@ def test_check_output_multiple_with_stdin_newline() -> None:
|
||||
must run command and put multiple lines to stdin with new line at the end
|
||||
"""
|
||||
assert check_output("python", "-c", "import sys; value = sys.stdin.read(); print(value)",
|
||||
exception=None, input_data="multiple\nlines\n") == "multiple\nlines"
|
||||
input_data="multiple\nlines\n") == "multiple\nlines"
|
||||
|
||||
|
||||
def test_check_output_failure(mocker: MockerFixture) -> None:
|
||||
@ -82,10 +82,10 @@ def test_check_output_failure(mocker: MockerFixture) -> None:
|
||||
mocker.patch("subprocess.Popen.wait", return_value=1)
|
||||
|
||||
with pytest.raises(subprocess.CalledProcessError):
|
||||
check_output("echo", "hello", exception=None)
|
||||
check_output("echo", "hello")
|
||||
|
||||
with pytest.raises(subprocess.CalledProcessError):
|
||||
check_output("echo", "hello", exception=None, logger=logging.getLogger(""))
|
||||
check_output("echo", "hello", logger=logging.getLogger(""))
|
||||
|
||||
|
||||
def test_check_output_failure_exception(mocker: MockerFixture) -> None:
|
||||
|
@ -10,4 +10,4 @@ def test_sync(rsync: Rsync, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
check_output_mock = mocker.patch("ahriman.core.upload.rsync.Rsync._check_output")
|
||||
rsync.sync(Path("path"), [])
|
||||
check_output_mock.assert_called_once_with(*rsync.command, "path", rsync.remote, exception=None, logger=rsync.logger)
|
||||
check_output_mock.assert_called_once_with(*rsync.command, "path", rsync.remote, logger=rsync.logger)
|
||||
|
Reference in New Issue
Block a user