tests: Make tests a build option
And don't skip tests if any test dependencies are missing.
This commit is contained in:
@@ -25,7 +25,7 @@ build_stable:
|
||||
- dnf update -y && dnf install -y $DEPENDENCIES
|
||||
- dnf reinstall -y glib2
|
||||
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 install
|
||||
- ninja -v -C _build uninstall
|
||||
|
@@ -14,6 +14,10 @@ $ ninja -v -C _build install
|
||||
```
|
||||
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
|
||||
-----
|
||||
|
||||
|
17
meson.build
17
meson.build
@@ -66,4 +66,19 @@ if get_option('gtk_doc')
|
||||
subdir('docs')
|
||||
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
|
||||
|
@@ -6,6 +6,10 @@ option('systemdsystemunitdir',
|
||||
description: 'systemd unit directory',
|
||||
type: 'string',
|
||||
value: 'auto')
|
||||
option('tests',
|
||||
description: 'Whether to run tests',
|
||||
type: 'boolean',
|
||||
value: false)
|
||||
option('gtk-tests',
|
||||
description: 'Whether to build GTK tests',
|
||||
type: 'boolean',
|
||||
|
@@ -21,32 +21,27 @@
|
||||
import os
|
||||
import sys
|
||||
import dbus
|
||||
import dbusmock
|
||||
import gi
|
||||
import tempfile
|
||||
import subprocess
|
||||
import psutil
|
||||
import subprocess
|
||||
import unittest
|
||||
import time
|
||||
|
||||
try:
|
||||
import gi
|
||||
from gi.repository import GLib
|
||||
from gi.repository import Gio
|
||||
except ImportError as e:
|
||||
sys.stderr.write('Skipping tests, PyGobject not available for Python 3, or missing GI typelibs: %s\n' % str(e))
|
||||
sys.exit(0)
|
||||
sys.stderr.write('PyGobject not available for Python 3, or missing GI typelibs: %s\n' % str(e))
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
gi.require_version('UMockdev', '1.0')
|
||||
from gi.repository import UMockdev
|
||||
except ImportError:
|
||||
sys.stderr.write('Skipping tests, umockdev not available (https://github.com/martinpitt/umockdev)\n')
|
||||
sys.exit(0)
|
||||
|
||||
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)
|
||||
sys.stderr.write('umockdev not available (https://github.com/martinpitt/umockdev)\n')
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
SP = 'net.hadess.SensorProxy'
|
||||
|
Reference in New Issue
Block a user