""" Headless test of the two-column GUI. Instantiates the real app class and drives its handlers without opening a window, so layout wiring and settings logic are verified automatically rather than by looking at the screen. """ import os import sys sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) os.chdir(os.path.dirname(os.path.abspath(__file__))) # Keep Kivy from parsing our argv; the real window backend is used but the app # event loop is never started, so nothing is displayed. os.environ.setdefault("KIVY_NO_ARGS", "1") def main() -> int: import label_printer_ptouch_gui as gui print("1. Window is a 600 x 300 landscape panel") print(f" WINDOW_SIZE : {gui.WINDOW_SIZE}") landscape = gui.WINDOW_SIZE[0] > gui.WINDOW_SIZE[1] print(f" landscape : {landscape} {'PASS' if landscape else 'FAIL'}") print("\n2. App.config is not shadowed (the bug that crashed the settings panel)") app = gui.PtouchPrinterApp() has_collision = "config" in vars(app) and not hasattr(vars(app)["config"], "get") print(f" app.config : {type(app.config).__name__}") print(f" label_cfg : {type(app.label_cfg).__name__}") cfg_ok = type(app.label_cfg).__name__ == "LabelConfig" print(f" config valid: {cfg_ok} {'PASS' if cfg_ok else 'FAIL'}") print("\n3. Two-column root layout") root = app.build() print(f" orientation : {root.orientation}") print(f" columns : {len(root.children)}") cols_ok = root.orientation == "horizontal" and len(root.children) == 2 print(f" {'PASS' if cols_ok else 'FAIL'}") # Children are in reverse order of addition: preview column first, then controls. preview_col, controls = root.children print(f" controls col: {controls.orientation}, {len(controls.children)} items") print(f" preview col : {preview_col.orientation}, {len(preview_col.children)} items") print("\n4. Required widgets exist") for name in ( "inventory_input", "printer_spinner", "print_button", "preview", "status_label", ): present = hasattr(app, name) print(f" {name:<18}: {'yes' if present else 'NO'}") if not present: return 1 print("\n5. Settings handlers are reachable (would have raised before)") # Accessing these properties is what failed previously. _ = app.label_cfg.logo_path _ = app.label_cfg.static_lines _ = app.label_cfg.qr_prefix _ = app.label_cfg.qr_suffix _ = app.label_cfg.qr_error_correction print(" loaded without error: PASS") print("\n6. Preview render works headless") app.update_preview() print(f" status text : {app.status_label.text!r}") print(f" texture set : {app.preview._texture is not None}") print("\n7. QR payload is built from the inventory field") app.inventory_input.text = "INV-42" app.update_preview() print(f" status text : {app.status_label.text!r}") payload_ok = "INV-42" in app.status_label.text print(f" reflects field: {payload_ok} {'PASS' if payload_ok else 'FAIL'}") print("\n" + "=" * 62) passed = landscape and cfg_ok and cols_ok and payload_ok print("RESULT:", "PASS" if passed else "FAIL") return 0 if passed else 1 if __name__ == "__main__": raise SystemExit(main())