VoyagerXHF's picture
Upload folder using huggingface_hub (part 108)
f7e6f7b verified
Raw History Blame Contribute Delete
45.6 kB
"""STRUCTURE lane — PyPlayer 0.6.0 beta (PyQt5 + libVLC) UIA suite.
This module owns exactly two things and nothing else:
1. the GATE (``jump_kind="none"``, 3 of 12 tests) — the app's top-level surfaces are
present at launch, plus one genuine geometry/layout check;
2. tree-SHAPE deltas — an interaction that changes the SHAPE of the widget tree:
a control-type count changes (a view toggle adds/removes widgets, a mode switch
adds a readout) or a new top-level window appears (a Qt dialog).
Shape only. Never content, never CHECKED, never wording, never a window rectangle —
those belong to the text / state / computation / menu / button lanes.
How shape is measured here: per-control-type counts,
``len(rb_uia.find_all(app, control_type=...))``, corroborated by the total node count
``len(app.descendants())``. ``rb_showing()`` is NOT a shape metric for this app: most
dock widgets have an empty UIA name, so four spinners collapse into a single
``"Spinner|"`` key (recon 0.7). It is used (via ``showing_all``) only for the NAMED
things — the dialog windows and menu items. Absolute totals are never asserted; only
the delta and the per-type change, because a faithful recreation may legitimately
carry a different absolute node count.
"""
import os
import time
import pytest
import rb_uia
from rb_uia import rb_showing, rb_reach, rb_flip, rb_value
TOP_MENUS = ("File", "Edit", "Video", "Audio", "Window", "Player", "Help")
def fixtures_dir():
"""FIXTURES_DIR when the eval runner sets it, else <parent-of-results>/fixtures."""
d = os.environ.get("FIXTURES_DIR")
if d and os.path.isdir(d):
return d
rd = os.environ.get("RB_RESULTS_DIR") or os.environ.get("RESULTS_DIR") or "."
cand = os.path.join(os.path.dirname(os.path.abspath(rd)), "fixtures")
if os.path.isdir(cand):
return cand
return os.path.join(os.path.abspath(rd), "fixtures")
def find_ctl(root, control_type=None, name=None, aid_suffix=None):
"""Locate ONE control. Prefers visible name + control_type (framework independent);
falls back to the Qt objectName tail only for the icon-only widgets that expose no name."""
els = rb_uia.find_all(root, control_type=control_type) or []
if name is not None:
for e in els:
try:
if (e.window_text() or "") == name:
return e
except Exception:
pass
if aid_suffix is not None:
for e in els:
try:
aid = e.element_info.automation_id or ""
if aid.split(".")[-1] == aid_suffix:
return e
except Exception:
pass
return None
def ctl_value(el):
"""Read a widget's UIA value (works for Edit / Slider / Spinner / QLabel)."""
if el is None:
return None
try:
v = el.legacy_properties().get("Value")
if v not in (None, ""):
return v
except Exception:
pass
try:
return el.window_text() or ""
except Exception:
return None
def status_text(app):
"""Text currently shown on the QStatusBar ('' when empty)."""
for sbar in rb_uia.find_all(app, control_type="StatusBar") or []:
try:
return " ".join(t for t in sbar.texts() if t)
except Exception:
return ""
return ""
def other_windows(app):
"""Top-level windows of the app's process other than the main window (Qt dialogs)."""
from pywinauto import Desktop
out = []
try:
pid, h = app.process_id(), app.handle
except Exception:
return out
try:
for w in Desktop(backend="uia").windows():
try:
if w.process_id() == pid and w.handle != h:
out.append(w)
except Exception:
pass
except Exception:
pass
return out
def showing_all(app):
"""rb_showing(app) UNION every sibling top-level window (needed for Qt dialogs)."""
s = set(rb_showing(app))
for w in other_windows(app):
try:
s.add("Window|%s" % (w.window_text() or ""))
s |= rb_showing(w)
except Exception:
pass
return s
def dialog_named(app, title, timeout=8.0):
"""Wait for and return the app-owned top-level window whose title contains `title`."""
deadline = time.time() + timeout
while time.time() < deadline:
for w in other_windows(app):
try:
if title.lower() in (w.window_text() or "").lower():
return w
except Exception:
pass
time.sleep(0.3)
return None
def menu_item(app, label):
"""A currently-visible QMenu/QMenuBar item with this exact label."""
for m in rb_uia.find_all(app, control_type="MenuItem") or []:
try:
if (m.window_text() or "") == label:
return m
except Exception:
pass
return None
def close_menus():
rb_uia.key("{ESC}")
time.sleep(0.25)
rb_uia.key("{ESC}")
time.sleep(0.25)
def open_menu(app, top):
"""Click a top-level menu; returns True when its popup is up."""
close_menus()
m = menu_item(app, top)
if m is None:
return False
m.click_input()
time.sleep(0.5)
return True
def click_menu_item(app, label):
it = menu_item(app, label)
if it is None:
return False
it.click_input()
time.sleep(0.5)
return True
# ---- surface crossings: rb_ prefix ⇒ counted by the depth audit ----------------
def rb_enter_menu(rb, app, top):
"""Open a top-level menu (surface crossing #1)."""
ok = open_menu(app, top)
if ok:
rb.enter("menu:%s" % top)
return ok
def rb_enter_submenu(rb, app, label):
"""Open a submenu inside an already-open menu (surface crossing #2)."""
ok = click_menu_item(app, label)
if ok:
rb.enter("submenu:%s" % label)
return ok
def rb_reach_media(rb, app, fixture):
"""Drive the app into its PRIMARY working state: File > Open... -> native dialog ->
type the fixture path -> Enter -> media loaded. Two surface crossings (menu, dialog).
Returns True once the window title shows the fixture name."""
if not open_menu(app, "File"):
return False
rb.enter("menu:File")
if not click_menu_item(app, "Open..."):
return False
rb.enter("dialog:open")
time.sleep(1.5)
edit = None
deadline = time.time() + 10
while time.time() < deadline and edit is None:
edit = find_ctl(app, control_type="Edit", name="File name:")
if edit is None:
time.sleep(0.4)
path = os.path.join(fixtures_dir(), fixture)
if edit is not None:
edit.click_input()
time.sleep(0.2)
try:
edit.set_edit_text(path)
except Exception:
rb_uia.type_text(path)
else:
# A different toolkit may label its file-name box something other than
# "File name:". Type blind ONLY when a file dialog really is up (its Cancel or
# Open button is reachable) so keystrokes can never leak into the main window
# and fire player hotkeys.
dialog_up = (find_ctl(app, control_type="Button", name="Cancel") is not None
or find_ctl(app, control_type="Button", name="Open") is not None
or bool(other_windows(app)))
if not dialog_up:
return False
rb_uia.type_text(path)
time.sleep(0.3)
rb_uia.key("{ENTER}")
# wait until the title carries the file name
deadline = time.time() + 12
while time.time() < deadline:
try:
if fixture in (app.window_text() or ""):
time.sleep(1.0)
return True
except Exception:
pass
time.sleep(0.4)
return False
def settle_media(seconds=5.0):
"""rb_silent.mp4 autoplays; after ~5 s it parks at its LAST frame — a deterministic
state (time 00:04.00, progress 39, spinSecond 4, spinFrame '10 FPS: 39')."""
time.sleep(seconds)
# ══ structure-lane additions: SHAPE metrics + in-page interactions ══════════════
# (plain names on purpose — none of these fake a surface crossing)
def count_type(root, control_type):
"""How many nodes of one control_type live under `root` RIGHT NOW.
This is THE framework-independent shape metric for this app."""
return len(rb_uia.find_all(root, control_type=control_type) or [])
def count_nodes(root):
"""Total node count of the tree under `root` (-1 when the walk itself fails)."""
try:
return len(root.descendants())
except Exception:
return -1
def classify_sliders(root):
"""(horizontal, vertical) slider counts, told apart by their OWN geometry: the
progress slider is wider than tall, the volume slider is taller than wide.
Lets a test prove WHICH slider vanished without naming any framework internal."""
horizontal = vertical = 0
for s in rb_uia.find_all(root, control_type="Slider") or []:
try:
r = s.rectangle()
w, h = r.right - r.left, r.bottom - r.top
except Exception:
continue
if w > h:
horizontal += 1
elif h > w:
vertical += 1
return horizontal, vertical
def top_of(root, control_type, pick="min"):
"""Top edge (y) of the requested control_type: the highest one, or the top of the
largest-area one when pick='largest'. None when there is no such control."""
best_top, best_area = None, -1
for el in rb_uia.find_all(root, control_type=control_type) or []:
try:
r = el.rectangle()
except Exception:
continue
area = max(0, r.right - r.left) * max(0, r.bottom - r.top)
if pick == "largest":
if area > best_area:
best_area, best_top = area, r.top
elif best_top is None or r.top < best_top:
best_top = r.top
return best_top
def _norm_label(text):
"""Menu labels, tolerantly: drop mnemonics, unify '…' with '...', drop trailing dots."""
s = (text or "").replace("&", "").replace("…", "...").strip()
while s.endswith("."):
s = s[:-1]
return s.strip().lower()
def menu_item_like(app, wanted, avoid=()):
"""menu_item() first (exact visible label), then a tolerant match that ignores
mnemonics and trailing dots — 'About...' vs 'About…' must not decide a test."""
exact = menu_item(app, wanted)
if exact is not None:
return exact
target = _norm_label(wanted)
skip = set(_norm_label(a) for a in avoid)
for m in rb_uia.find_all(app, control_type="MenuItem") or []:
try:
label = _norm_label(m.window_text())
except Exception:
continue
if label and label == target and label not in skip:
return m
return None
def click_menu_item_like(app, wanted, avoid=()):
it = menu_item_like(app, wanted, avoid)
if it is None:
return False
it.click_input()
time.sleep(0.5)
return True
def toggle_window_option(rb, app, label):
"""Flip one `Window`-menu view option through the real user path: open the Window
menu (a surface crossing), click the item, the popup closes again."""
if not rb_enter_menu(rb, app, "Window"):
return False
ok = click_menu_item_like(app, label)
rb.back()
time.sleep(0.7)
return ok
def leave_fullscreen(app, attempts=3):
"""{ESC} is the only way back out of fullscreen — the menu bar is hidden there."""
for i in range(attempts):
if i:
try:
rb_uia.focus_app_window(app)
except Exception:
pass
time.sleep(0.3)
rb_uia.key("{ESC}")
time.sleep(1.2)
if count_type(app, "MenuBar") > 0:
return True
return False
def exit_crop_mode(app, baseline_texts, attempts=3):
"""`c` leaves crop mode. The menu route back does not exist: crop mode hides the
menu bar and the window refuses to re-show it while crop is active."""
for _ in range(attempts):
try:
rb_uia.focus_app_window(app)
except Exception:
pass
time.sleep(0.2)
rb_uia.key("c")
time.sleep(1.0)
if count_type(app, "Text") == baseline_texts:
return True
return False
def click_dialog_ok(dlg):
"""Dismiss a Qt dialog through its own OK button ({ESC} only as a last resort)."""
if dlg is None:
rb_uia.key("{ESC}")
time.sleep(0.4)
return False
btn = find_ctl(dlg, control_type="Button", name="OK")
if btn is not None:
try:
btn.click_input()
time.sleep(0.8)
return True
except Exception:
pass
rb_uia.key("{ESC}")
time.sleep(0.4)
return False
# ══════════════════════════════════════════════════════════════════════════════
# 1. THE GATE — top-level surfaces at launch (3 tests, jump_kind="none", depth 0)
# ══════════════════════════════════════════════════════════════════════════════
@pytest.mark.rb(
jump_kind="none", depth=0,
expect="main window carries a non-empty title and an application MenuBar hosting the 7 "
"menus File Edit Video Audio Window Player Help, left to right")
def test_gate_window_hosts_seven_top_menus(app, rb):
# The OS window frame contributes its own MenuBar holding a single 'System' item,
# so the app's menu bar is identified by its 7 real captions, not by being the only one.
steps, title, n_menubars, captions = [], None, None, None
try:
title = app.window_text() or ""
except Exception as e:
steps.append("read window title raised: %r" % (e,))
try:
n_menubars = count_type(app, "MenuBar")
except Exception as e:
steps.append("count MenuBar raised: %r" % (e,))
try:
placed = []
for m in rb_uia.find_all(app, control_type="MenuItem") or []:
try:
label = m.window_text() or ""
if label == "System": # window-manager chrome, not the app's menu
continue
placed.append((m.rectangle().left, label))
except Exception:
pass
captions = [t for _, t in sorted(placed)]
except Exception as e:
steps.append("enumerate menu-bar MenuItems raised: %r" % (e,))
assert (title not in (None, "") and (n_menubars or 0) >= 1
and captions == list(TOP_MENUS)), (
"title=%r menubars=%r captions=%r (expected %r left-to-right) steps=%s"
% (title, n_menubars, captions, list(TOP_MENUS), steps))
@pytest.mark.rb(
jump_kind="none", depth=0,
expect="launch tree holds all four principal surfaces at once: MenuBar, the media "
"Group, the control dock (2 Sliders / 4 Spinners / >=6 CheckBoxes incl. "
"'Delete originals' and 'Skip marked files') and one StatusBar")
def test_gate_principal_surfaces_coexist(app, rb, results_dir):
steps, counts, checkbox_names = [], {}, []
for ct in ("MenuBar", "Group", "StatusBar", "Slider", "Spinner", "CheckBox"):
try:
counts[ct] = count_type(app, ct)
except Exception as e:
counts[ct] = -1
steps.append("count %s raised: %r" % (ct, e))
try:
for c in rb_uia.find_all(app, control_type="CheckBox") or []:
try:
checkbox_names.append(c.window_text() or "")
except Exception:
pass
except Exception as e:
steps.append("read CheckBox names raised: %r" % (e,))
try:
rb_uia.screenshot_assert(
"structure_gate_launch_surfaces",
"PyPlayer at launch in its dark 'Midnight' theme: a black playback area with "
"the VLC traffic-cone logo centred, a menu row reading File Edit Video Audio "
"Window Player Help across the top, a thin rainbow-gradient progress bar with "
"a '--:--' time label at each end, and a bottom control dock holding round "
"playback buttons, hour/minute/second/frame spin boxes, 'Start' and 'End' trim "
"buttons and the 'Delete originals' / 'Skip marked files' checkboxes, with a "
"narrow status bar along the very bottom edge.",
results_dir, window=app)
except Exception as e:
steps.append("screenshot raised: %r" % (e,))
ok = (counts.get("MenuBar", 0) >= 1
and counts.get("Group", 0) >= 1
and counts.get("StatusBar", 0) == 1
and counts.get("Slider", 0) == 2
and counts.get("Spinner", 0) == 4
and counts.get("CheckBox", 0) >= 6
and "Delete originals" in checkbox_names
and "Skip marked files" in checkbox_names)
assert ok, ("counts=%r (want MenuBar>=1, Group>=1, StatusBar==1, Slider==2, "
"Spinner==4, CheckBox>=6) checkbox names=%r steps=%s"
% (counts, checkbox_names, steps))
@pytest.mark.rb(
jump_kind="none", depth=0,
expect="vertical stacking menu bar < media surface < progress slider < spin-box row "
"< status bar, with the progress slider horizontal (>50% of the window width) "
"and the volume slider vertical")
def test_layout_vertical_stacking_and_slider_orientation(app, rb):
steps, tops, geom = [], {}, {}
for key, ct, pick in (("menubar", "MenuBar", "min"),
("media", "Group", "largest"),
("spins", "Spinner", "min"),
("statusbar", "StatusBar", "min")):
try:
tops[key] = top_of(app, ct, pick=pick)
except Exception as e:
tops[key] = None
steps.append("top of %s raised: %r" % (ct, e))
try:
for s in rb_uia.find_all(app, control_type="Slider") or []:
r = s.rectangle()
w, h = r.right - r.left, r.bottom - r.top
geom["progress" if w > h else "volume"] = (r.top, w, h)
except Exception as e:
steps.append("measure sliders raised: %r" % (e,))
try:
wr = app.rectangle()
geom["window_w"] = wr.right - wr.left
except Exception as e:
geom["window_w"] = None
steps.append("read window rect raised: %r" % (e,))
prog, vol, win_w = geom.get("progress"), geom.get("volume"), geom.get("window_w")
order_known = (all(tops.get(k) is not None
for k in ("menubar", "media", "spins", "statusbar"))
and prog is not None and vol is not None and win_w)
ok = bool(order_known
and tops["menubar"] < tops["media"] < prog[0] < tops["spins"] < tops["statusbar"]
and prog[1] > prog[2] and prog[1] > 0.5 * win_w
and vol[2] > vol[1])
assert ok, ("tops=%r progress(top,w,h)=%r volume(top,w,h)=%r window_w=%r steps=%s"
% (tops, prog, vol, win_w, steps))
# ══════════════════════════════════════════════════════════════════════════════
# 2. SHAPE DELTAS — no media needed (fast, deterministic)
# ══════════════════════════════════════════════════════════════════════════════
@pytest.mark.rb(
jump_kind="transition", depth=1,
expect="Window > Status Bar deletes the status bar from the tree: StatusBar count "
"1 -> 0 and the total node count drops; toggling it on again brings both back")
def test_status_bar_toggle_removes_status_bar_node(app, rb):
steps = []
sb_before = sb_off = sb_back = None
total_before = total_off = total_back = None
hid = shown = False
try:
sb_before, total_before = count_type(app, "StatusBar"), count_nodes(app)
except Exception as e:
steps.append("baseline count raised: %r" % (e,))
try:
hid = toggle_window_option(rb, app, "Status Bar")
if not hid:
steps.append("nav: 'Status Bar' not clickable in the Window menu")
except Exception as e:
steps.append("Window > Status Bar (off) raised: %r" % (e,))
try:
close_menus()
sb_off, total_off = count_type(app, "StatusBar"), count_nodes(app)
except Exception as e:
steps.append("count after hiding raised: %r" % (e,))
try:
shown = toggle_window_option(rb, app, "Status Bar")
if not shown:
steps.append("nav: could not re-enable 'Status Bar'")
except Exception as e:
steps.append("Window > Status Bar (on) raised: %r" % (e,))
try:
close_menus()
sb_back, total_back = count_type(app, "StatusBar"), count_nodes(app)
except Exception as e:
steps.append("count after restoring raised: %r" % (e,))
assert (rb_flip(sb_before, sb_off) and hid and shown
and sb_before == 1 and sb_off == 0 and sb_back == sb_before
and total_off < total_before and total_back > total_off), (
"StatusBar count %r -> %r -> %r (want 1 -> 0 -> 1); total %r -> %r -> %r "
"(want a drop then a recovery); clicked_off=%r clicked_on=%r steps=%s"
% (sb_before, sb_off, sb_back, total_before, total_off, total_back,
hid, shown, steps))
@pytest.mark.rb(
jump_kind="transition", depth=1,
expect="Window > Progress Bar removes the horizontal progress slider only: sliders "
"(h,v) (1,1) -> (0,1) — the vertical volume slider survives — and (1,1) again "
"after switching it back on")
def test_progress_bar_toggle_removes_only_the_horizontal_slider(app, rb):
steps = []
before = off = back = None
total_before = total_off = None
hid = shown = False
try:
before, total_before = classify_sliders(app), count_nodes(app)
except Exception as e:
steps.append("baseline slider census raised: %r" % (e,))
try:
hid = toggle_window_option(rb, app, "Progress Bar")
if not hid:
steps.append("nav: 'Progress Bar' not clickable in the Window menu")
except Exception as e:
steps.append("Window > Progress Bar (off) raised: %r" % (e,))
try:
close_menus()
off, total_off = classify_sliders(app), count_nodes(app)
except Exception as e:
steps.append("slider census after hiding raised: %r" % (e,))
try:
shown = toggle_window_option(rb, app, "Progress Bar")
if not shown:
steps.append("nav: could not re-enable 'Progress Bar'")
except Exception as e:
steps.append("Window > Progress Bar (on) raised: %r" % (e,))
try:
close_menus()
back = classify_sliders(app)
except Exception as e:
steps.append("slider census after restoring raised: %r" % (e,))
ok = (rb_flip(before, off) and hid and shown
and before is not None and off is not None
and before[0] >= 1 and off[0] == 0 # the wide progress slider went
and off[1] == before[1] and off[1] >= 1 # the tall volume slider stayed
and back == before
and total_off < total_before)
assert ok, ("(horizontal,vertical) sliders %r -> %r -> %r (want (1,1) -> (0,1) -> "
"(1,1)); total %r -> %r; clicked_off=%r clicked_on=%r steps=%s"
% (before, off, back, total_before, total_off, hid, shown, steps))
@pytest.mark.rb(
jump_kind="transition", depth=1,
expect="Window > Advanced Controls empties the bottom dock row: CheckBox 6 -> 0 and "
"Spinner 4 -> 0, total node count collapses; both counts return on re-enable")
def test_advanced_controls_toggle_collapses_dock_row(app, rb, results_dir):
steps = []
cb_before = cb_off = cb_back = None
sp_before = sp_off = sp_back = None
total_before = total_off = total_back = None
hid = shown = False
try:
cb_before, sp_before = count_type(app, "CheckBox"), count_type(app, "Spinner")
total_before = count_nodes(app)
except Exception as e:
steps.append("baseline count raised: %r" % (e,))
try:
hid = toggle_window_option(rb, app, "Advanced Controls")
if not hid:
steps.append("nav: 'Advanced Controls' not clickable in the Window menu")
except Exception as e:
steps.append("Window > Advanced Controls (off) raised: %r" % (e,))
try:
close_menus()
cb_off, sp_off = count_type(app, "CheckBox"), count_type(app, "Spinner")
total_off = count_nodes(app)
except Exception as e:
steps.append("count after hiding raised: %r" % (e,))
try:
rb_uia.screenshot_assert(
"structure_advanced_controls_off",
"PyPlayer with its advanced controls hidden: the whole bottom row of round "
"playback buttons, time spin boxes, trim buttons and checkboxes has "
"disappeared, leaving only the thin rainbow-gradient progress bar with its "
"'--:--' time labels between the black player area and the status bar.",
results_dir, window=app)
except Exception as e:
steps.append("screenshot raised: %r" % (e,))
try:
shown = toggle_window_option(rb, app, "Advanced Controls")
if not shown:
steps.append("nav: could not re-enable 'Advanced Controls'")
except Exception as e:
steps.append("Window > Advanced Controls (on) raised: %r" % (e,))
try:
close_menus()
cb_back, sp_back = count_type(app, "CheckBox"), count_type(app, "Spinner")
total_back = count_nodes(app)
except Exception as e:
steps.append("count after restoring raised: %r" % (e,))
ok = (rb_flip((cb_before, sp_before), (cb_off, sp_off)) and hid and shown
and cb_before is not None and sp_before is not None
and cb_before >= 2 and sp_before >= 1
and cb_off == 0 and sp_off == 0
and cb_back == cb_before and sp_back == sp_before
and total_off < total_before and total_back > total_off)
assert ok, ("CheckBox %r -> %r -> %r (want 6 -> 0 -> 6); Spinner %r -> %r -> %r "
"(want 4 -> 0 -> 4); total %r -> %r -> %r; clicked_off=%r clicked_on=%r "
"steps=%s" % (cb_before, cb_off, cb_back, sp_before, sp_off, sp_back,
total_before, total_off, total_back, hid, shown, steps))
@pytest.mark.rb(
jump_kind="transition", depth=1,
expect="hiding the Status Bar and then the Progress Bar compose: StatusBar 1 -> 0 "
"then horizontal Slider 1 -> 0, the total node count shrinking at each step "
"and growing back once both are re-enabled")
def test_status_and_progress_toggles_compose(app, rb):
steps = []
sb0 = sb1 = sb3 = None
h0 = h1 = h2 = h3 = None
t0 = t1 = t2 = t3 = None
clicks = []
try:
sb0, (h0, _v0), t0 = count_type(app, "StatusBar"), classify_sliders(app), count_nodes(app)
except Exception as e:
steps.append("baseline census raised: %r" % (e,))
try:
clicks.append(toggle_window_option(rb, app, "Status Bar"))
close_menus()
sb1, (h1, _v1), t1 = count_type(app, "StatusBar"), classify_sliders(app), count_nodes(app)
except Exception as e:
steps.append("step 1 (Status Bar off) raised: %r" % (e,))
try:
clicks.append(toggle_window_option(rb, app, "Progress Bar"))
close_menus()
(h2, _v2), t2 = classify_sliders(app), count_nodes(app)
except Exception as e:
steps.append("step 2 (Progress Bar off) raised: %r" % (e,))
try:
clicks.append(toggle_window_option(rb, app, "Progress Bar"))
clicks.append(toggle_window_option(rb, app, "Status Bar"))
close_menus()
sb3, (h3, _v3), t3 = count_type(app, "StatusBar"), classify_sliders(app), count_nodes(app)
except Exception as e:
steps.append("restore step raised: %r" % (e,))
ok = (rb_flip((sb0, h0, t0), (sb1, h2, t2)) and all(clicks) and len(clicks) == 4
and sb0 == 1 and sb1 == 0 and h0 == 1 and h1 == 1 and h2 == 0
and t0 is not None and t1 is not None and t2 is not None
and t2 < t1 < t0
and sb3 == sb0 and h3 == h0 and t3 is not None and t3 > t2)
assert ok, ("StatusBar %r -> %r -> (unchanged) -> %r; horizontal sliders %r -> %r -> "
"%r -> %r; totals %r -> %r -> %r -> %r (want a strict shrink at each step "
"then a recovery); menu clicks=%r steps=%s"
% (sb0, sb1, sb3, h0, h1, h2, h3, t0, t1, t2, t3, clicks, steps))
@pytest.mark.rb(
jump_kind="transition", depth=1,
expect="opening the Window menu materialises its item nodes (MenuItem count 7 -> 15, "
"i.e. at least 6 new items) and {ESC} removes them again")
def test_window_menu_popup_materialises_item_nodes(app, rb, results_dir):
steps, closed_menu = [], None
before = opened = after = None
entered = False
try:
before = count_type(app, "MenuItem")
except Exception as e:
steps.append("baseline MenuItem count raised: %r" % (e,))
try:
entered = rb_enter_menu(rb, app, "Window")
if not entered:
steps.append("nav: the 'Window' menu did not open")
except Exception as e:
steps.append("open Window menu raised: %r" % (e,))
try:
opened = count_type(app, "MenuItem")
except Exception as e:
steps.append("MenuItem count with the popup up raised: %r" % (e,))
try:
rb_uia.screenshot_assert(
"structure_window_menu_popup",
"The 'Window' menu is open as a dropdown over the PyPlayer window, listing the "
"view options: 'Fullscreen', three resize entries for the media's native size / "
"aspect ratio, and the 'Menu Bar', 'Status Bar', 'Progress Bar' and 'Advanced "
"Controls' toggles, the last four shown as ticked options.",
results_dir)
except Exception as e:
steps.append("screenshot raised: %r" % (e,))
try:
close_menus()
rb.back()
time.sleep(0.4)
closed_menu = True
after = count_type(app, "MenuItem")
except Exception as e:
closed_menu = False
steps.append("close menu / recount raised: %r" % (e,))
ok = (rb_flip(before, opened) and entered and closed_menu
and before is not None and opened is not None
and opened - before >= 6 and after == before)
assert ok, ("MenuItem nodes %r -> %r (popup up) -> %r (popup closed); wanted a growth "
"of at least 6 and a full restore; entered=%r steps=%s"
% (before, opened, after, entered, steps))
@pytest.mark.rb(
jump_kind="transition", depth=1,
expect="Window > Fullscreen collapses the window chrome at once: MenuBar 2 -> 0, "
"StatusBar 1 -> 0 and the total node count drops 48 -> 32; {ESC} restores")
def test_fullscreen_collapses_window_chrome(app, rb, results_dir):
steps = []
mb_before = sb_before = sp_before = total_before = None
mb_full = sb_full = sp_full = total_full = None
mb_back = sb_back = total_back = None
entered_fs = restored = False
try:
mb_before, sb_before = count_type(app, "MenuBar"), count_type(app, "StatusBar")
sp_before, total_before = count_type(app, "Spinner"), count_nodes(app)
except Exception as e:
steps.append("baseline census raised: %r" % (e,))
try:
entered_fs = toggle_window_option(rb, app, "Fullscreen")
if not entered_fs:
steps.append("nav: 'Fullscreen' not clickable in the Window menu")
time.sleep(1.2)
except Exception as e:
steps.append("Window > Fullscreen raised: %r" % (e,))
try:
mb_full, sb_full = count_type(app, "MenuBar"), count_type(app, "StatusBar")
sp_full, total_full = count_type(app, "Spinner"), count_nodes(app)
except Exception as e:
steps.append("census in fullscreen raised: %r" % (e,))
try:
rb_uia.screenshot_assert(
"structure_fullscreen_chrome_collapsed",
"PyPlayer switched to fullscreen with no media loaded: the black playback "
"surface with the VLC traffic-cone logo centred on it now covers the entire "
"screen, and the menu row (File Edit Video Audio Window Player Help) and the "
"status bar that framed the window before are both gone.",
results_dir)
except Exception as e:
steps.append("screenshot raised: %r" % (e,))
try:
restored = leave_fullscreen(app)
if not restored:
steps.append("restore: {ESC} did not bring the menu bar back")
except Exception as e:
steps.append("{ESC} out of fullscreen raised: %r" % (e,))
try:
mb_back, sb_back = count_type(app, "MenuBar"), count_type(app, "StatusBar")
total_back = count_nodes(app)
except Exception as e:
steps.append("census after restoring raised: %r" % (e,))
# Observed on the reference: MenuBar 2 -> 0, StatusBar 1 -> 0, total 48 -> 32.
# The dock's Spinners stay in the UIA tree while hidden, so their count is NOT a
# fullscreen signal here — the menu bar, the status bar and the total node count are.
ok = (rb_flip((mb_before, sb_before, total_before), (mb_full, sb_full, total_full))
and entered_fs
and mb_before is not None and mb_before >= 1 and sb_before == 1
and mb_full == 0 and sb_full == 0
and total_full is not None and total_before is not None
and total_before - total_full >= 10
and mb_back == mb_before and sb_back == sb_before
and total_back is not None and total_back > total_full)
assert ok, ("MenuBar %r -> %r -> %r, StatusBar %r -> %r -> %r, Spinner %r -> %r, "
"total %r -> %r -> %r (want the menu bar and status bar to hit 0 in "
"fullscreen, the node total to shed >=10 nodes, and everything to come "
"back after ESC); entered=%r restored=%r steps=%s"
% (mb_before, mb_full, mb_back, sb_before, sb_full, sb_back,
sp_before, sp_full, total_before, total_full, total_back,
entered_fs, restored, steps))
# ══════════════════════════════════════════════════════════════════════════════
# 3. SHAPE DELTAS — a dialog adds a whole new TOP-LEVEL WINDOW
# ══════════════════════════════════════════════════════════════════════════════
@pytest.mark.rb(
jump_kind="reach", depth=1,
expect="Edit > Settings adds a new top-level window titled 'Settings' (sibling-window "
"count 0 -> 1) while the Edit menu's own items leave the tree")
def test_settings_dialog_adds_top_level_window(app, rb, results_dir):
steps, dlg = [], None
before = after = set()
windows_before = windows_after = None
entered = clicked = False
try:
windows_before = len(other_windows(app))
except Exception as e:
steps.append("count sibling windows raised: %r" % (e,))
try:
entered = rb_enter_menu(rb, app, "Edit")
if not entered:
steps.append("nav: the 'Edit' menu did not open")
except Exception as e:
steps.append("open Edit menu raised: %r" % (e,))
try:
before = showing_all(app)
except Exception as e:
steps.append("snapshot before raised: %r" % (e,))
try:
clicked = click_menu_item_like(app, "Settings")
rb.back()
if not clicked:
steps.append("nav: 'Settings' not clickable in the Edit menu")
except Exception as e:
steps.append("click Settings raised: %r" % (e,))
try:
dlg = dialog_named(app, "Settings", timeout=10.0)
time.sleep(1.0)
if dlg is None:
steps.append("no top-level window titled 'Settings' appeared")
except Exception as e:
steps.append("wait for the Settings window raised: %r" % (e,))
try:
windows_after = len(other_windows(app))
after = showing_all(app)
except Exception as e:
steps.append("snapshot after raised: %r" % (e,))
try:
rb_uia.screenshot_assert(
"structure_settings_dialog_window",
"A separate tall, narrow light-grey 'Settings' window is open in front of the "
"PyPlayer main window, with a tab strip across the top reading General / "
"Editing / Hotkeys / Updates, a 'Theme' drop-down showing 'Midnight', a column "
"of option checkboxes below it and an OK button at the bottom.",
results_dir)
except Exception as e:
steps.append("screenshot raised: %r" % (e,))
try:
click_dialog_ok(dlg)
except Exception as e:
steps.append("closing the dialog raised: %r" % (e,))
assert (rb_reach(before, after, target="Settings", source="Edit timestamps")
and rb_flip(windows_before, windows_after)
and windows_before is not None and windows_after == windows_before + 1), (
"sibling top-level windows %r -> %r (want 0 -> 1); entered_menu=%r clicked=%r "
"new keys=%r steps=%s"
% (windows_before, windows_after, entered, clicked,
sorted(k for k in (after - before) if "setting" in k.lower())[:6], steps))
@pytest.mark.rb(
jump_kind="reach", depth=1,
expect="Help > About... adds a new top-level window titled 'About PyPlayer' "
"(sibling-window count 0 -> 1) while the Help menu's items leave the tree")
def test_about_dialog_adds_top_level_window(app, rb, results_dir):
steps, dlg = [], None
before = after = set()
windows_before = windows_after = None
entered = clicked = False
try:
windows_before = len(other_windows(app))
except Exception as e:
steps.append("count sibling windows raised: %r" % (e,))
try:
entered = rb_enter_menu(rb, app, "Help")
if not entered:
steps.append("nav: the 'Help' menu did not open")
except Exception as e:
steps.append("open Help menu raised: %r" % (e,))
try:
before = showing_all(app)
except Exception as e:
steps.append("snapshot before raised: %r" % (e,))
try:
clicked = click_menu_item_like(app, "About...", avoid=("About Qt...",))
rb.back()
if not clicked:
steps.append("nav: 'About...' not clickable in the Help menu")
except Exception as e:
steps.append("click About raised: %r" % (e,))
try:
dlg = dialog_named(app, "About PyPlayer", timeout=10.0)
time.sleep(0.8)
if dlg is None:
steps.append("no top-level window titled 'About PyPlayer' appeared")
except Exception as e:
steps.append("wait for the About window raised: %r" % (e,))
try:
windows_after = len(other_windows(app))
after = showing_all(app)
except Exception as e:
steps.append("snapshot after raised: %r" % (e,))
try:
rb_uia.screenshot_assert(
"structure_about_dialog_window",
"A small separate 'About PyPlayer' window is open in front of the main "
"PyPlayer window, showing the PyPlayer logo image, a heading naming the "
"application and its version, a couple of description lines about the player "
"and a single OK button.",
results_dir)
except Exception as e:
steps.append("screenshot raised: %r" % (e,))
try:
click_dialog_ok(dlg)
except Exception as e:
steps.append("closing the dialog raised: %r" % (e,))
assert (rb_reach(before, after, target="About PyPlayer", source="Check for updates")
and rb_flip(windows_before, windows_after)
and windows_before is not None and windows_after == windows_before + 1), (
"sibling top-level windows %r -> %r (want 0 -> 1); entered_menu=%r clicked=%r "
"new keys=%r steps=%s"
% (windows_before, windows_after, entered, clicked,
sorted(k for k in (after - before) if "about" in k.lower())[:6], steps))
# ══════════════════════════════════════════════════════════════════════════════
# 4. SHAPE DELTA — a mode switch that ADDS widgets (needs media; runs last)
# ══════════════════════════════════════════════════════════════════════════════
@pytest.mark.rb(
jump_kind="transition", depth=3,
expect="Video > Crop with rb_silent.mp4 loaded adds exactly 6 new Text nodes (the "
"Crop: / L: / R: / T: / B: / WxH readout); pressing 'c' removes them again")
def test_crop_mode_adds_six_crop_readout_text_nodes(app, rb, results_dir):
steps = []
text_before = text_crop = text_after = None
loaded = entered_menu = clicked = left_crop = False
try:
loaded = rb_reach_media(rb, app, "rb_silent.mp4")
if not loaded:
steps.append("nav: media did not load (title never showed rb_silent.mp4)")
settle_media()
except Exception as e:
steps.append("open media raised: %r" % (e,))
try:
text_before = count_type(app, "Text")
except Exception as e:
steps.append("baseline Text count raised: %r" % (e,))
try:
entered_menu = rb_enter_menu(rb, app, "Video")
if not entered_menu:
steps.append("nav: the 'Video' menu did not open")
clicked = click_menu_item_like(app, "Crop")
rb.back()
if not clicked:
steps.append("nav: 'Crop' not clickable in the Video menu")
time.sleep(1.2)
except Exception as e:
steps.append("Video > Crop raised: %r" % (e,))
try:
text_crop = count_type(app, "Text")
except Exception as e:
steps.append("Text count in crop mode raised: %r" % (e,))
try:
rb_uia.screenshot_assert(
"structure_crop_mode_readout",
"PyPlayer in crop mode with the colour-bar test video loaded: a crop rectangle "
"is drawn over the video with the area outside it dimmed, and at the right-hand "
"end of the control dock a readout labelled 'Crop:' shows L:, R:, T: and B: "
"edge values with a WxH size beneath them.",
results_dir, window=app)
except Exception as e:
steps.append("screenshot raised: %r" % (e,))
try:
left_crop = exit_crop_mode(app, text_before)
if not left_crop:
steps.append("restore: pressing 'c' did not take the crop readout back down")
except Exception as e:
steps.append("exit crop mode raised: %r" % (e,))
try:
text_after = count_type(app, "Text")
except Exception as e:
steps.append("Text count after leaving crop mode raised: %r" % (e,))
ok = (rb_flip(text_before, text_crop) and loaded and clicked
and text_before is not None and text_crop is not None
and text_crop - text_before == 6
and text_after == text_before)
assert ok, ("Text nodes %r -> %r -> %r (want +6 in crop mode and a full restore); "
"media_loaded=%r menu=%r clicked=%r left_crop=%r steps=%s"
% (text_before, text_crop, text_after, loaded, entered_menu, clicked,
left_crop, steps))