test: 重构CLI测试用例,统一使用px.CliRunner和px.run测试主函数
1. 替换所有旧的main函数测试逻辑,统一使用pyflowx的CliRunner和run方法进行测试 2. 重构测试类命名,将零散测试合并为TaskSpec验证测试 3. 优化测试用例结构,移除冗余的pytest依赖导入和旧版测试代码 4. 更新文件夹备份、压缩等模块的测试逻辑,适配新的工具函数实现
This commit is contained in:
+15
-26
@@ -2,25 +2,27 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
import pyflowx as px
|
||||
from pyflowx.cli import envqt
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------- #
|
||||
# set_qt_mirror
|
||||
# TaskSpec definitions
|
||||
# ---------------------------------------------------------------------- #
|
||||
class TestSetQtMirror:
|
||||
"""Test set_qt_mirror function."""
|
||||
class TestTaskSpecDefinitions:
|
||||
"""Test that all TaskSpec definitions are valid."""
|
||||
|
||||
def test_set_qt_mirror(self, tmp_path: Path) -> None:
|
||||
"""Should set Qt mirror."""
|
||||
with patch.object(Path, "home", return_value=tmp_path):
|
||||
envqt.set_qt_mirror()
|
||||
# Check Qt config
|
||||
def test_envqt_install_spec(self) -> None:
|
||||
"""envqt_install spec should be properly defined."""
|
||||
assert envqt.envqt_install.name == "envqt_install"
|
||||
assert envqt.envqt_install.cmd is not None
|
||||
|
||||
def test_envqt_fonts_spec(self) -> None:
|
||||
"""envqt_fonts spec should be properly defined."""
|
||||
assert envqt.envqt_fonts.name == "envqt_fonts"
|
||||
assert envqt.envqt_fonts.cmd is not None
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------- #
|
||||
@@ -31,19 +33,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:
|
||||
envqt.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", ["envqt", "--list"]), pytest.raises(SystemExit) as exc_info:
|
||||
envqt.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", ["envqt"]), pytest.raises(SystemExit) as exc_info:
|
||||
envqt.main()
|
||||
assert exc_info.value.code == 1
|
||||
assert mock_run_cli.called
|
||||
|
||||
Reference in New Issue
Block a user