Skip to content

Commit

Permalink
Merge pull request #77 from epics-containers/index-label-fix
Browse files Browse the repository at this point in the history
Ensure IndexEntry.label is converted to PascalCase for DeviceRef
  • Loading branch information
GDYendell authored Jan 19, 2024
2 parents c011c06 + 4c0e2b0 commit ce9f7ef
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/pvi/_format/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@

from pvi._yaml_utils import YamlValidatorMixin
from pvi.bases import BaseTyped
from pvi.device import Device, DeviceRef
from pvi.device import Device, DeviceRef, enforce_pascal_case


class IndexEntry(BaseTyped):
"""A structure defining an index button to launch a UI with some macros."""

type: Literal["IndexEntry"] = "IndexEntry"

label: str = Field("Button label")
label: str = Field(
"Button label. This will be converted to PascalCase if it is not already."
)
ui: str = Field("File name of UI to open with button")
macros: dict[str, str] = Field("Macros to launch UI with")

Expand Down Expand Up @@ -81,7 +83,7 @@ def format_index(self, label: str, index_entries: list[IndexEntry], path: Path):
label=label,
children=[
DeviceRef(
name=index.label,
name=enforce_pascal_case(index.label),
pv=index.label.upper(),
ui=index.ui,
macros=index.macros,
Expand Down
4 changes: 3 additions & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,9 @@ def test_index(tmp_path, helper):
[
IndexEntry(label="Button", ui="button.bob", macros={"P": "BUTTON"}),
IndexEntry(label="ComboBox", ui="combo_box.bob", macros={"P": "COMBOBOX"}),
IndexEntry(label="Table", ui="pva_table.bob", macros={"P": "TABLE"}),
# Check that lower case name is OK and will be capitalized to avoid
# PascalCase validation error
IndexEntry(label="table", ui="pva_table.bob", macros={"P": "TABLE"}),
],
output_bob,
)
Expand Down

0 comments on commit ce9f7ef

Please sign in to comment.