Skip to content

Commit

Permalink
CI: upload testing results as artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
mrakitin committed Feb 18, 2024
1 parent 08bcbf2 commit 1c6d5be
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 26 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ jobs:
# include:
# - python-version: pypy-3.10
# runs-on: ubuntu-latest
env:
TZ: America/New_York

steps:
- uses: actions/checkout@v4
Expand All @@ -61,6 +63,11 @@ jobs:
python-version: ${{ matrix.python-version }}
allow-prereleases: true

- name: Set env vars
run: |
export DATETIME_STRING=$(date +%Y%m%d%H%M%S)
echo "DATETIME_STRING=${DATETIME_STRING}" >> $GITHUB_ENV
- name: Install package
run: |
set -vxeuo pipefail
Expand All @@ -71,5 +78,12 @@ jobs:
python -m pytest -ra --cov --cov-report=xml --cov-report=term
--durations=20 -m "(not hardware) and (not tiled)" -s -vv
- name: Upload test artifacts
uses: actions/upload-artifact@v4
with:
name: test-artifacts-{{ env.DATETIME_STRING }}
path: /tmp/srx-caproto-iocs/
retention-days: 14

- name: Upload coverage report
uses: codecov/[email protected]
2 changes: 1 addition & 1 deletion src/srx_caproto_iocs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ class OphydDeviceWithCaprotoIOC(Device):
def set(self, command):
"""The set method with values for staging and acquiring."""

print(f"{now()}: {command = }")
# print(f"{now()}: {command = }")
if command in [StageStates.STAGED.value, "stage"]:
expected_old_value = StageStates.UNSTAGED.value
expected_new_value = StageStates.STAGED.value
Expand Down
54 changes: 29 additions & 25 deletions tests/test_base_ophyd.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import annotations

import tempfile
import shutil
import time as ttime
import uuid
from pathlib import Path

import h5py
Expand All @@ -13,38 +14,41 @@
@pytest.mark.cloud_friendly()
@pytest.mark.parametrize("date_template", ["%Y/%m/", "%Y/%m/%d", "mydir/%Y/%m/%d"])
def test_base_ophyd_templates(
base_caproto_ioc, base_ophyd_device, date_template, num_frames=50
base_caproto_ioc, base_ophyd_device, date_template, num_frames=50, remove=False
):
with tempfile.TemporaryDirectory(prefix="/tmp/") 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)
tmpdirname = f"/tmp/srx-caproto-iocs/{str(uuid.uuid4())[:2]}"
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)

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

dev = base_ophyd_device
dev.write_dir.put(dir_template)
dev.file_name.put(file_template)
dev = base_ophyd_device
dev.write_dir.put(dir_template)
dev.file_name.put(file_template)

dev.set("stage").wait()
dev.set("stage").wait()

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

for i in range(num_frames):
print(f"Collecting frame {i}...")
dev.set("acquire").wait()
ttime.sleep(0.1)
for i in range(num_frames):
print(f"Collecting frame {i}...")
dev.set("acquire").wait()
ttime.sleep(0.1)

dev.set("unstage").wait()
dev.set("unstage").wait()

assert full_file_path, "The returned 'full_file_path' did not change."
assert Path(full_file_path).is_file(), f"No such file '{full_file_path}'"
assert full_file_path, "The returned 'full_file_path' did not change."
assert Path(full_file_path).is_file(), f"No such file '{full_file_path}'"

with h5py.File(full_file_path, "r", swmr=True) as f:
dataset = f["/entry/data/data"]
assert dataset.shape == (num_frames, 256, 256)
with h5py.File(full_file_path, "r", swmr=True) as f:
dataset = f["/entry/data/data"]
assert dataset.shape == (num_frames, 256, 256)

ttime.sleep(1.0)

if remove:
shutil.rmtree(tmpdirname)

0 comments on commit 1c6d5be

Please sign in to comment.