pre-commit run changes

This commit is contained in:
NormannK 2025-02-16 15:35:17 +01:00
parent e7143f6540
commit 1d6b31ceb4
9 changed files with 167 additions and 167 deletions

View File

@ -1267,14 +1267,14 @@ class DataImportMixin:
# We jump back by 1 hour # We jump back by 1 hour
# Repeat the value(s) (reuse value index) # Repeat the value(s) (reuse value index)
for i in range(interval_steps_per_hour): for i in range(interval_steps_per_hour):
logger.debug(f"{i+1}: Repeat at {next_time} with index {value_index}") logger.debug(f"{i + 1}: Repeat at {next_time} with index {value_index}")
timestamps_with_indices.append((next_time, value_index)) timestamps_with_indices.append((next_time, value_index))
next_time = next_time.add(seconds=interval.total_seconds()) next_time = next_time.add(seconds=interval.total_seconds())
else: else:
# We jump forward by 1 hour # We jump forward by 1 hour
# Drop the value(s) # Drop the value(s)
logger.debug( logger.debug(
f"{i+1}: Skip {interval_steps_per_hour} at {next_time} with index {value_index}" f"{i + 1}: Skip {interval_steps_per_hour} at {next_time} with index {value_index}"
) )
value_index += interval_steps_per_hour value_index += interval_steps_per_hour

View File

@ -204,7 +204,7 @@ async def server_shutdown_task() -> None:
# Gracefully shut down this process. # Gracefully shut down this process.
pid = psutil.Process().pid pid = psutil.Process().pid
if os.name == "nt": if os.name == "nt":
os.kill(pid, signal.CTRL_C_EVENT) # type: ignore[attr-defined] os.kill(pid, signal.CTRL_C_EVENT)
else: else:
os.kill(pid, signal.SIGTERM) os.kill(pid, signal.SIGTERM)

View File

@ -123,23 +123,23 @@ def cfg_non_existent(request):
user_dir = user_config_dir(ConfigEOS.APP_NAME) user_dir = user_config_dir(ConfigEOS.APP_NAME)
user_config_file = Path(user_dir).joinpath(ConfigEOS.CONFIG_FILE_NAME) user_config_file = Path(user_dir).joinpath(ConfigEOS.CONFIG_FILE_NAME)
cwd_config_file = Path.cwd().joinpath(ConfigEOS.CONFIG_FILE_NAME) cwd_config_file = Path.cwd().joinpath(ConfigEOS.CONFIG_FILE_NAME)
assert ( assert not user_config_file.exists(), (
not user_config_file.exists() f"Config file {user_config_file} exists, please delete before test!"
), f"Config file {user_config_file} exists, please delete before test!" )
assert ( assert not cwd_config_file.exists(), (
not cwd_config_file.exists() f"Config file {cwd_config_file} exists, please delete before test!"
), f"Config file {cwd_config_file} exists, please delete before test!" )
# Yield to test # Yield to test
yield yield
# After test # After test
assert ( assert not user_config_file.exists(), (
not user_config_file.exists() f"Config file {user_config_file} created, please check test!"
), f"Config file {user_config_file} created, please check test!" )
assert ( assert not cwd_config_file.exists(), (
not cwd_config_file.exists() f"Config file {cwd_config_file} created, please check test!"
), f"Config file {cwd_config_file} created, please check test!" )
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
@ -311,7 +311,7 @@ def server_base(xprocess: XProcess) -> Generator[dict[str, Union[str, int]], Non
# Windows does not provide SIGKILL # Windows does not provide SIGKILL
sigkill = signal.SIGTERM sigkill = signal.SIGTERM
else: else:
sigkill = signal.SIGKILL sigkill = signal.SIGKILL # type: ignore
# - Use pid on EOS health endpoint # - Use pid on EOS health endpoint
try: try:
result = requests.get(f"{server}/v1/health", timeout=2) result = requests.get(f"{server}/v1/health", timeout=2)

View File

@ -115,9 +115,9 @@ def test_soc_limits(setup_pv_battery):
def test_max_charge_power_w(setup_pv_battery): def test_max_charge_power_w(setup_pv_battery):
battery = setup_pv_battery battery = setup_pv_battery
assert ( assert battery.parameters.max_charge_power_w == 8000, (
battery.parameters.max_charge_power_w == 8000 "Default max charge power should be 5000W, We ask for 8000W here"
), "Default max charge power should be 5000W, We ask for 8000W here" )
def test_charge_energy_within_limits(setup_pv_battery): def test_charge_energy_within_limits(setup_pv_battery):
@ -139,9 +139,9 @@ def test_charge_energy_exceeds_capacity(setup_pv_battery):
# Try to overcharge beyond max capacity # Try to overcharge beyond max capacity
charged_wh, losses_wh = battery.charge_energy(wh=20000, hour=2) charged_wh, losses_wh = battery.charge_energy(wh=20000, hour=2)
assert ( assert charged_wh + initial_soc_wh <= battery.max_soc_wh, (
charged_wh + initial_soc_wh <= battery.max_soc_wh "Charging should not exceed max capacity"
), "Charging should not exceed max capacity" )
assert losses_wh >= 0, "Losses should not be negative" assert losses_wh >= 0, "Losses should not be negative"
assert battery.soc_wh == battery.max_soc_wh, "SOC should be at max after overcharge attempt" assert battery.soc_wh == battery.max_soc_wh, "SOC should be at max after overcharge attempt"
@ -169,9 +169,9 @@ def test_charge_energy_relative_power(setup_pv_battery):
assert charged_wh > 0, "Charging should occur with relative power" assert charged_wh > 0, "Charging should occur with relative power"
assert losses_wh >= 0, "Losses should not be negative" assert losses_wh >= 0, "Losses should not be negative"
assert ( assert charged_wh <= battery.max_charge_power_w * relative_power, (
charged_wh <= battery.max_charge_power_w * relative_power "Charging should respect relative power limit"
), "Charging should respect relative power limit" )
assert battery.soc_wh > 0, "SOC should increase after charging" assert battery.soc_wh > 0, "SOC should increase after charging"
@ -200,19 +200,19 @@ def test_car_and_pv_battery_discharge_and_max_charge_power(setup_pv_battery, set
# Test discharge for PV battery # Test discharge for PV battery
pv_discharged_wh, pv_loss_wh = pv_battery.discharge_energy(3000, 5) pv_discharged_wh, pv_loss_wh = pv_battery.discharge_energy(3000, 5)
assert pv_discharged_wh > 0, "PV battery should discharge energy" assert pv_discharged_wh > 0, "PV battery should discharge energy"
assert ( assert pv_battery.current_soc_percentage() >= pv_battery.parameters.min_soc_percentage, (
pv_battery.current_soc_percentage() >= pv_battery.parameters.min_soc_percentage "PV battery SOC should stay above min SOC"
), "PV battery SOC should stay above min SOC" )
assert ( assert pv_battery.parameters.max_charge_power_w == 8000, (
pv_battery.parameters.max_charge_power_w == 8000 "PV battery max charge power should remain as defined"
), "PV battery max charge power should remain as defined" )
# Test discharge for car battery # Test discharge for car battery
car_discharged_wh, car_loss_wh = car_battery.discharge_energy(5000, 10) car_discharged_wh, car_loss_wh = car_battery.discharge_energy(5000, 10)
assert car_discharged_wh > 0, "Car battery should discharge energy" assert car_discharged_wh > 0, "Car battery should discharge energy"
assert ( assert car_battery.current_soc_percentage() >= car_battery.parameters.min_soc_percentage, (
car_battery.current_soc_percentage() >= car_battery.parameters.min_soc_percentage "Car battery SOC should stay above min SOC"
), "Car battery SOC should stay above min SOC" )
assert ( assert car_battery.parameters.max_charge_power_w == 7000, (
car_battery.parameters.max_charge_power_w == 7000 "Car battery max charge power should remain as defined"
), "Car battery max charge power should remain as defined" )

View File

@ -281,69 +281,69 @@ def test_simulation(create_ems_instance):
assert SimulationResult(**result) is not None assert SimulationResult(**result) is not None
# Check the length of the main arrays # Check the length of the main arrays
assert ( assert len(result["Last_Wh_pro_Stunde"]) == 47, (
len(result["Last_Wh_pro_Stunde"]) == 47 "The length of 'Last_Wh_pro_Stunde' should be 48."
), "The length of 'Last_Wh_pro_Stunde' should be 48." )
assert ( assert len(result["Netzeinspeisung_Wh_pro_Stunde"]) == 47, (
len(result["Netzeinspeisung_Wh_pro_Stunde"]) == 47 "The length of 'Netzeinspeisung_Wh_pro_Stunde' should be 48."
), "The length of 'Netzeinspeisung_Wh_pro_Stunde' should be 48." )
assert ( assert len(result["Netzbezug_Wh_pro_Stunde"]) == 47, (
len(result["Netzbezug_Wh_pro_Stunde"]) == 47 "The length of 'Netzbezug_Wh_pro_Stunde' should be 48."
), "The length of 'Netzbezug_Wh_pro_Stunde' should be 48." )
assert ( assert len(result["Kosten_Euro_pro_Stunde"]) == 47, (
len(result["Kosten_Euro_pro_Stunde"]) == 47 "The length of 'Kosten_Euro_pro_Stunde' should be 48."
), "The length of 'Kosten_Euro_pro_Stunde' should be 48." )
assert ( assert len(result["akku_soc_pro_stunde"]) == 47, (
len(result["akku_soc_pro_stunde"]) == 47 "The length of 'akku_soc_pro_stunde' should be 48."
), "The length of 'akku_soc_pro_stunde' should be 48." )
# Verify specific values in the 'Last_Wh_pro_Stunde' array # Verify specific values in the 'Last_Wh_pro_Stunde' array
assert ( assert result["Last_Wh_pro_Stunde"][1] == 1527.13, (
result["Last_Wh_pro_Stunde"][1] == 1527.13 "The value at index 1 of 'Last_Wh_pro_Stunde' should be 1527.13."
), "The value at index 1 of 'Last_Wh_pro_Stunde' should be 1527.13." )
assert ( assert result["Last_Wh_pro_Stunde"][2] == 1468.88, (
result["Last_Wh_pro_Stunde"][2] == 1468.88 "The value at index 2 of 'Last_Wh_pro_Stunde' should be 1468.88."
), "The value at index 2 of 'Last_Wh_pro_Stunde' should be 1468.88." )
assert ( assert result["Last_Wh_pro_Stunde"][12] == 1132.03, (
result["Last_Wh_pro_Stunde"][12] == 1132.03 "The value at index 12 of 'Last_Wh_pro_Stunde' should be 1132.03."
), "The value at index 12 of 'Last_Wh_pro_Stunde' should be 1132.03." )
# Verify that the value at index 0 is 'None' # Verify that the value at index 0 is 'None'
# Check that 'Netzeinspeisung_Wh_pro_Stunde' and 'Netzbezug_Wh_pro_Stunde' are consistent # Check that 'Netzeinspeisung_Wh_pro_Stunde' and 'Netzbezug_Wh_pro_Stunde' are consistent
assert ( assert result["Netzbezug_Wh_pro_Stunde"][1] == 0, (
result["Netzbezug_Wh_pro_Stunde"][1] == 0 "The value at index 1 of 'Netzbezug_Wh_pro_Stunde' should be 0."
), "The value at index 1 of 'Netzbezug_Wh_pro_Stunde' should be 0." )
# Verify the total balance # Verify the total balance
assert ( assert abs(result["Gesamtbilanz_Euro"] - 1.958185274567674) < 1e-5, (
abs(result["Gesamtbilanz_Euro"] - 1.958185274567674) < 1e-5 "Total balance should be 1.958185274567674."
), "Total balance should be 1.958185274567674." )
# Check total revenue and total costs # Check total revenue and total costs
assert ( assert abs(result["Gesamteinnahmen_Euro"] - 1.168863124510214) < 1e-5, (
abs(result["Gesamteinnahmen_Euro"] - 1.168863124510214) < 1e-5 "Total revenue should be 1.168863124510214."
), "Total revenue should be 1.168863124510214." )
assert ( assert abs(result["Gesamtkosten_Euro"] - 3.127048399077888) < 1e-5, (
abs(result["Gesamtkosten_Euro"] - 3.127048399077888) < 1e-5 "Total costs should be 3.127048399077888 ."
), "Total costs should be 3.127048399077888 ." )
# Check the losses # Check the losses
assert ( assert abs(result["Gesamt_Verluste"] - 2871.5330639359036) < 1e-5, (
abs(result["Gesamt_Verluste"] - 2871.5330639359036) < 1e-5 "Total losses should be 2871.5330639359036 ."
), "Total losses should be 2871.5330639359036 ." )
# Check the values in 'akku_soc_pro_stunde' # Check the values in 'akku_soc_pro_stunde'
assert ( assert result["akku_soc_pro_stunde"][-1] == 42.151590909090906, (
result["akku_soc_pro_stunde"][-1] == 42.151590909090906 "The value at index -1 of 'akku_soc_pro_stunde' should be 42.151590909090906."
), "The value at index -1 of 'akku_soc_pro_stunde' should be 42.151590909090906." )
assert ( assert result["akku_soc_pro_stunde"][1] == 60.08659090909091, (
result["akku_soc_pro_stunde"][1] == 60.08659090909091 "The value at index 1 of 'akku_soc_pro_stunde' should be 60.08659090909091."
), "The value at index 1 of 'akku_soc_pro_stunde' should be 60.08659090909091." )
# Check home appliances # Check home appliances
assert ( assert sum(ems.home_appliance.get_load_curve()) == 2000, (
sum(ems.home_appliance.get_load_curve()) == 2000 "The sum of 'ems.home_appliance.get_load_curve()' should be 2000."
), "The sum of 'ems.home_appliance.get_load_curve()' should be 2000." )
assert ( assert (
np.nansum( np.nansum(

View File

@ -211,44 +211,44 @@ def test_simulation(create_ems_instance):
assert key in result, f"The key '{key}' should be present in the result." assert key in result, f"The key '{key}' should be present in the result."
# Check the length of the main arrays # Check the length of the main arrays
assert ( assert len(result["Last_Wh_pro_Stunde"]) == 48, (
len(result["Last_Wh_pro_Stunde"]) == 48 "The length of 'Last_Wh_pro_Stunde' should be 48."
), "The length of 'Last_Wh_pro_Stunde' should be 48." )
assert ( assert len(result["Netzeinspeisung_Wh_pro_Stunde"]) == 48, (
len(result["Netzeinspeisung_Wh_pro_Stunde"]) == 48 "The length of 'Netzeinspeisung_Wh_pro_Stunde' should be 48."
), "The length of 'Netzeinspeisung_Wh_pro_Stunde' should be 48." )
assert ( assert len(result["Netzbezug_Wh_pro_Stunde"]) == 48, (
len(result["Netzbezug_Wh_pro_Stunde"]) == 48 "The length of 'Netzbezug_Wh_pro_Stunde' should be 48."
), "The length of 'Netzbezug_Wh_pro_Stunde' should be 48." )
assert ( assert len(result["Kosten_Euro_pro_Stunde"]) == 48, (
len(result["Kosten_Euro_pro_Stunde"]) == 48 "The length of 'Kosten_Euro_pro_Stunde' should be 48."
), "The length of 'Kosten_Euro_pro_Stunde' should be 48." )
assert ( assert len(result["akku_soc_pro_stunde"]) == 48, (
len(result["akku_soc_pro_stunde"]) == 48 "The length of 'akku_soc_pro_stunde' should be 48."
), "The length of 'akku_soc_pro_stunde' should be 48." )
# Verfify DC and AC Charge Bins # Verfify DC and AC Charge Bins
assert ( assert abs(result["akku_soc_pro_stunde"][2] - 44.70681818181818) < 1e-5, (
abs(result["akku_soc_pro_stunde"][2] - 44.70681818181818) < 1e-5 "'akku_soc_pro_stunde[2]' should be 44.70681818181818."
), "'akku_soc_pro_stunde[2]' should be 44.70681818181818." )
assert ( assert abs(result["akku_soc_pro_stunde"][10] - 10.0) < 1e-5, (
abs(result["akku_soc_pro_stunde"][10] - 10.0) < 1e-5 "'akku_soc_pro_stunde[10]' should be 10."
), "'akku_soc_pro_stunde[10]' should be 10." )
assert ( assert abs(result["Netzeinspeisung_Wh_pro_Stunde"][10] - 3946.93) < 1e-3, (
abs(result["Netzeinspeisung_Wh_pro_Stunde"][10] - 3946.93) < 1e-3 "'Netzeinspeisung_Wh_pro_Stunde[11]' should be 3946.93."
), "'Netzeinspeisung_Wh_pro_Stunde[11]' should be 3946.93." )
assert ( assert abs(result["Netzeinspeisung_Wh_pro_Stunde"][11] - 0.0) < 1e-3, (
abs(result["Netzeinspeisung_Wh_pro_Stunde"][11] - 0.0) < 1e-3 "'Netzeinspeisung_Wh_pro_Stunde[11]' should be 0.0."
), "'Netzeinspeisung_Wh_pro_Stunde[11]' should be 0.0." )
assert ( assert abs(result["akku_soc_pro_stunde"][20] - 10) < 1e-5, (
abs(result["akku_soc_pro_stunde"][20] - 10) < 1e-5 "'akku_soc_pro_stunde[20]' should be 10."
), "'akku_soc_pro_stunde[20]' should be 10." )
assert ( assert abs(result["Last_Wh_pro_Stunde"][20] - 6050.98) < 1e-3, (
abs(result["Last_Wh_pro_Stunde"][20] - 6050.98) < 1e-3 "'Last_Wh_pro_Stunde[20]' should be 6050.98."
), "'Last_Wh_pro_Stunde[20]' should be 6050.98." )
print("All tests passed successfully.") print("All tests passed successfully.")
@ -261,9 +261,9 @@ def test_set_parameters(create_ems_instance):
assert ems.load_energy_array is not None, "load_energy_array should not be None" assert ems.load_energy_array is not None, "load_energy_array should not be None"
assert ems.pv_prediction_wh is not None, "pv_prediction_wh should not be None" assert ems.pv_prediction_wh is not None, "pv_prediction_wh should not be None"
assert ems.elect_price_hourly is not None, "elect_price_hourly should not be None" assert ems.elect_price_hourly is not None, "elect_price_hourly should not be None"
assert ( assert ems.elect_revenue_per_hour_arr is not None, (
ems.elect_revenue_per_hour_arr is not None "elect_revenue_per_hour_arr should not be None"
), "elect_revenue_per_hour_arr should not be None" )
def test_set_akku_discharge_hours(create_ems_instance): def test_set_akku_discharge_hours(create_ems_instance):
@ -271,9 +271,9 @@ def test_set_akku_discharge_hours(create_ems_instance):
ems = create_ems_instance ems = create_ems_instance
discharge_hours = np.full(ems.config.prediction.hours, 1.0) discharge_hours = np.full(ems.config.prediction.hours, 1.0)
ems.set_akku_discharge_hours(discharge_hours) ems.set_akku_discharge_hours(discharge_hours)
assert np.array_equal( assert np.array_equal(ems.battery.discharge_array, discharge_hours), (
ems.battery.discharge_array, discharge_hours "Discharge hours should be set correctly"
), "Discharge hours should be set correctly" )
def test_set_akku_ac_charge_hours(create_ems_instance): def test_set_akku_ac_charge_hours(create_ems_instance):
@ -281,9 +281,9 @@ def test_set_akku_ac_charge_hours(create_ems_instance):
ems = create_ems_instance ems = create_ems_instance
ac_charge_hours = np.full(ems.config.prediction.hours, 1.0) ac_charge_hours = np.full(ems.config.prediction.hours, 1.0)
ems.set_akku_ac_charge_hours(ac_charge_hours) ems.set_akku_ac_charge_hours(ac_charge_hours)
assert np.array_equal( assert np.array_equal(ems.ac_charge_hours, ac_charge_hours), (
ems.ac_charge_hours, ac_charge_hours "AC charge hours should be set correctly"
), "AC charge hours should be set correctly" )
def test_set_akku_dc_charge_hours(create_ems_instance): def test_set_akku_dc_charge_hours(create_ems_instance):
@ -291,9 +291,9 @@ def test_set_akku_dc_charge_hours(create_ems_instance):
ems = create_ems_instance ems = create_ems_instance
dc_charge_hours = np.full(ems.config.prediction.hours, 1.0) dc_charge_hours = np.full(ems.config.prediction.hours, 1.0)
ems.set_akku_dc_charge_hours(dc_charge_hours) ems.set_akku_dc_charge_hours(dc_charge_hours)
assert np.array_equal( assert np.array_equal(ems.dc_charge_hours, dc_charge_hours), (
ems.dc_charge_hours, dc_charge_hours "DC charge hours should be set correctly"
), "DC charge hours should be set correctly" )
def test_set_ev_charge_hours(create_ems_instance): def test_set_ev_charge_hours(create_ems_instance):
@ -301,9 +301,9 @@ def test_set_ev_charge_hours(create_ems_instance):
ems = create_ems_instance ems = create_ems_instance
ev_charge_hours = np.full(ems.config.prediction.hours, 1.0) ev_charge_hours = np.full(ems.config.prediction.hours, 1.0)
ems.set_ev_charge_hours(ev_charge_hours) ems.set_ev_charge_hours(ev_charge_hours)
assert np.array_equal( assert np.array_equal(ems.ev_charge_hours, ev_charge_hours), (
ems.ev_charge_hours, ev_charge_hours "EV charge hours should be set correctly"
), "EV charge hours should be set correctly" )
def test_reset(create_ems_instance): def test_reset(create_ems_instance):
@ -311,9 +311,9 @@ def test_reset(create_ems_instance):
ems = create_ems_instance ems = create_ems_instance
ems.reset() ems.reset()
assert ems.ev.current_soc_percentage() == 100, "EV SOC should be reset to initial value" assert ems.ev.current_soc_percentage() == 100, "EV SOC should be reset to initial value"
assert ( assert ems.battery.current_soc_percentage() == 80, (
ems.battery.current_soc_percentage() == 80 "Battery SOC should be reset to initial value"
), "Battery SOC should be reset to initial value" )
def test_simulate_start_now(create_ems_instance): def test_simulate_start_now(create_ems_instance):

View File

@ -683,9 +683,9 @@ class TestDataProvider:
"""Test that DataProvider enforces singleton behavior.""" """Test that DataProvider enforces singleton behavior."""
instance1 = provider instance1 = provider
instance2 = DerivedDataProvider() instance2 = DerivedDataProvider()
assert ( assert instance1 is instance2, (
instance1 is instance2 "Singleton pattern is not enforced; instances are not the same."
), "Singleton pattern is not enforced; instances are not the same." )
def test_update_method_with_defaults(self, provider, sample_start_datetime, monkeypatch): def test_update_method_with_defaults(self, provider, sample_start_datetime, monkeypatch):
"""Test the `update` method with default parameters.""" """Test the `update` method with default parameters."""
@ -703,9 +703,9 @@ class TestDataProvider:
DerivedDataProvider.provider_updated = False DerivedDataProvider.provider_updated = False
provider.update_data(force_enable=True) provider.update_data(force_enable=True)
assert provider.enabled() is False, "Provider should be disabled, but enabled() is True." assert provider.enabled() is False, "Provider should be disabled, but enabled() is True."
assert ( assert DerivedDataProvider.provider_updated is True, (
DerivedDataProvider.provider_updated is True "Provider should have been executed, but was not."
), "Provider should have been executed, but was not." )
def test_delete_by_datetime(self, provider, sample_start_datetime): def test_delete_by_datetime(self, provider, sample_start_datetime):
"""Test `delete_by_datetime` method for removing records by datetime range.""" """Test `delete_by_datetime` method for removing records by datetime range."""
@ -720,12 +720,12 @@ class TestDataProvider:
start_datetime=sample_start_datetime - to_duration("2 hours"), start_datetime=sample_start_datetime - to_duration("2 hours"),
end_datetime=sample_start_datetime + to_duration("2 hours"), end_datetime=sample_start_datetime + to_duration("2 hours"),
) )
assert ( assert len(provider.records) == 1, (
len(provider.records) == 1 "Only one record should remain after deletion by datetime."
), "Only one record should remain after deletion by datetime." )
assert provider.records[0].date_time == sample_start_datetime - to_duration( assert provider.records[0].date_time == sample_start_datetime - to_duration("3 hours"), (
"3 hours" "Unexpected record remains."
), "Unexpected record remains." )
class TestDataImportProvider: class TestDataImportProvider:

View File

@ -151,9 +151,9 @@ class TestPredictionProvider:
"""Test that PredictionProvider enforces singleton behavior.""" """Test that PredictionProvider enforces singleton behavior."""
instance1 = provider instance1 = provider
instance2 = DerivedPredictionProvider() instance2 = DerivedPredictionProvider()
assert ( assert instance1 is instance2, (
instance1 is instance2 "Singleton pattern is not enforced; instances are not the same."
), "Singleton pattern is not enforced; instances are not the same." )
def test_update_computed_fields(self, provider, sample_start_datetime): def test_update_computed_fields(self, provider, sample_start_datetime):
"""Test that computed fields `end_datetime` and `keep_datetime` are correctly calculated.""" """Test that computed fields `end_datetime` and `keep_datetime` are correctly calculated."""
@ -169,12 +169,12 @@ class TestPredictionProvider:
provider.config.prediction.historic_hours * 3600 provider.config.prediction.historic_hours * 3600
) )
assert ( assert provider.end_datetime == expected_end_datetime, (
provider.end_datetime == expected_end_datetime "End datetime is not calculated correctly."
), "End datetime is not calculated correctly." )
assert ( assert provider.keep_datetime == expected_keep_datetime, (
provider.keep_datetime == expected_keep_datetime "Keep datetime is not calculated correctly."
), "Keep datetime is not calculated correctly." )
def test_update_method_with_defaults( def test_update_method_with_defaults(
self, provider, sample_start_datetime, config_eos, monkeypatch self, provider, sample_start_datetime, config_eos, monkeypatch
@ -209,9 +209,9 @@ class TestPredictionProvider:
DerivedPredictionProvider.provider_updated = False DerivedPredictionProvider.provider_updated = False
provider.update_data(force_enable=True) provider.update_data(force_enable=True)
assert provider.enabled() is False, "Provider should be disabled, but enabled() is True." assert provider.enabled() is False, "Provider should be disabled, but enabled() is True."
assert ( assert DerivedPredictionProvider.provider_updated is True, (
DerivedPredictionProvider.provider_updated is True "Provider should have been executed, but was not."
), "Provider should have been executed, but was not." )
def test_delete_by_datetime(self, provider, sample_start_datetime): def test_delete_by_datetime(self, provider, sample_start_datetime):
"""Test `delete_by_datetime` method for removing records by datetime range.""" """Test `delete_by_datetime` method for removing records by datetime range."""
@ -226,12 +226,12 @@ class TestPredictionProvider:
start_datetime=sample_start_datetime - to_duration("2 hours"), start_datetime=sample_start_datetime - to_duration("2 hours"),
end_datetime=sample_start_datetime + to_duration("2 hours"), end_datetime=sample_start_datetime + to_duration("2 hours"),
) )
assert ( assert len(provider.records) == 1, (
len(provider.records) == 1 "Only one record should remain after deletion by datetime."
), "Only one record should remain after deletion by datetime." )
assert provider.records[0].date_time == sample_start_datetime - to_duration( assert provider.records[0].date_time == sample_start_datetime - to_duration("3 hours"), (
"3 hours" "Unexpected record remains."
), "Unexpected record remains." )
class TestPredictionContainer: class TestPredictionContainer:

View File

@ -242,7 +242,7 @@ class TestServerStartStop:
# Windows does not provide SIGKILL # Windows does not provide SIGKILL
sigkill = signal.SIGTERM sigkill = signal.SIGTERM
else: else:
sigkill = signal.SIGKILL sigkill = signal.SIGKILL # type: ignore[attr-defined]
port = 8503 port = 8503
eosdash_port = 8504 eosdash_port = 8504
timeout = 120 timeout = 120