|
6 | 6 | (c) 2017 - 2025 Martin Pitt <martin@piware.de> |
7 | 7 | """ |
8 | 8 |
|
| 9 | +import fcntl |
| 10 | +import os |
9 | 11 | import re |
10 | 12 | import shutil |
11 | 13 | import subprocess |
@@ -42,6 +44,9 @@ def setUp(self): |
42 | 44 | self.addCleanup(self.p_mock.terminate) |
43 | 45 | self.addCleanup(self.p_mock.stdout.close) |
44 | 46 |
|
| 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 | + |
45 | 50 | def test_empty(self): |
46 | 51 | cmd = ["loginctl"] |
47 | 52 | if self.version >= "209": |
@@ -123,6 +128,17 @@ def test_inhibit(self): |
123 | 128 | out = subprocess.check_output(["systemd-inhibit"], text=True) |
124 | 129 | self.assertRegex(out, "No inhibitors|0 inhibitors listed") |
125 | 130 |
|
| 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 | + |
126 | 142 |
|
127 | 143 | if __name__ == "__main__": |
128 | 144 | # avoid writing to stderr |
|
0 commit comments