Skip to content

Commit

Permalink
Supported pva dicts and fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
evalott100 committed Mar 5, 2024
1 parent ace9e86 commit b3f1961
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
13 changes: 8 additions & 5 deletions src/ophyd_async/epics/_backend/_p4p.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
import atexit
import logging
import time
from dataclasses import dataclass
from enum import Enum
from typing import Any, Dict, List, Optional, Sequence, Type, Union
Expand Down Expand Up @@ -119,9 +120,7 @@ def value(self, value):

def descriptor(self, source: str, value) -> Descriptor:
choices = [e.value for e in self.enum_class]
return dict(
source=source, dtype="string", shape=[], choices=choices
) # type: ignore
return dict(source=source, dtype="string", shape=[], choices=choices)


class PvaEnumBoolConverter(PvaConverter):
Expand All @@ -142,9 +141,13 @@ def descriptor(self, source: str, value) -> Descriptor:


class PvaDictConverter(PvaConverter):
def reading(self, value):
value = value.todict()
ts = time.time()
return dict(value=value, timestamp=ts, alarm_severity=0)

def value(self, value):
return value
def value(self, value: Value):
return value.todict()

def descriptor(self, source: str, value) -> Descriptor:
raise NotImplementedError("Describing Dict signals not currently supported")
Expand Down
27 changes: 16 additions & 11 deletions tests/epics/test_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
Type,
TypedDict,
)
from unittest.mock import ANY

import numpy as np
import numpy.typing as npt
Expand Down Expand Up @@ -100,17 +101,12 @@ async def assert_updates(self, expected_value):
"timestamp": pytest.approx(time.time(), rel=0.1),
"alarm_severity": 0,
}
backend_reading = await asyncio.wait_for(self.backend.get_reading(), timeout=5)
reading, value = await asyncio.wait_for(self.updates.get(), timeout=5)
assert (
value
== expected_value
== await asyncio.wait_for(self.backend.get_value(), timeout=5)
)
assert (
reading
== expected_reading
== await asyncio.wait_for(self.backend.get_reading(), timeout=5)
)
backend_value = await asyncio.wait_for(self.backend.get_value(), timeout=5)

assert value == expected_value == backend_value
assert reading == expected_reading == backend_reading

def close(self):
self.backend.set_callback(None)
Expand Down Expand Up @@ -350,8 +346,10 @@ async def test_pvi_structure(ioc: IOC) -> None:
return
# Make and connect the backend
backend = await ioc.make_backend(Dict[str, Any], "pvi")

# Make a monitor queue that will monitor for updates
q = MonitorQueue(backend)

expected = {
"pvi": {
"width": {
Expand All @@ -360,8 +358,15 @@ async def test_pvi_structure(ioc: IOC) -> None:
"height": {
"rw": f"{PV_PREFIX}:{ioc.protocol}:height",
},
}
},
"record": {
"_options": {
"atomic": ANY, # the field can be true or false
"queueSize": 0,
},
},
}

try:
# Check descriptor
with pytest.raises(NotImplementedError):
Expand Down

0 comments on commit b3f1961

Please sign in to comment.