36 lines
1.4 KiB
Python
36 lines
1.4 KiB
Python
"""Tests for myagents.commands.upgrade (forwards to xiaohe upgrade)."""
|
|
|
|
from unittest.mock import patch
|
|
|
|
from click.testing import CliRunner
|
|
|
|
from myagents.commands import upgrade as up_mod
|
|
|
|
|
|
class TestUpgradeCommand:
|
|
def test_forwards_to_xiaohe(self) -> None:
|
|
with (
|
|
patch.object(up_mod.shutil, "which", return_value="/bin/xiaohe"),
|
|
patch.object(up_mod.subprocess, "call", return_value=0) as call,
|
|
):
|
|
result = CliRunner().invoke(up_mod.upgrade_cmd, ["0.5.1", "--force"])
|
|
assert result.exit_code == 0
|
|
call.assert_called_once_with(
|
|
["/bin/xiaohe", "upgrade", "0.5.1", "--force"]
|
|
)
|
|
|
|
def test_forwards_beta(self) -> None:
|
|
with (
|
|
patch.object(up_mod.shutil, "which", return_value="/bin/xiaohe"),
|
|
patch.object(up_mod.subprocess, "call", return_value=0) as call,
|
|
):
|
|
result = CliRunner().invoke(up_mod.upgrade_cmd, ["--beta"])
|
|
assert result.exit_code == 0
|
|
call.assert_called_once_with(["/bin/xiaohe", "upgrade", "--beta"])
|
|
|
|
def test_missing_xiaohe(self) -> None:
|
|
with patch.object(up_mod.shutil, "which", return_value=None):
|
|
result = CliRunner().invoke(up_mod.upgrade_cmd, [])
|
|
assert result.exit_code != 0
|
|
assert "Install xiaohe" in result.output or "xiaohe upgrade" in result.output
|