Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Pin Map Client to Measurement PlugIn SDK Service #854

Merged
merged 13 commits into from
Aug 31, 2024
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""Public API for accessing the NI Pin Map Service."""

from ni_measurement_plugin_sdk_service.pin_map._client import PinMapClient

__all__ = ["PinMapClient"]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Client for accessing the measurement pin map service."""
"""Client for accessing the NI Pin Map Service."""

import logging
import pathlib
Expand All @@ -21,7 +21,7 @@


class PinMapClient(object):
"""Client for accessing the measurement pin map service."""
"""Client for accessing the NI Pin Map Service."""

def __init__(
self,
Expand All @@ -30,7 +30,15 @@ def __init__(
grpc_channel: Optional[grpc.Channel] = None,
grpc_channel_pool: Optional[GrpcChannelPool] = None
) -> None:
"""Initialize the pin map client."""
"""Initialize the pin map client.

Args:
discovery_client: An optional discovery client (recommended).

grpc_channel: An optional pin map gRPC channel.

grpc_channel_pool: An optional gRPC channel pool (recommended).
"""
self._initialization_lock = threading.Lock()
self._discovery_client = discovery_client
self._grpc_channel_pool = grpc_channel_pool
Expand Down Expand Up @@ -74,7 +82,7 @@ def update_pin_map(self, pin_map_path: Union[str, pathlib.Path]) -> str:
# By convention, the pin map id is the .pinmap file path.
request = pin_map_service_pb2.UpdatePinMapFromXmlRequest(
pin_map_id=str(pin_map_path),
pin_map_xml=pathlib.Path(pin_map_path).read_text(encoding="utf-8"),
pin_map_xml=pathlib.Path(pin_map_path).read_text(encoding="utf-8-sig"),
)
response = self._get_stub().UpdatePinMapFromXml(request)
return response.pin_map_id
17 changes: 17 additions & 0 deletions packages/service/tests/acceptance/test_logging.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import pathlib
import re
from typing import Generator

Expand All @@ -12,6 +13,7 @@
)
from ni_measurement_plugin_sdk_service.discovery import DiscoveryClient
from ni_measurement_plugin_sdk_service.measurement.service import MeasurementService
from ni_measurement_plugin_sdk_service.pin_map import PinMapClient
from ni_measurement_plugin_sdk_service.session_management import SessionManagementClient
from tests.acceptance.test_streaming_data_measurement import (
_get_configuration_parameters as get_streaming_data_configuration_parameters,
Expand All @@ -37,6 +39,21 @@ def test___discovery_client___call___client_call_logged(
assert f"gRPC client call complete: {method_name}" in debug_messages


def test___pin_map_client___call___client_call_logged(
caplog: LogCaptureFixture,
pin_map_client: PinMapClient,
pin_map_directory: pathlib.Path,
) -> None:
with caplog.at_level(logging.DEBUG):
pin_map_path = pin_map_directory / "1Smu1ChannelGroup2Pin2Site.pinmap"
_ = pin_map_client.update_pin_map(pin_map_path)

method_name = "/ni.measurementlink.pinmap.v1.PinMapService/UpdatePinMapFromXml"
debug_messages = [r.message for r in caplog.records if r.levelno == logging.DEBUG]
assert f"gRPC client call starting: {method_name}" in debug_messages
assert f"gRPC client call complete: {method_name}" in debug_messages


def test___session_management_client___call___client_call_logged(
caplog: LogCaptureFixture, request: FixtureRequest
) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
PinMapContext,
)
from ni_measurement_plugin_sdk_service.measurement.service import MeasurementService
from ni_measurement_plugin_sdk_service.pin_map import PinMapClient
from tests.utilities.measurements import nidaqmx_measurement
from tests.utilities.pin_map_client import PinMapClient
from tests.utilities.stubs.nidaqmx.types_pb2 import Configurations, Outputs

_SITE = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
PinMapContext,
)
from ni_measurement_plugin_sdk_service.measurement.service import MeasurementService
from ni_measurement_plugin_sdk_service.pin_map import PinMapClient
from tests.utilities.measurements import nidcpower_measurement
from tests.utilities.pin_map_client import PinMapClient
from tests.utilities.stubs.nidcpower.types_pb2 import Configurations, Outputs

_SITE = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
PinMapContext,
)
from ni_measurement_plugin_sdk_service.measurement.service import MeasurementService
from ni_measurement_plugin_sdk_service.pin_map import PinMapClient
from tests.utilities.measurements import nidigital_measurement
from tests.utilities.pin_map_client import PinMapClient
from tests.utilities.stubs.nidigital.types_pb2 import Configurations, Outputs


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
PinMapContext,
)
from ni_measurement_plugin_sdk_service.measurement.service import MeasurementService
from ni_measurement_plugin_sdk_service.pin_map import PinMapClient
from tests.utilities.measurements import nidmm_measurement
from tests.utilities.pin_map_client import PinMapClient
from tests.utilities.stubs.nidmm.types_pb2 import Configurations, Outputs

_SITE = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
PinMapContext,
)
from ni_measurement_plugin_sdk_service.measurement.service import MeasurementService
from ni_measurement_plugin_sdk_service.pin_map import PinMapClient
from tests.utilities.measurements import nifgen_measurement
from tests.utilities.pin_map_client import PinMapClient
from tests.utilities.stubs.nifgen.types_pb2 import Configurations, Outputs

_SITE = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
PinMapContext,
)
from ni_measurement_plugin_sdk_service.measurement.service import MeasurementService
from ni_measurement_plugin_sdk_service.pin_map import PinMapClient
from tests.utilities.measurements import niscope_measurement
from tests.utilities.pin_map_client import PinMapClient
from tests.utilities.stubs.niscope.types_pb2 import Configurations, Outputs

_SITE = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
PinMapContext,
)
from ni_measurement_plugin_sdk_service.measurement.service import MeasurementService
from ni_measurement_plugin_sdk_service.pin_map import PinMapClient
from tests.utilities.measurements import niswitch_measurement
from tests.utilities.pin_map_client import PinMapClient
from tests.utilities.stubs.niswitch.types_pb2 import Configurations, Outputs

_SITE = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
PinMapContext,
)
from ni_measurement_plugin_sdk_service.measurement.service import MeasurementService
from ni_measurement_plugin_sdk_service.pin_map import PinMapClient
from tests.utilities.measurements import niswitch_multiplexer_measurement
from tests.utilities.pin_map_client import PinMapClient
from tests.utilities.stubs.niswitchmultiplexer.types_pb2 import Configurations, Outputs

_SITE = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
PinMapContext,
)
from ni_measurement_plugin_sdk_service.measurement.service import MeasurementService
from ni_measurement_plugin_sdk_service.pin_map import PinMapClient
from tests.utilities.discovery_service_process import DiscoveryServiceProcess
from tests.utilities.measurements import pin_aware_measurement
from tests.utilities.pin_map_client import PinMapClient
from tests.utilities.stubs.pinaware.types_pb2 import Configurations, Outputs


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<PinMap xmlns="http://www.ni.com/TestStand/SemiconductorModule/PinMap.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" schemaVersion="1.6">
<Instruments>
<NIDCPowerInstrument name="DCPower1" numberOfChannels="4">
<ChannelGroup name="CommonDCPowerChannelGroup" />
</NIDCPowerInstrument>
</Instruments>
<Pins>
<DUTPin name="Pin1" />
</Pins>
<PinGroups></PinGroups>
<Sites>
<Site siteNumber="0" />
</Sites>
<Connections>
<Connection pin="Pin1" siteNumber="0" instrument="DCPower1" channel="0" />
</Connections>
</PinMap>
2 changes: 1 addition & 1 deletion packages/service/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
GrpcChannelPool,
MeasurementService,
)
from ni_measurement_plugin_sdk_service.pin_map import PinMapClient
from ni_measurement_plugin_sdk_service.session_management import SessionManagementClient
from tests.utilities.discovery_service_process import DiscoveryServiceProcess
from tests.utilities.pin_map_client import PinMapClient


@pytest.fixture(scope="module")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

import pytest

from ni_measurement_plugin_sdk_service.pin_map import PinMapClient
from ni_measurement_plugin_sdk_service.session_management import (
PinMapContext,
SessionManagementClient,
)
from tests.utilities.connection_subset import ConnectionSubset, get_connection_subset
from tests.utilities.pin_map_client import PinMapClient

_SITE = 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

import pytest

from ni_measurement_plugin_sdk_service.pin_map import PinMapClient
from ni_measurement_plugin_sdk_service.session_management import (
PinMapContext,
SessionManagementClient,
)
from tests.utilities.connection_subset import ConnectionSubset, get_connection_subset
from tests.utilities.pin_map_client import PinMapClient

_SITE = 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

import pytest

from ni_measurement_plugin_sdk_service.pin_map import PinMapClient
from ni_measurement_plugin_sdk_service.session_management import (
PinMapContext,
SessionManagementClient,
)
from tests.utilities.connection_subset import ConnectionSubset, get_connection_subset
from tests.utilities.pin_map_client import PinMapClient


def test___single_session_reserved___initialize_nidigital_session___creates_single_session(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

import pytest

from ni_measurement_plugin_sdk_service.pin_map import PinMapClient
from ni_measurement_plugin_sdk_service.session_management import (
PinMapContext,
SessionManagementClient,
)
from tests.utilities.connection_subset import ConnectionSubset, get_connection_subset
from tests.utilities.pin_map_client import PinMapClient

_SITE = 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

import pytest

from ni_measurement_plugin_sdk_service.pin_map import PinMapClient
from ni_measurement_plugin_sdk_service.session_management import (
PinMapContext,
SessionManagementClient,
)
from tests.utilities.connection_subset import ConnectionSubset, get_connection_subset
from tests.utilities.pin_map_client import PinMapClient

_SITE = 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

import pytest

from ni_measurement_plugin_sdk_service.pin_map import PinMapClient
from ni_measurement_plugin_sdk_service.session_management import (
PinMapContext,
SessionManagementClient,
)
from tests.utilities.connection_subset import ConnectionSubset, get_connection_subset
from tests.utilities.pin_map_client import PinMapClient

_SITE = 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import niswitch
import pytest

from ni_measurement_plugin_sdk_service.pin_map import PinMapClient
from ni_measurement_plugin_sdk_service.session_management import (
PinMapContext,
SessionManagementClient,
Expand All @@ -12,7 +13,6 @@
ConnectionSubset,
get_connection_subset_with_multiplexer,
)
from tests.utilities.pin_map_client import PinMapClient

_SITE = 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

import pytest

from ni_measurement_plugin_sdk_service.pin_map import PinMapClient
from ni_measurement_plugin_sdk_service.session_management import (
PinMapContext,
SessionManagementClient,
)
from tests.utilities.connection_subset import ConnectionSubset, get_connection_subset
from tests.utilities.pin_map_client import PinMapClient

_SITE = 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pathlib
from contextlib import ExitStack

from ni_measurement_plugin_sdk_service.pin_map import PinMapClient
from ni_measurement_plugin_sdk_service.session_management import (
INSTRUMENT_TYPE_NI_DCPOWER,
INSTRUMENT_TYPE_NI_RELAY_DRIVER,
Expand All @@ -15,7 +16,6 @@
get_connection_subset,
get_connection_subset_with_multiplexer,
)
from tests.utilities.pin_map_client import PinMapClient

_PIN_MAP_A = "PinMapA_3Instruments_3DutPins_2SystemPins_2Sites.pinmap"
_PIN_MAP_A_PIN_NAMES = ["A", "B", "C", "S1", "S2"]
Expand Down
7 changes: 7 additions & 0 deletions packages/service/tests/unit/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Test fixtures for unit tests."""

import pathlib
from typing import Generator, cast
from unittest.mock import Mock

Expand Down Expand Up @@ -94,3 +95,9 @@ def session_management_client(
def single_session_reservation(mocker: MockerFixture) -> Mock:
"""Test fixture that creates a mock SingleSessionReservation."""
return mocker.create_autospec(SingleSessionReservation)


@pytest.fixture
def pin_map_directory(test_assets_directory: pathlib.Path) -> pathlib.Path:
"""Test fixture that returns the pin map directory."""
return test_assets_directory / "unit" / "pin_map"
Loading
Loading