Skip to content

Commit

Permalink
Add test case for measurements with no output configuration in client…
Browse files Browse the repository at this point in the history
… generation acceptance test (#900)

* feat : add test case for void measurement in client generator
  • Loading branch information
Jotheeswaran-Nandagopal authored Sep 20, 2024
1 parent 9e9c650 commit ea45764
Show file tree
Hide file tree
Showing 6 changed files with 353 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
"""Generated client API for the ${display_name | repr} measurement plug-in."""

import logging
import pathlib
import threading
% if len(enum_by_class_name):
from enum import Enum
% endif
% for module in built_in_import_modules:
${module}
% endfor
from typing import Any, Generator, Iterable, List, NamedTuple, Optional
from pathlib import Path
<%
typing_imports = ["Any", "Generator", "List", "Optional"]
if output_metadata:
typing_imports += ["Iterable", "NamedTuple"]
%>\
from typing import ${", ".join(sorted(typing_imports))}

import grpc
from google.protobuf import any_pb2
from google.protobuf import descriptor_pool
from google.protobuf import any_pb2, descriptor_pool
from ni_measurement_plugin_sdk_service._internal.stubs.ni.measurementlink.measurement.v2 import (
measurement_service_pb2 as v2_measurement_service_pb2,
measurement_service_pb2_grpc as v2_measurement_service_pb2_grpc,
Expand All @@ -27,7 +28,9 @@ from ni_measurement_plugin_sdk_service.discovery import DiscoveryClient
from ni_measurement_plugin_sdk_service.grpc.channelpool import GrpcChannelPool
from ni_measurement_plugin_sdk_service.measurement.client_support import (
create_file_descriptor,
% if output_metadata:
deserialize_parameters,
% endif
ParameterMetadata,
serialize_parameters,
)
Expand Down Expand Up @@ -268,7 +271,7 @@ class ${class_name}:
else:
return False

def register_pin_map(self, pin_map_path: pathlib.Path) -> None:
def register_pin_map(self, pin_map_path: Path) -> None:
"""Registers the pin map with the pin map service.

Args:
Expand Down
66 changes: 55 additions & 11 deletions packages/generator/tests/acceptance/test_client_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@

from tests.conftest import CliRunnerFunction
from tests.utilities.discovery_service_process import DiscoveryServiceProcess
from tests.utilities.measurements import non_streaming_data_measurement, streaming_data_measurement
from tests.utilities.measurements import (
non_streaming_data_measurement,
streaming_data_measurement,
void_measurement,
)


def test___command_line_args___create_client___render_without_error(
def test___non_streaming_measurement___create_client___render_without_error(
create_client: CliRunnerFunction,
test_assets_directory: pathlib.Path,
tmp_path_factory: pytest.TempPathFactory,
measurement_service: MeasurementService,
non_streaming_measurement_service: MeasurementService,
) -> None:
temp_directory = tmp_path_factory.mktemp("measurement_plugin_client_files")
module_name = "non_streaming_data_measurement_client"
Expand All @@ -43,7 +47,38 @@ def test___command_line_args___create_client___render_without_error(
)


def test___command_line_args___create_client_for_all_registered_measurements___renders_without_error(
def test___void_measurement___create_client___render_without_error(
create_client: CliRunnerFunction,
test_assets_directory: pathlib.Path,
tmp_path_factory: pytest.TempPathFactory,
void_measurement_service: MeasurementService,
) -> None:
temp_directory = tmp_path_factory.mktemp("measurement_plugin_client_files")
module_name = "void_measurement_client"
golden_path = test_assets_directory / "example_renders" / "measurement_plugin_client"
filename = f"{module_name}.py"

result = create_client(
[
"--measurement-service-class",
"ni.tests.VoidMeasurement_Python",
"--module-name",
module_name,
"--class-name",
"VoidMeasurementClient",
"--directory-out",
str(temp_directory),
]
)

assert result.exit_code == 0
_assert_equal(
golden_path / filename,
temp_directory / filename,
)


def test___all_registered_measurements___create_client___renders_without_error(
create_client: CliRunnerFunction,
tmp_path_factory: pytest.TempPathFactory,
multiple_measurement_service: MeasurementService,
Expand Down Expand Up @@ -72,11 +107,11 @@ def test___command_line_args___create_client_for_all_registered_measurements___r
)


def test___command_line_args_with_registered_measurements___create_client_using_interactive_mode___renders_without_error(
def test___interactive_mode_with_registered_measurements___create_client___renders_without_error(
create_client: CliRunnerFunction,
test_assets_directory: pathlib.Path,
tmp_path_factory: pytest.TempPathFactory,
measurement_service: MeasurementService,
non_streaming_measurement_service: MeasurementService,
) -> None:
temp_directory = tmp_path_factory.mktemp("measurement_plugin_client_files")
golden_path = test_assets_directory / "example_renders" / "measurement_plugin_client"
Expand All @@ -98,18 +133,18 @@ def test___command_line_args_with_registered_measurements___create_client_using_
)


def test___command_line_args_without_registering_any_measurement___create_client_using_interactive_mode___raises_exception(
def test___interactive_mode_without_registered_measurements___create_client___raises_exception(
create_client: CliRunnerFunction,
) -> None:
result = create_client(["--interactive"])
assert result.exit_code == 1
assert "No registered measurements." in str(result.exception)


def test___command_line_args___create_client___render_with_proper_line_ending(
def test___non_streaming_measurement___create_client___render_with_proper_line_ending(
create_client: CliRunnerFunction,
tmp_path_factory: pytest.TempPathFactory,
measurement_service: MeasurementService,
non_streaming_measurement_service: MeasurementService,
) -> None:
temp_directory = tmp_path_factory.mktemp("measurement_plugin_client_files")
module_name = "non_streaming_data_measurement_client"
Expand Down Expand Up @@ -154,14 +189,23 @@ def _assert_line_ending(file_path: pathlib.Path) -> None:


@pytest.fixture
def measurement_service(
def non_streaming_measurement_service(
discovery_service_process: DiscoveryServiceProcess,
) -> Generator[MeasurementService, None, None]:
"""Test fixture that creates and hosts a Measurement Plug-In Service."""
"""Test fixture that creates and hosts a non streaming Measurement Plug-In Service."""
with non_streaming_data_measurement.measurement_service.host_service() as service:
yield service


@pytest.fixture
def void_measurement_service(
discovery_service_process: DiscoveryServiceProcess,
) -> Generator[MeasurementService, None, None]:
"""Test fixture that creates and hosts a void Measurement Plug-In Service."""
with void_measurement.measurement_service.host_service() as service:
yield service


@pytest.fixture
def multiple_measurement_service(
discovery_service_process: DiscoveryServiceProcess,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
"""Generated client API for the 'Non-Streaming Data Measurement (Py)' measurement plug-in."""

import logging
import pathlib
import threading
from enum import Enum
from pathlib import Path
from typing import Any, Generator, Iterable, List, NamedTuple, Optional

import grpc
from google.protobuf import any_pb2
from google.protobuf import descriptor_pool
from google.protobuf import any_pb2, descriptor_pool
from ni_measurement_plugin_sdk_service._internal.stubs.ni.measurementlink.measurement.v2 import (
measurement_service_pb2 as v2_measurement_service_pb2,
measurement_service_pb2_grpc as v2_measurement_service_pb2_grpc,
Expand Down Expand Up @@ -622,7 +620,7 @@ def cancel(self) -> bool:
else:
return False

def register_pin_map(self, pin_map_path: pathlib.Path) -> None:
def register_pin_map(self, pin_map_path: Path) -> None:
"""Registers the pin map with the pin map service.
Args:
Expand Down
Loading

0 comments on commit ea45764

Please sign in to comment.