|
| 1 | +"""Source-Platform Smoke-Test für CloudLockFixer. |
| 2 | +
|
| 3 | +Prüft auf Linux und macOS (und Windows) ohne Cloud-Sync-Client oder GUI: |
| 4 | +- Modul-Import und Version |
| 5 | +- ops: rename, move, delete (plattformneutral, stdlib-only) |
| 6 | +- models: parse_txt_line, Queue-Persistenz |
| 7 | +- paths: data_dir cross-platform |
| 8 | +- worker: run_once ohne Cloud-Provider |
| 9 | +""" |
| 10 | +from __future__ import annotations |
| 11 | + |
| 12 | +from pathlib import Path |
| 13 | + |
| 14 | + |
| 15 | +def test_version_defined(): |
| 16 | + import cloudlockfixer |
| 17 | + assert cloudlockfixer.__version__ |
| 18 | + assert "." in cloudlockfixer.__version__ |
| 19 | + |
| 20 | + |
| 21 | +def test_ops_delete_file(tmp_path): |
| 22 | + from cloudlockfixer.ops import _delete_path |
| 23 | + f = tmp_path / "target.txt" |
| 24 | + f.write_text("x", encoding="utf-8") |
| 25 | + ok, msg = _delete_path(f) |
| 26 | + assert ok, msg |
| 27 | + assert not f.exists() |
| 28 | + |
| 29 | + |
| 30 | +def test_ops_rename_directory(tmp_path): |
| 31 | + from cloudlockfixer.ops import rename_path |
| 32 | + src = tmp_path / "old_dir" |
| 33 | + src.mkdir() |
| 34 | + (src / "file.txt").write_text("content", encoding="utf-8") |
| 35 | + ok, msg = rename_path(src, "new_dir") |
| 36 | + assert ok, msg |
| 37 | + assert (tmp_path / "new_dir" / "file.txt").exists() |
| 38 | + assert not src.exists() |
| 39 | + |
| 40 | + |
| 41 | +def test_ops_move_path(tmp_path): |
| 42 | + from cloudlockfixer.ops import move_path |
| 43 | + src = tmp_path / "a" / "item" |
| 44 | + src.mkdir(parents=True) |
| 45 | + (src / "data.txt").write_text("payload", encoding="utf-8") |
| 46 | + dst = tmp_path / "b" / "item" |
| 47 | + ok, msg = move_path(src, dst) |
| 48 | + assert ok, msg |
| 49 | + assert (dst / "data.txt").read_text(encoding="utf-8") == "payload" |
| 50 | + assert not src.exists() |
| 51 | + |
| 52 | + |
| 53 | +def test_parse_txt_line_variants(): |
| 54 | + from cloudlockfixer.models import parse_txt_line |
| 55 | + assert parse_txt_line("# Kommentar") is None |
| 56 | + assert parse_txt_line(" ") is None |
| 57 | + t = parse_txt_line('delete "/tmp/testfile"') |
| 58 | + assert t is not None |
| 59 | + assert t.chain[0].op == "delete" |
| 60 | + assert t.chain[0].src == "/tmp/testfile" |
| 61 | + t2 = parse_txt_line('rename "/tmp/old" "new_name"') |
| 62 | + assert t2.chain[0].op == "rename" |
| 63 | + assert t2.chain[0].arg == "new_name" |
| 64 | + |
| 65 | + |
| 66 | +def test_queue_add_and_roundtrip(tmp_path): |
| 67 | + from cloudlockfixer.models import Queue, Step, Task |
| 68 | + q = Queue(tmp_path) |
| 69 | + task = Task(chain=[Step(op="delete", src="/tmp/smoke_test_x")]) |
| 70 | + q.add(task) |
| 71 | + q2 = Queue(tmp_path) |
| 72 | + assert len(q2.tasks) == 1 |
| 73 | + assert q2.tasks[0].chain[0].op == "delete" |
| 74 | + assert q2.tasks[0].id == task.id |
| 75 | + |
| 76 | + |
| 77 | +def test_paths_data_dir_cross_platform(): |
| 78 | + from cloudlockfixer import paths |
| 79 | + d = paths.data_dir() |
| 80 | + assert isinstance(d, Path) |
| 81 | + # Linux/macOS: LOCALAPPDATA fehlt -> ~/.cloudlockfixer |
| 82 | + # Windows: %LOCALAPPDATA%\CloudLockFixer |
| 83 | + assert d.exists() |
| 84 | + |
| 85 | + |
| 86 | +def test_worker_run_once_local(tmp_path): |
| 87 | + from cloudlockfixer.models import Queue, Step, Task |
| 88 | + from cloudlockfixer.worker import run_once |
| 89 | + q = Queue(tmp_path) |
| 90 | + src = tmp_path / "source.txt" |
| 91 | + src.write_text("smoke", encoding="utf-8") |
| 92 | + q.add(Task(chain=[Step(op="rename", src=str(src), arg="renamed.txt")])) |
| 93 | + summary = run_once(q, force_pause=False) |
| 94 | + assert summary["done"] == 1 |
| 95 | + assert (tmp_path / "renamed.txt").exists() |
| 96 | + assert not src.exists() |
0 commit comments