File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44
55from codecarbon .core .units import Power
66from 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 !!!" )
Original file line number Diff line number Diff line change 11import os
2+ import sys
23import unittest
34from 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
You can’t perform that action at this time.
0 commit comments