Datasets:
File size: 8,971 Bytes
e5a3ec0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | """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)
|