MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / test_command_registry

Function test_command_registry

examples/API Test/test_api.py:575–625  ·  view source on GitHub ↗

Verify api.getCommands returns a populated registry.

(api: SerialStudioAPI, suite: TestSuite)

Source from the content-addressed store, hash-verified

573
574
575def test_command_registry(api: SerialStudioAPI, suite: TestSuite):
576 """Verify api.getCommands returns a populated registry."""
577 print(bold(info("\n[ Command Registry ]")))
578
579 t0 = time.time()
580 response = api.send_command("api.getCommands")
581 duration = (time.time() - t0) * 1000
582
583 if not response or not response.get("success"):
584 _record(
585 suite,
586 "api.getCommands succeeds",
587 TestResult.FAILED,
588 "no successful response",
589 )
590 return None
591
592 commands = response.get("result", {}).get("commands", [])
593 if not isinstance(commands, list) or len(commands) < 50:
594 _record(
595 suite,
596 "api.getCommands returns >= 50 commands",
597 TestResult.FAILED,
598 f"got {len(commands)}",
599 )
600 return commands
601
602 _record(
603 suite,
604 f"api.getCommands returns {len(commands)} commands",
605 TestResult.PASSED,
606 duration_ms=duration,
607 )
608
609 # Spot-check structure: each entry has name + description.
610 bad = [
611 c
612 for c in commands
613 if not isinstance(c, dict) or "name" not in c or "description" not in c
614 ]
615 if bad:
616 _record(
617 suite,
618 "every command has name+description",
619 TestResult.FAILED,
620 f"{len(bad)} entries malformed",
621 )
622 else:
623 _record(suite, "every command has name+description", TestResult.PASSED)
624
625 return commands
626
627
628def test_smoke(api: SerialStudioAPI, suite: TestSuite, available: set[str]):

Callers 1

cmd_testFunction · 0.85

Calls 5

boldFunction · 0.85
infoFunction · 0.85
_recordFunction · 0.85
send_commandMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected