commit
534b0434f3
|
@ -517,8 +517,14 @@ try:
|
|||
if data:
|
||||
yield interface, data.bytes_recv, data.bytes_sent
|
||||
|
||||
def _get_user(segment_info):
|
||||
return psutil.Process(os.getpid()).username
|
||||
# psutil-2.0.0: psutil.Process.username is unbound method
|
||||
if callable(psutil.Process.username):
|
||||
def _get_user(segment_info):
|
||||
return psutil.Process(os.getpid()).username()
|
||||
# pre psutil-2.0.0: psutil.Process.username has type property
|
||||
else:
|
||||
def _get_user(segment_info):
|
||||
return psutil.Process(os.getpid()).username
|
||||
|
||||
class CPULoadPercentSegment(ThreadedSegment):
|
||||
interval = 1
|
||||
|
|
|
@ -169,7 +169,18 @@ class TestCommon(TestCase):
|
|||
|
||||
def test_user(self):
|
||||
new_os = new_module('os', getpid=lambda: 1)
|
||||
new_psutil = new_module('psutil', Process=lambda pid: Args(username='def'))
|
||||
|
||||
class Process(object):
|
||||
def __init__(self, pid):
|
||||
pass
|
||||
|
||||
def username(self):
|
||||
return 'def'
|
||||
|
||||
if hasattr(common, 'psutil') and not callable(common.psutil.Process.username):
|
||||
username = property(username)
|
||||
|
||||
new_psutil = new_module('psutil', Process=Process)
|
||||
pl = Pl()
|
||||
with replace_env('USER', 'def') as segment_info:
|
||||
common.username = False
|
||||
|
|
Loading…
Reference in New Issue