feat: TUI 命令 stop/pause/continue + 单文件进度条改为文件计数轮询
This commit is contained in:
1 parent
7ab32bad24
commit
81857d6343
3 files changed
+145
-9
No files matched your search
@@ -1,6 +1,7 @@
|
||||
"""transfer.py 核心逻辑测试:解析器 / 日志轮转 / 参数解析 / 后端命令构建"""
|
||||
import re
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
@@ -307,3 +308,61 @@ def test_rsync_verify_cmd():
|
||||
def test_rsync_verify_cmd_no_bwlimit():
|
||||
cmd = transfer.RsyncBackend.build_verify_cmd("a/", "b/")
|
||||
assert "--bwlimit" not in " ".join(cmd)
|
||||
|
||||
# ---------- 暂停/继续/停止 (TUI 命令) ----------
|
||||
|
||||
def _proc_state(pid: int) -> str:
|
||||
with open(f"/proc/{pid}/stat") as fh:
|
||||
return fh.read().split()[2] # 状态字段: R/S/T/D/Z
|
||||
|
||||
|
||||
def _make_runner(tmp_path) -> "transfer.TaskRunner":
|
||||
cfg = transfer.TransferConfig("s", "d")
|
||||
lm = transfer.LogManager(str(tmp_path), keep=20)
|
||||
return transfer.TaskRunner(cfg, lm)
|
||||
|
||||
|
||||
def test_pause_sends_sigstop(tmp_path):
|
||||
r = _make_runner(tmp_path)
|
||||
p = subprocess.Popen(["sleep", "30"], start_new_session=True)
|
||||
r.proc = p
|
||||
r.pause()
|
||||
assert r._paused is True
|
||||
assert _proc_state(p.pid) == "T" # T = stopped
|
||||
p.kill()
|
||||
p.wait()
|
||||
|
||||
|
||||
def test_resume_sends_sigcont(tmp_path):
|
||||
r = _make_runner(tmp_path)
|
||||
p = subprocess.Popen(["sleep", "30"], start_new_session=True)
|
||||
r.proc = p
|
||||
r.pause()
|
||||
r.resume()
|
||||
assert r._paused is False
|
||||
assert _proc_state(p.pid) in ("S", "R") # 已恢复
|
||||
p.kill()
|
||||
p.wait()
|
||||
|
||||
|
||||
def test_pause_idempotent_when_no_proc(tmp_path):
|
||||
r = _make_runner(tmp_path)
|
||||
r.pause() # 无进程不报错
|
||||
assert r._paused is False
|
||||
|
||||
# ---------- 文件计数 (单文件进度条数据源) ----------
|
||||
|
||||
def test_count_files_recursive(tmp_path):
|
||||
(tmp_path / "a.flac").write_text("x")
|
||||
(tmp_path / "sub").mkdir()
|
||||
(tmp_path / "sub" / "b.lrc").write_text("y")
|
||||
(tmp_path / "sub" / "c.flac").write_text("z")
|
||||
assert transfer.count_files(str(tmp_path)) == 3
|
||||
|
||||
def test_count_files_missing_returns_zero():
|
||||
assert transfer.count_files("/nonexistent/xyz") == 0
|
||||
|
||||
def test_count_files_only_files(tmp_path):
|
||||
(tmp_path / "a.txt").write_text("x")
|
||||
(tmp_path / "dir1").mkdir()
|
||||
assert transfer.count_files(str(tmp_path)) == 1 # 目录不计
|
||||
Reference in new issue
Block a user