-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[releases/2.1] Cherry-pick: [High priority] Measurement Client: Raise…
… errors for invalid enums (#920) [High priority] Measurement Client: Raise errors for invalid enums (#916) * Fix: Raise errors for invalid enums * Refactor: Method names for clarity * Fix: Transform invalid enum values * Tests: Add unit tests for client * Revert: main.py change * Fix: Refine regex in support.py * Tests: Update expected and actual assert positioning (cherry picked from commit 4a4c464)
- Loading branch information
1 parent
66d21db
commit c0d41be
Showing
3 changed files
with
92 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import pytest | ||
from click import ClickException | ||
|
||
from ni_measurement_plugin_sdk_generator.client._support import ( | ||
_validate_and_transform_enum_annotations, | ||
) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"enum_annotations, expected_enum_annotations", | ||
[ | ||
('{"NONE": 0, "RED": 1, "GREEN": 2}', '{"NONE": 0, "RED": 1, "GREEN": 2}'), | ||
( | ||
'{"DC Volts": 0, "2-Wire Resistance": 1, "5 1/2": 2}', | ||
'{"DC_Volts": 0, "k_2_Wire_Resistance": 1, "k_5_1_2": 2}', | ||
), | ||
], | ||
) | ||
def test___enum_annotations___validate_and_transform_enum_annotations___returns_expected_enum_annotations( | ||
enum_annotations: str, expected_enum_annotations: str | ||
) -> None: | ||
actual_enum_annotations = _validate_and_transform_enum_annotations(enum_annotations) | ||
|
||
assert actual_enum_annotations == expected_enum_annotations | ||
|
||
|
||
def test___invalid_enum_annotations___validate_and_transform_enum_annotations___raises_invalid_enum_value_error() -> ( | ||
None | ||
): | ||
enum_annotations = '{"DC Volts": 0, "*": 1}' | ||
expected_error_message = "The enum value '*' is invalid." | ||
|
||
with pytest.raises(ClickException) as exc_info: | ||
_ = _validate_and_transform_enum_annotations(enum_annotations) | ||
|
||
assert exc_info.value.message == expected_error_message |