Skip to content

Commit

Permalink
update the tests, too
Browse files Browse the repository at this point in the history
  • Loading branch information
penguinland committed May 16, 2024
1 parent 48a6e77 commit c251941
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
10 changes: 7 additions & 3 deletions tests/mocks/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,16 @@ async def do_command(self, command: Mapping[str, ValueTypes], *, timeout: Option


class MockAnalog(Board.Analog):
def __init__(self, name: str, value: int):
self.value = value
def __init__(self, name: str, value: int, min_range: float, max_range: float, step_size: float):
self.value = self.Value()
self.value.value = value
self.value.min_range = min_range
self.value.max_range = max_range
self.value.step_size = step_size
self.timeout: Optional[float] = None
super().__init__(name)

async def read(self, *, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None, **kwargs) -> int:
async def read(self, *, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None, **kwargs) -> Board.Analog.Value:
self.extra = extra
self.timeout = timeout
return self.value
Expand Down
9 changes: 6 additions & 3 deletions tests/test_board.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def board() -> MockBoard:
return MockBoard(
name="board",
analogs={
"reader1": MockAnalog("reader1", 3),
"writer1": MockAnalog("writer1", 5),
"reader1": MockAnalog("reader1", 3, 0.0, 1.0, 0.1),
"writer1": MockAnalog("writer1", 5, 0.0, 1.0, 0.1),
},
digital_interrupts={
"interrupt1": MockDigitalInterrupt("interrupt1"),
Expand Down Expand Up @@ -119,7 +119,7 @@ async def test_status(self, board: MockBoard):
assert status.name == MockBoard.get_resource_name(board.name)
assert status.status == message_to_struct(
BoardStatus(
analogs={"reader1": int(read1), "writer1": int(read2)},
analogs={"reader1": int(read1.value), "writer1": int(read2.value)},
digital_interrupts={"interrupt1": val},
)
)
Expand Down Expand Up @@ -171,6 +171,9 @@ async def test_read_analog(self, board: MockBoard, service: BoardRPCService):
request = ReadAnalogReaderRequest(board_name=board.name, analog_reader_name="reader1", extra=dict_to_struct(extra))
response: ReadAnalogReaderResponse = await client.ReadAnalogReader(request, timeout=4.4)
assert response.value == 3
assert response.min_range == 0.0
assert response.max_range == 1.0
assert response.step_size == pytest.approx(0.1)

reader = cast(MockAnalog, board.analogs["reader1"])
assert reader.extra == extra
Expand Down

0 comments on commit c251941

Please sign in to comment.