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 模块的测试保留)
104 lines
3.6 KiB
Python
104 lines
3.6 KiB
Python
"""Tests for cli.filedate module."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
from pyflowx.cli._ops import files
|
|
|
|
|
|
# ---------------------------------------------------------------------- #
|
|
# get_file_timestamp
|
|
# ---------------------------------------------------------------------- #
|
|
class TestGetFileTimestamp:
|
|
"""Test get_file_timestamp function."""
|
|
|
|
def test_get_file_timestamp(self, tmp_path: Path) -> None:
|
|
"""Should get file timestamp."""
|
|
test_file = tmp_path / "test.txt"
|
|
test_file.write_text("test content")
|
|
|
|
timestamp = files.get_file_timestamp(test_file)
|
|
assert len(timestamp) == 8 # YYYYMMDD format
|
|
assert timestamp.isdigit()
|
|
|
|
|
|
# ---------------------------------------------------------------------- #
|
|
# remove_date_prefix
|
|
# ---------------------------------------------------------------------- #
|
|
class TestRemoveDatePrefix:
|
|
"""Test remove_date_prefix function."""
|
|
|
|
def test_remove_date_prefix_with_date(self, tmp_path: Path) -> None:
|
|
"""Should remove date prefix from filename."""
|
|
test_file = tmp_path / "20240101_test.txt"
|
|
test_file.write_text("test content")
|
|
|
|
new_path = files.remove_date_prefix(test_file)
|
|
assert new_path.name == "test.txt"
|
|
|
|
def test_remove_date_prefix_without_date(self, tmp_path: Path) -> None:
|
|
"""Should not change filename without date prefix."""
|
|
test_file = tmp_path / "test.txt"
|
|
test_file.write_text("test content")
|
|
|
|
new_path = files.remove_date_prefix(test_file)
|
|
assert new_path == test_file
|
|
|
|
|
|
# ---------------------------------------------------------------------- #
|
|
# add_date_prefix
|
|
# ---------------------------------------------------------------------- #
|
|
class TestAddDatePrefix:
|
|
"""Test add_date_prefix function."""
|
|
|
|
def test_add_date_prefix(self, tmp_path: Path) -> None:
|
|
"""Should add date prefix to filename."""
|
|
test_file = tmp_path / "test.txt"
|
|
test_file.write_text("test content")
|
|
|
|
new_path = files.add_date_prefix(test_file)
|
|
assert new_path.name.startswith("20") # Starts with year
|
|
assert "_test.txt" in new_path.name
|
|
|
|
|
|
# ---------------------------------------------------------------------- #
|
|
# process_file_date
|
|
# ---------------------------------------------------------------------- #
|
|
class TestProcessFileDate:
|
|
"""Test process_file_date function."""
|
|
|
|
def test_process_file_date_add(self, tmp_path: Path) -> None:
|
|
"""Should add date prefix."""
|
|
test_file = tmp_path / "test.txt"
|
|
test_file.write_text("test content")
|
|
|
|
files.process_file_date(test_file, clear=False)
|
|
# File should be renamed with date prefix
|
|
|
|
def test_process_file_date_clear(self, tmp_path: Path) -> None:
|
|
"""Should clear date prefix."""
|
|
test_file = tmp_path / "20240101_test.txt"
|
|
test_file.write_text("test content")
|
|
|
|
files.process_file_date(test_file, clear=True)
|
|
# File should be renamed without date prefix
|
|
|
|
|
|
# ---------------------------------------------------------------------- #
|
|
# process_files_date
|
|
# ---------------------------------------------------------------------- #
|
|
class TestProcessFilesDate:
|
|
"""Test process_files_date function."""
|
|
|
|
def test_process_files_date_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_date(file_list, clear=False)
|
|
# All files should be processed
|