Skip to content

Commit

Permalink
change Dict to Mapping and fix all the mypy issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Relm-Arrowny committed Apr 17, 2024
1 parent c9e73aa commit a47f96b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
# docs in the python documentation.
intersphinx_mapping = {
"python": ("https://docs.python.org/3", None),
"bluesky": ("https://blueskyproject.io/bluesky/", None),
"bluesky": ("https://blueskyproject.io/bluesky/main", None),
"numpy": ("https://numpy.org/devdocs/", None),
"databroker": ("https://blueskyproject.io/databroker/", None),
"event-model": ("https://blueskyproject.io/event-model/main", None),
Expand Down
8 changes: 4 additions & 4 deletions src/ophyd_async/core/signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def set_sim_callback(signal: Signal[T], callback: ReadingValueCallback[T]) -> No


async def _verify_readings(
func: Callable[[], dict[str, Reading] | Awaitable[dict[str, Reading]]],
func: Callable[[], Mapping[str, Reading] | Awaitable[Mapping[str, Reading]]],
expectation: Mapping[str, Reading],
) -> None:
"""Take a read/read_configuration function that return a dictionary and
Expand Down Expand Up @@ -308,7 +308,7 @@ async def assert_value(signal: SignalR[T], value: T) -> None:
assert await signal.get_value() == value


async def assert_reading(readable: Readable, reading: Mapping[str, Reading]) -> None:
async def assert_reading(readable: Readable, reading: Dict[str, Reading]) -> None:
"""Assert readable by calling_verify_readings
Parameters
Expand All @@ -330,7 +330,7 @@ async def assert_reading(readable: Readable, reading: Mapping[str, Reading]) ->

async def assert_configuration(
configurable: Configurable,
configuration: Dict[str, Reading],
configuration: Mapping[str, Reading],
) -> None:
"""
Assert configurable generated by configurable.read_configuration by
Expand All @@ -353,7 +353,7 @@ async def assert_configuration(
await _verify_readings(configurable.read_configuration, configuration)


def assert_emitted(docs: Dict[str, list[DocumentType]], **numbers: int):
def assert_emitted(docs: Mapping[str, list[DocumentType]], **numbers: int):
"""Assert emitted"""
assert list(docs) == list(numbers)
assert {name: len(d) for name, d in docs.items()} == numbers
Expand Down
23 changes: 11 additions & 12 deletions tests/core/test_signal.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
import re
import time
from typing import Mapping
from unittest.mock import ANY

import pytest
Expand Down Expand Up @@ -179,30 +180,28 @@ async def test_assert_configuration(sim_readable: DummyReadable):
set_sim_value(sim_readable.value, 123)
set_sim_value(sim_readable.mode, "super mode")
set_sim_value(sim_readable.mode2, "slow mode")
dummy_config_reading = {
"sim_readable-mode": Reading(
dummy_config_reading: Mapping[str, Reading] = {
"sim_readable-mode": (
{
"alarm_severity": 0,
"timestamp": ANY,
"value": "super mode",
}
),
"sim_readable-mode2": Reading(
{
"alarm_severity": 0,
"timestamp": ANY,
"value": "slow mode",
}
),
"sim_readable-mode2": {
"alarm_severity": 0,
"timestamp": ANY,
"value": "slow mode",
},
}
await assert_configuration(sim_readable, dummy_config_reading)
# test for none awaitable part of verify
from ophyd.sim import DetWithConf

something = DetWithConf(name="det")
dummy_config_reading1 = {
"det_c": Reading({"value": 3, "timestamp": ANY}),
"det_d": Reading({"value": 4, "timestamp": ANY}),
dummy_config_reading1: Mapping[str, Reading] = {
"det_c": {"value": 3, "timestamp": ANY},
"det_d": {"value": 4, "timestamp": ANY},
}

await assert_configuration(something, dummy_config_reading1)

0 comments on commit a47f96b

Please sign in to comment.