def opened_tdms_file(): """ Allow re-use of an opened TDMS file """ test_file, expected_data = scenarios.chunked_segment().values with test_file.get_tempfile() as temp_file: with TdmsFile.open(temp_file.file) as tdms_file: yield tdms_file, expected_data
def test_indexing_channel_with_ellipsis(): """ Test indexing into a channel with ellipsis returns all data """ test_file, expected_data = scenarios.chunked_segment().values with test_file.get_tempfile() as temp_file: with TdmsFile.open(temp_file.file) as tdms_file: for ((group, channel), expected_channel_data) in expected_data.items(): channel_object = tdms_file[group][channel] compare_arrays(channel_object[...], expected_channel_data)
def test_indexing_channel_with_integer(index): """ Test indexing into a channel with an integer index """ test_file, expected_data = scenarios.chunked_segment().values with test_file.get_tempfile() as temp_file: with TdmsFile.open(temp_file.file) as tdms_file: for ((group, channel), expected_channel_data) in expected_data.items(): channel_object = tdms_file[group][channel] assert channel_object[index] == expected_channel_data[index]
def test_indexing_channel_after_read_data(): """ Test indexing into a channel after reading all data """ test_file, expected_data = scenarios.chunked_segment().values with test_file.get_tempfile() as temp_file: tdms_file = TdmsFile.read(temp_file.file) for ((group, channel), expected_channel_data) in expected_data.items(): channel_object = tdms_file[group][channel] assert channel_object[0] == expected_channel_data[0] compare_arrays(channel_object[:], expected_channel_data)
def test_indexing_channel_with_invalid_integer_raises_error(index): """ Test indexing into a channel with an invalid integer index """ test_file, expected_data = scenarios.chunked_segment().values with test_file.get_tempfile() as temp_file: with TdmsFile.open(temp_file.file) as tdms_file: for ((group, channel), expected_channel_data) in expected_data.items(): channel_object = tdms_file[group][channel] with pytest.raises(IndexError): _ = channel_object[index]
def test_indexing_channel_with_invalid_type_raises_error(index): """ Test indexing into a channel with an invalid index type """ test_file, expected_data = scenarios.chunked_segment().values with test_file.get_tempfile() as temp_file: with TdmsFile.open(temp_file.file) as tdms_file: for ((group, channel), expected_channel_data) in expected_data.items(): channel_object = tdms_file[group][channel] with pytest.raises(TypeError) as exc_info: _ = channel_object[index] assert "Invalid index type" in str(exc_info.value)
def test_indexing_channel_with_zero_step_raises_error(): """ Test indexing into a channel with a slice with zero step size raises an error """ test_file, expected_data = scenarios.chunked_segment().values with test_file.get_tempfile() as temp_file: with TdmsFile.open(temp_file.file) as tdms_file: for ((group, channel), expected_channel_data) in expected_data.items(): channel_object = tdms_file[group][channel] with pytest.raises(ValueError) as exc_info: _ = channel_object[::0] assert str(exc_info.value) == "Step size cannot be zero"
def test_iterate_channel_data_in_read_mode(): """Test iterating over channel data after reading all data """ test_file, expected_data = scenarios.chunked_segment().values with test_file.get_tempfile() as temp_file: tdms_file = TdmsFile.read(temp_file.file) for ((group, channel), expected_channel_data) in expected_data.items(): actual_data = [] for value in tdms_file[group][channel]: actual_data.append(value) compare_arrays(actual_data, expected_channel_data)
def test_indexing_channel_with_integer_and_caching(): """ Test indexing into a channel with an integer index, reusing the same file to test caching """ test_file, expected_data = scenarios.chunked_segment().values with test_file.get_tempfile() as temp_file: with TdmsFile.open(temp_file.file) as tdms_file: for ((group, channel), expected_channel_data) in expected_data.items(): channel_object = tdms_file[group][channel] values = [] for i in range(len(channel_object)): values.append(channel_object[i]) compare_arrays(values, expected_channel_data)
def test_iterate_file_and_groups(): """ Test iterating over TdmsFile and TdmsGroup uses key values """ test_file, expected_data = scenarios.chunked_segment().values with test_file.get_tempfile() as temp_file: tdms_file = TdmsFile.read(temp_file.file) for group_name in tdms_file: group = tdms_file[group_name] for channel_name in group: channel = group[channel_name] expected_channel_data = expected_data[(group_name, channel_name)] compare_arrays(channel.data, expected_channel_data)
def test_streaming_to_hdf(tmp_path): """ Test conversion of channel data to HDF when streaming data from disk """ test_file, expected_data = scenarios.chunked_segment().values with test_file.get_tempfile() as temp_file: with TdmsFile.open(temp_file.file) as tdms_file: h5_path = tmp_path / 'h5_streaming_data_test.h5' h5 = tdms_file.as_hdf(h5_path) for ((group, channel), expected_data) in expected_data.items(): h5_channel = h5[group][channel] np.testing.assert_almost_equal(h5_channel[...], expected_data) h5.close()