Skip to content

Commit

Permalink
Merge pull request #53 from aureocarneiro/append_command
Browse files Browse the repository at this point in the history
add Append command
  • Loading branch information
coretl authored Aug 23, 2023
2 parents d9516e5 + 8b8badd commit 1581223
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
24 changes: 24 additions & 0 deletions pandablocks/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"GetLine",
"GetMultiline",
"Put",
"Append",
"Arm",
"Disarm",
"GetBlockInfo",
Expand Down Expand Up @@ -293,6 +294,29 @@ def execute(self) -> ExchangeGenerator[None]:
assert ex.line == "OK"


@dataclass
class Append(Command[None]):
"""Append the value of a table field.
Args:
field: The field, attribute, or star command to append
value: The value, list of strings, to append
For example::
Append("SEQ1.TABLE", ["1048576", "0", "1000", "1000"])
"""

field: str
value: List[str]

def execute(self) -> ExchangeGenerator[None]:
# Multiline table with blank line to terminate
ex = Exchange([f"{self.field}<<"] + self.value + [""])
yield ex
assert ex.line == "OK"


class Arm(Command[None]):
"""Arm PCAP for an acquisition by sending ``*PCAP.ARM=``"""

Expand Down
16 changes: 16 additions & 0 deletions tests/test_pandablocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pytest

from pandablocks.commands import (
Append,
ChangeGroup,
CommandException,
Get,
Expand Down Expand Up @@ -188,6 +189,21 @@ def test_connect_put_no_value():
assert get_responses(conn, b"OK\n") == [(cmd, None)]


def test_connect_append():
conn = ControlConnection()
cmd = Append("SEQ1.TABLE", ["1048576", "0", "1000", "1000"])
assert conn.send(cmd) == b"SEQ1.TABLE<<\n1048576\n0\n1000\n1000\n\n"
assert get_responses(conn, b"OK\n") == [(cmd, None)]


def test_connect_append_multi_bad_list_format():
"""Confirm that an invalid data format raises the expected exception"""
conn = ControlConnection()
cmd = Append("SEQ1.TABLE", [1, 2, 3])
with pytest.raises(TypeError):
assert conn.send(cmd) == b""


def test_get_block_info():
conn = ControlConnection()
cmd = GetBlockInfo()
Expand Down

0 comments on commit 1581223

Please sign in to comment.