|
1 | 1 | import datetime as dt |
2 | 2 |
|
3 | 3 | import numpy as np |
| 4 | +import pytest |
4 | 5 | from nitypes.bintime import DateTime |
5 | 6 | from nitypes.complex import ComplexInt32DType |
6 | 7 | from nitypes.waveform import ( |
@@ -94,6 +95,19 @@ def test___analog_waveform_with_standard_timing___convert___valid_protobuf() -> |
94 | 95 | assert dbl_analog_waveform.t0 == converted_t0 |
95 | 96 |
|
96 | 97 |
|
| 98 | +def test___analog_waveform_with_irregular_timing___convert___raises_value_error() -> None: |
| 99 | + analog_waveform = AnalogWaveform.from_array_1d(np.array([1.0, 2.0, 3.0])) |
| 100 | + t0_dt = dt.datetime(2000, 12, 1, tzinfo=dt.timezone.utc) |
| 101 | + analog_waveform.timing = Timing.create_with_irregular_interval( |
| 102 | + [t0_dt, t0_dt + dt.timedelta(milliseconds=1000), t0_dt + dt.timedelta(milliseconds=3000)] |
| 103 | + ) |
| 104 | + |
| 105 | + with pytest.raises(ValueError) as exc: |
| 106 | + _ = float64_analog_waveform_to_protobuf(analog_waveform) |
| 107 | + |
| 108 | + assert exc.value.args[0].startswith("Cannot convert irregular sample interval to protobuf.") |
| 109 | + |
| 110 | + |
97 | 111 | # ======================================================== |
98 | 112 | # DoubleAnalogWaveform to AnalogWaveform |
99 | 113 | # ======================================================== |
@@ -221,6 +235,19 @@ def test___float64_complex_waveform_with_standard_timing___convert___valid_proto |
221 | 235 | assert dbl_complex_waveform.t0 == converted_t0 |
222 | 236 |
|
223 | 237 |
|
| 238 | +def test___float64_complex_waveform_with_irregular_timing___convert___raises_value_error() -> None: |
| 239 | + complex_waveform = ComplexWaveform.from_array_1d([1.5 + 2.5j, 3.5 + 4.5j], np.complex128) |
| 240 | + t0_dt = dt.datetime(2000, 12, 1, tzinfo=dt.timezone.utc) |
| 241 | + complex_waveform.timing = Timing.create_with_irregular_interval( |
| 242 | + [t0_dt, t0_dt + dt.timedelta(milliseconds=1000)] |
| 243 | + ) |
| 244 | + |
| 245 | + with pytest.raises(ValueError) as exc: |
| 246 | + _ = float64_complex_waveform_to_protobuf(complex_waveform) |
| 247 | + |
| 248 | + assert exc.value.args[0].startswith("Cannot convert irregular sample interval to protobuf.") |
| 249 | + |
| 250 | + |
224 | 251 | # ======================================================== |
225 | 252 | # DoubleComplexWaveform to ComplexWaveform |
226 | 253 | # ======================================================== |
@@ -349,6 +376,19 @@ def test___int16_complex_waveform_with_standard_timing___convert___valid_protobu |
349 | 376 | assert i16_complex_waveform.t0 == converted_t0 |
350 | 377 |
|
351 | 378 |
|
| 379 | +def test___int16_complex_waveform_with_irregular_timing___convert___raises_value_error() -> None: |
| 380 | + complex_waveform = ComplexWaveform.from_array_1d([(1, 2), (3, 4)], ComplexInt32DType) |
| 381 | + t0_dt = dt.datetime(2000, 12, 1, tzinfo=dt.timezone.utc) |
| 382 | + complex_waveform.timing = Timing.create_with_irregular_interval( |
| 383 | + [t0_dt, t0_dt + dt.timedelta(milliseconds=1000)] |
| 384 | + ) |
| 385 | + |
| 386 | + with pytest.raises(ValueError) as exc: |
| 387 | + _ = int16_complex_waveform_to_protobuf(complex_waveform) |
| 388 | + |
| 389 | + assert exc.value.args[0].startswith("Cannot convert irregular sample interval to protobuf.") |
| 390 | + |
| 391 | + |
352 | 392 | def test___int16_complex_waveform_with_scaling___convert___valid_protobuf() -> None: |
353 | 393 | scale_mode = LinearScaleMode(2.0, 3.0) |
354 | 394 | complex_waveform = ComplexWaveform.from_array_1d( |
|
0 commit comments