-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from ZohebShaikh/training-rigs-system-test
Training rigs system test
- Loading branch information
Showing
12 changed files
with
149 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import pytest | ||
from blueapi.client.client import BlueapiClient | ||
from blueapi.config import ApplicationConfig, RestConfig, StompConfig | ||
from blueapi.worker.task import Task | ||
from bluesky_stomp.models import BasicAuthentication | ||
|
||
from htss_rig_bluesky.names import BEAMLINE | ||
|
||
|
||
@pytest.fixture | ||
def task_definition() -> dict[str, Task]: | ||
return { | ||
"step_scan_plan": Task( | ||
name="step_scan_plan", | ||
params={"detectors": "det", "motor": "sample_stage.theta"}, | ||
), | ||
"fly_and_collect_plan": Task( | ||
name="fly_and_collect_plan", | ||
params={"panda": "panda", "diff": "det"}, | ||
), | ||
"log_scan_plan": Task( | ||
name="log_scan_plan", | ||
params={"detectors": "det", "motor": "sample_stage.x"}, | ||
), | ||
} | ||
|
||
|
||
@pytest.fixture | ||
def config() -> ApplicationConfig: | ||
if BEAMLINE == "p46": | ||
return ApplicationConfig( | ||
stomp=StompConfig( | ||
host="172.23.168.198", | ||
auth=BasicAuthentication(username="guest", password="guest"), # type: ignore | ||
), | ||
api=RestConfig( | ||
host="p46-blueapi.diamond.ac.uk", port=443, protocol="https" | ||
), | ||
) | ||
else: | ||
return ApplicationConfig( | ||
stomp=StompConfig( | ||
host="localhost", | ||
auth=BasicAuthentication(username="guest", password="guest"), # type: ignore | ||
) | ||
) | ||
|
||
|
||
# This client will use authentication if a valid cached token is found | ||
@pytest.fixture | ||
def client(config: ApplicationConfig) -> BlueapiClient: | ||
return BlueapiClient.from_config(config=config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import pytest | ||
from blueapi.client.client import BlueapiClient | ||
from blueapi.client.event_bus import AnyEvent | ||
from blueapi.core.bluesky_types import DataEvent | ||
from blueapi.worker.event import TaskStatus, WorkerEvent, WorkerState | ||
from blueapi.worker.task import Task | ||
|
||
# Please export BEAMLINE=pXX before running the tests or add it in pyproject.toml | ||
|
||
|
||
def _check_all_events(all_events: list[AnyEvent]): | ||
assert ( | ||
isinstance(all_events[0], WorkerEvent) and all_events[0].task_status is not None | ||
) | ||
task_id = all_events[0].task_status.task_id | ||
# First event is WorkerEvent | ||
assert all_events[0] == WorkerEvent( | ||
state=WorkerState.RUNNING, | ||
task_status=TaskStatus( | ||
task_id=task_id, | ||
task_complete=False, | ||
task_failed=False, | ||
), | ||
) | ||
|
||
assert all( | ||
isinstance(event, DataEvent) for event in all_events[1:-2] | ||
), "Middle elements must be DataEvents." | ||
|
||
# Last 2 events are WorkerEvent | ||
assert all_events[-2:] == [ | ||
WorkerEvent( | ||
state=WorkerState.IDLE, | ||
task_status=TaskStatus( | ||
task_id=task_id, | ||
task_complete=False, | ||
task_failed=False, | ||
), | ||
), | ||
WorkerEvent( | ||
state=WorkerState.IDLE, | ||
task_status=TaskStatus( | ||
task_id=task_id, | ||
task_complete=True, | ||
task_failed=False, | ||
), | ||
), | ||
] | ||
|
||
|
||
@pytest.mark.parametrize("device", ["sample_stage", "panda", "det"]) | ||
def test_device_present(client: BlueapiClient, device: str): | ||
assert client.get_device(device), f"{device} is not available" | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"plan", ["step_scan_plan", "fly_and_collect_plan", "log_scan_plan"] | ||
) | ||
def test_spec_scan_task( | ||
client: BlueapiClient, | ||
task_definition: dict[str, Task], | ||
plan: str, | ||
): | ||
assert client.get_plan(plan), f"In {plan} is available" | ||
|
||
all_events: list[AnyEvent] = [] | ||
|
||
def on_event(event: AnyEvent): | ||
all_events.append(event) | ||
|
||
client.run_task(task_definition[plan], on_event=on_event) | ||
|
||
_check_all_events(all_events) | ||
|
||
assert client.get_state() is WorkerState.IDLE |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.