Skip to content

Commit

Permalink
Add fake PathProvider to startup module (#783)
Browse files Browse the repository at this point in the history
This is a workaround (not a fix) for #784, so won't close it. The
replacement of `PathProvider` in dodal will eventually provide the
proper fix. For now I think we should just pretend to write to a
directory with our start-up file, despite the fact that none of the
simulated detectors actually write files.
  • Loading branch information
callumforrester authored Feb 3, 2025
1 parent b605942 commit ffa0913
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 6 deletions.
17 changes: 17 additions & 0 deletions src/blueapi/startup/example_devices.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
from pathlib import Path

from dodal.common.beamlines.beamline_utils import set_path_provider
from dodal.common.visit import LocalDirectoryServiceClient, StaticVisitPathProvider
from ophyd.sim import Syn2DGauss, SynGauss, SynSignal

from .simmotor import BrokenSynAxis, SynAxisWithMotionEvents

# Some of our plans such as "count" and "spec_scan" require this global
# singleton to be set

# Workaround for https://github.com/DiamondLightSource/blueapi/issues/784
_tmp_dir = Path("/does/not/exist")
set_path_provider(
StaticVisitPathProvider(
"t01",
_tmp_dir,
client=LocalDirectoryServiceClient(),
)
)


def x(name="x") -> SynAxisWithMotionEvents:
return SynAxisWithMotionEvents(name=name, delay=1.0, events_per_move=8)
Expand Down
57 changes: 51 additions & 6 deletions tests/system_tests/test_blueapi_system.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import inspect
import textwrap
import time
from pathlib import Path

import pytest
from bluesky_stomp.models import BasicAuthentication
from pydantic import TypeAdapter
from requests.exceptions import ConnectionError
from scanspec.specs import Line

from blueapi.client.client import (
BlueapiClient,
Expand Down Expand Up @@ -147,7 +149,7 @@ def test_get_plans(client: BlueapiClient, expected_plans: PlanResponse):
retrieved_plans.plans.sort(key=lambda x: x.name)
expected_plans.plans.sort(key=lambda x: x.name)

assert retrieved_plans == expected_plans
assert retrieved_plans.model_dump() == expected_plans.model_dump()


def test_get_plans_by_name(client: BlueapiClient, expected_plans: PlanResponse):
Expand Down Expand Up @@ -337,11 +339,54 @@ def test_get_current_state_of_environment(client: BlueapiClient):
assert client.get_environment().initialized


@pytest.mark.skip(
reason=textwrap.dedent("""
The client should block until environment reload is complete but it does not,
this interferes with subsequent tests. See
https://github.com/DiamondLightSource/blueapi/issues/742
""")
)
def test_delete_current_environment(client: BlueapiClient):
current_env = client.get_environment()
old_env = client.get_environment()
client.reload_environment()
new_env = client.get_environment()
assert (
new_env.initialized is True
and new_env.environment_id != current_env.environment_id
)
assert new_env.initialized
assert new_env.environment_id != old_env.environment_id
assert new_env.error_message is None


@pytest.mark.xfail()
@pytest.mark.parametrize(
"task",
[
Task(
name="count",
params={
"detectors": [
"image_det",
"current_det",
],
"num": 5,
},
),
pytest.param(
Task(
name="spec_scan",
params={
"detectors": [
"image_det",
"current_det",
],
"spec": Line("x", 0.0, 10.0, 10) * Line("y", 5.0, 15.0, 20),
},
),
marks=pytest.mark.xfail(
reason="https://github.com/DiamondLightSource/blueapi/issues/782"
),
),
],
)
def test_plan_runs(client_with_stomp: BlueapiClient, task: Task):
final_event = client_with_stomp.run_task(task)
assert final_event.is_complete() and not final_event.is_error()
assert final_event.state is WorkerState.IDLE

0 comments on commit ffa0913

Please sign in to comment.