diff --git a/tests/test_hdf_ioc.py b/tests/test_hdf_ioc.py index 58bb3a74..9cb9a7e2 100644 --- a/tests/test_hdf_ioc.py +++ b/tests/test_hdf_ioc.py @@ -39,6 +39,7 @@ from pandablocks_ioc._hdf_ioc import ( CaptureMode, Dataset, + DatasetNameCache, HDF5Buffer, HDF5RecordController, NumCapturedSetter, @@ -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"}, + }