3f966a230e
CI / Lint, Typecheck & Test (push) Successful in 2m5s
将 13 个工具入口文件重构为通过 px.run_yaml 调用 YAML 配置, 辅助函数移至 _ops 模块。新增 run_yaml 便捷函数支持 job 选择 和传递依赖收集,修复 _build_cmd 列表变量展开,新增 bump_project_version 高层函数封装版本号更新+git 提交流程。
79 lines
2.8 KiB
Python
79 lines
2.8 KiB
Python
"""Tests for cli.folderzip module."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
from unittest.mock import patch
|
|
|
|
import pyflowx as px
|
|
from pyflowx.cli import folderzip
|
|
from pyflowx.cli._ops import files
|
|
|
|
|
|
# ---------------------------------------------------------------------- #
|
|
# archive_folder
|
|
# ---------------------------------------------------------------------- #
|
|
class TestArchiveFolder:
|
|
"""Test archive_folder function."""
|
|
|
|
def test_archive_folder(self, tmp_path: Path) -> None:
|
|
"""Should archive a folder."""
|
|
folder = tmp_path / "test_folder"
|
|
folder.mkdir()
|
|
(folder / "test.txt").write_text("test content")
|
|
|
|
with patch("shutil.make_archive") as mock_archive:
|
|
files.archive_folder(folder)
|
|
assert mock_archive.called
|
|
|
|
|
|
# ---------------------------------------------------------------------- #
|
|
# zip_folders
|
|
# ---------------------------------------------------------------------- #
|
|
class TestZipFolders:
|
|
"""Test zip_folders function."""
|
|
|
|
def test_zip_folders_with_cwd(self, tmp_path: Path) -> None:
|
|
"""Should zip folders in cwd."""
|
|
# Create some folders
|
|
(tmp_path / "folder1").mkdir()
|
|
(tmp_path / "folder2").mkdir()
|
|
(tmp_path / ".git").mkdir() # Should be ignored
|
|
|
|
with patch.object(files, "archive_folder") as mock_archive:
|
|
files.zip_folders(str(tmp_path))
|
|
# Should archive folder1 and folder2, but not .git
|
|
assert mock_archive.call_count == 2
|
|
|
|
def test_zip_folders_nonexistent_cwd(self, tmp_path: Path) -> None:
|
|
"""Should handle nonexistent cwd."""
|
|
files.zip_folders(str(tmp_path / "nonexistent"))
|
|
# Should print error message and return
|
|
|
|
|
|
# ---------------------------------------------------------------------- #
|
|
# 函数注册
|
|
# ---------------------------------------------------------------------- #
|
|
class TestRegisteredFunctions:
|
|
"""Test that folderzip functions are registered."""
|
|
|
|
def test_folderzip_default_spec(self) -> None:
|
|
"""folderzip_default should be a registered callable."""
|
|
# folderzip_default 现在是通过 @px.register_fn 注册的普通函数, 不是 TaskSpec
|
|
assert callable(files.folderzip_default)
|
|
|
|
|
|
# ---------------------------------------------------------------------- #
|
|
# main function
|
|
# ---------------------------------------------------------------------- #
|
|
class TestMain:
|
|
"""Test main function."""
|
|
|
|
def test_main_calls_run_yaml(self) -> None:
|
|
"""main() should parse args and call px.run_yaml()."""
|
|
with patch("sys.argv", ["folderzip", "--cwd", "."]), patch.object(px, "run_yaml") as mock_run_yaml:
|
|
folderzip.main()
|
|
assert mock_run_yaml.called
|
|
# 验证 jobs 参数为 "zip" (YAML 中的 job 名)
|
|
assert mock_run_yaml.call_args.kwargs["jobs"] == "zip"
|