VoyagerXHF's picture
Upload folder using huggingface_hub (part 7)
e5a3ec0 verified
Raw History Blame Contribute Delete
8.97 kB
"""STRUCTURE lane — DB Browser for SQLite (Qt5).
Owns ONLY: the launch/surfaces GATE (app + frame + main containers exist) and
tree-SHAPE deltas (an interaction that adds/removes widgets, or a dialog that
adds a top-level window). No computed values, CHECKED flips, focus, or text
content live here — those belong to the behavioral lanes.
"""
import time
import pytest, pytest_check as check
import rb_atspi
from rb_atspi import rb_showing, rb_reach
DB = "/workspace/output/fixtures/sample.db"
@pytest.fixture(scope="module", autouse=True)
def _load_db(app):
"""Ensure the sample DB is open (cold baseline starts with no DB)."""
rb_atspi.focus_app_window(app)
frame = rb_atspi.get_main_frame(app)
for _ in range(4):
rb_atspi.press_escape(); time.sleep(0.15)
title = (frame.get_name() or "")
if "sample.db" not in title:
fm = rb_atspi.find_first(frame, role="menu item", name="File")
if fm: rb_atspi.click_node(fm); time.sleep(0.4)
op = rb_atspi.find_first(frame, role="menu item", name="Open Database...")
if op:
rb_atspi.open_modal(op); time.sleep(1.2)
rb_atspi.type_text(DB); time.sleep(0.4)
rb_atspi.key("Return"); time.sleep(1.5)
# settle on Database Structure tab
st = rb_atspi.find_first(frame, role="page tab", name="Database Structure")
if st:
if not rb_atspi.do_action(st, "Press"):
rb_atspi.click_node(st)
time.sleep(0.5)
yield
def _tab(frame, name):
"""Activate a main page tab by name via its Press action (reliable inline
switch — an xdotool center-click misses when the window isn't WM-focused).
Returns after settle."""
t = rb_atspi.find_first(frame, role="page tab", name=name)
if t:
if not rb_atspi.do_action(t, "Press"):
rb_atspi.click_node(t)
time.sleep(0.7)
return t
def _showing_count(frame, role):
return sum(1 for n in rb_atspi.find_all(frame, role=role) if rb_atspi.is_showing(n))
def _win_count(app):
n = 0
for i in range(app.get_child_count()):
c = app.get_child_at_index(i)
if c is not None and (c.get_role_name() or "") in ("frame", "window", "dialog"):
n += 1
return n
# --------------------------------------------------------------------------- #
# GATE tests (jump_kind="none", depth 0) — the real top-level surfaces exist.
# --------------------------------------------------------------------------- #
@pytest.mark.rb(jump_kind="none", expect="4 main page tabs exist")
def test_gate_main_tabs_present(app, frame):
for name in ("Database Structure", "Browse Data", "Edit Pragmas", "Execute SQL"):
t = rb_atspi.find_first(frame, role="page tab", name=name)
check.is_true(t is not None, f"page tab {name!r} missing")
@pytest.mark.rb(jump_kind="none", expect="File/Edit/View/Tools/Help menus exist")
def test_gate_menubar_present(app, frame):
for name in ("File", "Edit", "View", "Tools", "Help"):
m = rb_atspi.find_first(frame, role="menu item", name=name)
check.is_true(m is not None, f"menu item {name!r} missing")
@pytest.mark.rb(jump_kind="none", expect="DB toolbar buttons exist")
def test_gate_db_toolbar_buttons(app, frame):
for name in ("New Database", "Open Database", "Write Changes"):
b = rb_atspi.find_first(frame, role="push button", name=name)
check.is_true(b is not None, f"push button {name!r} missing")
# --------------------------------------------------------------------------- #
# SHAPE-DELTA tests — an interaction that changes the tree's shape.
# --------------------------------------------------------------------------- #
@pytest.mark.rb(
jump_kind="transition",
expect="Browse Data adds a Table dropdown (showing combo-box count 4 -> 5) vs the schema tree",
)
def test_tab_switch_changes_widget_shape(app, frame, rb, results_dir):
_tab(frame, "Database Structure")
struct_combos = _showing_count(frame, "combo box")
rb.enter("browse")
_tab(frame, "Browse Data")
browse_combos = _showing_count(frame, "combo box")
# The tree SHAPE must observably differ between the two tabs: Browse Data adds
# its 'Table:' selector combo, absent from the Database Structure schema tree.
# (widget_count/cell totals are NOT used — Qt retains hidden-tab widgets in the
# tree once rendered, so only the per-tab showing combo count is a stable delta.)
check.not_equal(struct_combos, browse_combos, "showing combo-box count did not change")
check.greater(browse_combos, struct_combos, "Browse Data did not add a combo box")
rb_atspi.screenshot_assert(
"test_tab_switch_changes_widget_shape",
"Browse Data tab active: a data grid of rows with a 'Table:' dropdown at "
"top-left, replacing the Database Structure schema tree.",
results_dir, window=frame,
)
@pytest.mark.rb(
jump_kind="reach",
expect="Execute SQL toolbar (Execute SQL + New tab buttons) appears; not present on Structure",
)
def test_execute_tab_shows_sql_editor(app, frame, rb, results_dir):
_tab(frame, "Database Structure")
def _btn_showing(name):
b = rb_atspi.find_first(frame, role="push button", name=name)
return bool(b) and rb_atspi.is_showing(b)
exec_before = _btn_showing("Execute SQL")
newtab_before = _btn_showing("New tab")
rb.enter("execute")
_tab(frame, "Execute SQL")
exec_after = _btn_showing("Execute SQL")
newtab_after = _btn_showing("New tab")
check.is_false(exec_before, "Execute SQL button was already showing on Structure tab")
check.is_true(exec_after, "Execute SQL button not showing after switching to Execute SQL tab")
check.is_false(newtab_before, "New tab button was already showing on Structure tab")
check.is_true(newtab_after, "New tab button not showing after switching to Execute SQL tab")
rb_atspi.screenshot_assert(
"test_execute_tab_shows_sql_editor",
"Execute SQL tab active: an SQL editor area with a toolbar containing "
"'Execute SQL' and 'New tab' buttons, plus a results grid below.",
results_dir, window=frame,
)
@pytest.mark.rb(
jump_kind="reach",
expect="'About DB Browser for SQLite' dialog opens as a new top-level window",
)
def test_about_dialog_adds_window(app, frame, rb, results_dir):
rb_atspi.focus_app_window(app); time.sleep(0.2)
win_before = _win_count(app)
before = rb_showing(app)
hm = rb_atspi.find_first(frame, role="menu item", name="Help")
assert hm is not None, "Help menu missing (precondition)"
rb_atspi.click_node(hm); time.sleep(0.6)
ab = rb_atspi.find_first(frame, role="menu item", name_sub="About")
if ab is None:
rb_atspi.press_escape()
pytest.skip("About menu item not reachable")
rb.enter("about")
rb_atspi.open_modal(ab); time.sleep(1.2)
after = rb_showing(app)
win_after = _win_count(app)
check.is_true(
rb_reach(before, after, target="About DB Browser for SQLite"),
"About dialog did not appear as a new showing surface",
)
check.greater(win_after, win_before, "top-level window count did not increase")
rb_atspi.screenshot_assert(
"test_about_dialog_adds_window",
"The 'About DB Browser for SQLite' dialog is open on top of the main "
"window, showing the program name and version text.",
results_dir,
)
rb_atspi.press_escape(); time.sleep(0.3)
rb_atspi.press_escape(); time.sleep(0.3)
@pytest.mark.rb(
jump_kind="reach",
expect="'Edit table definition' dialog opens as a new top-level window",
)
def test_create_table_dialog_adds_window(app, frame, rb, results_dir):
rb_atspi.focus_app_window(app); time.sleep(0.2)
win_before = _win_count(app)
before = rb_showing(app)
em = rb_atspi.find_first(frame, role="menu item", name="Edit")
assert em is not None, "Edit menu missing (precondition)"
rb_atspi.click_node(em); time.sleep(0.6)
ct = rb_atspi.find_first(frame, role="menu item", name="Create Table...")
if ct is None:
rb_atspi.press_escape()
pytest.skip("Create Table... menu item not reachable")
rb.enter("create_table")
rb_atspi.open_modal(ct); time.sleep(1.3)
after = rb_showing(app)
win_after = _win_count(app)
check.is_true(
rb_reach(before, after, target="Edit table definition"),
"Create Table dialog did not appear as a new showing surface",
)
check.greater(win_after, win_before, "top-level window count did not increase")
rb_atspi.screenshot_assert(
"test_create_table_dialog_adds_window",
"The 'Edit table definition' dialog is open on top of the main window, "
"with a table-name field and an empty column-definition grid.",
results_dir,
)
rb_atspi.press_escape(); time.sleep(0.3)
rb_atspi.press_escape(); time.sleep(0.4)