Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion tests/batcontrol/inverter/test_inverter_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
from batcontrol.inverter.mqtt_inverter import MqttInverter


@pytest.fixture(autouse=True)
def reset_inverter_counter():
original_value = Inverter.num_inverters
Inverter.num_inverters = 0

yield

Inverter.num_inverters = original_value


def test_factory_creates_mqtt_inverter():
"""Factory should create an MQTT inverter for type mqtt."""
config = {
Expand Down Expand Up @@ -40,7 +50,7 @@ def test_factory_rejects_unknown_type():
"max_grid_charge_rate": 5000,
}

with pytest.raises(RuntimeError, match="Unkown inverter type"):
with pytest.raises(RuntimeError, match="inverter type"):
Inverter.create_inverter(config)


Expand Down
25 changes: 16 additions & 9 deletions tests/batcontrol/test_production_offset.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,30 +67,37 @@ def mock_config(self):
}

@pytest.fixture
def batcontrol_with_patched_factories(self, mock_config, mocker):
def make_batcontrol(self, mocker):
core_module = 'batcontrol.core'

mocker.patch(f'{core_module}.tariff_factory')
mocker.patch(f'{core_module}.inverter_factory')
mocker.patch(f'{core_module}.solar_factory')
mocker.patch(f'{core_module}.consumption_factory')

bc = Batcontrol(mock_config)
created_instances = []

yield bc
def _make(config):
bc = Batcontrol(config)
created_instances.append(bc)
return bc

bc.shutdown()
yield _make

def test_production_offset_initialization_default(
self, mock_config, batcontrol_with_patched_factories
):
for bc in created_instances:
bc.shutdown()

@pytest.fixture
def batcontrol_with_patched_factories(self, mock_config, make_batcontrol):
yield make_batcontrol(mock_config)

def test_production_offset_initialization_default(self, mock_config, make_batcontrol):
"""Test that production offset initializes with default value when not configured"""
del mock_config['battery_control_expert']['production_offset_percent']

batcontrol = Batcontrol(mock_config)
batcontrol = make_batcontrol(mock_config)

assert batcontrol.production_offset_percent == 1.0
batcontrol.shutdown()

def test_production_offset_initialization_from_config(
self, batcontrol_with_patched_factories
Expand Down