Skip to content

Commit

Permalink
fix failing test
Browse files Browse the repository at this point in the history
Signed-off-by: Giampaolo Rodola <[email protected]>
  • Loading branch information
giampaolo committed Oct 23, 2023
1 parent 48d50e7 commit c7a60cb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
36 changes: 19 additions & 17 deletions psutil/tests/test_linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -1513,25 +1513,27 @@ def test_boot_time_mocked(self):
psutil._pslinux.boot_time)
assert m.called

def test_users_mocked(self):
def test_users_utmp_mocked(self):
# Make sure ':0' and ':0.0' (returned by C ext) are converted
# to 'localhost'.
with mock.patch('psutil._pslinux.cext.users',
return_value=[('giampaolo', 'pts/2', ':0',
1436573184.0, True, 2)]) as m:
self.assertEqual(psutil.users()[0].host, 'localhost')
assert m.called
with mock.patch('psutil._pslinux.cext.users',
return_value=[('giampaolo', 'pts/2', ':0.0',
1436573184.0, True, 2)]) as m:
self.assertEqual(psutil.users()[0].host, 'localhost')
assert m.called
# ...otherwise it should be returned as-is
with mock.patch('psutil._pslinux.cext.users',
return_value=[('giampaolo', 'pts/2', 'foo',
1436573184.0, True, 2)]) as m:
self.assertEqual(psutil.users()[0].host, 'foo')
assert m.called
with mock.patch('psutil._pslinux.cext.users_systemd',
return_value=None):
with mock.patch('psutil._pslinux.cext.users_utmp',
return_value=[('giampaolo', 'pts/2', ':0',
1436573184.0, True, 2)]) as m:
self.assertEqual(psutil.users()[0].host, 'localhost')
assert m.called
with mock.patch('psutil._pslinux.cext.users_utmp',
return_value=[('giampaolo', 'pts/2', ':0.0',
1436573184.0, True, 2)]) as m:
self.assertEqual(psutil.users()[0].host, 'localhost')
assert m.called
# ...otherwise it should be returned as-is
with mock.patch('psutil._pslinux.cext.users_utmp',
return_value=[('giampaolo', 'pts/2', 'foo',
1436573184.0, True, 2)]) as m:
self.assertEqual(psutil.users()[0].host, 'foo')
assert m.called

def test_procfs_path(self):
tdir = self.get_testfn()
Expand Down
8 changes: 8 additions & 0 deletions psutil/tests/test_memleaks.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,14 @@ def test_win_service_get_description(self):
name = next(psutil.win_service_iter()).name()
self.execute(lambda: cext.winservice_query_descr(name))

if LINUX:

def test_users_systemd(self):
self.execute(cext.users_systemd)

def test_users_utmp(self):
self.execute(cext.users_utmp)


if __name__ == '__main__':
from psutil.tests.runner import run_from_name
Expand Down

0 comments on commit c7a60cb

Please sign in to comment.