Skip to content

Commit

Permalink
Fix/filter warnings
Browse files Browse the repository at this point in the history
Signed-off-by: David Curtiss <david.curtiss@ni.com>
  • Loading branch information
DavidCurtiss committed Oct 24, 2024
1 parent 3ffa1f9 commit 45fbc08
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 13 deletions.
11 changes: 11 additions & 0 deletions packages/service/tests/acceptance/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
"""Pytest configuration file for acceptance tests."""

import pathlib
import warnings
from typing import Generator

from ni_measurement_plugin_sdk_service.measurement import WrongMessageTypeWarning

import pytest

Expand All @@ -9,3 +13,10 @@
def pin_map_directory(test_assets_directory: pathlib.Path) -> pathlib.Path:
"""Test fixture that returns the pin map directory."""
return test_assets_directory / "acceptance" / "session_management"


@pytest.fixture
def filter_wrong_configurations_message_type_warnings() -> Generator:
"""Test fixture to filter out WrongMessageTypeWarning warnings for Configurations messages."""
warnings.filterwarnings("ignore", ".*Configurations.*", WrongMessageTypeWarning)
yield
5 changes: 4 additions & 1 deletion packages/service/tests/acceptance/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,12 @@ def test___streaming_data_measurement___measure___server_call_logged(
)
num_responses = 10

metadata = stub_v2.GetMetadata(v2_measurement_service_pb2.GetMetadataRequest())

measure_request = v2_measurement_service_pb2.MeasureRequest(
configuration_parameters=get_streaming_data_configuration_parameters(
num_responses=num_responses
message_type=metadata.measurement_signature.configuration_parameters_message_type,
num_responses=num_responses,
)
)
response_iterator = stub_v2.Measure(measure_request)
Expand Down
18 changes: 14 additions & 4 deletions packages/service/tests/acceptance/test_measurement_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ def test___measurement_service_v1___measure___returns_output(
string_array_in: List[str],
stub_v1: v1_measurement_service_pb2_grpc.MeasurementServiceStub,
):
metadata = stub_v1.GetMetadata(v1_measurement_service_pb2.GetMetadataRequest())

request = v1_measurement_service_pb2.MeasureRequest(
configuration_parameters=_get_configuration_parameters(
float_in,
Expand All @@ -85,6 +87,7 @@ def test___measurement_service_v1___measure___returns_output(
enum_in,
protobuf_enum_in,
string_array_in,
message_type=metadata.measurement_signature.configuration_parameters_message_type,
)
)
response = stub_v1.Measure(request)
Expand Down Expand Up @@ -119,6 +122,8 @@ def test___measurement_service_v2___measure___returns_output(
string_array_in: List[str],
stub_v2: v2_measurement_service_pb2_grpc.MeasurementServiceStub,
):
metadata = stub_v2.GetMetadata(v2_measurement_service_pb2.GetMetadataRequest())

request = v2_measurement_service_pb2.MeasureRequest(
configuration_parameters=_get_configuration_parameters(
float_in,
Expand All @@ -128,6 +133,7 @@ def test___measurement_service_v2___measure___returns_output(
enum_in,
protobuf_enum_in,
string_array_in,
message_type=metadata.measurement_signature.configuration_parameters_message_type,
)
)
response_iterator = stub_v2.Measure(request)
Expand All @@ -154,6 +160,8 @@ def test___measurement_service_v1___measure_with_large_array___returns_output(
protobuf_enum_in = ProtobufColor.WHITE
string_array_in = ["", "TestString1", "#$%!@<*(&^~`"]

metadata = stub_v1.GetMetadata(v1_measurement_service_pb2.GetMetadataRequest())

request = v1_measurement_service_pb2.MeasureRequest(
configuration_parameters=_get_configuration_parameters(
float_in,
Expand All @@ -163,6 +171,7 @@ def test___measurement_service_v1___measure_with_large_array___returns_output(
enum_in,
protobuf_enum_in,
string_array_in,
message_type=metadata.measurement_signature.configuration_parameters_message_type,
)
)
response = stub_v1.Measure(request)
Expand All @@ -187,6 +196,8 @@ def test___measurement_service_v2___measure_with_large_array___returns_output(
string_in = "InputString"
string_array_in = ["", "TestString1", "#$%!@<*(&^~`"]

metadata = stub_v2.GetMetadata(v2_measurement_service_pb2.GetMetadataRequest())

request = v2_measurement_service_pb2.MeasureRequest(
configuration_parameters=_get_configuration_parameters(
float_in,
Expand All @@ -196,6 +207,7 @@ def test___measurement_service_v2___measure_with_large_array___returns_output(
enum_in,
protobuf_enum_in,
string_array_in,
message_type=metadata.measurement_signature.configuration_parameters_message_type,
)
)
response_iterator = stub_v2.Measure(request)
Expand All @@ -215,13 +227,11 @@ def measurement_service(discovery_service_process) -> Generator[MeasurementServi
yield service


def _get_configuration_parameters(*args, **kwargs) -> any_pb2.Any:
def _get_configuration_parameters(*args, message_type: str = "", **kwargs) -> any_pb2.Any:
serialized_parameter = _get_serialized_measurement_signature(*args, **kwargs)
config_params_any = any_pb2.Any()
config_params_any.type_url = "type.googleapis.com/" + message_type
config_params_any.value = serialized_parameter
config_params_any.type_url = (
"type.googleapis.com/ni.tests.LoopbackMeasurement_Python.Configurations"
)
return config_params_any


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def test___single_session___measure___creates_single_session(
assert _get_output(outputs) == [_MeasurementOutput("Dev1", "Dev1", "Dev1/ai0", "Dev1/ai0")]


@pytest.mark.usefixtures("filter_wrong_configurations_message_type_warnings")
def test___multiple_sessions___measure___creates_multiple_sessions(
pin_map_context: PinMapContext,
stub_v2: MeasurementServiceStub,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def test___single_session___measure___creates_single_session(
]


@pytest.mark.usefixtures("filter_wrong_configurations_message_type_warnings")
def test___multiple_sessions___measure___creates_multiple_sessions(
pin_map_context: PinMapContext,
stub_v2: MeasurementServiceStub,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def test___single_session___measure___creates_single_session(
]


@pytest.mark.usefixtures("filter_wrong_configurations_message_type_warnings")
def test___multiple_sessions___measure___creates_multiple_sessions(
pin_map_id: str,
stub_v2: MeasurementServiceStub,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def test___single_session___measure___creates_single_session(
assert _get_output(outputs) == [_MeasurementOutput("DMM1", "DMM1", "0", "0")]


@pytest.mark.usefixtures("filter_wrong_configurations_message_type_warnings")
def test___multiple_sessions___measure___creates_multiple_sessions(
pin_map_context: PinMapContext,
stub_v2: MeasurementServiceStub,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def test___single_session___measure___creates_single_session(
assert _get_output(outputs) == [_MeasurementOutput("FGEN1", "FGEN1", "0", "0")]


@pytest.mark.usefixtures("filter_wrong_configurations_message_type_warnings")
def test___multiple_sessions___measure___creates_multiple_sessions(
pin_map_context: PinMapContext,
stub_v2: MeasurementServiceStub,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def test___single_session___measure___creates_single_session(
assert _get_output(outputs) == [_MeasurementOutput("SCOPE1", "SCOPE1", "0", "0")]


@pytest.mark.usefixtures("filter_wrong_configurations_message_type_warnings")
def test___multiple_sessions___measure___creates_multiple_sessions(
pin_map_context: PinMapContext,
stub_v2: MeasurementServiceStub,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def test___single_session___measure___creates_single_session(
assert _get_output(outputs) == [_MeasurementOutput("RelayDriver1", "RelayDriver1", "K0", "K0")]


@pytest.mark.usefixtures("filter_wrong_configurations_message_type_warnings")
def test___multiple_sessions___measure___creates_multiple_sessions(
pin_map_context: PinMapContext,
stub_v2: MeasurementServiceStub,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def test___single_session___measure___creates_single_session(
]


@pytest.mark.usefixtures("filter_wrong_configurations_message_type_warnings")
def test___multiple_sessions___measure___creates_multiple_sessions(
pin_map_context: PinMapContext,
stub_v2: MeasurementServiceStub,
Expand Down
4 changes: 4 additions & 0 deletions packages/service/tests/acceptance/test_session_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from tests.utilities.stubs.pinaware.types_pb2 import Configurations, Outputs


@pytest.mark.usefixtures("filter_wrong_configurations_message_type_warnings")
def test___pin_map_context___measure___sends_pin_map_id_and_sites(
pin_map_client: PinMapClient,
pin_map_directory: pathlib.Path,
Expand Down Expand Up @@ -207,6 +208,7 @@ class Configuration(NamedTuple):
@pytest.mark.parametrize(
"configuration", _FGEN_SINGLE_SESSION_CONFIGURATIONS + _SMU_SINGLE_SESSION_CONFIGURATIONS
)
@pytest.mark.usefixtures("filter_wrong_configurations_message_type_warnings")
def test___single_session___measure___reserves_single_session(
configuration: Configuration,
pin_map_client: PinMapClient,
Expand All @@ -231,6 +233,7 @@ def test___single_session___measure___reserves_single_session(
+ _SMU_SINGLE_SESSION_CONFIGURATIONS
+ _SMU_MULTI_SESSION_CONFIGURATIONS,
)
@pytest.mark.usefixtures("filter_wrong_configurations_message_type_warnings")
def test___multi_session___measure___reserves_multiple_sessions(
configuration: Configuration,
pin_map_client: PinMapClient,
Expand All @@ -251,6 +254,7 @@ def test___multi_session___measure___reserves_multiple_sessions(
@pytest.mark.parametrize(
"configuration", _FGEN_MULTI_SESSION_CONFIGURATIONS + _SMU_MULTI_SESSION_CONFIGURATIONS
)
@pytest.mark.usefixtures("filter_wrong_configurations_message_type_warnings")
def test___multi_session_but_expecting_single_session___measure___raises_too_many_sessions_error(
configuration: Configuration,
pin_map_client: PinMapClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@
def test___streaming_measurement_service___request_number_of_responses___receives_responses(
num_responses: int, stub_v2: v2_measurement_service_pb2_grpc.MeasurementServiceStub
):
metadata = stub_v2.GetMetadata(v2_measurement_service_pb2.GetMetadataRequest())

request = v2_measurement_service_pb2.MeasureRequest(
configuration_parameters=_get_configuration_parameters(num_responses=num_responses)
configuration_parameters=_get_configuration_parameters(
message_type=metadata.measurement_signature.configuration_parameters_message_type,
num_responses=num_responses,
)
)

response_iterator = stub_v2.Measure(request)
Expand All @@ -33,9 +38,12 @@ def test___streaming_measurement_service___request_number_of_responses___receive
def test___streaming_measurement_service___request_data_cumulatively___receives_expected_amount_of_data(
data_size: int, stub_v2: v2_measurement_service_pb2_grpc.MeasurementServiceStub
):
metadata = stub_v2.GetMetadata(v2_measurement_service_pb2.GetMetadataRequest())

name = "testing-cumulative"
request = v2_measurement_service_pb2.MeasureRequest(
configuration_parameters=_get_configuration_parameters(
message_type=metadata.measurement_signature.configuration_parameters_message_type,
name=name,
data_size=data_size,
cumulative_data=True,
Expand All @@ -57,9 +65,12 @@ def test___streaming_measurement_service___request_data_cumulatively___receives_
def test___streaming_measurement_service___specify_data_size___receives_expected_amount_of_data(
data_size: int, stub_v2: v2_measurement_service_pb2_grpc.MeasurementServiceStub
):
metadata = stub_v2.GetMetadata(v2_measurement_service_pb2.GetMetadataRequest())

name = "testing-not-cumulative"
request = v2_measurement_service_pb2.MeasureRequest(
configuration_parameters=_get_configuration_parameters(
message_type=metadata.measurement_signature.configuration_parameters_message_type,
name=name,
data_size=data_size,
cumulative_data=False,
Expand All @@ -80,8 +91,13 @@ def test___streaming_measurement_service___specify_data_size___receives_expected
def test___streaming_measurement_service___specify_error_index___errors_at_expected_response(
error_on_index: int, stub_v2: v2_measurement_service_pb2_grpc.MeasurementServiceStub
):
metadata = stub_v2.GetMetadata(v2_measurement_service_pb2.GetMetadataRequest())

request = v2_measurement_service_pb2.MeasureRequest(
configuration_parameters=_get_configuration_parameters(error_on_index=error_on_index)
configuration_parameters=_get_configuration_parameters(
message_type=metadata.measurement_signature.configuration_parameters_message_type,
error_on_index=error_on_index,
)
)

response_iterator = stub_v2.Measure(request)
Expand All @@ -92,12 +108,10 @@ def test___streaming_measurement_service___specify_error_index___errors_at_expec
assert (index + 1) == error_on_index


def _get_configuration_parameters(*args, **kwargs) -> any_pb2.Any:
def _get_configuration_parameters(*args, message_type: str = "", **kwargs) -> any_pb2.Any:
serialized_parameter = _get_serialized_measurement_configuration_parameters(*args, **kwargs)
config_params_any = any_pb2.Any()
config_params_any.type_url = (
"type.googleapis.com/ni.tests.StreamingDataMeasurement_Python.Configurations"
)
config_params_any.type_url = "type.googleapis.com/" + message_type
config_params_any.value = serialized_parameter
return config_params_any

Expand Down
9 changes: 7 additions & 2 deletions packages/service/tests/acceptance/test_yield_vs_return.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@
def test___measurement_utilizing_yield_and_return___call_measurement___receives_responses_from_yield_and_return(
stub_v2: v2_measurement_service_pb2_grpc.MeasurementServiceStub,
):
metadata = stub_v2.GetMetadata(v2_measurement_service_pb2.GetMetadataRequest())

request = v2_measurement_service_pb2.MeasureRequest(
configuration_parameters=_get_configuration_parameters()
configuration_parameters=_get_configuration_parameters(
message_type=metadata.measurement_signature.configuration_parameters_message_type
)
)

response_iterator = stub_v2.Measure(request)
Expand All @@ -33,9 +37,10 @@ def test___measurement_utilizing_yield_and_return___call_measurement___receives_
assert output.status == f"Update: {index + 1}"


def _get_configuration_parameters(*args, **kwargs) -> any_pb2.Any:
def _get_configuration_parameters(*args, message_type: str = "", **kwargs) -> any_pb2.Any:
serialized_parameter = _get_serialized_measurement_configuration_parameters(*args, **kwargs)
config_params_any = any_pb2.Any()
config_params_any.type_url = "type.googleapis.com/" + message_type
config_params_any.value = serialized_parameter
return config_params_any

Expand Down

0 comments on commit 45fbc08

Please sign in to comment.