Skip to content

Commit

Permalink
Merge pull request #170 from yannachen/load_robot
Browse files Browse the repository at this point in the history
Using config.get() to get robot
  • Loading branch information
yannachen authored Feb 26, 2024
2 parents 6f26676 + e73b831 commit 4b05d5c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/haven/instrument/robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,11 @@ def load_robot_coros(config=None):
# Load PV's from config
if config is None:
config = load_config()
robots = config["robot"]
for name, cfg in robots.items():
yield make_device(Robot, name=name, labels={"robots"}, prefix=cfg["prefix"])
robots = config.get("robot")

if robots is not None:
for name, cfg in robots.items():
yield make_device(Robot, name=name, labels={"robots"}, prefix=cfg["prefix"])


def load_robot(config=None):
Expand Down
15 changes: 15 additions & 0 deletions src/haven/tests/test_robot.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import pytest
from ophydregistry.exceptions import ComponentNotFound

from haven.instrument import Robot, load_robot


Expand All @@ -17,6 +20,18 @@ def test_load_robot(sim_registry):
assert rbt.prefix == "255idAustin"


def test_load_no_robot(sim_registry):
load_robot(config={})

# Test the robot is not in config
result = pytest.raises(ComponentNotFound, sim_registry.findall, label="robots")

# Assert that the expected exception is raised
assert 'Could not find components matching: label="robots", name="None"' in str(
result.value
)


# -----------------------------------------------------------------------------
# :author: Yanna Chen
# :email: [email protected]
Expand Down

0 comments on commit 4b05d5c

Please sign in to comment.