Skip to content

Commit a08c13f

Browse files
committed
logind: Add SetWallMessage
`systemctl suspend` and friends call this. Add a test case.
1 parent a289b4b commit a08c13f

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

dbusmock/templates/logind.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def load(mock, parameters):
5858
("GetUser", "u", "o", 'ret = "/org/freedesktop/login1/user/" + args[0]'),
5959
("KillUser", "us", "", ""),
6060
("TerminateUser", "u", "", ""),
61+
("SetWallMessage", "sb", "", ""),
6162
],
6263
)
6364

tests/test_logind.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
(c) 2017 - 2025 Martin Pitt <martin@piware.de>
77
"""
88

9+
import fcntl
10+
import os
911
import re
1012
import shutil
1113
import subprocess
@@ -42,6 +44,9 @@ def setUp(self):
4244
self.addCleanup(self.p_mock.terminate)
4345
self.addCleanup(self.p_mock.stdout.close)
4446

47+
flags = fcntl.fcntl(self.p_mock.stdout, fcntl.F_GETFL)
48+
fcntl.fcntl(self.p_mock.stdout, fcntl.F_SETFL, flags | os.O_NONBLOCK)
49+
4550
def test_empty(self):
4651
cmd = ["loginctl"]
4752
if self.version >= "209":
@@ -123,6 +128,17 @@ def test_inhibit(self):
123128
out = subprocess.check_output(["systemd-inhibit"], text=True)
124129
self.assertRegex(out, "No inhibitors|0 inhibitors listed")
125130

131+
def test_suspend(self):
132+
(p_mock_polkit, _obj_polkitd) = self.spawn_server_template("polkitd", {}, stdout=subprocess.DEVNULL)
133+
self.addCleanup(p_mock_polkit.wait)
134+
self.addCleanup(p_mock_polkit.terminate)
135+
136+
subprocess.check_call(["systemctl", "suspend"])
137+
138+
log = self.p_mock.stdout.read().decode()
139+
self.assertIn('SetWallMessage "" True', log)
140+
self.assertIn("Suspend True", log)
141+
126142

127143
if __name__ == "__main__":
128144
# avoid writing to stderr

0 commit comments

Comments
 (0)