Skip to content

Commit e26f343

Browse files
committed
test(RAM): ✅ fix tests
1 parent 9591940 commit e26f343

3 files changed

Lines changed: 4 additions & 2 deletions

File tree

codecarbon/core/resource_tracker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def set_CPU_tracking(self):
4141
logger.info("[setup] CPU Tracking...")
4242
cpu_number = self.tracker._conf.get("cpu_physical_count")
4343
tdp = cpu.TDP()
44-
max_power = tdp.tdp * cpu_number
44+
max_power = tdp.tdp * cpu_number if tdp.tdp is not None else None
4545
if self.tracker._conf.get("force_mode_cpu_load", False) and tdp.tdp is not None:
4646
if tdp.tdp is None:
4747
logger.warning(

codecarbon/core/util.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ def count_physical_cpus():
127127
for line in output.split("\n"):
128128
if "Socket(s):" in line:
129129
return int(line.split(":")[1].strip())
130+
return 1
130131
except Exception as e:
131132
logger.warning(
132133
f"Error while trying to count physical CPUs: {e}. Defaulting to 1."

tests/test_emissions_tracker_constant.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def test_carbon_tracker_offline_constant(self):
6666
@mock.patch.object(cpu.TDP, "_get_cpu_power_from_registry")
6767
@mock.patch.object(cpu, "is_psutil_available")
6868
def test_carbon_tracker_offline_constant_default_cpu_power(
69-
self, mock_tdp, mock_psutil
69+
self, mock_psutil, mock_tdp
7070
):
7171
# Same as test_carbon_tracker_offline_constant test but this time forcing the default cpu power
7272
USER_INPUT_CPU_POWER = 1_000
@@ -78,6 +78,7 @@ def test_carbon_tracker_offline_constant_default_cpu_power(
7878
output_dir=self.emissions_path,
7979
output_file=self.emissions_file,
8080
default_cpu_power=USER_INPUT_CPU_POWER,
81+
allow_multiple_runs=True,
8182
)
8283
tracker.start()
8384
heavy_computation(run_time_secs=1)

0 commit comments

Comments
 (0)