from pathlib import Path
import pytest
from tui import ROOT, Tui, build
@pytest.fixture(scope="session")
def binary():
return build()
@pytest.fixture
def tui(binary):
with Tui(binary) as t:
yield t
def dismiss_launch_popup(tui: Tui) -> None:
tui.expect("search github")
tui.key("ESC")
tui.key("ESC")
tui.expect_gone("search github")
FS_PROVIDER = ROOT / "examples" / "providers" / "fs_provider.py"
def make_fs_root(tmp: Path) -> Path:
root = tmp / "code"
alpha = root / "alpha"
(alpha / "src").mkdir(parents=True)
(alpha / "src" / "main.rs").write_text(
"fn main() {\n"
" let view = render();\n"
" println!(\"{view}\");\n"
"}\n"
"\n"
"fn render() -> &'static str {\n"
" \"rootle\"\n"
"}\n"
)
(alpha / "README.md").write_text("# alpha\nrender docs\n")
beta = root / "beta"
beta.mkdir(parents=True)
(beta / "notes.txt").write_text("nothing to see\n")
return root
@pytest.fixture
def provider_tui(tmp_path, binary):
root = make_fs_root(tmp_path)
config = tmp_path / "provider.toml"
config.write_text(
"[provider]\n"
'kind = "stdio"\n'
f'command = ["python3", "{FS_PROVIDER}", "{root}"]\n'
)
t = Tui(binary, cols=110, rows=30, args=["--config", str(config)]).start()
yield t
t.stop()
def open_fs_repo(tui: Tui) -> None:
tui.type_query("alpha")
tui.key("ENTER")
tui.expect("local/alpha")
tui.key("ENTER")
tui.expect("README.md")