|
10 | 10 | from codecarbon.core.config import normalize_gpu_ids |
11 | 11 | from codecarbon.core.cpu import ( |
12 | 12 | DEFAULT_POWER_PER_CORE, |
| 13 | + TDP, |
| 14 | + IntelPowerGadget, |
| 15 | + IntelRAPL, |
13 | 16 | _check_energy_file, |
14 | 17 | _get_candidate_bases, |
15 | 18 | _is_main_domain, |
16 | 19 | _scan_base_for_rapl, |
17 | 20 | _scan_direct_entries, |
18 | 21 | _scan_domain_directories, |
19 | | - TDP, |
20 | | - IntelPowerGadget, |
21 | | - IntelRAPL, |
22 | 22 | is_powergadget_available, |
23 | | - is_rapl_available, |
24 | 23 | is_psutil_available, |
| 24 | + is_rapl_available, |
25 | 25 | ) |
26 | 26 | from codecarbon.core.resource_tracker import ResourceTracker |
27 | 27 | from codecarbon.core.units import Energy, Power, Time |
|
32 | 32 |
|
33 | 33 | class TestCPU(unittest.TestCase): |
34 | 34 | @mock.patch("codecarbon.core.cpu.IntelPowerGadget", side_effect=Exception("boom")) |
35 | | - def test_is_powergadget_available_returns_false_on_exception(self, mock_powergadget): |
| 35 | + def test_is_powergadget_available_returns_false_on_exception( |
| 36 | + self, mock_powergadget |
| 37 | + ): |
36 | 38 | self.assertFalse(is_powergadget_available()) |
37 | 39 |
|
38 | 40 | @mock.patch("psutil.cpu_times") |
@@ -141,19 +143,21 @@ def test_scan_base_for_rapl_checks_direct_entries_fallback(self): |
141 | 143 | with ( |
142 | 144 | mock.patch("codecarbon.core.cpu.os.listdir", return_value=["intel-rapl:0"]), |
143 | 145 | mock.patch("codecarbon.core.cpu.os.path.isdir", return_value=False), |
144 | | - mock.patch("codecarbon.core.cpu._scan_domain_directories", return_value=False), |
| 146 | + mock.patch( |
| 147 | + "codecarbon.core.cpu._scan_domain_directories", return_value=False |
| 148 | + ), |
145 | 149 | mock.patch("codecarbon.core.cpu._scan_direct_entries", return_value=True), |
146 | 150 | ): |
147 | 151 | assert _scan_base_for_rapl("/tmp/base", lambda _: None) is True |
148 | 152 |
|
149 | 153 | @mock.patch("codecarbon.core.cpu._scan_base_for_rapl", side_effect=[False, True]) |
150 | 154 | @mock.patch("codecarbon.core.cpu._get_candidate_bases", return_value=["a", "b"]) |
151 | | - def test_is_rapl_available_scans_candidate_bases( |
152 | | - self, mock_candidates, mock_scan |
153 | | - ): |
| 155 | + def test_is_rapl_available_scans_candidate_bases(self, mock_candidates, mock_scan): |
154 | 156 | assert is_rapl_available("/tmp/custom") is True |
155 | 157 |
|
156 | | - @mock.patch("codecarbon.core.cpu._scan_base_for_rapl", side_effect=Exception("boom")) |
| 158 | + @mock.patch( |
| 159 | + "codecarbon.core.cpu._scan_base_for_rapl", side_effect=Exception("boom") |
| 160 | + ) |
157 | 161 | @mock.patch("codecarbon.core.cpu._get_candidate_bases", return_value=["a"]) |
158 | 162 | def test_is_rapl_available_returns_false_on_unexpected_error( |
159 | 163 | self, mock_candidates, mock_scan |
@@ -221,9 +225,7 @@ def test_setup_cli_uses_windows_backup_when_primary_missing(self): |
221 | 225 | ), |
222 | 226 | mock.patch( |
223 | 227 | "codecarbon.core.cpu.shutil.which", |
224 | | - side_effect=lambda path: None |
225 | | - if path == "PowerLog3.0.exe" |
226 | | - else path, |
| 228 | + side_effect=lambda path: None if path == "PowerLog3.0.exe" else path, |
227 | 229 | ), |
228 | 230 | ): |
229 | 231 | gadget = IntelPowerGadget() |
@@ -269,7 +271,9 @@ def test_log_values_warns_on_nonzero_returncode_windows(self): |
269 | 271 | gadget._log_file_path = "intel.csv" |
270 | 272 |
|
271 | 273 | with ( |
272 | | - mock.patch("codecarbon.core.cpu.subprocess.call", return_value=1) as mock_call, |
| 274 | + mock.patch( |
| 275 | + "codecarbon.core.cpu.subprocess.call", return_value=1 |
| 276 | + ) as mock_call, |
273 | 277 | mock.patch("codecarbon.core.cpu.logger.warning") as mock_warning, |
274 | 278 | ): |
275 | 279 | gadget._log_values() |
|
0 commit comments