-
Notifications
You must be signed in to change notification settings - Fork 30
/
test_sensors.py
75 lines (70 loc) · 2.11 KB
/
test_sensors.py
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import pytest
from flexmeasures.api.common.schemas.sensors import (
SensorField,
EntityAddressValidationError,
)
from flexmeasures.utils.entity_address_utils import build_entity_address
@pytest.mark.parametrize(
"entity_address, entity_type, fm_scheme, exp_deserialization_name",
[
(
build_entity_address(dict(sensor_id=1), "sensor"),
"sensor",
"fm1",
"height",
),
],
)
def test_sensor_field_straightforward(
add_sensors,
setup_markets,
add_battery_assets,
entity_address,
entity_type,
fm_scheme,
exp_deserialization_name,
):
"""Testing straightforward cases"""
sf = SensorField(entity_type, fm_scheme)
deser = sf.deserialize(entity_address, None, None)
assert deser.name == exp_deserialization_name
assert sf.serialize(entity_type, {entity_type: deser}) == entity_address
@pytest.mark.parametrize(
"entity_address, entity_type, fm_scheme, error_msg",
[
(
build_entity_address(
dict(market_name="epex_da"), "market", fm_scheme="fm0"
),
"market",
"fm0",
"fm0 scheme is no longer supported",
),
(
"ea1.2021-01.io.flexmeasures:fm1.some.weird:identifier%that^is*not)used",
"sensor",
"fm1",
"Could not parse",
),
(
build_entity_address(
dict(sensor_id=99999999999999), "sensor", fm_scheme="fm1"
),
"sensor",
"fm1",
"doesn't exist",
),
(
build_entity_address(dict(sensor_id=-1), "sensor", fm_scheme="fm1"),
"sensor",
"fm1",
"Could not parse",
),
("ea1.2021-13.io.flexmeasures:fm1.9", "sensor", "fm1", "date specification"),
],
)
def test_sensor_field_invalid(entity_address, entity_type, fm_scheme, error_msg):
sf = SensorField(entity_type, fm_scheme)
with pytest.raises(EntityAddressValidationError) as ve:
sf.deserialize(entity_address, None, None)
assert error_msg in str(ve)