test: 重构CLI测试用例,统一使用px.CliRunner和px.run测试主函数

1.  替换所有旧的main函数测试逻辑,统一使用pyflowx的CliRunner和run方法进行测试
2.  重构测试类命名,将零散测试合并为TaskSpec验证测试
3.  优化测试用例结构,移除冗余的pytest依赖导入和旧版测试代码
4.  更新文件夹备份、压缩等模块的测试逻辑,适配新的工具函数实现
This commit is contained in:
2026-06-22 12:03:30 +08:00
parent 843e9369fe
commit d4a1a5c2de
6 changed files with 212 additions and 269 deletions
+17 -17
View File
@@ -2,10 +2,11 @@
from __future__ import annotations
from unittest.mock import MagicMock, patch
from unittest.mock import patch, MagicMock
import pytest
import pyflowx as px
from pyflowx.cli import bumpversion
@@ -39,10 +40,22 @@ class TestBumpVersion:
def test_bump_version_with_tag(self) -> None:
"""Should bump version with tag."""
with patch("subprocess.run") as mock_run:
mock_run.return_value = MagicMock(returncode=0)
mock_run.return_value = MagicMock(returncode=0, stdout="v1.0.0")
bumpversion.bump_version("patch", tag=True)
assert mock_run.called
def test_bump_version_with_commit(self) -> None:
"""Should bump version with commit."""
with patch("subprocess.run") as mock_run:
mock_run.return_value = MagicMock(returncode=0)
bumpversion.bump_version("patch", commit=True)
assert mock_run.called
def test_bump_version_file_not_found(self) -> None:
"""Should handle FileNotFoundError."""
with patch("subprocess.run", side_effect=FileNotFoundError), pytest.raises(FileNotFoundError):
bumpversion.bump_version("patch")
# ---------------------------------------------------------------------- #
# bump_version_alpha
@@ -88,19 +101,6 @@ class TestMain:
def test_main_calls_run_cli(self) -> None:
"""main() should create a CliRunner and call run_cli()."""
with pytest.raises(SystemExit) as exc_info:
with patch.object(px.CliRunner, "run_cli") as mock_run_cli:
bumpversion.main()
# run_cli() calls sys.exit(), so we should get SystemExit
assert exc_info.value.code in (0, 1, 2)
def test_main_with_list_argument(self) -> None:
"""main() should handle --list argument."""
with patch("sys.argv", ["bumpversion", "--list"]), pytest.raises(SystemExit) as exc_info:
bumpversion.main()
assert exc_info.value.code == 0
def test_main_with_no_args_shows_help(self) -> None:
"""main() with no args should show help and exit."""
with patch("sys.argv", ["bumpversion"]), pytest.raises(SystemExit) as exc_info:
bumpversion.main()
assert exc_info.value.code == 1
assert mock_run_cli.called