Skip to content

Commit 1aada8a

Browse files
committed
Fix tests
1 parent d167935 commit 1aada8a

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

tests/unit/test_ecoclient.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import pytest
33
import time
44
import pytest_mock
5-
5+
import pytest
66
import simvue.eco.api_client as sv_eco_api
77
import simvue.eco.emissions_monitor as sv_eco_ems
88

@@ -81,17 +81,15 @@ def test_co2_monitor_properties(mock_co2_signal) -> None:
8181
assert _ems_monitor.process_data["test_co2_monitor_properties"]
8282

8383
# Will use this equation
84-
# Power used = (TDP_cpu * cpu_percent / num_cores) + (TDP_gpu * gpu_percent)
85-
assert _ems_monitor.total_power_usage == (80 * 0.2 * 1 / 4) + (130 * 0.4 * 1)
84+
# Power used = (TDP_cpu * cpu_percent / num_cores) + (TDP_gpu * gpu_percent) / 1000 (for kW)
85+
assert _ems_monitor.total_power_usage == pytest.approx(((80 * 0.2 * 1 / 4) + (130 * 0.4 * 1)) / 1000)
8686

87-
# Energy used = power used * measure interval
88-
assert _ems_monitor.total_energy == _ems_monitor.total_power_usage * 2
87+
# Energy used = power used * measure interval / 3600 (for kWh)
88+
assert _ems_monitor.total_energy == pytest.approx(_ems_monitor.total_power_usage * 2 / 3600)
8989

9090
# CO2 emission = energy * CO2 intensity
91-
# Need to convert CO2 intensity from g/kWh to kg/kWs
92-
# So divide by 1000 (g -> kg)
93-
# And divide by 60*60 (kWh -> kws)
94-
assert _ems_monitor.total_co2_emission == _ems_monitor.total_energy * 40 / (60*60*1000)
91+
# Need to convert CO2 intensity from g/kWh to kg/kWh, so divide by 1000
92+
assert _ems_monitor.total_co2_emission == pytest.approx(_ems_monitor.total_energy * 40 / 1000)
9593

9694
_ems_monitor.estimate_co2_emissions(**_measure_params)
9795
# Check delta is half of total, since we've now called this twice

0 commit comments

Comments
 (0)