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

Add fake PathProvider to startup module #783

Merged
merged 5 commits into from
Feb 3, 2025
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
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
Loading