diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2021-04-21 09:02:40 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2021-04-22 10:02:46 +1000 |
commit | 1557668364496ecd724d8f80f915e0c9d6be803e (patch) | |
tree | 3cc47d7c42e6113457e55249567329e04a88b2b0 /test | |
parent | f60bdb1680650a131e8e21ffa4a8a16775a35c9f (diff) | |
download | xorg-lib-libxkbcommon-1557668364496ecd724d8f80f915e0c9d6be803e.tar.gz |
test: allow skipping errors in certain conditions
Add a skipError test function that can analyse rc, stdout, stderr to skip a test
even when we expect an error. We use that to skip if we couldn't find a keyboard
in the interactive-evdev test.
Fixes #235
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'test')
-rwxr-xr-x | test/tool-option-parsing.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/test/tool-option-parsing.py b/test/tool-option-parsing.py index 4fc4490..9517ea8 100755 --- a/test/tool-option-parsing.py +++ b/test/tool-option-parsing.py @@ -76,10 +76,11 @@ class XkbcliTool: xkbcli_tool = 'xkbcli' subtool = None - def __init__(self, subtool=None, skipIf=()): + def __init__(self, subtool=None, skipIf=(), skipError=()): self.tool_path = top_builddir self.subtool = subtool self.skipIf = skipIf + self.skipError = skipError def run_command(self, args): for condition, reason in self.skipIf: @@ -95,6 +96,10 @@ class XkbcliTool: def run_command_success(self, args): rc, stdout, stderr = self.run_command(args) + if rc != 0: + for testfunc, reason in self.skipError: + if testfunc(rc, stdout, stderr): + raise unittest.SkipTest(reason) assert rc == 0, (stdout, stderr) return stdout, stderr @@ -132,7 +137,11 @@ class TestXkbcli(unittest.TestCase): (not int(os.getenv('HAVE_XKBCLI_INTERACTIVE_EVDEV', '1')), 'evdev not enabled'), (not os.path.exists('/dev/input/event0'), 'event node required'), (not os.access('/dev/input/event0', os.R_OK), 'insufficient permissions'), - )) + ), skipError=( + (lambda rc, stdout, stderr: 'Couldn\'t find any keyboards' in stderr, + 'No keyboards available'), + ), + ) cls.xkbcli_interactive_x11 = XkbcliTool('interactive-x11', skipIf=( (not int(os.getenv('HAVE_XKBCLI_INTERACTIVE_X11', '1')), 'x11 not enabled'), (not os.getenv('DISPLAY'), 'DISPLAY not set'), |