stupidcache / psutil

Automatically exported from code.google.com/p/psutil
Other
0 stars 0 forks source link

test_cpu_times fails with Linux >=3.10 #420

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
======================================================================
ERROR: test_cpu_times (_linux.LinuxSpecificTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/psutil/test/_linux.py", line 123, in test_cpu_times
    kernel_ver = re.findall('\d.\d.\d', os.uname()[2])[0]
IndexError: list index out of range

----------------------------------------------------------------------

os.uname()[2] is a string starting with e.g. '3.10.9'.

>>> re.findall('\d.\d.\d', '3.10.9')
[]

Truncation of version number is also possible for older Linux versions:

>>> re.findall('\d.\d.\d', '3.9.11')
['3.9.1']

Original issue reported on code.google.com by Arfrever...@gmail.com on 23 Aug 2013 at 2:03

GoogleCodeExporter commented 9 years ago
Fix:

--- test/_linux.py
+++ test/_linux.py
@@ -120,7 +120,7 @@

     def test_cpu_times(self):
         fields = psutil.cpu_times()._fields
-        kernel_ver = re.findall('\d.\d.\d', os.uname()[2])[0]
+        kernel_ver = re.findall('\d+.\d+.\d+', os.uname()[2])[0]
         kernel_ver_info = tuple(map(int, kernel_ver.split('.')))
         # steal >= 2.6.11
         # guest >= 2.6.24

Original comment by Arfrever...@gmail.com on 23 Aug 2013 at 2:07

GoogleCodeExporter commented 9 years ago
Actually '.' also should be escaped:

--- test/_linux.py
+++ test/_linux.py
@@ -120,7 +120,7 @@

     def test_cpu_times(self):
         fields = psutil.cpu_times()._fields
-        kernel_ver = re.findall('\d.\d.\d', os.uname()[2])[0]
+        kernel_ver = re.findall('\d+\.\d+\.\d+', os.uname()[2])[0]
         kernel_ver_info = tuple(map(int, kernel_ver.split('.')))
         # steal >= 2.6.11
         # guest >= 2.6.24

Original comment by Arfrever...@gmail.com on 23 Aug 2013 at 2:09

GoogleCodeExporter commented 9 years ago
Pushed in revision 25339c50d117. Thanks.

Original comment by g.rodola on 24 Aug 2013 at 5:56