From baba13f05fd6920908c5ea912a965906481a3374 Mon Sep 17 00:00:00 2001
From: Peter Hutterer <peter.hutterer@who-t.net>
Date: Thu, 12 Mar 2020 07:33:06 +1000
Subject: [PATCH] test: skip local device tests if we don't have local devices

These break when running offa custom VM that may not have any local devices at
all.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
---
 test/test_clib.py | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/test/test_clib.py b/test/test_clib.py
index 20e782e..ba34d34 100644
--- a/test/test_clib.py
+++ b/test/test_clib.py
@@ -2,6 +2,7 @@ import os
 import unittest
 import ctypes
 from libevdev._clib import Libevdev, UinputDevice
+from pathlib import Path
 
 # Note: these tests test for the correct functioning of the python bindings,
 # not of libevdev underneath. Some ranges are hardcoded for simplicity, e.g.
@@ -13,6 +14,10 @@ def is_root():
     return os.getuid() == 0
 
 
+def has_event_devices():
+    return list(Path('/dev/input/').glob('event*'))
+
+
 class TestNameConversion(unittest.TestCase):
 
     def test_type_max(self):
@@ -225,6 +230,7 @@ class TestLibevdevDevice(unittest.TestCase):
         self.assertEqual(id["version"], 5)
 
 
+@unittest.skipUnless(has_event_devices(), 'Local event devices required')
 class TestRealDevice(unittest.TestCase):
     """
     Tests various things against /dev/input/event3 which is usually the
@@ -492,6 +498,7 @@ class TestAbsDevice(unittest.TestCase):
         self.assertTrue(dev.has_property("INPUT_PROP_ACCELEROMETER"))
 
 
+@unittest.skipUnless(has_event_devices(), 'Local event devices required')
 class TestMTDevice(unittest.TestCase):
     """
     Tests various things against the first MT device found.
@@ -530,6 +537,7 @@ class TestMTDevice(unittest.TestCase):
 
     @unittest.skipUnless(is_root(), 'Test requires root')
     def test_slot_value(self):
+
         dev = Libevdev(self.fd)
         a = dev.absinfo("ABS_MT_POSITION_X")
         v = dev.slot_value(dev.current_slot, "ABS_MT_POSITION_X")
-- 
GitLab