-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some type ignores for bugs in mypy. These will be removed when moved to pyright.
- Loading branch information
Showing
4 changed files
with
245 additions
and
58 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
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 |
---|---|---|
@@ -1,17 +1,39 @@ | ||
import pytest | ||
|
||
from fastcs.attributes import AttrR | ||
from fastcs.backends.epics.util import convert_if_enum | ||
from fastcs.backends.epics.util import ( | ||
attr_is_enum, | ||
enum_index_to_value, | ||
enum_value_to_index, | ||
) | ||
from fastcs.datatypes import String | ||
|
||
|
||
def test_convert_if_enum(): | ||
string_attr = AttrR(String()) | ||
enum_attr = AttrR(String(), allowed_values=["disabled", "enabled"]) | ||
def test_attr_is_enum(): | ||
assert not attr_is_enum(AttrR(String())) | ||
assert attr_is_enum(AttrR(String(), allowed_values=["disabled", "enabled"])) | ||
|
||
assert convert_if_enum(string_attr, "enabled") == "enabled" | ||
|
||
assert convert_if_enum(enum_attr, "enabled") == 1 | ||
def test_enum_index_to_value(): | ||
"""Test enum_index_to_value.""" | ||
attribute = AttrR(String(), allowed_values=["disabled", "enabled"]) | ||
|
||
with pytest.raises(ValueError): | ||
convert_if_enum(enum_attr, "off") | ||
assert enum_index_to_value(attribute, 0) == "disabled" | ||
assert enum_index_to_value(attribute, 1) == "enabled" | ||
with pytest.raises(IndexError, match="Invalid index"): | ||
enum_index_to_value(attribute, 2) | ||
|
||
with pytest.raises(ValueError, match="Cannot lookup value by index"): | ||
enum_index_to_value(AttrR(String()), 0) | ||
|
||
|
||
def test_enum_value_to_index(): | ||
attribute = AttrR(String(), allowed_values=["disabled", "enabled"]) | ||
|
||
assert enum_value_to_index(attribute, "disabled") == 0 | ||
assert enum_value_to_index(attribute, "enabled") == 1 | ||
with pytest.raises(ValueError, match="not in allowed values"): | ||
enum_value_to_index(attribute, "off") | ||
|
||
with pytest.raises(ValueError, match="Cannot convert value to index"): | ||
enum_value_to_index(AttrR(String()), "disabled") |