Skip to content

Commit

Permalink
Fix/pydantic 2 compatibility (#99)
Browse files Browse the repository at this point in the history
* chore: update s2-python and remove pydantic pin

Signed-off-by: F.N. Claessen <[email protected]>

* chore: remove pydantic dependency altogether (not a direct dependency, and pydantic is now limited in s2-python)

Signed-off-by: F.N. Claessen <[email protected]>

* chore: add optional package requirements

Signed-off-by: F.N. Claessen <[email protected]>

* fix: test should rely on exact IDs that were meant, not new IDs

Signed-off-by: F.N. Claessen <[email protected]>

* fix: aware datetimes

Signed-off-by: F.N. Claessen <[email protected]>

* refactor: prefer timezone.utc (shorter, clearer)

Signed-off-by: F.N. Claessen <[email protected]>

* fix: no more __root__

Signed-off-by: F.N. Claessen <[email protected]>

* Revert "chore: add optional package requirements"

This reverts commit bdf06a8.

---------

Signed-off-by: F.N. Claessen <[email protected]>
  • Loading branch information
Flix6x authored Jan 23, 2025
1 parent b88c8d6 commit 49bcda7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
3 changes: 1 addition & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ install_requires =
importlib-metadata; python_version<"3.8"
aiohttp<=3.9.1
pandas>=2.1.4
pydantic>=1.10.8,<2.0
s2-python==0.1.3
s2-python>=0.4.0
async_timeout

[options.packages.find]
Expand Down
12 changes: 6 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from datetime import datetime
from datetime import datetime, timezone

import pytest
from s2python.common import (
Expand Down Expand Up @@ -46,7 +46,7 @@ def frbc_system_description():
)

thp_operation_mode = FRBCOperationMode(
id="tarnoc-operation-mode",
id=get_unique_id(),
elements=[thp_operation_mode_element],
abnormal_condition_only=False,
)
Expand All @@ -64,13 +64,13 @@ def frbc_system_description():
)

nes_operation_mode = FRBCOperationMode(
id="nestore-operation-mode",
id=get_unique_id(),
elements=[nes_operation_mode_element],
abnormal_condition_only=False,
)

actuator = FRBCActuatorDescription(
id="id-of-the-actuator",
id=get_unique_id(),
supported_commodities=[Commodity.ELECTRICITY],
operation_modes=[thp_operation_mode, nes_operation_mode],
transitions=[],
Expand All @@ -86,7 +86,7 @@ def frbc_system_description():

system_description_message = FRBCSystemDescription(
message_id=get_unique_id(),
valid_from=datetime(2024, 1, 1),
valid_from=datetime(2024, 1, 1, tzinfo=timezone.utc),
actuators=[actuator],
storage=storage,
)
Expand All @@ -100,7 +100,7 @@ def resource_manager_details():
message_id=get_unique_id(),
resource_id=get_unique_id(),
roles=[Role(role=RoleType.ENERGY_STORAGE, commodity=Commodity.ELECTRICITY)],
instruction_processing_delay=Duration(__root__=1.0),
instruction_processing_delay=Duration(1),
available_control_types=[
ControlType.FILL_RATE_BASED_CONTROL,
ControlType.NO_SELECTION,
Expand Down
29 changes: 17 additions & 12 deletions tests/test_frbc_tunes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from flexmeasures_client.s2.control_types.FRBC.frbc_tunes import (
FillRateBasedControlTUNES,
)
from flexmeasures_client.s2.utils import get_unique_id


@pytest.fixture(scope="function")
Expand Down Expand Up @@ -79,12 +80,12 @@ async def cem_in_frbc_control_type(setup_cem, frbc_system_description):
await cem.handle_message(frbc_system_description)
await cem.get_message()

return cem, fm_client
return cem, fm_client, frbc_system_description


@pytest.mark.asyncio
async def test_system_description(cem_in_frbc_control_type, frbc_system_description):
cem, fm_client = await cem_in_frbc_control_type
cem, fm_client, frbc_system_description = await cem_in_frbc_control_type

########
# FRBC #
Expand All @@ -110,7 +111,7 @@ async def test_system_description(cem_in_frbc_control_type, frbc_system_descript
first_call = fm_client.post_measurements.call_args_list[0][1]
first_call_expected = {
"sensor_id": frbc._thp_efficiency_sensor_id,
"start": datetime(2024, 1, 1),
"start": datetime(2024, 1, 1, tzinfo=timezone.utc),
"values": [0.2] * N_SAMPLES,
"unit": "%",
"duration": "PT24H",
Expand All @@ -123,7 +124,7 @@ async def test_system_description(cem_in_frbc_control_type, frbc_system_descript

second_call_expected = {
"sensor_id": frbc._nes_efficiency_sensor_id,
"start": datetime(2024, 1, 1),
"start": datetime(2024, 1, 1, tzinfo=timezone.utc),
"values": [0.1] * N_SAMPLES,
"unit": "%",
"duration": "PT24H",
Expand All @@ -150,12 +151,12 @@ def get_pending_tasks():

@pytest.mark.asyncio
async def test_fill_level_target_profile(cem_in_frbc_control_type):
cem, fm_client = await cem_in_frbc_control_type
cem, fm_client, frbc_system_description = await cem_in_frbc_control_type

fill_level_target_profile = {
"start_time": "2024-01-01T00:00:00+01:00",
"message_type": "FRBC.FillLevelTargetProfile",
"message_id": "a-valid-id",
"message_id": get_unique_id(),
"elements": [
{
"duration": 1e3 * 3600,
Expand Down Expand Up @@ -208,14 +209,16 @@ async def test_fill_rate_relay(cem_in_frbc_control_type):
corresponds correctly to the Tarnoc fill rate sensor or the Nestor fill rate sensor.
"""

cem, fm_client = await cem_in_frbc_control_type
cem, fm_client, frbc_system_description = await cem_in_frbc_control_type
frbc = cem._control_types_handlers[cem.control_type]

actuator_status = {
"active_operation_mode_id": "tarnoc-operation-mode",
"actuator_id": "id-of-the-actuator",
"active_operation_mode_id": frbc_system_description.actuators[0]
.operation_modes[0]
.id, # ID representing Tarnoc operation mode
"actuator_id": frbc_system_description.actuators[0].id, # ID of the actuator
"message_type": "FRBC.ActuatorStatus",
"message_id": "a-valid-id",
"message_id": get_unique_id(),
"operation_mode_factor": 0.0,
}

Expand All @@ -237,7 +240,9 @@ async def test_fill_rate_relay(cem_in_frbc_control_type):
assert second_call["sensor_id"] == frbc._fill_rate_sensor_id

# Switch operation mode to Nestore
actuator_status["active_operation_mode_id"] = "nestore-operation-mode"
actuator_status["active_operation_mode_id"] = (
frbc_system_description.actuators[0].operation_modes[1].id
) # ID representing NEStore operation mode

await cem.handle_message(actuator_status)
tasks = get_pending_tasks()
Expand Down Expand Up @@ -274,7 +279,7 @@ async def test_trigger_schedule(cem_in_frbc_control_type):
S2 2 FM: converging system description to flex config
FM 2 S2: schedules to instructions
"""
cem, fm_client = await cem_in_frbc_control_type
cem, fm_client, frbc_system_description = await cem_in_frbc_control_type
# frbc = cem._control_types_handlers[cem.control_type]

tasks = get_pending_tasks()
Expand Down

0 comments on commit 49bcda7

Please sign in to comment.