Skip to content

Commit 014e239

Browse files
authored
Merge pull request mlco2#920 from cianc/test/fix-gpu-and-cpu-tests-for-mac
Fix two gpu and cpu tests for mac
2 parents 8b794a1 + 6220f31 commit 014e239

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

tests/test_cpu_load.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from codecarbon.core.units import Power
66
from codecarbon.emissions_tracker import OfflineEmissionsTracker
7-
from codecarbon.external.hardware import CPU, MODE_CPU_LOAD
7+
from codecarbon.external.hardware import CPU, MODE_CPU_LOAD, AppleSiliconChip
88

99

1010
@mock.patch("codecarbon.core.cpu.is_psutil_available", return_value=True)
@@ -57,7 +57,9 @@ def test_cpu_load_detection(
5757
):
5858
tracker = OfflineEmissionsTracker(country_iso_code="FRA")
5959
for hardware in tracker._hardware:
60-
if isinstance(hardware, CPU) and hardware._mode == MODE_CPU_LOAD:
60+
if (
61+
isinstance(hardware, CPU) and hardware._mode == MODE_CPU_LOAD
62+
) or isinstance(hardware, AppleSiliconChip):
6163
break
6264
else:
6365
raise Exception("No CPU load !!!")

tests/test_unsupported_gpu.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import sys
23
import unittest
34
from unittest.mock import MagicMock, patch
45

@@ -18,6 +19,10 @@ def tearDown(self):
1819
if os.path.exists(self.output_csv):
1920
os.remove(self.output_csv)
2021

22+
# If we run this on macOS, NVMLError_NotSupported has no effect
23+
# and we end up with non-zero values for GPU energy and power because
24+
# we use the non-NVML code-path in hardware.AppleSiliconChip().
25+
@unittest.skipIf(sys.platform == "darwin", "NVML not available on macOS")
2126
@patch("codecarbon.core.gpu.pynvml")
2227
def test_emissions_tracker_unsupported_gpu(self, mock_pynvml):
2328
mock_pynvml.NVMLError_NotSupported = self.NVMLError_NotSupported

0 commit comments

Comments
 (0)