gvalkov / python-evdev

Python bindings for the Linux input subsystem
https://python-evdev.rtfd.org/
BSD 3-Clause "New" or "Revised" License
320 stars 108 forks source link

1.4.0: test suite is failing #153

Open kloczek opened 3 years ago

kloczek commented 3 years ago

Both setuptools and pytest based.

+ /usr/bin/python3 setup.py test
running test
WARNING: Testing via this command is deprecated and will be removed in a future version. Users looking for a generic test entry point independent of test runner are encouraged to use tox.
running egg_info
writing evdev.egg-info/PKG-INFO
writing dependency_links to evdev.egg-info/dependency_links.txt
writing top-level names to evdev.egg-info/top_level.txt
reading manifest file 'evdev.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'evdev.egg-info/SOURCES.txt'
running build_ext
ecodes.c already exists ... skipping build_ecodes
copying build/lib.linux-x86_64-3.8/evdev/_input.cpython-38-x86_64-linux-gnu.so -> evdev
copying build/lib.linux-x86_64-3.8/evdev/_uinput.cpython-38-x86_64-linux-gnu.so -> evdev
copying build/lib.linux-x86_64-3.8/evdev/_ecodes.cpython-38-x86_64-linux-gnu.so -> evdev
no input macros found in: test
+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-evdev-1.4.0-2.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-evdev-1.4.0-2.fc35.x86_64/usr/lib/python3.8/site-packages
+ /usr/bin/python3 -Bm pytest -ra
=========================================================================== test session starts ============================================================================
platform linux -- Python 3.8.9, pytest-6.2.3, py-1.10.0, pluggy-0.13.1
rootdir: /home/tkloczko/rpmbuild/BUILD/python-evdev-1.4.0
plugins: forked-1.3.0, shutil-1.7.0, virtualenv-1.7.0, asyncio-0.14.0, expect-1.1.0, cov-2.11.1, mock-3.5.1, httpbin-1.0.0, xdist-2.2.1, flake8-1.0.7, timeout-1.4.2, betamax-0.8.1, pyfakefs-4.4.0, freezegun-0.4.2, flaky-3.7.0, cases-3.4.6, hypothesis-6.9.2
collected 0 items / 4 errors

================================================================================== ERRORS ==================================================================================
__________________________________________________________________ ERROR collecting tests/test_ecodes.py ___________________________________________________________________
ImportError while importing test module '/home/tkloczko/rpmbuild/BUILD/python-evdev-1.4.0/tests/test_ecodes.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib64/python3.8/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/test_ecodes.py:3: in <module>
    from evdev import ecodes
evdev/__init__.py:5: in <module>
    from evdev.device import DeviceInfo, InputDevice, AbsInfo, EvdevError
evdev/device.py:9: in <module>
    from evdev import _input, ecodes, util
evdev/ecodes.py:44: in <module>
    from evdev import _ecodes
E   ImportError: cannot import name '_ecodes' from partially initialized module 'evdev' (most likely due to a circular import) (/home/tkloczko/rpmbuild/BUILD/python-evdev-1.4.0/evdev/__init__.py)
__________________________________________________________________ ERROR collecting tests/test_events.py ___________________________________________________________________
ImportError while importing test module '/home/tkloczko/rpmbuild/BUILD/python-evdev-1.4.0/tests/test_events.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib64/python3.8/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/test_events.py:3: in <module>
    from evdev import events, ecodes, util
evdev/__init__.py:5: in <module>
    from evdev.device import DeviceInfo, InputDevice, AbsInfo, EvdevError
evdev/device.py:9: in <module>
    from evdev import _input, ecodes, util
evdev/ecodes.py:44: in <module>
    from evdev import _ecodes
E   ImportError: cannot import name '_ecodes' from partially initialized module 'evdev' (most likely due to a circular import) (/home/tkloczko/rpmbuild/BUILD/python-evdev-1.4.0/evdev/__init__.py)
__________________________________________________________________ ERROR collecting tests/test_uinput.py ___________________________________________________________________
ImportError while importing test module '/home/tkloczko/rpmbuild/BUILD/python-evdev-1.4.0/tests/test_uinput.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib64/python3.8/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/test_uinput.py:6: in <module>
    from evdev import uinput, ecodes, events, device, util
evdev/__init__.py:5: in <module>
    from evdev.device import DeviceInfo, InputDevice, AbsInfo, EvdevError
evdev/device.py:9: in <module>
    from evdev import _input, ecodes, util
evdev/ecodes.py:44: in <module>
    from evdev import _ecodes
E   ImportError: cannot import name '_ecodes' from partially initialized module 'evdev' (most likely due to a circular import) (/home/tkloczko/rpmbuild/BUILD/python-evdev-1.4.0/evdev/__init__.py)
___________________________________________________________________ ERROR collecting tests/test_util.py ____________________________________________________________________
ImportError while importing test module '/home/tkloczko/rpmbuild/BUILD/python-evdev-1.4.0/tests/test_util.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib64/python3.8/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/test_util.py:1: in <module>
    from evdev import util
evdev/__init__.py:5: in <module>
    from evdev.device import DeviceInfo, InputDevice, AbsInfo, EvdevError
evdev/device.py:9: in <module>
    from evdev import _input, ecodes, util
evdev/ecodes.py:44: in <module>
    from evdev import _ecodes
E   ImportError: cannot import name '_ecodes' from partially initialized module 'evdev' (most likely due to a circular import) (/home/tkloczko/rpmbuild/BUILD/python-evdev-1.4.0/evdev/__init__.py)
========================================================================= short test summary info ==========================================================================
ERROR tests/test_ecodes.py
ERROR tests/test_events.py
ERROR tests/test_uinput.py
ERROR tests/test_util.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 4 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
============================================================================ 4 errors in 0.31s =============================================================================
kloczek commented 2 years ago

After fixing issue with importing module I have fails because no write permission to /dev/uinput. Do I have wrong perm on that device file?

+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-evdev-1.4.0-2.1.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-evdev-1.4.0-2.1.fc35.x86_64/usr/lib/python3.8/site-packages
+ /usr/bin/pytest -ra
=========================================================================== test session starts ============================================================================
platform linux -- Python 3.8.11, pytest-6.2.5, py-1.10.0, pluggy-0.13.1
benchmark: 3.4.1 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)
Using --randomly-seed=1338524622
rootdir: /home/tkloczko/rpmbuild/BUILD/python-evdev-1.4.0
plugins: forked-1.3.0, shutil-1.7.0, virtualenv-1.7.0, expect-1.1.0, flake8-1.0.7, timeout-1.4.2, betamax-0.8.1, freezegun-0.4.2, aspectlib-1.5.2, toolbox-0.5, rerunfailures-9.1.1, requests-mock-1.9.3, cov-2.12.1, flaky-3.7.0, benchmark-3.4.1, xdist-2.3.0, pylama-7.7.1, datadir-1.3.1, regressions-2.2.0, cases-3.6.3, xprocess-0.18.1, black-0.3.12, anyio-3.3.0, asyncio-0.15.1, trio-0.7.0, subtests-0.5.0, isort-2.0.0, hypothesis-6.14.6, mock-3.6.1, profiling-1.7.0, randomly-3.8.0, Faker-8.12.1, nose2pytest-1.0.8, pyfakefs-4.5.1, tornado-0.8.1
collected 12 items

tests/test_ecodes.py ...                                                                                                                                             [ 25%]
tests/test_uinput.py FFF.FF                                                                                                                                          [ 75%]
tests/test_util.py .                                                                                                                                                 [ 83%]
tests/test_events.py ..                                                                                                                                              [100%]

================================================================================= FAILURES =================================================================================
_____________________________________________________________________________ test_abs_values ______________________________________________________________________________

c = {'bustype': 3, 'events': {1: [30, 48], 3: [(0, (0, 255, 0, 0)), (1, AbsInfo(value=0, min=255, max=5, fuzz=10, flat=0, resolution=0))]}, 'name': 'test-py-evdev-uinput', 'product': 8704, ...}

    def test_abs_values(c):
        e = ecodes
        c['events'] = {
            e.EV_KEY: [e.KEY_A, e.KEY_B],
            e.EV_ABS: [(e.ABS_X, (0, 255, 0, 0)),
                       (e.ABS_Y, device.AbsInfo(0, 255, 5, 10, 0, 0))],
        }

>       with uinput.UInput(**c) as ui:

tests/test_uinput.py:68:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../BUILDROOT/python-evdev-1.4.0-2.1.fc35.x86_64/usr/lib64/python3.8/site-packages/evdev/uinput.py:127: in __init__
    self._verify()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = UInput('test-py-evdev-uinput', 3, 4352, 8704, 13056, 'py-evdev-uinput')

    def _verify(self):
        '''
        Verify that an uinput device exists and is readable and writable
        by the current process.
        '''

        try:
            m = os.stat(self.devnode)[stat.ST_MODE]
            if not stat.S_ISCHR(m):
                raise
        except (IndexError, OSError):
            msg = '"{}" does not exist or is not a character device file '\
                  '- verify that the uinput module is loaded'
            raise UInputError(msg.format(self.devnode))

        if not os.access(self.devnode, os.W_OK):
            msg = '"{}" cannot be opened for writing'
>           raise UInputError(msg.format(self.devnode))
E           evdev.uinput.UInputError: "/dev/uinput" cannot be opened for writing

../../BUILDROOT/python-evdev-1.4.0-2.1.fc35.x86_64/usr/lib64/python3.8/site-packages/evdev/uinput.py:274: UInputError
________________________________________________________________________________ test_write ________________________________________________________________________________

c = {'bustype': 3, 'name': 'test-py-evdev-uinput', 'product': 8704, 'vendor': 4352, ...}

    def test_write(c):
>       with uinput.UInput(**c) as ui:

tests/test_uinput.py:84:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../BUILDROOT/python-evdev-1.4.0-2.1.fc35.x86_64/usr/lib64/python3.8/site-packages/evdev/uinput.py:127: in __init__
    self._verify()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = UInput('test-py-evdev-uinput', 3, 4352, 8704, 13056, 'py-evdev-uinput')

    def _verify(self):
        '''
        Verify that an uinput device exists and is readable and writable
        by the current process.
        '''

        try:
            m = os.stat(self.devnode)[stat.ST_MODE]
            if not stat.S_ISCHR(m):
                raise
        except (IndexError, OSError):
            msg = '"{}" does not exist or is not a character device file '\
                  '- verify that the uinput module is loaded'
            raise UInputError(msg.format(self.devnode))

        if not os.access(self.devnode, os.W_OK):
            msg = '"{}" cannot be opened for writing'
>           raise UInputError(msg.format(self.devnode))
E           evdev.uinput.UInputError: "/dev/uinput" cannot be opened for writing

../../BUILDROOT/python-evdev-1.4.0-2.1.fc35.x86_64/usr/lib64/python3.8/site-packages/evdev/uinput.py:274: UInputError
________________________________________________________________________________ test_open _________________________________________________________________________________

c = {'bustype': 3, 'name': 'test-py-evdev-uinput', 'product': 8704, 'vendor': 4352, ...}

    def test_open(c):
>       ui = uinput.UInput(**c)

tests/test_uinput.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../BUILDROOT/python-evdev-1.4.0-2.1.fc35.x86_64/usr/lib64/python3.8/site-packages/evdev/uinput.py:127: in __init__
    self._verify()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = UInput('test-py-evdev-uinput', 3, 4352, 8704, 13056, 'py-evdev-uinput')

    def _verify(self):
        '''
        Verify that an uinput device exists and is readable and writable
        by the current process.
        '''

        try:
            m = os.stat(self.devnode)[stat.ST_MODE]
            if not stat.S_ISCHR(m):
                raise
        except (IndexError, OSError):
            msg = '"{}" does not exist or is not a character device file '\
                  '- verify that the uinput module is loaded'
            raise UInputError(msg.format(self.devnode))

        if not os.access(self.devnode, os.W_OK):
            msg = '"{}" cannot be opened for writing'
>           raise UInputError(msg.format(self.devnode))
E           evdev.uinput.UInputError: "/dev/uinput" cannot be opened for writing

../../BUILDROOT/python-evdev-1.4.0-2.1.fc35.x86_64/usr/lib64/python3.8/site-packages/evdev/uinput.py:274: UInputError
____________________________________________________________________________ test_open_context _____________________________________________________________________________

c = {'bustype': 3, 'name': 'test-py-evdev-uinput', 'product': 8704, 'vendor': 4352, ...}

    def test_open_context(c):
        args = (c['bustype'], c['vendor'], c['product'], c['version'])
>       with uinput.UInput(**c):

tests/test_uinput.py:42:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../BUILDROOT/python-evdev-1.4.0-2.1.fc35.x86_64/usr/lib64/python3.8/site-packages/evdev/uinput.py:127: in __init__
    self._verify()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = UInput('test-py-evdev-uinput', 3, 4352, 8704, 13056, 'py-evdev-uinput')

    def _verify(self):
        '''
        Verify that an uinput device exists and is readable and writable
        by the current process.
        '''

        try:
            m = os.stat(self.devnode)[stat.ST_MODE]
            if not stat.S_ISCHR(m):
                raise
        except (IndexError, OSError):
            msg = '"{}" does not exist or is not a character device file '\
                  '- verify that the uinput module is loaded'
            raise UInputError(msg.format(self.devnode))

        if not os.access(self.devnode, os.W_OK):
            msg = '"{}" cannot be opened for writing'
>           raise UInputError(msg.format(self.devnode))
E           evdev.uinput.UInputError: "/dev/uinput" cannot be opened for writing

../../BUILDROOT/python-evdev-1.4.0-2.1.fc35.x86_64/usr/lib64/python3.8/site-packages/evdev/uinput.py:274: UInputError
____________________________________________________________________________ test_enable_events ____________________________________________________________________________

c = {'bustype': 3, 'events': {1: [30, 48, 46]}, 'name': 'test-py-evdev-uinput', 'product': 8704, ...}

    def test_enable_events(c):
        e = ecodes
        c['events'] = {e.EV_KEY : [e.KEY_A, e.KEY_B, e.KEY_C]}

>       with uinput.UInput(**c) as ui:

tests/test_uinput.py:55:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../BUILDROOT/python-evdev-1.4.0-2.1.fc35.x86_64/usr/lib64/python3.8/site-packages/evdev/uinput.py:127: in __init__
    self._verify()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = UInput('test-py-evdev-uinput', 3, 4352, 8704, 13056, 'py-evdev-uinput')

    def _verify(self):
        '''
        Verify that an uinput device exists and is readable and writable
        by the current process.
        '''

        try:
            m = os.stat(self.devnode)[stat.ST_MODE]
            if not stat.S_ISCHR(m):
                raise
        except (IndexError, OSError):
            msg = '"{}" does not exist or is not a character device file '\
                  '- verify that the uinput module is loaded'
            raise UInputError(msg.format(self.devnode))

        if not os.access(self.devnode, os.W_OK):
            msg = '"{}" cannot be opened for writing'
>           raise UInputError(msg.format(self.devnode))
E           evdev.uinput.UInputError: "/dev/uinput" cannot be opened for writing

../../BUILDROOT/python-evdev-1.4.0-2.1.fc35.x86_64/usr/lib64/python3.8/site-packages/evdev/uinput.py:274: UInputError
============================================================================= warnings summary =============================================================================
../../BUILDROOT/python-evdev-1.4.0-2.1.fc35.x86_64/usr/lib64/python3.8/site-packages/evdev/eventio_async.py:89
  /home/tkloczko/rpmbuild/BUILDROOT/python-evdev-1.4.0-2.1.fc35.x86_64/usr/lib64/python3.8/site-packages/evdev/eventio_async.py:89: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead
    def __anext__(self):

-- Docs: https://docs.pytest.org/en/stable/warnings.html
========================================================================= short test summary info ==========================================================================
FAILED tests/test_uinput.py::test_abs_values - evdev.uinput.UInputError: "/dev/uinput" cannot be opened for writing
FAILED tests/test_uinput.py::test_write - evdev.uinput.UInputError: "/dev/uinput" cannot be opened for writing
FAILED tests/test_uinput.py::test_open - evdev.uinput.UInputError: "/dev/uinput" cannot be opened for writing
FAILED tests/test_uinput.py::test_open_context - evdev.uinput.UInputError: "/dev/uinput" cannot be opened for writing
FAILED tests/test_uinput.py::test_enable_events - evdev.uinput.UInputError: "/dev/uinput" cannot be opened for writing
================================================================== 5 failed, 7 passed, 1 warning in 0.48s ==================================================================
pytest-xprocess reminder::Be sure to terminate the started process by running 'pytest --xkill' if you have not explicitly done so in your fixture with 'xprocess.getinfo(<process_name>).terminate()'.
kloczek commented 3 months ago

Gentle ping .. any update? 🤔

sezanzeb commented 3 months ago

try

ls -l /dev/uinput
getfacl /dev/uinput

to figure out the permissions of it. I have, for whatever reason, rw access to this file via its acl. Probably by default. You can replicate this on your system by using sudo setfacl -m u:${USER}:rw /dev/uinput

Running python3 -c "import evdev; evdev.UInput()" can help you verify if your permissions work.