|
1 | 1 | from typing import Any, Final, Literal
|
2 | 2 | from unittest.mock import Mock
|
3 | 3 |
|
| 4 | +import pytest |
4 | 5 | from tests.sml_values.test_operations.helper import check_description, check_operation_repr
|
5 | 6 |
|
| 7 | +from sml2mqtt.const import SmlFrameValues |
| 8 | +from sml2mqtt.sml_value import SmlValue |
6 | 9 | from sml2mqtt.sml_value.base import ValueOperationBase
|
7 | 10 | from sml2mqtt.sml_value.operations import OffsetOperation, OrOperation, SequenceOperation
|
8 | 11 |
|
@@ -32,12 +35,20 @@ def get_operation_mock(self, return_value: Any) -> Mock:
|
32 | 35 | return m
|
33 | 36 |
|
34 | 37 | def process_value(self, value: float):
|
| 38 | + if isinstance(self.operation, SmlValue): |
| 39 | + m = Mock() |
| 40 | + m.get_value = Mock(return_value=value) |
| 41 | + m.obis = 'obis' |
| 42 | + ret = self.operation.process_frame(SmlFrameValues.create(0, [m])) |
| 43 | + self.sentinel = self.mocks[0].call_args[0][1] |
| 44 | + return ret |
| 45 | + |
35 | 46 | return self.operation.process_value(value, self.sentinel)
|
36 | 47 |
|
37 | 48 |
|
38 |
| -def get_mock_group(cls: type[OrOperation | SequenceOperation], *return_values: Any) -> MockOperationsGroup: |
| 49 | +def get_mock_group(cls: type[OrOperation | SequenceOperation | SmlValue], *return_values: Any) -> MockOperationsGroup: |
39 | 50 |
|
40 |
| - c = cls() |
| 51 | + c = cls() if cls is not SmlValue else cls('obis', Mock()) |
41 | 52 | m = MockOperationsGroup(c)
|
42 | 53 | for return_value in return_values:
|
43 | 54 | c.add_operation(m.get_operation_mock(return_value))
|
@@ -97,26 +108,30 @@ def test_or_description():
|
97 | 108 | assert o.process_value(None, None) is None
|
98 | 109 |
|
99 | 110 |
|
100 |
| -def test_seq_no_exit(): |
101 |
| - m = get_mock_group(SequenceOperation, 1, 2, 3) |
| 111 | +@pytest.mark.parametrize('cls', [SequenceOperation, SmlValue]) |
| 112 | +def test_seq_no_exit(cls): |
| 113 | + m = get_mock_group(cls, 1, 2, 3) |
102 | 114 | assert m.process_value(0) == 3
|
103 | 115 | m.assert_called(0, 1, 2)
|
104 | 116 |
|
105 | 117 |
|
106 |
| -def test_seq_first_exit(): |
107 |
| - m = get_mock_group(SequenceOperation, None, 2, None) |
| 118 | +@pytest.mark.parametrize('cls', [SequenceOperation, SmlValue]) |
| 119 | +def test_seq_first_exit(cls): |
| 120 | + m = get_mock_group(cls, None, 2, None) |
108 | 121 | assert m.process_value(1) is None
|
109 | 122 | m.assert_called(1, None, 2)
|
110 | 123 |
|
111 | 124 |
|
112 |
| -def test_seq_last_exit(): |
113 |
| - m = get_mock_group(SequenceOperation, 1, 2, None) |
| 125 | +@pytest.mark.parametrize('cls', [SequenceOperation, SmlValue]) |
| 126 | +def test_seq_last_exit(cls): |
| 127 | + m = get_mock_group(cls, 1, 2, None) |
114 | 128 | assert m.process_value(0) is None
|
115 | 129 | m.assert_called(0, 1, 2)
|
116 | 130 |
|
117 | 131 |
|
118 |
| -def test_seq_single(): |
119 |
| - m = get_mock_group(SequenceOperation, None) |
| 132 | +@pytest.mark.parametrize('cls', [SequenceOperation, SmlValue]) |
| 133 | +def test_seq_single(cls): |
| 134 | + m = get_mock_group(cls, None) |
120 | 135 | assert m.process_value(1) is None
|
121 | 136 | m.assert_called(1)
|
122 | 137 |
|
|
0 commit comments