diff --git a/psutil/tests/test_linux.py b/psutil/tests/test_linux.py index 55839a1ba..58de4a1cb 100755 --- a/psutil/tests/test_linux.py +++ b/psutil/tests/test_linux.py @@ -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() diff --git a/psutil/tests/test_memleaks.py b/psutil/tests/test_memleaks.py index cd1b3f290..ec0866158 100755 --- a/psutil/tests/test_memleaks.py +++ b/psutil/tests/test_memleaks.py @@ -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