File: 0002-Fill-unknown-if-cpuinfo-module-is-not-supported-the-.patch

package info (click to toggle)
python-pyppmd 1.2.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,648 kB
  • sloc: ansic: 5,644; python: 1,604; makefile: 15
file content (42 lines) | stat: -rw-r--r-- 1,703 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
From: YOKOTA Hiroshi <yokota.hgml@gmail.com>
Date: Sat, 29 Jun 2024 11:24:07 +0900
Subject: Fill "unknown" if cpuinfo module is not supported the platform

---
 tests/conftest.py | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/tests/conftest.py b/tests/conftest.py
index 5b142cf..ad820a1 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -1,3 +1,7 @@
+try:
+    import cpuinfo
+except:
+    cpuinfo = None
 
 def pytest_benchmark_update_json(config, benchmarks, output_json):
     """Calculate compression/decompression speed and add as extra_info"""
@@ -8,11 +12,13 @@ def pytest_benchmark_update_json(config, benchmarks, output_json):
 
 
 def pytest_benchmark_update_machine_info(config, machine_info):
-    cpuinfo = pytest.importorskip("cpuinfo")
-
-    cpu_info = cpuinfo.get_cpu_info()
-    brand = cpu_info.get("brand_raw", None)
-    if brand is None:
-        brand = "{} core(s) {} CPU ".format(cpu_info.get("count", "unknown"), cpu_info.get("arch", "unknown"))
-    machine_info["cpu"]["brand"] = brand
-    machine_info["cpu"]["hz_actual_friendly"] = cpu_info.get("hz_actual_friendly", "unknown")
+    if cpuinfo is not None:
+        cpu_info = cpuinfo.get_cpu_info()
+        brand = cpu_info.get("brand_raw", None)
+        if brand is None:
+            brand = "{} core(s) {} CPU ".format(cpu_info.get("count", "unknown"), cpu_info.get("arch", "unknown"))
+            machine_info["cpu"]["brand"] = brand
+            machine_info["cpu"]["hz_actual_friendly"] = cpu_info.get("hz_actual_friendly", "unknown")
+    else:
+        machine_info["cpu"]["brand"] = "unknown"
+        machine_info["cpu"]["hz_actual_friendly"] = "unknown"