Skip to content

Commit

Permalink
Merge branch 'main' into 131-make-a-simulated-detector-that-can-write…
Browse files Browse the repository at this point in the history
…-hdf-files
  • Loading branch information
stan-dot authored Apr 15, 2024
2 parents d04c5dd + f7f651c commit 107a825
Show file tree
Hide file tree
Showing 34 changed files with 1,096 additions and 410 deletions.
4 changes: 2 additions & 2 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# The devcontainer should use the build target and run as root with podman
# or docker with user namespaces.
#
FROM python:3.9 as build
FROM python:3.10 as build

ARG PIP_OPTIONS

Expand All @@ -24,7 +24,7 @@ WORKDIR /context
# install python package into /venv
RUN pip install ${PIP_OPTIONS}

FROM python:3.9-slim as runtime
FROM python:3.10-slim as runtime

# Add apt-get system dependecies for runtime here if needed

Expand Down
2 changes: 1 addition & 1 deletion .github/actions/install_requirements/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ inputs:
required: true
python_version:
description: Python version to install
default: "3.9"
default: "3.10"

runs:
using: composite
Expand Down
16 changes: 9 additions & 7 deletions .github/workflows/code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install python packages
uses: ./.github/actions/install_requirements
Expand All @@ -29,12 +29,12 @@ jobs:
fail-fast: false
matrix:
os: ["ubuntu-latest"] # can add windows-latest, macos-latest
python: ["3.10", "3.11"]
python: ["3.10","3.11"] # 3.12 should be added when p4p is updated
install: ["-e .[dev]"]
# Make one version be non-editable to test both paths of version code
include:
- os: "ubuntu-latest"
python: "3.9"
python: "3.10"
install: ".[dev]"

runs-on: ${{ matrix.os }}
Expand All @@ -44,7 +44,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
# Need this to get version number from last tag
fetch-depth: 0
Expand All @@ -63,18 +63,20 @@ jobs:
run: tox -e pytest

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
name: ${{ matrix.python }}/${{ matrix.os }}
files: cov.xml
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

dist:
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository
runs-on: "ubuntu-latest"

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
# Need this to get version number from last tag
fetch-depth: 0
Expand Down Expand Up @@ -125,7 +127,7 @@ jobs:
- name: Github Release
# We pin to the SHA, not the tag, for security reasons.
# https://docs.github.com/en/actions/learn-github-actions/security-hardening-for-github-actions#using-third-party-actions
uses: softprops/action-gh-release@1e07f4398721186383de40550babbdf2b84acfc5 # v0.1.14
uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 # v0.1.15
with:
prerelease: ${{ contains(github.ref_name, 'a') || contains(github.ref_name, 'b') || contains(github.ref_name, 'rc') }}
files: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
run: sleep 60

- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
# Need this to get version number from last tag
fetch-depth: 0
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs_clean.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: gh-pages

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linkcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install python packages
uses: ./.github/actions/install_requirements
Expand Down
2 changes: 1 addition & 1 deletion docs/developer/how-to/pin-requirements.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ of the dependencies and sub-dependencies with pinned versions.
You can download any of these files by clicking on them. It is best to use
the one that ran with the lowest Python version as this is more likely to
be compatible with all the versions of Python in the test matrix.
i.e. ``requirements-test-ubuntu-latest-3.9.txt`` in this example.
i.e. ``requirements-test-ubuntu-latest-3.10.txt`` in this example.

Applying the lock file
----------------------
Expand Down
2 changes: 1 addition & 1 deletion docs/developer/tutorials/dev-install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Install dependencies
--------------------

You can choose to either develop on the host machine using a `venv` (which
requires python 3.9 or later) or to run in a container under `VSCode
requires python 3.10 or later) or to run in a container under `VSCode
<https://code.visualstudio.com/>`_

.. tab-set::
Expand Down
45 changes: 45 additions & 0 deletions docs/user/how-to/write-tests-for-devices.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
.. note::

Ophyd async is included on a provisional basis until the v1.0 release and
may change API on minor release numbers before then

Write Tests for Devices
=======================

Testing ophyd-async devices using tools like mocking, patching, and fixtures can become complicated very quickly. The library provides several utilities to make it easier.

Async Tests
-----------

`pytest-asyncio <https://github.com/pytest-dev/pytest-asyncio>`_ is required for async tests. It is should be included as a dev dependency of your project. Tests can either be decorated with ``@pytest.mark.asyncio`` or the project can be automatically configured to detect async tests.

.. code:: toml
# pyproject.toml
[tool.pytest.ini_options]
...
asyncio_mode = "auto"
Sim Backend
-----------

Ophyd devices initialized with a sim backend behave in a similar way to mocks, without requiring you to mock out all the dependencies and internals. The :class:`~ophyd-async.core.DeviceCollector` can initialize any number of devices, and their signals and sub-devices (recursively), with a sim backend.

.. literalinclude:: ../../../tests/epics/demo/test_demo.py
:pyobject: sim_sensor


Sim Utility Functions
---------------------

Sim signals behave as simply as possible, holding a sensible default value when initialized and retaining any value (in memory) to which they are set. This model breaks down in the case of read-only signals, which cannot be set because there is an expectation of some external device setting them in the real world. There is a utility function, ``set_sim_value``, to mock-set values for sim signals, including read-only ones.

.. literalinclude:: ../../../tests/epics/demo/test_demo.py
:pyobject: test_sensor_reading_shows_value


There is another utility function, ``set_sim_callback``, for hooking in logic when a sim value changes (e.g. because someone puts to it).

.. literalinclude:: ../../../tests/epics/demo/test_demo.py
:pyobject: test_mover_stopped
1 change: 1 addition & 0 deletions docs/user/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ side-bar.
:maxdepth: 1

how-to/make-a-simple-device
how-to/write-tests-for-devices
how-to/run-container

+++
Expand Down
2 changes: 1 addition & 1 deletion docs/user/tutorials/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Installation
Check your version of python
----------------------------

You will need python 3.9 or later. You can check your version of python by
You will need python 3.10 or later. You can check your version of python by
typing into a terminal::

$ python3 --version
Expand Down
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ name = "ophyd-async"
classifiers = [
"Development Status :: 3 - Alpha",
"License :: OSI Approved :: BSD License",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
]
Expand All @@ -19,15 +18,15 @@ dependencies = [
"packaging",
"pint",
"bluesky>=1.13.0a3",
"event-model",
"event-model<1.21.0",
"p4p",
"pyyaml",
]

dynamic = ["version"]
license.file = "LICENSE"
readme = "README.rst"
requires-python = ">=3.9"
requires-python = ">=3.10"

[project.optional-dependencies]
ca = ["aioca>=1.6"]
Expand Down
10 changes: 8 additions & 2 deletions src/ophyd_async/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
StaticDirectoryProvider,
)
from .async_status import AsyncStatus
from .detector import DetectorControl, DetectorTrigger, DetectorWriter, StandardDetector
from .detector import (
DetectorControl,
DetectorTrigger,
DetectorWriter,
StandardDetector,
TriggerInfo,
)
from .device import Device, DeviceCollector, DeviceVector
from .device_save_loader import (
get_signal_values,
Expand All @@ -17,7 +23,7 @@
set_signal_values,
walk_rw_signals,
)
from .flyer import HardwareTriggeredFlyable, TriggerInfo, TriggerLogic
from .flyer import HardwareTriggeredFlyable, TriggerLogic
from .signal import (
Signal,
SignalR,
Expand Down
Loading

0 comments on commit 107a825

Please sign in to comment.