Skip to content

Commit

Permalink
Allow for blank enum names from binary records (#152)
Browse files Browse the repository at this point in the history
* Allow for blank enum names from binary records

* Remove duplicate record
  • Loading branch information
DiamondJoseph authored Mar 14, 2024
1 parent e19e8d2 commit fd6b8ab
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/ophyd_async/epics/_backend/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ def get_supported_enum_class(
if set(choices).difference(pv_choices):
raise TypeError(f"{pv} has choices {pv_choices}: not all in {choices}")
return Enum(
"GeneratedChoices", {x: x for x in pv_choices}, type=str
"GeneratedChoices", {x or "_": x for x in pv_choices}, type=str
) # type: ignore
5 changes: 5 additions & 0 deletions tests/epics/test_records.db
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ record(bo, "$(P)bool") {
field(PINI, "YES")
}

record(bo, "$(P)bool_unnamed") {
field(VAL, "1")
field(PINI, "YES")
}

record(longout, "$(P)int") {
field(HOPR, "100")
field(HIHI, "98")
Expand Down
5 changes: 3 additions & 2 deletions tests/epics/test_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,11 @@ async def test_backend_get_put_monitor(
assert np.all(loaded[0]["test"] == put_value)


async def test_bool_conversion_of_enum(ioc: IOC) -> None:
@pytest.mark.parametrize("suffix", ["bool", "bool_unnamed"])
async def test_bool_conversion_of_enum(ioc: IOC, suffix: str) -> None:
await assert_monitor_then_put(
ioc,
suffix="bool",
suffix=suffix,
descriptor=integer_d(True),
initial_value=True,
put_value=False,
Expand Down

0 comments on commit fd6b8ab

Please sign in to comment.