de368ea810
CI / Lint, Typecheck & Test (push) Successful in 1m11s
1. 删除 13 个已有 YAML 配置的 cli .py 入口脚本, 统一通过 pf 调用 2. gittool.yaml 用 CLEAN_EXCLUDES 数组变量配置 git clean 的 -e 参数, 保留 .venv/.tox/node_modules/.idea 等目录避免误删 3. run_cli 执行前打印调用信息: [gittool] 执行: c 4. 更新 pyproject.toml 移除 13 个冗余 entry points, 仅保留 pf 5. 清理测试文件中的 TestMain 类 (测 _ops 模块的测试保留)
97 lines
3.3 KiB
Python
97 lines
3.3 KiB
Python
"""Tests for cli.filelevel module."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
from pyflowx.cli._ops import files
|
|
|
|
|
|
# ---------------------------------------------------------------------- #
|
|
# remove_marks
|
|
# ---------------------------------------------------------------------- #
|
|
class TestRemoveMarks:
|
|
"""Test remove_marks function."""
|
|
|
|
def test_remove_marks_single_mark(self) -> None:
|
|
"""Should remove single mark."""
|
|
stem = "filename(PUB)"
|
|
result = files.remove_marks(stem, ["PUB"])
|
|
assert result == "filename"
|
|
|
|
def test_remove_marks_multiple_marks(self) -> None:
|
|
"""Should remove multiple marks."""
|
|
stem = "filename(PUB)(NOR)"
|
|
result = files.remove_marks(stem, ["PUB", "NOR"])
|
|
assert result == "filename"
|
|
|
|
def test_remove_marks_no_marks(self) -> None:
|
|
"""Should not change stem without marks."""
|
|
stem = "filename"
|
|
result = files.remove_marks(stem, ["PUB"])
|
|
assert result == "filename"
|
|
|
|
|
|
# ---------------------------------------------------------------------- #
|
|
# process_file_level
|
|
# ---------------------------------------------------------------------- #
|
|
class TestProcessFileLevel:
|
|
"""Test process_file_level function."""
|
|
|
|
def test_process_file_level_set_pub(self, tmp_path: Path) -> None:
|
|
"""Should set PUB level."""
|
|
test_file = tmp_path / "test.txt"
|
|
test_file.write_text("test content")
|
|
|
|
files.process_file_level(test_file, level=1)
|
|
# File should be renamed with PUB level
|
|
|
|
def test_process_file_level_set_int(self, tmp_path: Path) -> None:
|
|
"""Should set INT level."""
|
|
test_file = tmp_path / "test.txt"
|
|
test_file.write_text("test content")
|
|
|
|
files.process_file_level(test_file, level=2)
|
|
# File should be renamed with INT level
|
|
|
|
def test_process_file_level_clear(self, tmp_path: Path) -> None:
|
|
"""Should clear level."""
|
|
test_file = tmp_path / "test(PUB).txt"
|
|
test_file.write_text("test content")
|
|
|
|
files.process_file_level(test_file, level=0)
|
|
# File should be renamed without level
|
|
|
|
def test_process_file_level_invalid_level(self, tmp_path: Path) -> None:
|
|
"""Should handle invalid level."""
|
|
test_file = tmp_path / "test.txt"
|
|
test_file.write_text("test content")
|
|
|
|
files.process_file_level(test_file, level=5)
|
|
# Should print error message
|
|
|
|
def test_process_file_level_nonexistent_file(self, tmp_path: Path) -> None:
|
|
"""Should handle nonexistent file."""
|
|
test_file = tmp_path / "nonexistent.txt"
|
|
|
|
files.process_file_level(test_file, level=1)
|
|
# Should print error message
|
|
|
|
|
|
# ---------------------------------------------------------------------- #
|
|
# process_files_level
|
|
# ---------------------------------------------------------------------- #
|
|
class TestProcessFilesLevel:
|
|
"""Test process_files_level function."""
|
|
|
|
def test_process_files_level_batch(self, tmp_path: Path) -> None:
|
|
"""Should process multiple files."""
|
|
file_list = []
|
|
for i in range(3):
|
|
test_file = tmp_path / f"test{i}.txt"
|
|
test_file.write_text(f"content{i}")
|
|
file_list.append(test_file)
|
|
|
|
files.process_files_level(file_list, level=1)
|
|
# All files should be processed
|