From 1c6d5be730ef8143b9bed7c0de630eecf9e647c9 Mon Sep 17 00:00:00 2001 From: Max Rakitin Date: Sun, 18 Feb 2024 01:30:39 -0500 Subject: [PATCH] CI: upload testing results as artifacts --- .github/workflows/ci.yml | 14 ++++++++++ src/srx_caproto_iocs/base.py | 2 +- tests/test_base_ophyd.py | 54 +++++++++++++++++++----------------- 3 files changed, 44 insertions(+), 26 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 19d52df..7fbd578 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -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 @@ -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/codecov-action@v4.0.1 diff --git a/src/srx_caproto_iocs/base.py b/src/srx_caproto_iocs/base.py index 20bdb76..2ad314f 100644 --- a/src/srx_caproto_iocs/base.py +++ b/src/srx_caproto_iocs/base.py @@ -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 diff --git a/tests/test_base_ophyd.py b/tests/test_base_ophyd.py index b157dfd..ad00dab 100644 --- a/tests/test_base_ophyd.py +++ b/tests/test_base_ophyd.py @@ -1,7 +1,8 @@ from __future__ import annotations -import tempfile +import shutil import time as ttime +import uuid from pathlib import Path import h5py @@ -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)