Skip to content

Commit 89ec574

Browse files
jonlugoatxJonathan Lugo
andauthored
Fix incorrect reporting of non-ASCII characters in the measurement display name (#1093)
* Read the serviceconfig using utf-8 encoding * Add unit test and support SBOM. * Fix client generation with localized service config and default values. * Remove protobuf color enum & fix lint errors --------- Co-authored-by: Jonathan Lugo <[email protected]>
1 parent 2d1f663 commit 89ec574

File tree

8 files changed

+918
-5
lines changed

8 files changed

+918
-5
lines changed

packages/generator/ni_measurement_plugin_sdk_generator/client/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def _create_file(
5252
mode=black.Mode(line_length=100),
5353
)
5454

55-
with output_file.open("w") as file:
55+
with output_file.open("w", encoding="utf-8") as file:
5656
file.write(formatted_output)
5757

5858

packages/generator/tests/acceptance/test_client_generator.py

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
non_streaming_data_measurement,
1515
streaming_data_measurement,
1616
void_measurement,
17+
localized_measurement,
1718
)
1819

1920

@@ -79,6 +80,37 @@ def test___void_measurement___create_client___render_without_error(
7980
)
8081

8182

83+
def test___localized_measurement___create_client___render_without_error(
84+
create_client: CliRunnerFunction,
85+
test_assets_directory: pathlib.Path,
86+
tmp_path_factory: pytest.TempPathFactory,
87+
localized_measurement_service: MeasurementService,
88+
) -> None:
89+
temp_directory = tmp_path_factory.mktemp("measurement_plugin_client_files")
90+
module_name = "localized_measurement_client"
91+
golden_path = test_assets_directory / "example_renders" / "measurement_plugin_client"
92+
filename = f"{module_name}.py"
93+
94+
result = create_client(
95+
[
96+
"--measurement-service-class",
97+
"ni.tests.LocalizedMeasurement_Python",
98+
"--module-name",
99+
module_name,
100+
"--class-name",
101+
"LocalizedMeasurementClient",
102+
"--directory-out",
103+
str(temp_directory),
104+
]
105+
)
106+
107+
assert result.exit_code == 0
108+
_assert_equal(
109+
golden_path / filename,
110+
temp_directory / filename,
111+
)
112+
113+
82114
def test___all_registered_measurements___create_client___renders_without_error(
83115
create_client: CliRunnerFunction,
84116
tmp_path_factory: pytest.TempPathFactory,
@@ -197,8 +229,8 @@ def test___non_streaming_measurement___create_client___render_without_mypy_error
197229

198230

199231
def _assert_equal(expected_path: pathlib.Path, result_path: pathlib.Path) -> None:
200-
expected = expected_path.read_text()
201-
result = result_path.read_text()
232+
expected = expected_path.read_text(encoding="utf-8")
233+
result = result_path.read_text(encoding="utf-8")
202234

203235
assert expected == result
204236

@@ -235,6 +267,15 @@ def void_measurement_service(
235267
yield service
236268

237269

270+
@pytest.fixture
271+
def localized_measurement_service(
272+
discovery_service_process: DiscoveryServiceProcess,
273+
) -> Generator[MeasurementService, None, None]:
274+
"""Test fixture that creates and hosts a localized Measurement Plug-In Service."""
275+
with localized_measurement.measurement_service.host_service() as service:
276+
yield service
277+
278+
238279
@pytest.fixture
239280
def multiple_measurement_service(
240281
discovery_service_process: DiscoveryServiceProcess,

0 commit comments

Comments
 (0)