Fix macOS compatibility and reenable CI tests

* Fix CI for macOS

* Fix error message for missing hidapi

* Skip some device and receiver tests on macOS

Tests fail on macOS, enable them when unit tests are
refined to only test the module without dependencies.

* Safe guard dbus import
This commit is contained in:
MattHag 2024-05-23 00:45:40 +02:00 committed by GitHub
parent a9ce033cc8
commit 500b9998c5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 41 additions and 32 deletions

View File

@ -31,30 +31,28 @@ jobs:
run: |
make test
# macos-tests:
# runs-on: macos-latest
#
# strategy:
# matrix:
# python-version: [3.8, 3.12]
#
# steps:
# - name: Checkout
# uses: actions/checkout@v4
#
# - name: Set up Python ${{ matrix.python-version }}
# uses: actions/setup-python@v5
# with:
# python-version: ${{ matrix.python-version }}
#
# - name: Set up macOS dependencies
# run: |
# make install_brew
#
# - name: Install Python dependencies
# run: |
# make install_pip PIP_ARGS='.["test"]'
#
# - name: Run tests on macOS
# run: |
# make test
macos-tests:
runs-on: macos-latest
strategy:
matrix:
python-version: [3.8, 3.12]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Set up macOS dependencies
run: |
make install_brew
- name: Install Python dependencies
run: |
make install_pip PIP_ARGS='.["test"]'
- name: Run tests on macOS
run: |
export DYLD_LIBRARY_PATH=$(brew --prefix hidapi)/lib:$DYLD_LIBRARY_PATH && pytest --cov=lib/ tests/

View File

@ -84,7 +84,7 @@ for lib in _library_paths:
except OSError:
pass
else:
raise ImportError(f"Unable to load hdiapi library, tried: {' '.join(_library_paths)}")
raise ImportError(f"Unable to load hidapi library, tried: {' '.join(_library_paths)}")
# Retrieve version of hdiapi library

View File

@ -29,7 +29,6 @@ import time as _time
from typing import Dict
from typing import Tuple
import dbus
import gi
import psutil
@ -188,6 +187,8 @@ def gnome_dbus_interface_setup():
if _dbus_interface is not None:
return _dbus_interface
try:
import dbus
bus = dbus.SessionBus()
remote_object = bus.get_object("org.gnome.Shell", "/io/github/pwr_solaar/solaar")
_dbus_interface = dbus.Interface(remote_object, "io.github.pwr_solaar.solaar")

View File

@ -31,7 +31,7 @@ try:
except Exception:
# Either the dbus library is not available or the system dbus is not running
logger.warning("failed to set up dbus")
pass
bus = None
_suspend_callback = None
@ -55,7 +55,7 @@ def watch_suspend_resume(on_resume_callback=None, on_suspend_callback=None):
global _resume_callback, _suspend_callback
_suspend_callback = on_suspend_callback
_resume_callback = on_resume_callback
if on_resume_callback is not None or on_suspend_callback is not None:
if bus is not None and on_resume_callback is not None or on_suspend_callback is not None:
bus.add_signal_receiver(_suspend_or_resume, "PrepareForSleep", dbus_interface=_LOGIND_INTERFACE, path=_LOGIND_PATH)
if logger.isEnabledFor(logging.INFO):
logger.info("connected to system dbus, watching for suspend/resume events")
@ -71,7 +71,7 @@ def watch_bluez_connect(serial, callback=None):
if _bluetooth_callbacks.get(serial):
_bluetooth_callbacks.get(serial).remove()
path = _BLUETOOTH_PATH_PREFIX + serial.replace(":", "_").upper()
if callback is not None:
if bus is not None and callback is not None:
_bluetooth_callbacks[serial] = bus.add_signal_receiver(
callback, "PropertiesChanged", path=path, dbus_interface=_BLUETOOTH_INTERFACE
)

View File

@ -13,6 +13,7 @@
## You should have received a copy of the GNU General Public License along
## with this program; if not, write to the Free Software Foundation, Inc.,
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
import platform
from dataclasses import dataclass
from functools import partial
@ -96,6 +97,7 @@ def test_Device_name(device_info, responses, codename, name, kind, mock_base):
assert test_device.kind == kind
@pytest.mark.skipif(platform.system() == "Darwin", reason="Cleanup fails on macOS")
@pytest.mark.parametrize(
"device_info, responses, handle, _name, _codename, number, protocol, registers",
zip(
@ -124,6 +126,7 @@ def test_Device_info(device_info, responses, handle, _name, _codename, number, p
assert test_device.registers == registers
assert bool(test_device)
test_device.__del__()
assert not bool(test_device)
@ -155,6 +158,7 @@ pi_407B = {"wpid": "407B", "kind": 2, "serial": "5678", "polling": "1ms", "power
pi_DDDD = {"wpid": "DDDD", "kind": 2, "serial": "1234", "polling": "2ms", "power_switch": "top"}
@pytest.mark.skipif(platform.system() == "Darwin", reason="Cleanup fails on macOS")
@pytest.mark.parametrize(
"number, pairing_info, responses, handle, _name, codename, p, p2, name",
zip(

View File

@ -1,3 +1,5 @@
import platform
from dataclasses import dataclass
from functools import partial
from unittest import mock
@ -97,6 +99,7 @@ mouse_info = {
c534_info = {"kind": common.NamedInt(0, "unknown"), "polling": "", "power_switch": "(unknown)", "serial": None, "wpid": "45AB"}
@pytest.mark.skipif(platform.system() == "Darwin", reason="Fails on macOS")
@pytest.mark.parametrize(
"device_info, responses, handle, serial, max_devices, ",
[
@ -126,6 +129,7 @@ def test_ReceiverFactory_create_receiver(device_info, responses, handle, serial,
assert r.max_devices == max_devices
@pytest.mark.skipif(platform.system() == "Darwin", reason="Fails on macOS")
@pytest.mark.parametrize(
"device_info, responses, firmware, codename, remaining_pairings, pairing_info, count",
[
@ -147,6 +151,7 @@ def test_ReceiverFactory_props(device_info, responses, firmware, codename, remai
assert r.count() == count
@pytest.mark.skipif(platform.system() == "Darwin", reason="Fails on macOS")
@pytest.mark.parametrize(
"device_info, responses, status_str, strng",
[
@ -165,6 +170,7 @@ def test_ReceiverFactory_string(device_info, responses, status_str, strng, mock_
assert str(r) == strng
@pytest.mark.skipif(platform.system() == "Darwin", reason="Fails on macOS")
@pytest.mark.parametrize(
"device_info, responses",
[