Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,7 @@ exclude = ["**/*_pb2_grpc.py", "**/*_pb2_grpc.pyi", "**/*_pb2.py", "**/*_pb2.pyi
[tool.pytest.ini_options]
addopts = "--doctest-modules --doctest-plus --strict-markers"
testpaths = ["tests"]
norecursedirs = [".venv"]
filterwarnings = [
"ignore:cannot collect test class.*because it has a __init__ constructor:pytest.PytestCollectionWarning",
]
9 changes: 2 additions & 7 deletions src/ni/datastore/data/_grpc_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,9 @@ def get_publish_measurement_timestamp(
elif value_case == "digital_waveform":
waveform_t0 = publish_request.digital_waveform.t0

# If an initialized waveform t0 value is present
# If an initialized waveform t0 value is present and no client timestamp was provided,
# use the waveform t0 as the measurement start time.
if waveform_t0 is not None and waveform_t0 != PrecisionTimestamp():
if no_client_timestamp_provided:
# If the client did not provide a timestamp, use the waveform t0 value
publish_time = waveform_t0
elif publish_time != waveform_t0:
raise ValueError(
"The provided timestamp does not match the waveform t0. Please provide a matching timestamp or "
"omit the timestamp to use the waveform t0."
)
return publish_time
37 changes: 32 additions & 5 deletions tests/unit/data/test_publish_measurement.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,9 @@ def test___publish_analog_waveform_data_without_t0___uses_timestamp_parameter(
assert request.timestamp == hightime_datetime_to_protobuf(timestamp)


def test___publish_analog_waveform_data_with_mismatched_timestamp_parameter___raises_error(
def test___publish_analog_waveform_data_with_mismatched_timestamp_parameter___uses_provided_timestamp(
data_store_client: DataStoreClient,
mocked_data_store_service_client: NonCallableMock,
) -> None:
timestamp = datetime.now(tz=std_datetime.timezone.utc)
waveform_values = [1.0, 2.0, 3.0]
Expand All @@ -235,11 +236,37 @@ def test___publish_analog_waveform_data_with_mismatched_timestamp_parameter___ra
timing=Timing.create_with_regular_interval(timedelta(seconds=1), timestamp),
)
mismatched_timestamp = timestamp + timedelta(seconds=1)
mocked_data_store_service_client.publish_measurement.return_value = PublishMeasurementResponse(
measurement_id="response_id"
)

with pytest.raises(ValueError):
data_store_client.publish_measurement(
"name", analog_waveform, "step_id", mismatched_timestamp
)
measurement_id = data_store_client.publish_measurement(
"name", analog_waveform, "step_id", mismatched_timestamp
)

args, __ = mocked_data_store_service_client.publish_measurement.call_args
request = cast(PublishMeasurementRequest, args[0])
assert measurement_id == "response_id"
assert request.timestamp == hightime_datetime_to_protobuf(mismatched_timestamp)


def test___publish_analog_waveform_data_without_t0_or_timestamp___uses_now(
data_store_client: DataStoreClient,
mocked_data_store_service_client: NonCallableMock,
) -> None:
now = datetime.now(tz=std_datetime.timezone.utc)
analog_waveform = AnalogWaveform.from_array_1d([1.0, 2.0, 3.0], dtype=float)
mocked_data_store_service_client.publish_measurement.return_value = PublishMeasurementResponse(
measurement_id="response_id"
)

with unittest.mock.patch("ni.datastore.data._grpc_conversion.ht.datetime") as mock_ht_datetime:
mock_ht_datetime.now.return_value = now
data_store_client.publish_measurement("name", analog_waveform, "step_id")

args, __ = mocked_data_store_service_client.publish_measurement.call_args
request = cast(PublishMeasurementRequest, args[0])
assert request.timestamp == hightime_datetime_to_protobuf(now)


def test___none___publish_measurement___raises_type_error(
Expand Down
Loading