feat(client): spec-style moves and wm print the BEC command they run
umv/umvr/mv/mvr: the transformed line prints the BEC call before running it (printed at run time, not in the transformer, which IPython calls more than once). wm prints dev.wm([...]). Now every spec-style command shows its BEC equivalent, as ascan/dscan/ct already did. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M8zoDygkWk6LupmHh3tyET
This commit is contained in:
1 parent
c39f3f5ff0
commit
f44daf1c59
2 files changed
+28
-6
No files matched your search
@@ -12,7 +12,9 @@ Scans (the number is spec's *intervals*, so 10 intervals = 11 points):
|
||||
dscan samx -1 1 10 0.1 -> same with relative=True
|
||||
ct 0.5 / ct -> ct(0.5) / ct() runs scans.acquire(exp_time=...)
|
||||
|
||||
ascan, dscan and ct print the BEC command before running it.
|
||||
Every command prints the real BEC command before running it, so users keep
|
||||
the connection to BEC (moves: the transformed line prints it; ascan, dscan,
|
||||
ct and wm print it themselves, also when called directly).
|
||||
|
||||
Positions:
|
||||
wm samx samy -> wm("samx", "samy") runs dev.wm(["samx", "samy"])
|
||||
@@ -70,6 +72,10 @@ def shell_moves(lines):
|
||||
if not _NAME.match(name) or not _is_value(pos):
|
||||
return lines
|
||||
args += [_dev(name), pos]
|
||||
# umv/umvr/mv/mvr are BEC's own commands: print the call in the
|
||||
# executed line (not here: IPython runs transformers more than once)
|
||||
call = f"{cmd}({', '.join(args)})"
|
||||
return [f"{indent}print({call!r}); {call}\n"]
|
||||
return [f"{indent}{cmd}({', '.join(args)})\n"]
|
||||
|
||||
|
||||
@@ -109,6 +115,7 @@ def ct(exp_time=_CT_DEFAULT):
|
||||
def wm(*devices):
|
||||
"""spec wm: show readback, setpoint and limits; names, devices or wildcards."""
|
||||
names = [d if isinstance(d, str) else d.name for d in devices]
|
||||
print(f"dev.wm({names!r})")
|
||||
return builtins.__dict__["dev"].wm(names)
|
||||
|
||||
|
||||
|
||||
@@ -16,10 +16,16 @@ from csaxs_bec.bec_ipython_client.plugins.tool_box.spec_commands import (
|
||||
@pytest.mark.parametrize(
|
||||
"src, want",
|
||||
[
|
||||
("umv samx 1 samy 2\n", "umv(dev.samx, 1, dev.samy, 2)\n"),
|
||||
("umvr samx -0.5\n", "umvr(dev.samx, -0.5)\n"),
|
||||
("mv dev.samx 3, samy pos+1\n", "mv(dev.samx, 3, dev.samy, pos+1)\n"),
|
||||
("mvr lsamrot 1e-3 \n", "mvr(dev.lsamrot, 1e-3)\n"),
|
||||
(
|
||||
"umv samx 1 samy 2\n",
|
||||
"print('umv(dev.samx, 1, dev.samy, 2)'); umv(dev.samx, 1, dev.samy, 2)\n",
|
||||
),
|
||||
("umvr samx -0.5\n", "print('umvr(dev.samx, -0.5)'); umvr(dev.samx, -0.5)\n"),
|
||||
(
|
||||
"mv dev.samx 3, samy pos+1\n",
|
||||
"print('mv(dev.samx, 3, dev.samy, pos+1)'); mv(dev.samx, 3, dev.samy, pos+1)\n",
|
||||
),
|
||||
("mvr lsamrot 1e-3 \n", "print('mvr(dev.lsamrot, 1e-3)'); mvr(dev.lsamrot, 1e-3)\n"),
|
||||
("umv(dev.samx, 1)\n", None),
|
||||
("umv (dev.samx, 1)\n", None),
|
||||
("umv = 3\n", None),
|
||||
@@ -119,8 +125,17 @@ def test_ct(bec_scans, capsys):
|
||||
assert "scans.acquire(exp_time=0.5)" in out and "scans.acquire(exp_time=1.0)" in out
|
||||
|
||||
|
||||
def test_wm_passes_names_to_dev_wm():
|
||||
def test_wm_passes_names_to_dev_wm(capsys):
|
||||
dev = mock.MagicMock()
|
||||
with mock.patch.dict(builtins.__dict__, {"dev": dev}):
|
||||
wm("samx", _motor("samy"), "sam*")
|
||||
dev.wm.assert_called_once_with(["samx", "samy", "sam*"])
|
||||
assert "dev.wm(['samx', 'samy', 'sam*'])" in capsys.readouterr().out
|
||||
|
||||
|
||||
def test_transformed_move_prints_bec_command(capsys):
|
||||
calls = []
|
||||
ns = {"umv": lambda *a: calls.append(a), "dev": mock.MagicMock()}
|
||||
exec(shell_moves(["umv samx 1\n"])[0], ns)
|
||||
assert capsys.readouterr().out == "umv(dev.samx, 1)\n"
|
||||
assert calls == [(ns["dev"].samx, 1)]
|
||||
Reference in new issue
Block a user