tests: Make tests a build option

And don't skip tests if any test dependencies are missing.
This commit is contained in:
Bastien Nocera
2022-04-04 17:46:57 +02:00
parent ad2c296b46
commit e4f0e05af3
5 changed files with 32 additions and 14 deletions

View File

@@ -25,7 +25,7 @@ build_stable:
- dnf update -y && dnf install -y $DEPENDENCIES - dnf update -y && dnf install -y $DEPENDENCIES
- dnf reinstall -y glib2 - dnf reinstall -y glib2
script: script:
- meson -Dgtk_doc=true -Dgtk-tests=true _build - meson -Dtests=true -Dgtk_doc=true -Dgtk-tests=true _build
- ninja -v -C _build - ninja -v -C _build
- ninja -v -C _build install - ninja -v -C _build install
- ninja -v -C _build uninstall - ninja -v -C _build uninstall

View File

@@ -14,6 +14,10 @@ $ ninja -v -C _build install
``` ```
It requires libgudev, systemd (>= 233 for the accelerometer quirks) and polkit-gobject. It requires libgudev, systemd (>= 233 for the accelerometer quirks) and polkit-gobject.
Running the tests will require gobject-introspection support for Python,
[python-dbusmock](https://github.com/martinpitt/python-dbusmock/),
[umockdev](https://github.com/martinpitt/umockdev) and [psutil](https://github.com/giampaolo/psutil).
Usage Usage
----- -----

View File

@@ -66,4 +66,19 @@ if get_option('gtk_doc')
subdir('docs') subdir('docs')
endif endif
subdir('tests') if get_option('tests')
# Python 3 required modules
python3_required_modules = ['psutil', 'dbusmock', 'gi']
python = import('python')
python3 = python.find_installation('python3')
foreach p : python3_required_modules
# Source: https://docs.python.org/3/library/importlib.html#checking-if-a-module-can-be-imported
script = 'import importlib.util; import sys; exit(1) if importlib.util.find_spec(\''+ p +'\') is None else exit(0)'
if run_command(python3, '-c', script, check: false).returncode() != 0
error('Python3 module \'' + p + '\' required for running tests but not found')
endif
endforeach
subdir('tests')
endif

View File

@@ -6,6 +6,10 @@ option('systemdsystemunitdir',
description: 'systemd unit directory', description: 'systemd unit directory',
type: 'string', type: 'string',
value: 'auto') value: 'auto')
option('tests',
description: 'Whether to run tests',
type: 'boolean',
value: false)
option('gtk-tests', option('gtk-tests',
description: 'Whether to build GTK tests', description: 'Whether to build GTK tests',
type: 'boolean', type: 'boolean',

View File

@@ -21,32 +21,27 @@
import os import os
import sys import sys
import dbus import dbus
import dbusmock
import gi
import tempfile import tempfile
import subprocess
import psutil import psutil
import subprocess
import unittest import unittest
import time import time
try: try:
import gi
from gi.repository import GLib from gi.repository import GLib
from gi.repository import Gio from gi.repository import Gio
except ImportError as e: except ImportError as e:
sys.stderr.write('Skipping tests, PyGobject not available for Python 3, or missing GI typelibs: %s\n' % str(e)) sys.stderr.write('PyGobject not available for Python 3, or missing GI typelibs: %s\n' % str(e))
sys.exit(0) sys.exit(1)
try: try:
gi.require_version('UMockdev', '1.0') gi.require_version('UMockdev', '1.0')
from gi.repository import UMockdev from gi.repository import UMockdev
except ImportError: except ImportError:
sys.stderr.write('Skipping tests, umockdev not available (https://github.com/martinpitt/umockdev)\n') sys.stderr.write('umockdev not available (https://github.com/martinpitt/umockdev)\n')
sys.exit(0) sys.exit(1)
try:
import dbusmock
except ImportError:
sys.stderr.write('Skipping tests, python-dbusmock not available (http://pypi.python.org/pypi/python-dbusmock).\n')
sys.exit(0)
SP = 'net.hadess.SensorProxy' SP = 'net.hadess.SensorProxy'