test/tools: cover workspace, file, run_command and PTY

This commit is contained in:
2026-07-14 18:20:32 +08:00
parent f23780171b
commit f45af76c9b
6 changed files with 212 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
from __future__ import annotations
from plyngent.tools.file import edit_replace, listdir, read_file, write_file
from tests.test_tools.helpers import call_sync
def test_write_read_listdir_edit(workspace: object) -> None:
del workspace
assert "wrote" in call_sync(write_file, "notes/a.txt", "hello world")
assert call_sync(read_file, "notes/a.txt") == "hello world"
listing = call_sync(listdir, "notes")
assert "a.txt" in listing
assert "file" in listing
result = call_sync(edit_replace, "notes/a.txt", "world", "there")
assert "replaced" in result
assert call_sync(read_file, "notes/a.txt") == "hello there"
def test_edit_replace_first_only(workspace: object) -> None:
del workspace
_ = call_sync(write_file, "t.txt", "aa aa")
_ = call_sync(edit_replace, "t.txt", "aa", "bb")
assert call_sync(read_file, "t.txt") == "bb aa"
def test_edit_missing_old_string(workspace: object) -> None:
del workspace
_ = call_sync(write_file, "t.txt", "x")
assert "not found" in call_sync(edit_replace, "t.txt", "missing", "y")
def test_read_offset_limit(workspace: object) -> None:
del workspace
_ = call_sync(write_file, "lines.txt", "a\nb\nc\nd\n")
assert call_sync(read_file, "lines.txt", offset=1, limit=2) == "b\nc\n"
def test_listdir_missing(workspace: object) -> None:
del workspace
assert "error" in call_sync(listdir, "nope")