Files
pyflowx/tests/cli/test_folderzip.py
T
zhou d93da0d8b4
CI / Lint, Typecheck & Test (push) Successful in 1m35s
refactor: 迁移 cli/_ops/ 到 ops/, 按类别保持 dev/files/media/system 分类
将 src/pyflowx/cli/_ops/ 整体迁移至 src/pyflowx/ops/, 与 cli/ 平级
(工具函数非 CLI 专属, 可被 YAML 任务编排通用引用). 分类保持不变:
dev (git/pip/bump/autofmt), files (date/level/back/zip),
media (pdf/screenshot), system (ls/pack/ssh).

同步更新 15 个引用文件 (yaml_loader + 14 个测试) 的 import 路径,
README 模块结构表与 test_registry docstring.
2026-07-05 17:30:35 +08:00

62 lines
2.2 KiB
Python

"""Tests for cli.folderzip module."""
from __future__ import annotations
from pathlib import Path
from unittest.mock import patch
from pyflowx.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)