From 9703656b25b31f3e41c6220aeef7bfd66770e588 Mon Sep 17 00:00:00 2001 From: Xubin Ren <52506698+Re-bin@users.noreply.github.com> Date: Thu, 13 Aug 2026 23:52:51 +0900 Subject: [PATCH] test(webui): make folder picker tests portable --- tests/utils/test_native_folder_picker.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/utils/test_native_folder_picker.py b/tests/utils/test_native_folder_picker.py index 464f52633..f62a605f9 100644 --- a/tests/utils/test_native_folder_picker.py +++ b/tests/utils/test_native_folder_picker.py @@ -1,5 +1,6 @@ from __future__ import annotations +import sys from pathlib import Path import pytest @@ -7,22 +8,21 @@ import pytest from nanobot.webui import native_folder_picker as picker -def _picker_script(tmp_path: Path, body: str) -> Path: - script = tmp_path / "picker.sh" - script.write_text(f"#!/bin/sh\n{body}\n", encoding="utf-8") - script.chmod(0o755) - return script +def _picker_command(tmp_path: Path, body: str) -> picker._PickerCommand: + script = tmp_path / "picker.py" + script.write_text(f"{body}\n", encoding="utf-8") + return picker._PickerCommand((sys.executable, str(script)), frozenset({1})) @pytest.mark.asyncio async def test_pick_native_folder_returns_selected_directory(tmp_path, monkeypatch) -> None: selected = tmp_path / "project" selected.mkdir() - script = _picker_script(tmp_path, f"printf '%s' '{selected}'") + command = _picker_command(tmp_path, f"print({str(selected)!r}, end='')") monkeypatch.setattr( picker, "_picker_command", - lambda: picker._PickerCommand((str(script),), frozenset({1})), + lambda: command, ) assert await picker.pick_native_folder() == str(selected) @@ -30,11 +30,11 @@ async def test_pick_native_folder_returns_selected_directory(tmp_path, monkeypat @pytest.mark.asyncio async def test_pick_native_folder_maps_dialog_cancel_to_none(tmp_path, monkeypatch) -> None: - script = _picker_script(tmp_path, "exit 1") + command = _picker_command(tmp_path, "raise SystemExit(1)") monkeypatch.setattr( picker, "_picker_command", - lambda: picker._PickerCommand((str(script),), frozenset({1})), + lambda: command, ) assert await picker.pick_native_folder() is None @@ -43,11 +43,11 @@ async def test_pick_native_folder_maps_dialog_cancel_to_none(tmp_path, monkeypat @pytest.mark.asyncio async def test_pick_native_folder_rejects_non_directory_result(tmp_path, monkeypatch) -> None: missing = tmp_path / "missing" - script = _picker_script(tmp_path, f"printf '%s' '{missing}'") + command = _picker_command(tmp_path, f"print({str(missing)!r}, end='')") monkeypatch.setattr( picker, "_picker_command", - lambda: picker._PickerCommand((str(script),), frozenset({1})), + lambda: command, ) with pytest.raises(picker.NativeFolderPickerError, match="invalid directory"):