|
| 1 | +#!/usr/bin/env python3 |
| 2 | +"""The Builder's default tool panes stay docked on small screens, headless. |
| 3 | +
|
| 4 | + tests/apps/tool_column_test.py [--png DIR] [--sizes 1024x600,...] |
| 5 | +
|
| 6 | +A calculation that has not been run opens with the building tools: Open |
| 7 | +structures, Build, Coordinates or Selection, Symmetry and the Log. On a |
| 8 | +laptop screen these do not fit the right-hand column at their full height; |
| 9 | +the last of them (Symmetry) used to get no height at all and its window was |
| 10 | +drawn where it was created, over the 3-D viewer. For each screen size and |
| 11 | +the classic and list + detail layouts every shown tool pane must be docked, |
| 12 | +a child of the frame, inside the window, at least MIN_HEIGHT high, and clear |
| 13 | +of the viewer. |
| 14 | +
|
| 15 | +Same installed tree and isolation as run_tests.py (ECCE_TEST_HOME, |
| 16 | +ECCE_TEST_WRAPPERS); exit 77 (skip) without an install or Xvfb. |
| 17 | +""" |
| 18 | +import argparse |
| 19 | +import os |
| 20 | +import sys |
| 21 | + |
| 22 | +HERE = os.path.dirname(os.path.abspath(__file__)) |
| 23 | +sys.path.insert(0, HERE) |
| 24 | + |
| 25 | +import apps # noqa: E402 |
| 26 | +import fixture # noqa: E402 |
| 27 | +import pbc_ux_test # noqa: E402 |
| 28 | + |
| 29 | +SIZES = ("1024x600", "1366x768", "1400x900") |
| 30 | +MODES = ("classic", "detail") |
| 31 | +TOOLS = ["Open_structures", "Build", "Coordinates", "Selection", "Symmetry", |
| 32 | + "Atom_Table"] |
| 33 | +MIN_HEIGHT = 30 |
| 34 | + |
| 35 | + |
| 36 | +def rects(st): |
| 37 | + """{pane name: (x, y, w, h)} of every shown pane.""" |
| 38 | + out = {} |
| 39 | + for line in st.get("raw", []): |
| 40 | + name = line.split('"')[1] |
| 41 | + x, y, w, h = (int(v) for v in line.split('"')[2].split()[1:5]) |
| 42 | + out[name] = (x, y, w, h) |
| 43 | + return out |
| 44 | + |
| 45 | + |
| 46 | +def problems(st, label): |
| 47 | + if st is None: |
| 48 | + return ["%s: no state written" % label] |
| 49 | + found = [] |
| 50 | + sym = st["tools"].get("Symmetry") |
| 51 | + if not sym or not sym["shown"]: |
| 52 | + found.append("%s: Symmetry not shown (%s)" |
| 53 | + % (label, ", ".join(st["shown"]))) |
| 54 | + cw, ch = st["client"] |
| 55 | + viewer = rects(st).get("Viewer") |
| 56 | + for name, t in sorted(st["tools"].items()): |
| 57 | + if not t["shown"]: |
| 58 | + continue |
| 59 | + where = "%s, %s %dx%d+%d+%d" % (label, name, t["w"], t["h"], |
| 60 | + t["x"], t["y"]) |
| 61 | + if t["floating"]: |
| 62 | + found.append(where + ": floating") |
| 63 | + if not t["child"]: |
| 64 | + found.append(where + ": window left the frame") |
| 65 | + if t["h"] < MIN_HEIGHT: |
| 66 | + found.append(where + ": no room in the column") |
| 67 | + if (t["x"] < 0 or t["y"] < 0 or t["x"] + t["w"] > cw or |
| 68 | + t["y"] + t["h"] > ch): |
| 69 | + found.append(where + ": outside the %dx%d window" % (cw, ch)) |
| 70 | + if viewer: |
| 71 | + vx, vy, vw, vh = viewer |
| 72 | + if (t["x"] < vx + vw and vx < t["x"] + t["w"] and |
| 73 | + t["y"] < vy + vh and vy < t["y"] + t["h"]): |
| 74 | + found.append(where + ": covers the viewer") |
| 75 | + return found |
| 76 | + |
| 77 | + |
| 78 | +def main(): |
| 79 | + parser = argparse.ArgumentParser(description=__doc__) |
| 80 | + parser.add_argument("--png", help="write one screenshot per case here") |
| 81 | + parser.add_argument("--sizes", default=",".join(SIZES)) |
| 82 | + args = parser.parse_args() |
| 83 | + |
| 84 | + import isolate |
| 85 | + import xdisplay |
| 86 | + |
| 87 | + for var in ("ECCE_DATASERVER_PORT", "ECCE_BROKER_PORT"): |
| 88 | + os.environ.pop(var, None) |
| 89 | + os.environ["ECCE_REALUSER"] = fixture.USER |
| 90 | + if not apps.installed("builder"): |
| 91 | + print("SKIP no installed builder") |
| 92 | + return 77 |
| 93 | + settings = isolate.apply(apps.INSTALL) |
| 94 | + isolate.killLeftovers(settings["ECCE_REALUSERHOME"]) |
| 95 | + os.environ["ECCE_NO_REAP"] = "1" |
| 96 | + |
| 97 | + failures, checks = [], 0 |
| 98 | + for size in args.sizes.split(","): |
| 99 | + xdisplay.SCREEN = size + "x24" |
| 100 | + with xdisplay.Display() as display: |
| 101 | + log = [] |
| 102 | + apps.startServices(display, log) |
| 103 | + try: |
| 104 | + if not all(apps.serviceState(display).values()): |
| 105 | + print("FAIL services did not come up: %s" % log) |
| 106 | + return 1 |
| 107 | + fixture.ensureRealUserAccount() |
| 108 | + restore = fixture.settleUpgradeNotices() |
| 109 | + try: |
| 110 | + url, error = pbc_ux_test.install("tool-column", |
| 111 | + pbc_ux_test.notRun) |
| 112 | + if error: |
| 113 | + print("FAIL cannot install fixture: " + error) |
| 114 | + return 1 |
| 115 | + auth = fixture.authFile( |
| 116 | + os.path.join(fixture.stateHome(), ".ECCE", |
| 117 | + "auth.pipe"), user=fixture.USER) |
| 118 | + for mode in MODES: |
| 119 | + checks += 1 |
| 120 | + label = "%s, %s layout" % (size, mode) |
| 121 | + script = ["columntab 0"] |
| 122 | + if args.png: |
| 123 | + os.makedirs(args.png, exist_ok=True) |
| 124 | + script.append("xshot " + os.path.join( |
| 125 | + args.png, "tools-%s-%s.png" % (size, mode))) |
| 126 | + script.append("panestate state " + " ".join(TOOLS)) |
| 127 | + work, found, out = pbc_ux_test.runScene( |
| 128 | + display, "tools-%s-%s" % (size, mode), script, |
| 129 | + url, ("-pipe", auth, "-context", url), |
| 130 | + env={"ECCE_PANEL_MODE": mode}) |
| 131 | + found += problems(pbc_ux_test.readState( |
| 132 | + os.path.join(work, "state.txt")), label) |
| 133 | + print("%s %s" % ("FAIL" if found else "ok ", label)) |
| 134 | + for p in found: |
| 135 | + print(" " + p) |
| 136 | + failures += found |
| 137 | + fixture.remove("tool-column") |
| 138 | + finally: |
| 139 | + restore() |
| 140 | + finally: |
| 141 | + apps.stopServices(display) |
| 142 | + print("%s %d cases, %d problems" % ("FAIL" if failures else "PASS", |
| 143 | + checks, len(failures))) |
| 144 | + return 1 if failures else 0 |
| 145 | + |
| 146 | + |
| 147 | +if __name__ == "__main__": |
| 148 | + sys.exit(main()) |
0 commit comments