Skip to content

Commit

Permalink
Changed enum values back to uint8 before updating the table
Browse files Browse the repository at this point in the history
Added a test to add to the panda table after initially leaving it blank
  • Loading branch information
evalott100 committed Oct 6, 2023
1 parent 11cad5d commit 52bd496
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
17 changes: 14 additions & 3 deletions src/pandablocks_ioc/_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,10 +628,21 @@ def update_table(self, new_values: List[str]) -> None:
for field_name, field_record in self.table_fields_records.items():
assert field_record.record_info

value = field_data[field_name]

# If the value is a list of strings then we need to convert
# to a numpy array
if isinstance(value, list):
value = np.array(
[
self.field_info.fields[field_name].labels.index(x)
for x in value
],
dtype=np.uint8,
)

# Must skip processing as the validate method would reject the update
field_record.record_info.record.set(
field_data[field_name], process=False
)
field_record.record_info.record.set(value, process=False)
self._update_scalar(field_record.record_info.record.name)

# All items in field_data have the same length, so just use 0th.
Expand Down
11 changes: 10 additions & 1 deletion tests/fixtures/mocked_panda.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ def multiple_seq_responses(table_field_info, table_data_1, table_data_2):
),
command_to_key(GetBlockInfo(skip_description=False)): repeat(
{
"SEQ": BlockInfo(number=2, description="SEQ Desc"),
"SEQ": BlockInfo(number=3, description="SEQ Desc"),
}
),
command_to_key(
Expand All @@ -485,10 +485,19 @@ def multiple_seq_responses(table_field_info, table_data_1, table_data_2):
values={
"*METADATA.LABEL_SEQ1": "SeqMetadataLabel",
"*METADATA.LABEL_SEQ2": "SeqMetadataLabel",
"*METADATA.LABEL_SEQ3": "SeqMetadataLabel",
},
multiline_values={
"SEQ1.TABLE": table_data_1,
"SEQ2.TABLE": table_data_2,
"SEQ3.TABLE": [],
},
),
respond_with_no_changes(number_of_iterations=5),
changes_iterator_wrapper(
values={},
multiline_values={
"SEQ3.TABLE": table_data_1,
},
),
# Keep the panda active with no changes until pytest tears it down
Expand Down
28 changes: 28 additions & 0 deletions tests/test_ioc_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,34 @@ async def test_metadata_parses_into_multiple_pvs_caput_single_pv(
) in multiprocessing_queue_to_list(command_queue)


async def test_non_defined_seq_table_can_be_added_to(
mocked_panda_multiple_seq_responses,
):
(
tmp_path,
child_conn,
response_handler,
command_queue,
test_prefix,
) = mocked_panda_multiple_seq_responses

initial_table_outd2 = await caget(
test_prefix + ":SEQ3:TABLE:OUTD2", timeout=TIMEOUT
)

assert list(initial_table_outd2) == []
try:
capturing_queue = asyncio.Queue()

# The mocked panda adds SEQ3 values after some time
monitor = camonitor(test_prefix + ":SEQ3:TABLE:OUTD2", capturing_queue.put)
curr_val = await asyncio.wait_for(capturing_queue.get(), TIMEOUT)
assert list(curr_val) == [0, 0, 1]

finally:
monitor.close()


async def test_not_including_number_in_metadata_throws_error(
no_numbered_suffix_to_metadata_responses,
):
Expand Down

0 comments on commit 52bd496

Please sign in to comment.