Skip to content

Commit

Permalink
Merge branch 'main' into 80-areadetector-regular-attribute-names-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
subinsaji committed Jul 25, 2024
2 parents 5f49153 + c6a9c79 commit 368dba7
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 25 deletions.
4 changes: 2 additions & 2 deletions docs/how-to/make-a-standard-detector.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ Writing a non-AreaDetector StandardDetector
A non-AreaDetector `StandardDetector` should implement `DetectorControl` and `DetectorWriter` directly.
Here we construct a `DetectorControl` that co-ordinates signals on a PandA PositionCapture block - a child device "pcap" of the `StandardDetector` implementation, analogous to the :py:class:`FooDriver`.

.. literalinclude:: ../../src/ophyd_async/fastcs/panda/_panda_controller.py
.. literalinclude:: ../../src/ophyd_async/fastcs/panda/_control.py
:pyobject: PandaPcapController

The PandA may write a number of fields, and the :py:class:`PandaHDFWriter` co-ordinates those, configures the filewriter and describes the data for the RunEngine.

.. literalinclude:: ../../src/ophyd_async/fastcs/panda/_hdf_writer.py
.. literalinclude:: ../../src/ophyd_async/fastcs/panda/_writer.py
:pyobject: PandaHDFWriter

The PandA StandardDetector implementation simply ties the component parts and its child devices together.
Expand Down
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,11 @@ lint.select = [
"F", # pyflakes rules - https://beta.ruff.rs/docs/rules/#pyflakes-f
"W", # pycodestyle warnings - https://beta.ruff.rs/docs/rules/#warning-w
"I001", # isort
"SLF", # self - https://docs.astral.sh/ruff/settings/#lintflake8-self
]

[tool.ruff.lint.per-file-ignores]
# By default, private member access is allowed in tests
# See https://github.com/DiamondLightSource/python-copier-template/issues/154
# Remove this line to forbid private member access in tests
"tests/**/*" = ["SLF001"]
2 changes: 1 addition & 1 deletion src/ophyd_async/core/_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ async def _check_config_sigs(self):
await signal.get_value()
except NotImplementedError:
raise Exception(
f"config signal {signal._name} must be connected before it is "
f"config signal {signal.name} must be connected before it is "
+ "passed to the detector"
)

Expand Down
7 changes: 4 additions & 3 deletions src/ophyd_async/core/_mock_signal_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@


def _get_mock_signal_backend(signal: Signal) -> MockSignalBackend:
assert isinstance(signal._backend, MockSignalBackend), (
backend = signal._backend # noqa:SLF001
assert isinstance(backend, MockSignalBackend), (
"Expected to receive a `MockSignalBackend`, instead "
f" received {type(signal._backend)}. "
f" received {type(backend)}. "
)
return signal._backend
return backend


def set_mock_value(signal: Signal[T], value: T):
Expand Down
6 changes: 3 additions & 3 deletions src/ophyd_async/fastcs/panda/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ._common_blocks import (
from ._block import (
CommonPandaBlocks,
DataBlock,
EnableDisableOptions,
Expand All @@ -9,9 +9,8 @@
SeqBlock,
TimeUnits,
)
from ._control import PandaPcapController
from ._hdf_panda import HDFPanda
from ._hdf_writer import PandaHDFWriter
from ._panda_controller import PandaPcapController
from ._table import (
DatasetTable,
PandaHdf5DatasetType,
Expand All @@ -28,6 +27,7 @@
StaticSeqTableTriggerLogic,
)
from ._utils import phase_sorter
from ._writer import PandaHDFWriter

__all__ = [
"CommonPandaBlocks",
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
wait_for_value,
)

from ._common_blocks import PcapBlock
from ._block import PcapBlock


class PandaPcapController(DetectorControl):
Expand Down
6 changes: 3 additions & 3 deletions src/ophyd_async/fastcs/panda/_hdf_panda.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from ophyd_async.core import DEFAULT_TIMEOUT, PathProvider, SignalR, StandardDetector
from ophyd_async.epics.pvi import create_children_from_annotations, fill_pvi_entries

from ._common_blocks import CommonPandaBlocks
from ._hdf_writer import PandaHDFWriter
from ._panda_controller import PandaPcapController
from ._block import CommonPandaBlocks
from ._control import PandaPcapController
from ._writer import PandaHDFWriter


class HDFPanda(CommonPandaBlocks, StandardDetector):
Expand Down
2 changes: 1 addition & 1 deletion src/ophyd_async/fastcs/panda/_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from ophyd_async.core import TriggerLogic, wait_for_value

from ._common_blocks import PcompBlock, PcompDirectionOptions, SeqBlock, TimeUnits
from ._block import PcompBlock, PcompDirectionOptions, SeqBlock, TimeUnits
from ._table import SeqTable


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
wait_for_value,
)

from ._common_blocks import CommonPandaBlocks
from ._block import CommonPandaBlocks


class PandaHDFWriter(DetectorWriter):
Expand Down
4 changes: 2 additions & 2 deletions tests/core/test_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def test_default_config_ophyd_async_logging():
assert _log.logger.getEffectiveLevel() <= logging.WARNING


def test_config_ophyd_async_logging_with_file_handler():
config_ophyd_async_logging(file="file")
def test_config_ophyd_async_logging_with_file_handler(tmp_path):
config_ophyd_async_logging(file=tmp_path / "file")
assert isinstance(_log.current_handler, logging.StreamHandler)
assert _log.logger.getEffectiveLevel() <= logging.WARNING

Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_subset_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from ophyd_async.core import SubsetEnum
from ophyd_async.epics.signal import epics_signal_rw

# I think we want to allow these as calling these is only needed for tests?
# Allow these imports from private modules for tests
from ophyd_async.epics.signal._aioca import make_converter as aioca_make_converter
from ophyd_async.epics.signal._p4p import make_converter as p4p_make_converter

Expand Down
2 changes: 1 addition & 1 deletion tests/fastcs/panda/test_panda_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
NotConnected,
)
from ophyd_async.epics.pvi import create_children_from_annotations, fill_pvi_entries
from ophyd_async.epics.pvi._pvi import _PVIEntry # Allow as edge case for typing
from ophyd_async.epics.pvi._pvi import _PVIEntry # noqa
from ophyd_async.fastcs.panda import (
PcapBlock,
PulseBlock,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,15 @@ class PcapBlock(Device):
pass # Not filled

pandaController = PandaPcapController(pcap=PcapBlock())
with patch(
"ophyd_async.fastcs.panda._panda_controller.wait_for_value", return_value=None
):
with patch("ophyd_async.fastcs.panda._control.wait_for_value", return_value=None):
with pytest.raises(AttributeError) as exc:
await pandaController.arm(num=1, trigger=DetectorTrigger.constant_gate)
assert ("'PcapBlock' object has no attribute 'arm'") in str(exc.value)


async def test_panda_controller_arm_disarm(mock_panda):
pandaController = PandaPcapController(mock_panda.pcap)
with patch(
"ophyd_async.fastcs.panda._panda_controller.wait_for_value", return_value=None
):
with patch("ophyd_async.fastcs.panda._control.wait_for_value", return_value=None):
await pandaController.arm(num=1, trigger=DetectorTrigger.constant_gate)
await pandaController.disarm()

Expand Down

0 comments on commit 368dba7

Please sign in to comment.