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

Added check for metadata validation #807

Merged
merged 11 commits into from
Aug 5, 2024
LazeringDeath marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,10 @@ def __init__(
raise RuntimeError(f"File does not exist. {service_config_path}")

with open(service_config_path) as service_config_file:
service_config = json.load(service_config_file)
try:
service_config = json.loads(service_config_file.read())
except json.decoder.JSONDecodeError:
raise NameError(f"Invalid character(s) in {service_config_path}")
LazeringDeath marked this conversation as resolved.
Show resolved Hide resolved

if service_class is None:
service = next(iter(service_config["services"]), None)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"services": [
{
"displayName": "SampleMeasurement",
"serviceClass": "SampleMeasurement_Python",
"descriptionUrl": "https://www.example.com/SampleMeasurement.html",
"providedInterfaces": [
"ni.measurementlink.measurement.v1.MeasurementService",
"ni.measurementlink.measurement.v2.MeasurementService"
],
"path": "start.bat",
"annotations": {
"ni/service.description": """,
"ni/service.collection": "CurrentTests.Inrush",
"ni/service.tags": [ "powerup", "current" ]
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"services": [
{
"displayName": "SampleMeasurement\",
"serviceClass": "SampleMeasurement_Python",
"descriptionUrl": "https://www.example.com/SampleMeasurement.html",
"providedInterfaces": [
"ni.measurementlink.measurement.v1.MeasurementService",
"ni.measurementlink.measurement.v2.MeasurementService"
],
"path": "start.bat",
"annotations": {
"ni/service.description": "Measure inrush current with a shorted load and validate results against configured limits.",
"ni/service.collection": "\",
"ni/service.tags": [ "powerup", "current" ]
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"services": [
{
"displayName": "\\SampleMeasurement\",
"serviceClass": "SampleMeasurement_Python",
"descriptionUrl": "https://www.example.com/SampleMeasurement.html",
"providedInterfaces": [
"ni.measurementlink.measurement.v1.MeasurementService",
"ni.measurementlink.measurement.v2.MeasurementService"
],
"path": "start.bat",
"annotations": {
"ni/service.description": "Measure inrush current with a shorted load and validate results against configured limits.",
"ni/service.collection": "CurrentTests.Inrush",
"ni/service.tags": [ "powerup", "current" ]
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"services": [
{
"displayName": "SampleMeasurement\",
"serviceClass": "SampleMeasurement_Python",
"descriptionUrl": "https://www.example.com/SampleMeasurement.html",
"providedInterfaces": [
"ni.measurementlink.measurement.v1.MeasurementService",
"ni.measurementlink.measurement.v2.MeasurementService"
],
"path": "start.bat",
"annotations": {
"ni/service.description": "Measure inrush current with a shorted load and validate results against configured limits.",
"ni/service.collection": "CurrentTests.Inrush",
"ni/service.tags": [ "powerup", "\"" ]
}
}
]
}
34 changes: 32 additions & 2 deletions packages/service/tests/unit/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@

from ni_measurement_plugin_sdk_service import _datatypeinfo
from ni_measurement_plugin_sdk_service._annotations import TYPE_SPECIALIZATION_KEY
from ni_measurement_plugin_sdk_service._internal.stubs.ni.protobuf.types import xydata_pb2
from ni_measurement_plugin_sdk_service.measurement.info import DataType, TypeSpecialization
from ni_measurement_plugin_sdk_service._internal.stubs.ni.protobuf.types import (
xydata_pb2,
)
from ni_measurement_plugin_sdk_service.measurement.info import (
DataType,
TypeSpecialization,
)
from ni_measurement_plugin_sdk_service.measurement.service import MeasurementService


Expand Down Expand Up @@ -421,6 +426,31 @@ def test___service_config___create_measurement_service___service_info_matches_se
assert measurement_service.service_info.annotations == provided_annotations


@pytest.mark.parametrize(
"service_config",
[
"example.ErrorDisplayName.serviceconfig",
"example.ErrorAnnotations.serviceconfig",
"example.ErrorTags.serviceconfig",
"example.ErrorCollections.serviceconfig",
],
)
def test___service_config___check_service_config___name_error_exception(
test_assets_directory: pathlib.Path,
service_config: str,
):
try:
MeasurementService(
service_config_path=test_assets_directory / f"check_char/{service_config}",
version="1.0.0.0",
ui_file_paths=[],
)
error_occurred = False
except NameError:
error_occurred = True
assert error_occurred


@pytest.mark.parametrize(
"display_name,type,default_value,enum_type",
[
Expand Down
Loading