Files
pyflowx/tests/cli/test_folderzip.py
T
zhou 04d6871e8d chore: 发布v0.4.8版本,清理冗余代码并优化跨平台实现
1. 移除folderzip和folderback模块中的默认导出函数与测试用例
2. 重构跨平台命令获取逻辑,统一使用platform_common工具函数
3. 移动IGNORE_PATTERNS常量到公共模块,精简packtool和autofmt代码
4. 重构平台检查逻辑,复用ensure_platform减少重复代码
5. 优化pdftool模块的依赖检查逻辑,提取公共检查函数
6. 修复测试用例中的字符串断言冗余内容
2026-07-06 20:22:59 +08:00

50 lines
1.7 KiB
Python

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