Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using config.get() to get robot #170

Merged
merged 8 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading