diff options
author | Benjamin Berg <bberg@redhat.com> | 2018-01-04 15:46:01 +0100 |
---|---|---|
committer | Benjamin Berg <bberg@redhat.com> | 2018-01-15 15:00:22 +0100 |
commit | 450a9361915ad08ee5716f65d7858683e2c160e5 (patch) | |
tree | 073a01d0721c8d8c5ed9d8712751b1fa44d5f31c /plugins/power/test.py | |
parent | 9701a4a71295ff5737e279add19b32b944b4500c (diff) | |
download | gnome-settings-daemon-450a9361915ad08ee5716f65d7858683e2c160e5.tar.gz |
power: Add helper to read plugin log during test
Add a generic helper to find needles in the gsd-power plugin log.
https://bugzilla.gnome.org/show_bug.cgi?id=792210
Diffstat (limited to 'plugins/power/test.py')
-rwxr-xr-x | plugins/power/test.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/plugins/power/test.py b/plugins/power/test.py index 938064f6..b88adc64 100755 --- a/plugins/power/test.py +++ b/plugins/power/test.py @@ -291,6 +291,31 @@ class PowerPluginTest(gsdtestcase.GSDTestCase): self.assertTrue(b' Suspend' in log, 'missing Suspend request') self.assertFalse(b' Hibernate' in log, 'unexpected Hibernate request') + def check_plugin_log(self, needle, timeout=0, failmsg=None): + '''Check that needle is found in the log within the given timeout. + Returns immediately when found. + + Fail after the given timeout. + ''' + # Fast path if the message was already logged + log = self.plugin_log.read() + if needle in log: + return + + while timeout > 0: + time.sleep(0.5) + timeout -= 0.5 + + # read new data (lines) from the log + log = self.plugin_log.read() + if needle in log: + break + else: + if failmsg is not None: + self.fail(failmsg) + else: + self.fail('timed out waiting for needle "%s"' % needle) + def check_no_dim(self, seconds): '''Check that mode is not set to dim in the given time''' |