Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_cpu_times fails with Linux >=3.10 #420

Closed
giampaolo opened this issue May 23, 2014 · 3 comments
Closed

test_cpu_times fails with Linux >=3.10 #420

giampaolo opened this issue May 23, 2014 · 3 comments

Comments

@giampaolo
Copy link
Owner

From Arfrever...@gmail.com on August 23, 2013 04:03:30

======================================================================
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: http://code.google.com/p/psutil/issues/detail?id=420

@giampaolo
Copy link
Owner Author

From Arfrever...@gmail.com on August 22, 2013 19:07:30

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

@giampaolo
Copy link
Owner Author

From Arfrever...@gmail.com on August 22, 2013 19:09:20

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

@giampaolo
Copy link
Owner Author

From g.rodola on August 24, 2013 10:56:25

Pushed in revision 25339c50d117 . Thanks.

Status: Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant