Skip to content

Commit

Permalink
add test to dataset name cache
Browse files Browse the repository at this point in the history
  • Loading branch information
evalott100 committed Jun 18, 2024
1 parent 56d3188 commit 05ec830
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/test_hdf_ioc.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from pandablocks_ioc._hdf_ioc import (
CaptureMode,
Dataset,
DatasetNameCache,
HDF5Buffer,
HDF5RecordController,
NumCapturedSetter,
Expand Down Expand Up @@ -1308,3 +1309,41 @@ def test_hdf_capture_validate_exception(
)

assert hdf5_controller._capture_validate(None, 1) is False


def test_dataset_name_cache():
with patch(
"pandablocks_ioc._hdf_ioc.ReadOnlyPvaTable", autospec=True
) as mock_table:
mock_table_instance = MagicMock()
mock_table.return_value = mock_table_instance

# Initialize DatasetNameCache
datasets = {
"TEST1:OUT": Dataset("", "Value"),
"TEST2:OUT": Dataset("test2", "No"),
"TEST3:OUT": Dataset("test3", "Value"),
"TEST4:OUT": Dataset("test4", "Min Max Mean"),
"TEST5:OUT": Dataset("test5", "Min Max"),
}
cache = DatasetNameCache(datasets, "record_name")

# Check that set_rows was called once with the correct arguments
mock_table_instance.set_rows.assert_called_once_with(
["Name", "Type"], [[], []], length=300, default_data_type=str
)
cache.update_datasets_record()

# Check that update_row was called with the correct arguments
mock_table_instance.update_row.assert_any_call(
"Name", ["test3", "test4", "test5"]
)
mock_table_instance.update_row.assert_any_call(
"Type", ["float64", "float64", "float64"]
)

assert cache.hdf_writer_names() == {
"TEST3.OUT": {"Value": "test3"},
"TEST4.OUT": {"Mean": "test4", "Min": "test4-min", "Max": "test4-max"},
"TEST5.OUT": {"Min": "test5-min", "Max": "test5-max"},
}

0 comments on commit 05ec830

Please sign in to comment.