Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing the occasional errors in tests #63

Merged
merged 3 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 77 additions & 2 deletions tests/fixtures/mocked_panda.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ def multiple_seq_responses(table_field_info, table_data_1, table_data_2):
"SEQ4.TABLE": [],
},
),
respond_with_no_changes(number_of_iterations=10),
respond_with_no_changes(number_of_iterations=50),
changes_iterator_wrapper(
values={},
multiline_values={
Expand Down Expand Up @@ -670,6 +670,57 @@ def faulty_multiple_pcap_responses():
}


@pytest.fixture
def standard_responses_no_panda_update(table_field_info, table_data_1):
"""
Used to test if the softioc can be started.
"""
return {
command_to_key(GetFieldInfo(block="PCAP", extended_metadata=True)): repeat(
{
"TRIG_EDGE": EnumFieldInfo(
type="param",
subtype="enum",
description="Trig Edge Desc",
labels=["Rising", "Falling", "Either"],
),
"GATE": BitMuxFieldInfo(
type="bit_mux",
subtype=None,
description="Gate Desc",
max_delay=100,
labels=["TTLIN1.VAL", "INENC1.A", "CLOCK1.OUT"],
),
}
),
command_to_key(GetFieldInfo(block="SEQ", extended_metadata=True)): repeat(
{"TABLE": table_field_info}
),
command_to_key(GetBlockInfo(skip_description=False)): repeat(
{
"PCAP": BlockInfo(number=1, description="PCAP Desc"),
"SEQ": BlockInfo(number=1, description="SEQ Desc"),
}
),
# Changes are given at 10Hz, the changes provided are used for many
# different tests
command_to_key(GetChanges(group=ChangeGroup.ALL, get_multiline=True)): chain(
# Initial value of every field
changes_iterator_wrapper(
values={
"PCAP.TRIG_EDGE": "Falling",
"PCAP.GATE": "CLOCK1.OUT",
"PCAP.GATE.DELAY": "1",
"PCAP.ARM": "0",
"*METADATA.LABEL_PCAP1": "PcapMetadataLabel",
},
multiline_values={"SEQ.TABLE": table_data_1},
),
respond_with_no_changes(),
),
}


@pytest.fixture
def standard_responses(table_field_info, table_data_1, table_data_2):
"""
Expand Down Expand Up @@ -795,7 +846,7 @@ def standard_responses(table_field_info, table_data_1, table_data_2):
),
# 0.5 seconds of no changes in case the ioc setup completes
# before the test starts
respond_with_no_changes(number_of_iterations=10),
respond_with_no_changes(number_of_iterations=15),
changes_iterator_wrapper(
values={
"PCAP.TRIG_EDGE": "Either",
Expand Down Expand Up @@ -857,6 +908,30 @@ def mocked_panda_standard_responses(
)


@pytest.fixture
def mocked_panda_standard_responses_no_panda_update(
standard_responses_no_panda_update,
new_random_test_prefix,
tmp_path: Path,
caplog,
caplog_workaround,
table_field_info,
table_fields,
clear_records,
) -> Generator[Tuple[Path, Connection, ResponseHandler, Queue, str], None, None]:
response_handler = ResponseHandler(standard_responses_no_panda_update)

yield from create_subprocess_ioc_and_responses(
response_handler,
tmp_path,
new_random_test_prefix,
caplog,
caplog_workaround,
table_field_info,
table_fields,
)


def chunked_read(f: BufferedReader, size: int) -> Iterator[bytes]:
data = f.read(size)
while data:
Expand Down
12 changes: 6 additions & 6 deletions tests/test_ioc_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ async def test_introspect_panda(


async def test_create_softioc_system(
mocked_panda_standard_responses,
mocked_panda_standard_responses_no_panda_update,
table_unpacked_data: OrderedDict[EpicsName, ndarray],
):
"""Top-level system test of the entire program, using some pre-canned data. Tests
Expand All @@ -102,16 +102,16 @@ async def test_create_softioc_system(
response_handler,
command_queue,
test_prefix,
) = mocked_panda_standard_responses

assert await caget(test_prefix + ":PCAP:TRIG_EDGE") == 1 # == Falling
assert await caget(test_prefix + ":PCAP:GATE") == "CLOCK1.OUT"
assert await caget(test_prefix + ":PCAP:GATE:DELAY") == 1
) = mocked_panda_standard_responses_no_panda_update

for field_name, expected_array in table_unpacked_data.items():
actual_array = await caget(test_prefix + ":SEQ:TABLE:" + field_name)
assert numpy.array_equal(actual_array, expected_array)

assert await caget(test_prefix + ":PCAP:TRIG_EDGE") == 1 # == Falling
assert await caget(test_prefix + ":PCAP:GATE") == "CLOCK1.OUT"
assert await caget(test_prefix + ":PCAP:GATE:DELAY") == 1

pcap1_label = await caget(test_prefix + ":PCAP:LABEL")
assert numpy.array_equal(
pcap1_label,
Expand Down
17 changes: 12 additions & 5 deletions tests/test_pvaccess.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import asyncio
import collections
from typing import OrderedDict

import numpy
from fixtures.mocked_panda import TIMEOUT
from numpy import ndarray
from p4p import Value
from p4p.client.thread import Context
from p4p.client.asyncio import Context

from pandablocks_ioc._types import EpicsName


async def test_table_column_info(
mocked_panda_standard_responses,
mocked_panda_multiple_seq_responses,
table_unpacked_data: OrderedDict[EpicsName, ndarray],
):
"""Test that the table columns have the expected PVAccess information in the
Expand All @@ -21,10 +22,16 @@ async def test_table_column_info(
response_handler,
command_queue,
test_prefix,
) = mocked_panda_standard_responses
) = mocked_panda_multiple_seq_responses

ctxt = Context("pva", nt=False)

table_value: Value = ctxt.get(test_prefix + ":SEQ:TABLE")
try:
capturing_queue: asyncio.Queue = asyncio.Queue()
monitor = ctxt.monitor(test_prefix + ":SEQ1:TABLE", capturing_queue.put)
table_value = await asyncio.wait_for(capturing_queue.get(), timeout=TIMEOUT)
finally:
monitor.close()

for (actual_name, actual_value), (expected_name, expected_value) in zip(
table_value.todict(wrapper=collections.OrderedDict)["value"].items(),
Expand Down
Loading