forked from openWB/core
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathloadmanagement_test.py
More file actions
58 lines (49 loc) · 2.67 KB
/
Copy pathloadmanagement_test.py
File metadata and controls
58 lines (49 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from typing import List, Optional, Tuple
from unittest.mock import Mock
import pytest
from control import loadmanagement
from control.counter import Counter
from control.limiting_value import LoadmanagementLimit
from control.loadmanagement import LimitingValue, Loadmanagement
COUNTER_NAME = "test counter"
@pytest.mark.parametrize(
"available_currents, raw_power_left, expected_ret",
[
pytest.param([5, 10, 15], 6900, ([5, 10, 15], LoadmanagementLimit(None, None))),
pytest.param([5, 10, 25], 1000, ([0.5434782608695652, 1.0869565217391304,
2.717391304347826], LoadmanagementLimit(LimitingValue.POWER.value.format(COUNTER_NAME),
LimitingValue.POWER))),
pytest.param([5, 10, 25], 0, ([0, 0, 0], LoadmanagementLimit(LimitingValue.POWER.value.format(COUNTER_NAME),
LimitingValue.POWER))),
pytest.param([5, 10, 25], None, ([5, 10, 25], LoadmanagementLimit(None, None))),
pytest.param([5, 10, 25], 5000, ([2.717391304347826, 5.434782608695652,
13.58695652173913], LoadmanagementLimit(LimitingValue.POWER.value.format(COUNTER_NAME),
LimitingValue.POWER))),
])
def test_limit_by_power(available_currents: List[float],
raw_power_left: Optional[float],
expected_ret: Tuple[List[float], LoadmanagementLimit],
monkeypatch):
# setup
counter_name_mock = Mock(return_value=COUNTER_NAME)
monkeypatch.setattr(loadmanagement, "get_component_name_by_id", counter_name_mock)
# evaluation
ret = Loadmanagement()._limit_by_power(Counter(0), available_currents, 230, raw_power_left, None)
# assertion
assert ret == expected_ret
@pytest.mark.parametrize(
"missing_currents, raw_currents_left, expected_currents",
[
pytest.param([5, 10, 15], [20]*3, ([5, 10, 15], LoadmanagementLimit(None, None))),
pytest.param([5, 10, 15], [5, 8, 5], ([5, 8, 5], LoadmanagementLimit(
LimitingValue.CURRENT.value.format(COUNTER_NAME), LimitingValue.CURRENT))),
])
def test_limit_by_current(
missing_currents: List[float], raw_currents_left: List[float], expected_currents: List[float], monkeypatch):
# setup
counter_name_mock = Mock(return_value=COUNTER_NAME)
monkeypatch.setattr(loadmanagement, "get_component_name_by_id", counter_name_mock)
# evaluation
currents = Loadmanagement()._limit_by_current(Counter(0), missing_currents, raw_currents_left)
# assertion
assert currents == expected_currents