mirror of
https://github.com/NCBM/plyngent.git
synced 2026-07-23 05:55:16 +08:00
core/cli: multiline \"\"\" input and /edit via EDITOR
Add triple-quote block messages in the REPL and /edit to compose a turn in $EDITOR (temp file). Empty multiline or empty edit cancels.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from click.testing import CliRunner
|
||||
@@ -14,9 +14,6 @@ from plyngent.cli.editor import (
|
||||
resolve_config_path,
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def test_get_editor(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.delenv("EDITOR", raising=False)
|
||||
@@ -66,6 +63,42 @@ def test_open_in_editor_missing_editor(tmp_path: Path, monkeypatch: pytest.Monke
|
||||
open_in_editor(tmp_path / "x.toml", editor=None)
|
||||
|
||||
|
||||
def test_edit_text_in_editor(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
from plyngent.cli.editor import edit_text_in_editor
|
||||
|
||||
def fake_run(argv: list[str], check: bool = False) -> object:
|
||||
del check
|
||||
path = Path(argv[-1])
|
||||
_ = path.write_text("hello from editor\n", encoding="utf-8")
|
||||
|
||||
class Result:
|
||||
returncode: int = 0
|
||||
|
||||
return Result()
|
||||
|
||||
monkeypatch.setenv("EDITOR", "true")
|
||||
monkeypatch.setattr("plyngent.cli.editor.subprocess.run", fake_run)
|
||||
assert edit_text_in_editor("seed") == "hello from editor"
|
||||
|
||||
|
||||
def test_edit_text_empty_cancels(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
from plyngent.cli.editor import edit_text_in_editor
|
||||
|
||||
def fake_run(argv: list[str], check: bool = False) -> object:
|
||||
del check
|
||||
path = Path(argv[-1])
|
||||
_ = path.write_text(" \n", encoding="utf-8")
|
||||
|
||||
class Result:
|
||||
returncode: int = 0
|
||||
|
||||
return Result()
|
||||
|
||||
monkeypatch.setenv("EDITOR", "true")
|
||||
monkeypatch.setattr("plyngent.cli.editor.subprocess.run", fake_run)
|
||||
assert edit_text_in_editor("") is None
|
||||
|
||||
|
||||
def test_prompt_edit_no_editor(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.delenv("EDITOR", raising=False)
|
||||
assert prompt_edit_config(tmp_path / "p.toml") is False
|
||||
|
||||
Reference in New Issue
Block a user