File tree Expand file tree Collapse file tree 1 file changed +7
-9
lines changed Expand file tree Collapse file tree 1 file changed +7
-9
lines changed Original file line number Diff line number Diff line change 2
2
import pytest
3
3
import time
4
4
import pytest_mock
5
-
5
+ import pytest
6
6
import simvue .eco .api_client as sv_eco_api
7
7
import simvue .eco .emissions_monitor as sv_eco_ems
8
8
@@ -81,17 +81,15 @@ def test_co2_monitor_properties(mock_co2_signal) -> None:
81
81
assert _ems_monitor .process_data ["test_co2_monitor_properties" ]
82
82
83
83
# 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 )
86
86
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 )
89
89
90
90
# 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 )
95
93
96
94
_ems_monitor .estimate_co2_emissions (** _measure_params )
97
95
# Check delta is half of total, since we've now called this twice
You can’t perform that action at this time.
0 commit comments