Files
OrcaSlicer/tools/mcp/test_printer_commands.py
T
SoftFever cbf5226d13 Let MCP clients read the connected printer's status and pause, resume or stop its print
printer_status reads what the Device tab shows of the printer it is connected to: its state, progress, layer, the
file printing and the temperatures, with no serial number and nothing sent to the printer. print_pause, print_resume
and print_stop do what the tab's buttons do, and are refused, saying why, where the printer's state does not allow
them or a job can be resumed only at the printer.
2026-11-19 22:58:34 +08:00

43 lines
1.7 KiB
Python

#!/usr/bin/env python3
"""printer_status, print_pause, print_resume and print_stop with no printer connected, as the test_printer_commands
entry of tools/mcp/test-entries/windows_web.md designs them.
tools/mcp/orca_mcp.py launch
tools/mcp/test_printer_commands.py
A scratch datadir is not cut off from the account it may be signed in to, so the test reads printer_status first and
goes on only when it says no printer is connected: otherwise it fails, naming the printer it found, and calls nothing
else. Then each job command is refused no_printer_connected, and printer_status still reads no printer and no dialog
is open. It sends nothing to any printer, and exits 0 when every check passes.
"""
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import orca_mcp # noqa: E402
from checks import Checks, dialogs # noqa: E402
NO_PRINTER = {"connected": False}
def main():
client, _session = orca_mcp.session_client()
t = Checks()
# The guard: no job command is called while a printer is connected.
status = client.call("printer_status")
if not t.equal("no printer is connected", status, NO_PRINTER):
print(f"printer_status found {status.get('name')!r} ({status.get('model')!r}); the test calls nothing else", flush=True)
return t.exit_code()
for command in ("print_pause", "print_resume", "print_stop"):
t.refused(f"{command}: refused", lambda: client.call(command), code="no_printer_connected")
t.equal(f"{command}: printer_status still reads no printer", client.call("printer_status"), NO_PRINTER)
t.equal(f"{command}: no dialog", dialogs(client), [])
return t.exit_code()
if __name__ == "__main__":
sys.exit(main())