def test_daqmx_linear_voltage(): tf = TdmsFile("./tests/tdms_files/daqmx_linear_voltage.tdms") data = tf.group_0.cDAQ1Mod2_ai0.data assert isinstance(data, WaveformDT) assert data.size == 10 assert data[:3].Y == approx((-0.000409137, -0.000727973, -9.0301e-5)) t0 = data.t0 expected = datetime(2019, 10, 3, 2, 31, 10, 787163, tzinfo=timezone.utc) expected = expected.astimezone().replace(tzinfo=None) assert t0 == expected dt = data.dt assert dt == 0.001
def test_channeldata_continued_interleaved(): tf = TdmsFile("./tests/tdms_files/channeldata_continued_interleaved.tdms") ch_0_values = tf.group_0.ch_0.data expected = np.asarray(range(0, 30)) results = ch_0_values == expected assert results.all() ch_1_values = tf.group_0.ch_1.data expected = [] for i in range(3): expected.extend([i * 10 + j for j in range(9, -1, -1)]) results = ch_1_values == np.asarray(expected) assert results.all()
def test_channeldata_2ch_floatbigendianinterleaved(): tf = TdmsFile("./tests/tdms_files/channeldata_2ch_floatbigendianinterleaved.tdms") ch_0_values = tf.group_0.ch_0.data assert isinstance(ch_0_values[0], float) assert ch_0_values.size == 10 for value, expected in zip(ch_0_values, range(10)): assert value == expected ch_1_values = tf.group_0.ch_1.data assert isinstance(ch_1_values[0], float) assert ch_1_values.size == 10 for value, expected in zip(ch_1_values, range(10, 20)): assert value == expected
def test_channeldata_timestamp(): tf = TdmsFile("./tests/tdms_files/channeldata_timestamp.tdms") data = tf.group_0.ch_0.data assert isinstance(data[0], datetime) assert data.size == 10 def compute_expected(s): t = datetime(2019, 1, 1, 6, 0, s, tzinfo=timezone.utc) t = t.astimezone().replace(tzinfo=None) return t expected = [compute_expected(s) for s in range(10)] results = data == expected assert results.all()
def test_channeldata_2ch_complexsingle(): tf = TdmsFile("./tests/tdms_files/channeldata_2ch_complexsingle.tdms") ch_0_values = tf.group_0.ch_0.data assert isinstance(ch_0_values[0], complex) assert ch_0_values.size == 10 expecteds = map(lambda ri: complex(*ri), zip(range(10), range(19, 9, -1))) for value, expected in zip(ch_0_values, expecteds): assert value == expected ch_1_values = tf.group_0.ch_1.data assert isinstance(ch_1_values[0], complex) assert ch_1_values.size == 10 expecteds = map(lambda ri: complex(*ri), zip(range(10, 20), range(9, -1, -1))) for value, expected in zip(ch_1_values, expecteds): assert value == expected
def test_channeldata_digitalwfmpattern(): tf = TdmsFile("./tests/tdms_files/channeldata_digitalwfmpattern.tdms") group = tf.group_0 data = [ch.data for ch in group] data.reverse() data = list(zip(*data)) values = [] for t in data: value = 0 for i, bit_value in enumerate(t): value += 2 ** i * bit_value values.append(value) assert values == list(range(8)) assert group.wf_start_time == 0.0
def test_toxy_absolute(): tf = TdmsFile("./tests/tdms_files/wdt_absolutet0.tdms") wf = tf.group_0.ch0.data expected = datetime(2019, 1, 1, 6, 0, tzinfo=timezone.utc) expected = expected.astimezone().replace(tzinfo=None) assert wf.t0 == expected x, _ = wf.to_xy(False) def compute_expected(s): t = datetime(2019, 1, 1, 6, 0, s, tzinfo=timezone.utc) t = t.astimezone().replace(tzinfo=None) return np.datetime64(t) expected = np.asarray([compute_expected(s) for s in range(10)]) results = x == expected assert results.all()
def test_channeldata_nodata(): tf = TdmsFile("./tests/tdms_files/channeldata_nodata.tdms") data = tf.group_0.ch_0.data assert data.size == 0
def test_channeldata_timestamp_interleaved(): tf = TdmsFile("./tests/tdms_files/channeldata_timestamp_interleaved.tdms") seconds = [ts.second for ts in tf.group_0.ch_0.data] assert seconds == list(range(0, 10, 2)) seconds = [ts.second for ts in tf.group_0.ch_1.data] assert seconds == list(range(1, 10, 2))
def test_channel_iter(): tf = TdmsFile("./tests/tdms_files/channeldata.tdms") for expected, value in enumerate(tf.group_0.ch_0): assert value == expected
def test_datatypenotsupporterror(): with raises(DataTypeNotSupportedError): TdmsFile("./tests/tdms_files/extended data type.tdms")
def test_channeldata_continued(): tf = TdmsFile("./tests/tdms_files/channeldata_continued.tdms") data = tf.group_0.ch_0.data assert data.size == 30 for value, expected in zip(data, range(30)): assert value == expected
def test_logfile(): tf = TdmsFile("./tests/tdms_files/log.tdms") data = tf.run0.temperature.data assert len(data) == 13
def test_filenotfound(): with raises(FileNotFoundError): TdmsFile("")
"""Test TDMS objects and properties""" from pytest import raises from nitdms.reader import TdmsFile from nitdms.common import TdmsObject, Group, Channel # pylint: disable=missing-docstring # pylint: disable=pointless-statement # pylint: disable=no-member # pylint: disable=unnecessary-comprehension TF = TdmsFile("./tests/tdms_files/objects and properties.tdms") def test_fileobject(): assert issubclass(TF.__class__, TdmsObject) assert isinstance(TF, TdmsFile) def test_groupobject(): assert issubclass(TF.group_0.__class__, TdmsObject) assert isinstance(TF.group_0, Group) def test_channelobject(): assert issubclass(TF.group_0.ch_0.__class__, TdmsObject) assert isinstance(TF.group_0.ch_0, Channel) def test_fileproperty(): value = TF.file_prop_0 assert value == 0
"""test data type decoding""" from datetime import datetime, timezone from nitdms.reader import TdmsFile # pylint: disable=missing-docstring # pylint: disable=pointless-statement # pylint: disable=no-member TF = TdmsFile("./tests/tdms_files/data types.tdms") def test_u8(): value = TF.U8 assert isinstance(value, int) assert value == 1 def test_i8(): value = TF.I8 assert isinstance(value, int) assert value == -1 def test_u16(): value = TF.U16 assert isinstance(value, int) assert value == 1 def test_i16(): value = TF.I16
def test_daqmx_digital_1ch1line(): tf = TdmsFile("./tests/tdms_files/daqmx_digital_1ch1line.tdms") group = tf["group_0 - line0"] data = group.PXI1Slot7_port0_line0.data result = data == np.asarray([0] * 10) assert result.all()
def test_daqmx_linear_current(): tf = TdmsFile("./tests/tdms_files/daqmx_linear_current.tdms") data = tf.group_0.NI9208_ai0.data assert data.size == 10 assert data[0].Y == approx(1.311302263e-8)
def test_daqmx_rtd_below0degc(): tf = TdmsFile("./tests/tdms_files/daqmx_rtd_below0degC.tdms") data = tf.group_0.cDAQ1Mod1_ai0.data assert data.size == 10 assert data[:3].Y == approx( (-128.656508921, -128.629116858, -128.628971925))
def test_daqmx_rtd(): tf = TdmsFile("./tests/tdms_files/daqmx_rtd.tdms") data = tf.group_0.cDAQ1Mod1_ai0.data assert data.size == 10 assert data[:3].Y == approx((704.140641532, 704.121962322, 704.091729236))
def test_segmentcorruptederror(): with raises(SegmentCorruptedError): TdmsFile("./tests/tdms_files/segment corrupted.tdms")
def test_analog_multiplewrites(): tf = TdmsFile("./tests/tdms_files/wdt_analog_multiplewrites.tdms") wf = tf.group_0.ch0.data assert wf.Y.shape == (2, 100)
def test_channeldata_bigendian(): tf = TdmsFile("./tests/tdms_files/channeldata_bigendian.tdms") data = tf.group_0.ch_0.data assert data.size == 10 for value, expected in zip(data, range(10)): assert value == expected
def test_invaliddimensionerror(): with raises(InvalidDimensionError): TdmsFile("./tests/tdms_files/invalid dimension.tdms")
def test_dir_invalid_name(): tf = TdmsFile("./tests/tdms_files/invalid attributes names.tdms") assert '["file-prop 0"]' in dir(tf)
def test_daqmx_counter_pulsewidth(): tf = TdmsFile("./tests/tdms_files/daqmx_counter_pulsewidth.tdms") assert tf.group_0.PXI1Slot7_ctr0.data.Y == approx(10 * [0.001])
def test_daqmx_linear_voltage(): tf = TdmsFile("./tests/tdms_files/daqmx_linear_voltage.tdms") wf = tf.group_0.cDAQ1Mod2_ai0.data assert wf.dt == 0.001 assert wf.Y.shape == (10,)
def test_changebyteorder(): tf = TdmsFile("./tests/tdms_files/change byte order.tdms") assert tf.file_prop_0 == 0 assert tf.file_prop_1 == 1
def test_extraattributes(): tf = TdmsFile("./tests/tdms_files/wdt_analog.tdms") wf = tf.group_0.ch0.data assert wf.signal == "sine"
def test_invalidversionerror(): with raises(InvalidTDMSVersionError): TdmsFile("./tests/tdms_files/invalid version.tdms")