diff --git a/example-synoptic/b23-services/synoptic/techui-support/bob/pmac/motor_embed.bob b/example-synoptic/b23-services/synoptic/techui-support/bob/pmac/motor_embed.bob
index 1508bca2..5c763131 100644
--- a/example-synoptic/b23-services/synoptic/techui-support/bob/pmac/motor_embed.bob
+++ b/example-synoptic/b23-services/synoptic/techui-support/bob/pmac/motor_embed.bob
@@ -76,7 +76,11 @@
OpenDisplay
- ./MOTOR.bob
+ $(IOC)/pmacAxis.pvi.bob
+
+ :$(M)
+ $(P)
+
tab
Open Display
diff --git a/src/techui_builder/builder.py b/src/techui_builder/builder.py
index 9dafd842..6338f0f1 100644
--- a/src/techui_builder/builder.py
+++ b/src/techui_builder/builder.py
@@ -62,7 +62,7 @@ def setup(self):
self.clean_files()
- self.generator = Generator(synoptic_dir)
+ self.generator = Generator(synoptic_dir, self.conf.beamline.url)
def clean_files(self):
exclude = {"index.bob"}
diff --git a/src/techui_builder/generate.py b/src/techui_builder/generate.py
index 963038b0..2795ab29 100644
--- a/src/techui_builder/generate.py
+++ b/src/techui_builder/generate.py
@@ -20,6 +20,7 @@
@dataclass
class Generator:
synoptic_dir: Path = field(repr=False)
+ beamline_url: str = field(repr=False)
# These are global params for the class (not accessible by user)
support_path: Path = field(init=False, repr=False)
@@ -220,6 +221,9 @@ def _allocate_widget(
new_widget.macro(
f"{suffix_label}", suffix.removeprefix(":").removesuffix(":")
)
+ # TODO: Change this to pvi_button
+ if True:
+ new_widget.macro("IOC", f"{self.beamline_url}/{component.P.lower()}")
# The only other option is for related displays
else:
diff --git a/src/techui_builder/validator.py b/src/techui_builder/validator.py
index 52613264..280883cd 100644
--- a/src/techui_builder/validator.py
+++ b/src/techui_builder/validator.py
@@ -4,6 +4,7 @@
from pathlib import Path
from lxml import etree
+from lxml.objectify import ObjectifiedElement
from phoebusgen.widget.widgets import ActionButton, EmbeddedDisplay
from techui_builder.utils import read_bob
@@ -74,4 +75,43 @@ def validate_bob(
f"{pwidget.get_element_value('file')} != {file_widget.file}"
)
+ self._validate_macros(pwidget, file_widget)
+
LOGGER.info(f"{screen_name}.bob has been validated successfully")
+
+ def _validate_macros(
+ self, pwidget: EmbeddedDisplay | ActionButton, file_widget: ObjectifiedElement
+ ):
+ pmacros_element = pwidget.find_element("macros")
+ # Annoyingly iterating over this also includes the element tag\
+ # so it needs ignoring, hence the '!= "macros"'
+ pmacros = {
+ macro.tag: macro.text for macro in pmacros_element if macro.tag != "macros"
+ }
+ pmacros_keys = set(pmacros.keys())
+
+ fmacros = file_widget.macros.getchildren()
+ fmacros_keys = {str(macro.tag) for macro in fmacros}
+
+ # Checks if there is any difference in expected macros
+ diff_expected_macros = pmacros_keys - fmacros_keys
+ if diff_expected_macros:
+ LOGGER.error(
+ f"Expected macros {diff_expected_macros} missing from \
+{file_widget.name}."
+ )
+
+ # ---------- This is how we could overwrite macros in the future ----------
+
+ # for expected_macro in diff_expected_macros:
+ # macro_element = Element(expected_macro)
+ # # Get the macro value from generated pwidget macros
+ # macro_element.text = pmacros[expected_macro]
+ # print(pmacros[expected_macro])
+
+ # # Convert xml.etree.Element to ObjectifiedElement
+ # new_macro = fromstring(tostring(macro_element))
+
+ # file_widget.macros.append(new_macro)
+
+ # write_bob("")
diff --git a/tests/conftest.py b/tests/conftest.py
index fe0a9059..d68d62c1 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -60,7 +60,7 @@ def example_json_map():
def generator():
synoptic_dir = Path(__file__).parent.joinpath(Path("t01-services/synoptic"))
- g = Generator(synoptic_dir)
+ g = Generator(synoptic_dir, "test_url")
return g
@@ -97,9 +97,10 @@ def example_embedded_widget():
height_element = SubElement(widget_element, "height")
height_element.text = "120"
file_element = SubElement(widget_element, "file")
- file_element.text = (
- "example/t01-services/synoptic/techui-support/bob/pmac/motor_embed.bob"
- )
+ file_element.text = "tests/test-files/motor_embed.bob"
+ macros_element = SubElement(widget_element, "macros")
+ macro_element_1 = SubElement(macros_element, "macro1")
+ macro_element_1.text = "test_macro_1"
# ... which requires this horror
widget_element = fromstring(tostring(widget_element))
diff --git a/tests/test_files/motor-edited.bob b/tests/test_files/motor-edited.bob
index 93e1b4cc..06900ea4 100644
--- a/tests/test_files/motor-edited.bob
+++ b/tests/test_files/motor-edited.bob
@@ -12,7 +12,7 @@
X
205
120
- example/t01-services/synoptic/techui-support/bob/pmac/motor_embed.bob
+ tests/test-files/motor_embed.bob
BL01T-MO-MOTOR-01
X
diff --git a/tests/test_files/motor_embed.bob b/tests/test_files/motor_embed.bob
index 1508bca2..5c763131 100644
--- a/tests/test_files/motor_embed.bob
+++ b/tests/test_files/motor_embed.bob
@@ -76,7 +76,11 @@
OpenDisplay
- ./MOTOR.bob
+ $(IOC)/pmacAxis.pvi.bob
+
+ :$(M)
+ $(P)
+
tab
Open Display
diff --git a/tests/test_files/widget.xml b/tests/test_files/widget.xml
index 56ef39e6..ddda1618 100644
--- a/tests/test_files/widget.xml
+++ b/tests/test_files/widget.xml
@@ -9,5 +9,6 @@
BL23B-DI-MOD-02
CAM
+ test_url/bl23b-di-mod-02
diff --git a/tests/test_validator.py b/tests/test_validator.py
index 3936c43f..08cd74ed 100644
--- a/tests/test_validator.py
+++ b/tests/test_validator.py
@@ -49,11 +49,12 @@ def test_validator_validate_bob(validator, example_embedded_widget):
validator.validate = {"motor-edited": Path("tests/test_files/motor-edited.bob")}
test_pwidget = EmbeddedDisplay(
"motor",
- "example/t01-services/synoptic/techui-support/bob/pmac/motor_embed.bob",
+ "tests/test-files/motor_embed.bob",
0,
0,
205,
120,
)
+ test_pwidget.macro("macro1", "test_macro_1")
validator.validate_bob("motor-edited", "motor", [test_pwidget])