From 96ef36d2543f32dd76d024b718f21601721820df Mon Sep 17 00:00:00 2001 From: Maverick <87385184+Maverick-F@users.noreply.github.com> Date: Tue, 10 Nov 2026 13:55:25 -0600 Subject: [PATCH 1/3] GUI tests: find the tool search box by its accessible name, not as the first Edit With the left side in splitters, UI Automation lists the tool form first, so the window's first Edit was the form's input file box: select_tool typed tool names there, the tree was never filtered, and tools outside the expanded Mapping category weren't found. The search box now has the accessible name "Search tools", and tool_search_box() finds it by that name. From 6962470 in BERATool/beratools_full. --- beratools/gui/bt_gui_main.py | 2 ++ tests/pywinauto/conftest.py | 20 ++++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/beratools/gui/bt_gui_main.py b/beratools/gui/bt_gui_main.py index cb62984..5f0b9a3 100644 --- a/beratools/gui/bt_gui_main.py +++ b/beratools/gui/bt_gui_main.py @@ -79,6 +79,8 @@ def __init__(self, parent=None): # controls self.tool_search = QtWidgets.QLineEdit() self.tool_search.setPlaceholderText("Search...") + # the name screen readers and UI Automation (the pywinauto GUI tests) know the box by + self.tool_search.setAccessibleName("Search tools") self.tags_model = _SearchProxyModel() self.tree_model = QtGui.QStandardItemModel() diff --git a/tests/pywinauto/conftest.py b/tests/pywinauto/conftest.py index f588bda..84b7403 100644 --- a/tests/pywinauto/conftest.py +++ b/tests/pywinauto/conftest.py @@ -147,10 +147,26 @@ def bera_app(): # --------------------------------------------------------------------------- +TOOL_SEARCH_NAME = "Search tools" # the accessible name of BTTreeView's search box + + +def tool_search_box(main, timeout=10): + """The tool tree's search box, by its accessible name. Not the window's first Edit: which Edit + comes first depends on the layout (with the left side in splitters it is the tool form's first + input). Nor child_window(title=...): for an Edit, pywinauto matches the title against its text.""" + end = time.time() + timeout + while True: + for edit in main.descendants(control_type="Edit"): + if edit.element_info.name == TOOL_SEARCH_NAME and edit.is_visible() and edit.is_enabled(): + return edit + if time.time() > end: + raise TimeoutError(f"No visible, enabled Edit named {TOOL_SEARCH_NAME!r} in the window") + time.sleep(0.2) + + def select_tool(main, tool_name: str): """Select a tool from the tree view using the search box.""" - search = main.child_window(control_type="Edit", found_index=0) - search.wait("visible enabled", timeout=10) + search = tool_search_box(main) search.set_edit_text("") time.sleep(0.3) search.set_edit_text(tool_name) From b3d778a4d32e7b96797b46a12ee68f6d2d3a6e3f Mon Sep 17 00:00:00 2001 From: Maverick <87385184+Maverick-F@users.noreply.github.com> Date: Tue, 10 Nov 2026 13:55:26 -0600 Subject: [PATCH 2/3] GUI tests: run off screen with an empty home folder of their own The pytest-qt tests showed their windows on the desktop, and used the user's saved GUI settings in ~/.beratools: a saved value changed the forms they check, and the tests wrote the settings back. conftest now gives them a temporary home folder (USERPROFILE and HOME) and sets QT_QPA_PLATFORM to offscreen unless it is set, before beratools.gui is imported. From 91c8eed in BERATool/beratools_full, without its test_tool_forms.py changes: the tests they touch aren't here, or already set their paths explicitly. --- tests/pytest_qt/conftest.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/pytest_qt/conftest.py b/tests/pytest_qt/conftest.py index 0420108..d3d60a9 100644 --- a/tests/pytest_qt/conftest.py +++ b/tests/pytest_qt/conftest.py @@ -11,7 +11,11 @@ pytest tests/pytest_qt/ -v -m gui_qt """ +import atexit +import os +import shutil import sys +import tempfile from pathlib import Path from unittest.mock import patch @@ -20,6 +24,23 @@ sys.path.insert(0, Path(__file__).parents[2].as_posix()) +# The GUI keeps its saved tool parameters, tool history and last folder in ~/.beratools, and +# fills the forms from them. The tests get an empty home folder of their own, so a value saved +# while using the GUI (skip_existing set to true, say) doesn't change the forms they check, and +# the tests don't change the user's settings. It must be set before beratools.gui is imported, as +# bt_gui_main reads the settings when imported. Path.home() reads USERPROFILE on Windows and HOME +# elsewhere. +# resolved: TEMP can be an 8.3 short path (C:/Users/ABCDEF~1/...), which Qt's dialogs report long +_TEST_HOME = str(Path(tempfile.mkdtemp(prefix="beratools_test_home_")).resolve()) +os.environ["USERPROFILE"] = _TEST_HOME +os.environ["HOME"] = _TEST_HOME +atexit.register(shutil.rmtree, _TEST_HOME, ignore_errors=True) + +# The widgets are made off screen, so the tests don't flash windows, or tooltips at the mouse (the +# CPU slider shows its value at the cursor when it changes), on the desktop. Set QT_QPA_PLATFORM +# (to "windows", say) to watch them on screen. It must be set before the QApplication is made. +os.environ.setdefault("QT_QPA_PLATFORM", "offscreen") + from beratools.gui.bt_data import BTData from beratools.gui.bt_gui_main import MainWindow from beratools.gui.tool_widgets import ( From 278fb0377f727c58ea72856e02894f7321711b1d Mon Sep 17 00:00:00 2001 From: Maverick <87385184+Maverick-F@users.noreply.github.com> Date: Tue, 10 Nov 2026 13:55:26 -0600 Subject: [PATCH 3/3] GUI tests: fix two failing pytest-qt tests TestGroundFootprint::test_round_trip used the layer footprint_rel, which tests/data/integration_aoi.gpkg doesn't have; it now uses footprint_abs. TestToolHistoryPersistence::test_switch_away_and_back_restores_saved_parameter saved a form whose required input and output files are empty, so get_widgets_arguments() returned None and the patched add_tool_history failed. Only the numeric round trip is under test, so it reads the raw values with get_widgets_values() instead, as in beratools_full. --- tests/pytest_qt/test_main_window.py | 7 +++++++ tests/pytest_qt/test_tool_forms.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/pytest_qt/test_main_window.py b/tests/pytest_qt/test_main_window.py index edf6451..f535fe8 100644 --- a/tests/pytest_qt/test_main_window.py +++ b/tests/pytest_qt/test_main_window.py @@ -585,7 +585,14 @@ def _get_saved(self, tool_api, variable=None): saved_value = 42 if isinstance(target.default_value, int) else 42.0 target.set_value(saved_value) + # the form's required in/out files are empty, so get_widgets_arguments() rejects it; + # read the raw values instead since only the numeric round trip is under test with ( + patch.object( + main_window.tool_widget, + "get_widgets_arguments", + side_effect=main_window.tool_widget.get_widgets_values, + ), patch("beratools.gui.bt_gui_main.bt.add_tool_history", side_effect=_add_tool_history), patch("beratools.gui.bt_gui_main.bt.save_tool_info"), patch.object(bt_data.BTData, "get_saved_tool_params", autospec=True, side_effect=_get_saved), diff --git a/tests/pytest_qt/test_tool_forms.py b/tests/pytest_qt/test_tool_forms.py index ed7c261..ae3439b 100644 --- a/tests/pytest_qt/test_tool_forms.py +++ b/tests/pytest_qt/test_tool_forms.py @@ -363,7 +363,7 @@ def test_round_trip(self, make_tool_widget, testdata_dir, tmp_path): "in_line": {"path": str(testdata_dir / "integration_aoi.gpkg"), "layer": "centerline"}, "in_footprint": { "path": str(testdata_dir / "integration_aoi.gpkg"), - "layer": "footprint_rel", + "layer": "footprint_abs", }, "n_samples": 15, "offset": 30.0,