Skip to content

Commit

Permalink
TST: add a caproto IOC fixture to be able to start and test against i…
Browse files Browse the repository at this point in the history
…t in CI
  • Loading branch information
mrakitin committed Feb 14, 2024
1 parent a61223f commit ca99a7e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ testpaths = [
markers = [
"hardware: marks tests as requiring the hardware IOC to be available/running (deselect with '-m \"not hardware\"')",
"tiled: marks tests as requiring tiled",
"cloud_friendly: marks tests to be able to execute in the CI in the cloud",
]

[tool.coverage]
Expand Down
26 changes: 20 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import subprocess
import sys
import time as ttime

import pytest
Expand All @@ -16,20 +17,33 @@ def zebra_ophyd_caproto():


@pytest.fixture(scope="session")
def _caproto_ioc():
command = 'EPICS_CAS_BEACON_ADDR_LIST=127.0.0.1 EPICS_CAS_AUTO_BEACON_ADDR_LIST=no python -m srx_caproto_iocs.zebra.caproto_ioc --prefix="XF:05IDD-ES:1{{Dev:Zebra2}}:" --list-pvs'
def caproto_ioc(wait=3):
env = {
"EPICS_CAS_BEACON_ADDR_LIST": "127.0.0.1",
"EPICS_CAS_AUTO_BEACON_ADDR_LIST": "no",
}
command = (
sys.executable
+ " -m srx_caproto_iocs.zebra.caproto_ioc --prefix=XF:05IDD-ES:1{{Dev:Zebra2}}: --list-pvs"
)
print(
f"Starting caproto IOC in via a fixture using the following command:\n\n {command}\n"
)
p = subprocess.Popen(
command.split(),
start_new_session=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
shell=True,
shell=False,
env=env,
)
ttime.sleep(2.0)
print(f"Wait for {wait} seconds...")
ttime.sleep(wait)

yield
yield p

p.terminate()

std_out, std_err = p.communicate()
std_out = std_out.decode()
print(std_out)
p.terminate()
9 changes: 4 additions & 5 deletions tests/test_zebra_ophyd.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,16 @@
from srx_caproto_iocs.utils import now


@pytest.mark.hardware()
@pytest.mark.usefixtures("_caproto_ioc")
@pytest.mark.cloud_friendly()
@pytest.mark.parametrize("date_template", ["%Y/%m/", "%Y/%m/%d", "mydir/%Y/%m/%d"])
def test_zebra_ophyd_caproto(zebra_ophyd_caproto, date_template):
def test_zebra_ophyd_caproto(caproto_ioc, zebra_ophyd_caproto, date_template):
with tempfile.TemporaryDirectory() as tmpdirname:
date = now(as_object=True)
write_dir_root = Path(tmpdirname)
dir_template = f"{write_dir_root}/{date_template}"
write_dir = Path(date.strftime(dir_template))
write_dir.mkdir(parents=True, exist_ok=True)

print(f"{write_dir = }")

file_template = "scan_{num:06d}_{uid}.hdf5"

dev = zebra_ophyd_caproto
Expand All @@ -39,3 +36,5 @@ def cb(value, old_value, **kwargs):

full_file_path = dev.full_file_path.get()
print(f"{full_file_path = }")

assert full_file_path, "The returned 'full_file_path' did not change."

0 comments on commit ca99a7e

Please sign in to comment.