python-dbusmock 0.36.0__tar.gz → 0.37.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/.github/workflows/pages.yml +1 -1
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/.github/workflows/release.yml +1 -1
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/.github/workflows/tests.yml +1 -1
- {python_dbusmock-0.36.0/python_dbusmock.egg-info → python_dbusmock-0.37.1}/PKG-INFO +1 -1
- python_dbusmock-0.37.1/dbusmock/_version.py +1 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/dbusmock/templates/systemd.py +1 -2
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/dbusmock/testcase.py +10 -61
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/distro/python-dbusmock.spec +0 -4
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1/python_dbusmock.egg-info}/PKG-INFO +1 -1
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/python_dbusmock.egg-info/SOURCES.txt +0 -3
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/tests/run-centos +0 -1
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/tests/run-fedora +0 -1
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/tests/test_api.py +3 -1
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/tests/test_notification_daemon.py +1 -0
- python_dbusmock-0.36.0/.github/release.eloquent.yml +0 -2
- python_dbusmock-0.36.0/dbusmock/_version.py +0 -1
- python_dbusmock-0.36.0/dbusmock/templates/iio-sensors-proxy.py +0 -208
- python_dbusmock-0.36.0/tests/test_iio_sensors_proxy.py +0 -408
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/.fmf/version +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/.gitignore +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/.pre-commit-config.yaml +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/COPYING +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/NEWS +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/README.md +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/dbusmock/__init__.py +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/dbusmock/__main__.py +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/dbusmock/mockobject.py +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/dbusmock/pytest_fixtures.py +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/dbusmock/templates/SKELETON +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/dbusmock/templates/__init__.py +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/dbusmock/templates/bluez5-obex.py +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/dbusmock/templates/bluez5.py +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/dbusmock/templates/gnome_screensaver.py +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/dbusmock/templates/gsd_rfkill.py +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/dbusmock/templates/logind.py +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/dbusmock/templates/low_memory_monitor.py +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/dbusmock/templates/modemmanager.py +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/dbusmock/templates/networkmanager.py +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/dbusmock/templates/notification_daemon.py +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/dbusmock/templates/ofono.py +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/dbusmock/templates/polkitd.py +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/dbusmock/templates/power_profiles_daemon.py +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/dbusmock/templates/timedated.py +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/dbusmock/templates/upower.py +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/dbusmock/templates/upower_power_profiles_daemon.py +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/dbusmock/templates/urfkill.py +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/doc/conf.py +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/doc/index.rst +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/packit.yaml +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/plans/all.fmf +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/pyproject.toml +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/python_dbusmock.egg-info/dependency_links.txt +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/python_dbusmock.egg-info/requires.txt +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/python_dbusmock.egg-info/top_level.txt +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/setup.cfg +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/tests/__init__.py +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/tests/conftest.py +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/tests/main.fmf +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/tests/run +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/tests/run-debian +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/tests/run-ubuntu +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/tests/test_api_pytest.py +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/tests/test_bluez5.py +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/tests/test_cli.py +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/tests/test_code.py +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/tests/test_gnome_screensaver.py +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/tests/test_gsd_rfkill.py +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/tests/test_logind.py +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/tests/test_low_memory_monitor.py +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/tests/test_modemmanager.py +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/tests/test_networkmanager.py +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/tests/test_ofono.py +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/tests/test_polkitd.py +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/tests/test_power_profiles_daemon.py +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/tests/test_systemd.py +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/tests/test_timedated.py +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/tests/test_upower.py +0 -0
- {python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/tests/test_urfkill.py +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.37.1"
|
|
@@ -13,10 +13,8 @@ __copyright__ = """
|
|
|
13
13
|
"""
|
|
14
14
|
|
|
15
15
|
import enum
|
|
16
|
-
import errno
|
|
17
16
|
import os
|
|
18
17
|
import shutil
|
|
19
|
-
import signal
|
|
20
18
|
import subprocess
|
|
21
19
|
import sys
|
|
22
20
|
import tempfile
|
|
@@ -172,15 +170,17 @@ class PrivateDBus:
|
|
|
172
170
|
|
|
173
171
|
def start(self):
|
|
174
172
|
"""Start the D-Bus daemon"""
|
|
175
|
-
argv = ["dbus-daemon", f"--config-file={self._config}"]
|
|
173
|
+
argv = ["dbus-daemon", f"--config-file={self._config}", "--print-pid=1"]
|
|
176
174
|
# pylint: disable=consider-using-with
|
|
177
|
-
self._daemon = subprocess.Popen(argv)
|
|
178
|
-
for
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
175
|
+
self._daemon = subprocess.Popen(argv, stdout=subprocess.PIPE)
|
|
176
|
+
# we don't need the value, but waiting for it ensures that the bus has
|
|
177
|
+
# started up and is listening
|
|
178
|
+
assert self._daemon.stdout is not None
|
|
179
|
+
pid = self._daemon.stdout.readline().strip()
|
|
180
|
+
assert int(pid) == self._daemon.pid, "dbus-daemon pid mismatch"
|
|
181
|
+
self._daemon.stdout.close()
|
|
182
|
+
|
|
183
|
+
assert self._socket.exists(), "D-Bus socket not created"
|
|
184
184
|
|
|
185
185
|
env, _ = self.bustype.environ
|
|
186
186
|
os.environ[env] = self.address
|
|
@@ -307,57 +307,6 @@ class DBusTestCase(unittest.TestCase):
|
|
|
307
307
|
"""
|
|
308
308
|
cls.__start_bus("system")
|
|
309
309
|
|
|
310
|
-
@staticmethod
|
|
311
|
-
def start_dbus(conf: Optional[str] = None) -> Tuple[int, str]:
|
|
312
|
-
"""Start a D-Bus daemon
|
|
313
|
-
|
|
314
|
-
Return (pid, address) pair.
|
|
315
|
-
|
|
316
|
-
Normally you do not need to call this directly. Use start_system_bus()
|
|
317
|
-
and start_session_bus() instead.
|
|
318
|
-
"""
|
|
319
|
-
argv = ["dbus-daemon", "--fork", "--print-address=1", "--print-pid=1"]
|
|
320
|
-
if conf:
|
|
321
|
-
argv.append("--config-file=" + str(conf))
|
|
322
|
-
else:
|
|
323
|
-
argv.append("--session")
|
|
324
|
-
lines = subprocess.check_output(argv, text=True).strip().splitlines()
|
|
325
|
-
assert len(lines) == 2, "expected exactly 2 lines of output from dbus-daemon"
|
|
326
|
-
# usually the first line is the address, but be lenient and accept any order
|
|
327
|
-
try:
|
|
328
|
-
return (int(lines[1]), lines[0])
|
|
329
|
-
except ValueError:
|
|
330
|
-
return (int(lines[0]), lines[1])
|
|
331
|
-
|
|
332
|
-
@staticmethod
|
|
333
|
-
def stop_dbus(pid: int) -> None:
|
|
334
|
-
"""Stop a D-Bus daemon
|
|
335
|
-
|
|
336
|
-
Normally you do not need to call this directly. When you use
|
|
337
|
-
start_system_bus() and start_session_bus(), these buses are
|
|
338
|
-
automatically stopped in tearDownClass().
|
|
339
|
-
"""
|
|
340
|
-
signal.signal(signal.SIGTERM, signal.SIG_IGN)
|
|
341
|
-
for _ in range(50):
|
|
342
|
-
try:
|
|
343
|
-
os.kill(pid, signal.SIGTERM)
|
|
344
|
-
os.waitpid(pid, os.WNOHANG)
|
|
345
|
-
except ChildProcessError:
|
|
346
|
-
break
|
|
347
|
-
except OSError as e:
|
|
348
|
-
if e.errno == errno.ESRCH:
|
|
349
|
-
break
|
|
350
|
-
raise
|
|
351
|
-
time.sleep(0.1)
|
|
352
|
-
else:
|
|
353
|
-
sys.stderr.write("ERROR: timed out waiting for bus process to terminate\n")
|
|
354
|
-
os.kill(pid, signal.SIGKILL)
|
|
355
|
-
try:
|
|
356
|
-
os.waitpid(pid, 0)
|
|
357
|
-
except ChildProcessError:
|
|
358
|
-
pass
|
|
359
|
-
signal.signal(signal.SIGTERM, signal.SIG_DFL)
|
|
360
|
-
|
|
361
310
|
@staticmethod
|
|
362
311
|
def get_dbus(system_bus: bool = False) -> dbus.Bus:
|
|
363
312
|
"""Get a dbus.bus.BusConnection() object to this bus
|
|
@@ -11,11 +11,7 @@ Source0: https://files.pythonhosted.org/packages/source/p/%{name}/pytho
|
|
|
11
11
|
|
|
12
12
|
BuildArch: noarch
|
|
13
13
|
BuildRequires: git
|
|
14
|
-
BuildRequires: python3-dbus
|
|
15
14
|
BuildRequires: python3-devel
|
|
16
|
-
BuildRequires: python3dist(setuptools-scm)
|
|
17
|
-
BuildRequires: python3dist(wheel)
|
|
18
|
-
BuildRequires: python3-setuptools
|
|
19
15
|
BuildRequires: python3-gobject
|
|
20
16
|
BuildRequires: python3-pytest
|
|
21
17
|
BuildRequires: dbus-x11
|
|
@@ -6,7 +6,6 @@ README.md
|
|
|
6
6
|
packit.yaml
|
|
7
7
|
pyproject.toml
|
|
8
8
|
.fmf/version
|
|
9
|
-
.github/release.eloquent.yml
|
|
10
9
|
.github/workflows/pages.yml
|
|
11
10
|
.github/workflows/release.yml
|
|
12
11
|
.github/workflows/tests.yml
|
|
@@ -22,7 +21,6 @@ dbusmock/templates/bluez5-obex.py
|
|
|
22
21
|
dbusmock/templates/bluez5.py
|
|
23
22
|
dbusmock/templates/gnome_screensaver.py
|
|
24
23
|
dbusmock/templates/gsd_rfkill.py
|
|
25
|
-
dbusmock/templates/iio-sensors-proxy.py
|
|
26
24
|
dbusmock/templates/logind.py
|
|
27
25
|
dbusmock/templates/low_memory_monitor.py
|
|
28
26
|
dbusmock/templates/modemmanager.py
|
|
@@ -60,7 +58,6 @@ tests/test_cli.py
|
|
|
60
58
|
tests/test_code.py
|
|
61
59
|
tests/test_gnome_screensaver.py
|
|
62
60
|
tests/test_gsd_rfkill.py
|
|
63
|
-
tests/test_iio_sensors_proxy.py
|
|
64
61
|
tests/test_logind.py
|
|
65
62
|
tests/test_low_memory_monitor.py
|
|
66
63
|
tests/test_modemmanager.py
|
|
@@ -6,7 +6,6 @@ dnf -y install python3-setuptools python3 python3-gobject-base \
|
|
|
6
6
|
upower NetworkManager ModemManager bluez libnotify polkit
|
|
7
7
|
|
|
8
8
|
if ! grep -q :el /etc/os-release; then
|
|
9
|
-
# skip iio-sensor-proxy: https://github.com/martinpitt/python-dbusmock/issues/241
|
|
10
9
|
dnf -y install power-profiles-daemon python3-pytest
|
|
11
10
|
else
|
|
12
11
|
dnf -y install python3-pip
|
|
@@ -6,7 +6,6 @@ dnf -y install python3-setuptools python3 python3-gobject-base \
|
|
|
6
6
|
upower NetworkManager ModemManager bluez libnotify polkit
|
|
7
7
|
|
|
8
8
|
if ! grep -q :el /etc/os-release; then
|
|
9
|
-
# skip iio-sensor-proxy: https://github.com/martinpitt/python-dbusmock/issues/241
|
|
10
9
|
dnf -y install power-profiles-daemon python3-pytest
|
|
11
10
|
else
|
|
12
11
|
dnf -y install python3-pip
|
|
@@ -13,6 +13,7 @@ __copyright__ = """
|
|
|
13
13
|
import importlib.util
|
|
14
14
|
import os
|
|
15
15
|
import shutil
|
|
16
|
+
import signal
|
|
16
17
|
import subprocess
|
|
17
18
|
import sys
|
|
18
19
|
import tempfile
|
|
@@ -1026,7 +1027,8 @@ class TestCleanup(dbusmock.DBusTestCase):
|
|
|
1026
1027
|
|
|
1027
1028
|
self.start_session_bus()
|
|
1028
1029
|
p_mock = self.spawn_server("org.freedesktop.Test", "/", "org.freedesktop.Test.Main")
|
|
1029
|
-
self.
|
|
1030
|
+
assert self.session_bus_pid is not None
|
|
1031
|
+
os.kill(self.session_bus_pid, signal.SIGTERM)
|
|
1030
1032
|
|
|
1031
1033
|
# give the mock 2 seconds to terminate
|
|
1032
1034
|
timeout = 20
|
|
@@ -28,6 +28,7 @@ except (OSError, subprocess.CalledProcessError):
|
|
|
28
28
|
|
|
29
29
|
|
|
30
30
|
@unittest.skipUnless(notify_send_version, "notify-send not installed")
|
|
31
|
+
@unittest.skipIf(os.path.exists("/etc/apparmor.d/notify-send"), "AppArmor profile for notify-send active")
|
|
31
32
|
class TestNotificationDaemon(dbusmock.DBusTestCase):
|
|
32
33
|
"""Test mocking notification-daemon"""
|
|
33
34
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.36.0"
|
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
"""sensors proxy mock template
|
|
2
|
-
"""
|
|
3
|
-
|
|
4
|
-
# This program is free software; you can redistribute it and/or modify it under
|
|
5
|
-
# the terms of the GNU Lesser General Public License as published by the Free
|
|
6
|
-
# Software Foundation; either version 3 of the License, or (at your option) any
|
|
7
|
-
# later version. See http://www.gnu.org/copyleft/lgpl.html for the full text
|
|
8
|
-
# of the license.
|
|
9
|
-
|
|
10
|
-
__author__ = "Marco Trevisan"
|
|
11
|
-
__copyright__ = """
|
|
12
|
-
(c) 2021 Canonical Ltd.
|
|
13
|
-
(c) 2017 - 2022 Martin Pitt <martin@piware.de>
|
|
14
|
-
"""
|
|
15
|
-
|
|
16
|
-
import re
|
|
17
|
-
|
|
18
|
-
import dbus
|
|
19
|
-
|
|
20
|
-
from dbusmock import MOCK_IFACE
|
|
21
|
-
|
|
22
|
-
BUS_NAME = "net.hadess.SensorProxy"
|
|
23
|
-
MAIN_OBJ = "/net/hadess/SensorProxy"
|
|
24
|
-
MAIN_IFACE = "net.hadess.SensorProxy"
|
|
25
|
-
COMPASS_IFACE = "net.hadess.SensorProxy.Compass"
|
|
26
|
-
SYSTEM_BUS = True
|
|
27
|
-
|
|
28
|
-
CAMEL_TO_SNAKE_CASE_RE = re.compile(r"(?<!^)(?=[A-Z])")
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
def load(mock, parameters=None):
|
|
32
|
-
mock.has_accelerometer = False
|
|
33
|
-
mock.accelerometer_owners = {}
|
|
34
|
-
mock.accelerometer_orientation = "undefined"
|
|
35
|
-
mock.has_ambient_light = False
|
|
36
|
-
mock.ambient_light_owners = {}
|
|
37
|
-
mock.light_level_unit = "lux"
|
|
38
|
-
mock.light_level = 0.0
|
|
39
|
-
mock.has_proximity = False
|
|
40
|
-
mock.proximity_near = False
|
|
41
|
-
mock.proximity_owners = {}
|
|
42
|
-
mock.has_compass = False
|
|
43
|
-
mock.compass_owners = {}
|
|
44
|
-
mock.compass_heading = -1.0
|
|
45
|
-
|
|
46
|
-
if parameters:
|
|
47
|
-
for p, v in parameters.items():
|
|
48
|
-
setattr(mock, p, v)
|
|
49
|
-
|
|
50
|
-
for iface in [MAIN_IFACE, COMPASS_IFACE]:
|
|
51
|
-
mock.AddProperties(iface, mock.GetAll(iface))
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
def emit_signal_to_destination(mock, interface, name, signature, destination, *args):
|
|
55
|
-
# We need to do this manually, could be made easier via
|
|
56
|
-
# https://gitlab.freedesktop.org/dbus/dbus-python/-/merge_requests/13
|
|
57
|
-
message = dbus.lowlevel.SignalMessage(mock.path, interface, name)
|
|
58
|
-
if destination:
|
|
59
|
-
message.set_destination(destination)
|
|
60
|
-
message.append(*args, signature=signature)
|
|
61
|
-
for location in mock.locations:
|
|
62
|
-
location[0].send_message(message)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
def emit_properties_changed(mock, interface=MAIN_IFACE, properties=None, destination=None):
|
|
66
|
-
if properties is None:
|
|
67
|
-
properties = mock.GetAll(interface)
|
|
68
|
-
elif isinstance(properties, str):
|
|
69
|
-
properties = [properties]
|
|
70
|
-
|
|
71
|
-
if isinstance(properties, (list, set)):
|
|
72
|
-
properties = {p: mock.Get(interface, p) for p in properties}
|
|
73
|
-
elif not isinstance(properties, dict):
|
|
74
|
-
raise TypeError("Unsupported properties type")
|
|
75
|
-
|
|
76
|
-
emit_signal_to_destination(
|
|
77
|
-
mock, dbus.PROPERTIES_IFACE, "PropertiesChanged", "sa{sv}as", destination, interface, properties, []
|
|
78
|
-
)
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
@dbus.service.method(dbus.PROPERTIES_IFACE, in_signature="s", out_signature="a{sv}")
|
|
82
|
-
def GetAll(self, interface):
|
|
83
|
-
if interface == MAIN_IFACE:
|
|
84
|
-
return {
|
|
85
|
-
"HasAccelerometer": dbus.Boolean(self.has_accelerometer),
|
|
86
|
-
"AccelerometerOrientation": dbus.String(self.accelerometer_orientation),
|
|
87
|
-
"HasAmbientLight": dbus.Boolean(self.has_ambient_light),
|
|
88
|
-
"LightLevelUnit": dbus.String(self.light_level_unit),
|
|
89
|
-
"LightLevel": dbus.Double(self.light_level),
|
|
90
|
-
"HasProximity": dbus.Boolean(self.has_proximity),
|
|
91
|
-
"ProximityNear": dbus.Boolean(self.proximity_near),
|
|
92
|
-
}
|
|
93
|
-
if interface == COMPASS_IFACE:
|
|
94
|
-
return {
|
|
95
|
-
"HasCompass": dbus.Boolean(self.has_compass),
|
|
96
|
-
"CompassHeading": dbus.Double(self.compass_heading),
|
|
97
|
-
}
|
|
98
|
-
return dbus.Dictionary({}, signature="sv")
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
def register_owner(self, owners_dict, name):
|
|
102
|
-
if name in owners_dict:
|
|
103
|
-
return
|
|
104
|
-
|
|
105
|
-
def name_cb(unique_name):
|
|
106
|
-
if unique_name:
|
|
107
|
-
return
|
|
108
|
-
owners_dict.pop(name).cancel()
|
|
109
|
-
|
|
110
|
-
owners_dict[name] = self.connection.watch_name_owner(name, name_cb)
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
def unregister_owner(owners_dict, name):
|
|
114
|
-
watcher = owners_dict.pop(name, None)
|
|
115
|
-
if watcher:
|
|
116
|
-
watcher.cancel()
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
@dbus.service.method(MAIN_IFACE, sender_keyword="sender")
|
|
120
|
-
def ClaimAccelerometer(self, sender):
|
|
121
|
-
register_owner(self, self.accelerometer_owners, sender)
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
@dbus.service.method(MAIN_IFACE, sender_keyword="sender")
|
|
125
|
-
def ReleaseAccelerometer(self, sender):
|
|
126
|
-
unregister_owner(self.accelerometer_owners, sender)
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
@dbus.service.method(MAIN_IFACE, sender_keyword="sender")
|
|
130
|
-
def ClaimLight(self, sender):
|
|
131
|
-
register_owner(self, self.ambient_light_owners, sender)
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
@dbus.service.method(MAIN_IFACE, sender_keyword="sender")
|
|
135
|
-
def ReleaseLight(self, sender):
|
|
136
|
-
unregister_owner(self.ambient_light_owners, sender)
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
@dbus.service.method(MAIN_IFACE, sender_keyword="sender")
|
|
140
|
-
def ClaimProximity(self, sender):
|
|
141
|
-
register_owner(self, self.proximity_owners, sender)
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
@dbus.service.method(MAIN_IFACE, sender_keyword="sender")
|
|
145
|
-
def ReleaseProximity(self, sender):
|
|
146
|
-
unregister_owner(self.proximity_owners, sender)
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
@dbus.service.method(MAIN_IFACE, sender_keyword="sender")
|
|
150
|
-
def ClaimCompass(self, sender):
|
|
151
|
-
register_owner(self, self.compass_owners, sender)
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
@dbus.service.method(MAIN_IFACE, sender_keyword="sender")
|
|
155
|
-
def ReleaseCompass(self, sender):
|
|
156
|
-
unregister_owner(self.compass_owners, sender)
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
def sensor_to_attribute(sensor):
|
|
160
|
-
if sensor == "light":
|
|
161
|
-
return "ambient_light"
|
|
162
|
-
return sensor
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
def is_valid_sensor_for_interface(sensor, interface):
|
|
166
|
-
if interface == "net.hadess.SensorProxy":
|
|
167
|
-
return sensor in ["accelerometer", "ambient_light", "proximity"]
|
|
168
|
-
|
|
169
|
-
if interface == "net.hadess.SensorProxy.Compass":
|
|
170
|
-
return sensor == "compass"
|
|
171
|
-
|
|
172
|
-
return False
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
@dbus.service.method(MOCK_IFACE, in_signature="ssv")
|
|
176
|
-
def SetInternalProperty(self, interface, property_name, value):
|
|
177
|
-
property_attribute = CAMEL_TO_SNAKE_CASE_RE.sub("_", property_name).lower()
|
|
178
|
-
sensor = sensor_to_attribute(property_attribute.split("_")[0])
|
|
179
|
-
|
|
180
|
-
owners = None
|
|
181
|
-
if is_valid_sensor_for_interface(sensor, interface):
|
|
182
|
-
if not getattr(self, f"has_{sensor}"):
|
|
183
|
-
raise dbus.exceptions.DBusException(
|
|
184
|
-
f"No {sensor} sensor available", name="org.freedesktop.DBus.Mock.Error"
|
|
185
|
-
)
|
|
186
|
-
|
|
187
|
-
owners = getattr(self, f"{sensor}_owners")
|
|
188
|
-
# We allow setting a property from any client here, even if not claiming
|
|
189
|
-
# but only owners, if any, will be notified about sensors changes
|
|
190
|
-
|
|
191
|
-
pre_value = getattr(self, property_attribute)
|
|
192
|
-
if pre_value != value:
|
|
193
|
-
setattr(self, property_attribute, value)
|
|
194
|
-
if owners:
|
|
195
|
-
for owner in owners:
|
|
196
|
-
emit_properties_changed(self, interface, property_name, owner)
|
|
197
|
-
elif owners is None:
|
|
198
|
-
emit_properties_changed(self, interface, property_name, None)
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
@dbus.service.method(MOCK_IFACE, in_signature="s")
|
|
202
|
-
def GetInternalProperty(self, property_name):
|
|
203
|
-
property_attribute = CAMEL_TO_SNAKE_CASE_RE.sub("_", property_name).lower()
|
|
204
|
-
value = getattr(self, property_attribute)
|
|
205
|
-
|
|
206
|
-
if property_name.endswith("Owners"):
|
|
207
|
-
return dbus.Array(value.keys(), signature="s")
|
|
208
|
-
return value
|
|
@@ -1,408 +0,0 @@
|
|
|
1
|
-
# This program is free software; you can redistribute it and/or modify it under
|
|
2
|
-
# the terms of the GNU Lesser General Public License as published by the Free
|
|
3
|
-
# Software Foundation; either version 3 of the License, or (at your option) any
|
|
4
|
-
# later version. See http://www.gnu.org/copyleft/lgpl.html for the full text
|
|
5
|
-
# of the license.
|
|
6
|
-
|
|
7
|
-
__author__ = "Marco Trevisan"
|
|
8
|
-
__copyright__ = """
|
|
9
|
-
(c) 2021 Canonical Ltd.
|
|
10
|
-
(c) 2017 - 2022 Martin Pitt <martin@piware.de>
|
|
11
|
-
"""
|
|
12
|
-
|
|
13
|
-
import fcntl
|
|
14
|
-
import os
|
|
15
|
-
import shutil
|
|
16
|
-
import subprocess
|
|
17
|
-
import sys
|
|
18
|
-
import time
|
|
19
|
-
import unittest
|
|
20
|
-
|
|
21
|
-
import dbus
|
|
22
|
-
import dbus.mainloop.glib
|
|
23
|
-
from gi.repository import GLib
|
|
24
|
-
|
|
25
|
-
import dbusmock
|
|
26
|
-
|
|
27
|
-
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
|
|
28
|
-
|
|
29
|
-
have_monitor_sensor = shutil.which("monitor-sensor")
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
class TestIIOSensorsProxyBase(dbusmock.DBusTestCase):
|
|
33
|
-
"""Test mocking iio-sensors-proxy"""
|
|
34
|
-
|
|
35
|
-
dbus_interface = ""
|
|
36
|
-
|
|
37
|
-
@classmethod
|
|
38
|
-
def setUpClass(cls):
|
|
39
|
-
super().setUpClass()
|
|
40
|
-
cls.start_system_bus()
|
|
41
|
-
cls.dbus_con = cls.get_dbus(True)
|
|
42
|
-
|
|
43
|
-
def setUp(self):
|
|
44
|
-
super().setUp()
|
|
45
|
-
(self.p_mock, self.p_obj) = self.spawn_server_template("iio-sensors-proxy", {}, stdout=subprocess.PIPE)
|
|
46
|
-
|
|
47
|
-
def tearDown(self):
|
|
48
|
-
if self.p_mock:
|
|
49
|
-
self.p_mock.stdout.close()
|
|
50
|
-
self.p_mock.terminate()
|
|
51
|
-
self.p_mock.wait()
|
|
52
|
-
|
|
53
|
-
super().tearDown()
|
|
54
|
-
|
|
55
|
-
def get_property(self, name):
|
|
56
|
-
return self.p_obj.Get(self.dbus_interface, name, dbus_interface=dbus.PROPERTIES_IFACE)
|
|
57
|
-
|
|
58
|
-
def get_internal_property(self, name):
|
|
59
|
-
return self.p_obj.GetInternalProperty(name)
|
|
60
|
-
|
|
61
|
-
def set_internal_property(self, name, value):
|
|
62
|
-
return self.p_obj.SetInternalProperty(self.dbus_interface, name, value)
|
|
63
|
-
|
|
64
|
-
def wait_for_properties_changed(self, max_wait=2000):
|
|
65
|
-
changed_properties = []
|
|
66
|
-
timeout_id = 0
|
|
67
|
-
|
|
68
|
-
def on_properties_changed(interface, properties, _invalidated):
|
|
69
|
-
nonlocal changed_properties
|
|
70
|
-
|
|
71
|
-
if interface == self.dbus_interface:
|
|
72
|
-
changed_properties = properties.keys()
|
|
73
|
-
|
|
74
|
-
def on_timeout():
|
|
75
|
-
nonlocal timeout_id
|
|
76
|
-
|
|
77
|
-
timeout_id = 0
|
|
78
|
-
|
|
79
|
-
loop = GLib.MainLoop()
|
|
80
|
-
timeout_id = GLib.timeout_add(max_wait, on_timeout)
|
|
81
|
-
match = self.p_obj.connect_to_signal("PropertiesChanged", on_properties_changed, dbus.PROPERTIES_IFACE)
|
|
82
|
-
|
|
83
|
-
while not changed_properties and timeout_id != 0:
|
|
84
|
-
loop.get_context().iteration(True)
|
|
85
|
-
|
|
86
|
-
if timeout_id:
|
|
87
|
-
GLib.source_remove(timeout_id)
|
|
88
|
-
|
|
89
|
-
match.remove()
|
|
90
|
-
|
|
91
|
-
return changed_properties
|
|
92
|
-
|
|
93
|
-
def wait_for_property_changed(self, property_name, expected_value):
|
|
94
|
-
self.assertIn(property_name, self.wait_for_properties_changed())
|
|
95
|
-
self.assertEqual(self.get_internal_property(property_name), expected_value)
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
class TestIIOSensorsProxy(TestIIOSensorsProxyBase):
|
|
99
|
-
"""main SensorsProxy interface tests"""
|
|
100
|
-
|
|
101
|
-
dbus_interface = "net.hadess.SensorProxy"
|
|
102
|
-
|
|
103
|
-
def test_accelerometer_none(self):
|
|
104
|
-
self.assertFalse(self.get_property("HasAccelerometer"))
|
|
105
|
-
|
|
106
|
-
def test_accelerometer_claimed(self):
|
|
107
|
-
self.p_obj.ClaimAccelerometer()
|
|
108
|
-
self.assertTrue(self.get_internal_property("AccelerometerOwners"))
|
|
109
|
-
|
|
110
|
-
def test_accelerometer_claimed_released(self):
|
|
111
|
-
self.p_obj.ClaimAccelerometer()
|
|
112
|
-
self.assertTrue(self.get_internal_property("AccelerometerOwners"))
|
|
113
|
-
self.p_obj.ReleaseAccelerometer()
|
|
114
|
-
self.assertFalse(self.get_internal_property("AccelerometerOwners"))
|
|
115
|
-
|
|
116
|
-
def test_accelerometer_available(self):
|
|
117
|
-
self.assertFalse(self.get_property("HasAccelerometer"))
|
|
118
|
-
self.set_internal_property("HasAccelerometer", True)
|
|
119
|
-
self.assertTrue(self.get_property("HasAccelerometer"))
|
|
120
|
-
|
|
121
|
-
def test_accelerometer_property_with_no_sensor(self):
|
|
122
|
-
with self.assertRaises(dbus.exceptions.DBusException) as ctx:
|
|
123
|
-
self.set_internal_property("AccelerometerOrientation", "normal")
|
|
124
|
-
self.assertEqual(ctx.exception.get_dbus_name(), "org.freedesktop.DBus.Mock.Error")
|
|
125
|
-
self.assertIn("No accelerometer sensor available", ctx.exception.get_dbus_message().split("\n"))
|
|
126
|
-
|
|
127
|
-
def test_accelerometer_claimed_properties_changes(self):
|
|
128
|
-
self.set_internal_property("HasAccelerometer", True)
|
|
129
|
-
self.p_obj.ClaimAccelerometer()
|
|
130
|
-
self.set_internal_property("AccelerometerOrientation", "normal")
|
|
131
|
-
self.wait_for_property_changed("AccelerometerOrientation", "normal")
|
|
132
|
-
|
|
133
|
-
def test_accelerometer_unclaimed_properties_changes(self):
|
|
134
|
-
self.set_internal_property("HasAccelerometer", True)
|
|
135
|
-
self.assertTrue(self.get_property("HasAccelerometer"))
|
|
136
|
-
self.set_internal_property("AccelerometerOrientation", "normal")
|
|
137
|
-
self.assertFalse(self.wait_for_properties_changed(max_wait=500))
|
|
138
|
-
self.assertEqual(self.get_property("AccelerometerOrientation"), "normal")
|
|
139
|
-
|
|
140
|
-
def test_ambient_light_none(self):
|
|
141
|
-
self.assertFalse(self.get_property("HasAmbientLight"))
|
|
142
|
-
|
|
143
|
-
def test_ambient_light_claimed(self):
|
|
144
|
-
self.p_obj.ClaimLight()
|
|
145
|
-
self.assertTrue(self.get_internal_property("AmbientLightOwners"))
|
|
146
|
-
self.assertFalse(self.get_property("HasAmbientLight"))
|
|
147
|
-
|
|
148
|
-
def test_ambient_light_claimed_released(self):
|
|
149
|
-
self.p_obj.ClaimLight()
|
|
150
|
-
self.assertTrue(self.get_internal_property("AmbientLightOwners"))
|
|
151
|
-
self.p_obj.ReleaseLight()
|
|
152
|
-
self.assertFalse(self.get_internal_property("AmbientLightOwners"))
|
|
153
|
-
|
|
154
|
-
def test_ambient_light_available(self):
|
|
155
|
-
self.assertFalse(self.get_property("HasAmbientLight"))
|
|
156
|
-
self.set_internal_property("HasAmbientLight", True)
|
|
157
|
-
self.assertTrue(self.get_property("HasAmbientLight"))
|
|
158
|
-
|
|
159
|
-
def test_ambient_light_property_with_no_sensor(self):
|
|
160
|
-
with self.assertRaises(dbus.exceptions.DBusException) as ctx:
|
|
161
|
-
self.set_internal_property("LightLevelUnit", "vendor")
|
|
162
|
-
self.assertEqual(ctx.exception.get_dbus_name(), "org.freedesktop.DBus.Mock.Error")
|
|
163
|
-
self.assertIn("No ambient_light sensor available", ctx.exception.get_dbus_message().split("\n"))
|
|
164
|
-
with self.assertRaises(dbus.exceptions.DBusException) as ctx:
|
|
165
|
-
self.set_internal_property("LightLevel", 0.5)
|
|
166
|
-
self.assertEqual(ctx.exception.get_dbus_name(), "org.freedesktop.DBus.Mock.Error")
|
|
167
|
-
self.assertIn("No ambient_light sensor available", ctx.exception.get_dbus_message().split("\n"))
|
|
168
|
-
|
|
169
|
-
def test_ambient_light_claimed_properties_changes(self):
|
|
170
|
-
self.set_internal_property("HasAmbientLight", True)
|
|
171
|
-
self.p_obj.ClaimLight()
|
|
172
|
-
self.set_internal_property("LightLevelUnit", "vendor")
|
|
173
|
-
self.wait_for_property_changed("LightLevelUnit", "vendor")
|
|
174
|
-
self.set_internal_property("LightLevel", 111100.0)
|
|
175
|
-
self.wait_for_property_changed("LightLevel", 111100.0)
|
|
176
|
-
|
|
177
|
-
def test_ambient_light_unclaimed_properties_changes(self):
|
|
178
|
-
self.set_internal_property("HasAmbientLight", True)
|
|
179
|
-
self.assertTrue(self.get_property("HasAmbientLight"))
|
|
180
|
-
self.set_internal_property("LightLevelUnit", "vendor")
|
|
181
|
-
self.assertFalse(self.wait_for_properties_changed(max_wait=500))
|
|
182
|
-
self.assertEqual(self.get_property("LightLevelUnit"), "vendor")
|
|
183
|
-
|
|
184
|
-
def test_proximity_none(self):
|
|
185
|
-
self.assertFalse(self.get_property("HasProximity"))
|
|
186
|
-
|
|
187
|
-
def test_proximity_claimed(self):
|
|
188
|
-
self.p_obj.ClaimProximity()
|
|
189
|
-
self.assertTrue(self.get_internal_property("ProximityOwners"))
|
|
190
|
-
self.assertFalse(self.get_property("HasProximity"))
|
|
191
|
-
|
|
192
|
-
def test_proximity_claimed_released(self):
|
|
193
|
-
self.p_obj.ClaimProximity()
|
|
194
|
-
self.assertTrue(self.get_internal_property("ProximityOwners"))
|
|
195
|
-
self.assertFalse(self.get_property("HasProximity"))
|
|
196
|
-
self.p_obj.ReleaseProximity()
|
|
197
|
-
self.assertFalse(self.get_internal_property("ProximityOwners"))
|
|
198
|
-
|
|
199
|
-
def test_proximity_available(self):
|
|
200
|
-
self.assertFalse(self.get_property("HasProximity"))
|
|
201
|
-
self.set_internal_property("HasProximity", True)
|
|
202
|
-
self.assertTrue(self.get_property("HasProximity"))
|
|
203
|
-
|
|
204
|
-
def test_proximity_property_with_no_sensor(self):
|
|
205
|
-
with self.assertRaises(dbus.exceptions.DBusException) as ctx:
|
|
206
|
-
self.set_internal_property("ProximityNear", True)
|
|
207
|
-
self.assertEqual(ctx.exception.get_dbus_name(), "org.freedesktop.DBus.Mock.Error")
|
|
208
|
-
self.assertIn("No proximity sensor available", ctx.exception.get_dbus_message().split("\n"))
|
|
209
|
-
|
|
210
|
-
def test_proximity_claimed_properties_changes(self):
|
|
211
|
-
self.set_internal_property("HasProximity", True)
|
|
212
|
-
self.p_obj.ClaimProximity()
|
|
213
|
-
self.set_internal_property("ProximityNear", True)
|
|
214
|
-
self.wait_for_property_changed("ProximityNear", True)
|
|
215
|
-
|
|
216
|
-
def test_proximity_unclaimed_properties_changes(self):
|
|
217
|
-
self.set_internal_property("HasProximity", True)
|
|
218
|
-
self.assertTrue(self.get_property("HasProximity"))
|
|
219
|
-
self.set_internal_property("ProximityNear", True)
|
|
220
|
-
self.assertFalse(self.wait_for_properties_changed(max_wait=500))
|
|
221
|
-
self.assertTrue(self.get_property("ProximityNear"))
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
class TestIIOSensorsProxyCompass(TestIIOSensorsProxyBase):
|
|
225
|
-
"""main SensorsProxy compass interface tests"""
|
|
226
|
-
|
|
227
|
-
dbus_interface = "net.hadess.SensorProxy.Compass"
|
|
228
|
-
|
|
229
|
-
def test_compass_none(self):
|
|
230
|
-
self.assertFalse(self.get_property("HasCompass"))
|
|
231
|
-
|
|
232
|
-
def test_compass_claimed(self):
|
|
233
|
-
self.p_obj.ClaimCompass()
|
|
234
|
-
self.assertTrue(self.get_internal_property("CompassOwners"))
|
|
235
|
-
self.assertFalse(self.get_property("HasCompass"))
|
|
236
|
-
|
|
237
|
-
def test_compass_claimed_released(self):
|
|
238
|
-
self.p_obj.ClaimCompass()
|
|
239
|
-
self.assertTrue(self.get_internal_property("CompassOwners"))
|
|
240
|
-
self.assertFalse(self.get_property("HasCompass"))
|
|
241
|
-
self.p_obj.ReleaseCompass()
|
|
242
|
-
self.assertFalse(self.get_internal_property("CompassOwners"))
|
|
243
|
-
|
|
244
|
-
def test_compass_available(self):
|
|
245
|
-
self.assertFalse(self.get_property("HasCompass"))
|
|
246
|
-
self.set_internal_property("HasCompass", True)
|
|
247
|
-
self.assertTrue(self.get_property("HasCompass"))
|
|
248
|
-
|
|
249
|
-
def test_compass_property_with_no_sensor(self):
|
|
250
|
-
with self.assertRaises(dbus.exceptions.DBusException) as ctx:
|
|
251
|
-
self.set_internal_property("CompassHeading", 180)
|
|
252
|
-
self.assertEqual(ctx.exception.get_dbus_name(), "org.freedesktop.DBus.Mock.Error")
|
|
253
|
-
self.assertIn("No compass sensor available", ctx.exception.get_dbus_message().split("\n"))
|
|
254
|
-
|
|
255
|
-
def test_compass_claimed_properties_changes(self):
|
|
256
|
-
self.set_internal_property("HasCompass", True)
|
|
257
|
-
self.p_obj.ClaimCompass()
|
|
258
|
-
self.set_internal_property("CompassHeading", 55)
|
|
259
|
-
self.wait_for_property_changed("CompassHeading", 55)
|
|
260
|
-
|
|
261
|
-
def test_compass_unclaimed_properties_changes(self):
|
|
262
|
-
self.set_internal_property("HasCompass", True)
|
|
263
|
-
self.assertTrue(self.get_property("HasCompass"))
|
|
264
|
-
self.set_internal_property("CompassHeading", 85)
|
|
265
|
-
self.assertFalse(self.wait_for_properties_changed(max_wait=500))
|
|
266
|
-
self.assertEqual(self.get_property("CompassHeading"), 85)
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
@unittest.skipUnless(have_monitor_sensor, "monitor-sensor utility not available")
|
|
270
|
-
class TestIIOSensorsProxyMonitorSensorBase(TestIIOSensorsProxyBase):
|
|
271
|
-
"""Base SensorsProxy interface tests using monitor-sensor"""
|
|
272
|
-
|
|
273
|
-
p_monitor_sensor = None
|
|
274
|
-
|
|
275
|
-
def start_monitor_sensor(self):
|
|
276
|
-
self.assertIsNone(self.p_monitor_sensor)
|
|
277
|
-
# pylint: disable=consider-using-with
|
|
278
|
-
self.p_monitor_sensor = subprocess.Popen("monitor-sensor", stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
|
279
|
-
flags = fcntl.fcntl(self.p_monitor_sensor.stdout, fcntl.F_GETFL)
|
|
280
|
-
fcntl.fcntl(self.p_monitor_sensor.stdout, fcntl.F_SETFL, flags | os.O_NONBLOCK)
|
|
281
|
-
self.assertOutputContains(
|
|
282
|
-
[
|
|
283
|
-
" Waiting for iio-sensor-proxy to appear",
|
|
284
|
-
"+++ iio-sensor-proxy appeared",
|
|
285
|
-
]
|
|
286
|
-
)
|
|
287
|
-
|
|
288
|
-
def stop_monitor_sensor(self):
|
|
289
|
-
self.assertIsNotNone(self.p_monitor_sensor)
|
|
290
|
-
self.assertEmptyOutput()
|
|
291
|
-
self.p_monitor_sensor.stdout.close()
|
|
292
|
-
self.p_monitor_sensor.terminate()
|
|
293
|
-
self.p_monitor_sensor.wait()
|
|
294
|
-
|
|
295
|
-
def tearDown(self):
|
|
296
|
-
if self.p_monitor_sensor:
|
|
297
|
-
self.stop_monitor_sensor()
|
|
298
|
-
super().tearDown()
|
|
299
|
-
|
|
300
|
-
def assertOutputContains(self, expected_lines, max_wait=2000):
|
|
301
|
-
self.assertIsNotNone(self.p_monitor_sensor)
|
|
302
|
-
start_time = int(time.time() * 1000)
|
|
303
|
-
for line in expected_lines:
|
|
304
|
-
output = None
|
|
305
|
-
while True:
|
|
306
|
-
output = self.p_monitor_sensor.stdout.readline()
|
|
307
|
-
if output:
|
|
308
|
-
break
|
|
309
|
-
self.assertLessEqual(int(time.time() * 1000) - start_time, max_wait, msg="Timeout exceeded")
|
|
310
|
-
self.assertEqual(output.decode("utf-8"), f"{line}\n")
|
|
311
|
-
|
|
312
|
-
def assertOutputEquals(self, expected_lines, max_wait=2000):
|
|
313
|
-
self.assertOutputContains(expected_lines, max_wait)
|
|
314
|
-
self.assertEmptyOutput()
|
|
315
|
-
|
|
316
|
-
def assertEmptyOutput(self, max_wait=100):
|
|
317
|
-
start_time = int(time.time() * 1000)
|
|
318
|
-
while int(time.time() * 1000) - start_time < max_wait:
|
|
319
|
-
self.assertFalse(self.p_monitor_sensor.stdout.readline(), msg="Unexpected output")
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
class TestIIOSensorsProxyMonitorSensor(TestIIOSensorsProxyMonitorSensorBase):
|
|
323
|
-
"""main SensorsProxy interface tests using monitor-sensor"""
|
|
324
|
-
|
|
325
|
-
dbus_interface = "net.hadess.SensorProxy"
|
|
326
|
-
|
|
327
|
-
def test_accelerometer_added(self):
|
|
328
|
-
self.set_internal_property("HasAccelerometer", True)
|
|
329
|
-
self.start_monitor_sensor()
|
|
330
|
-
|
|
331
|
-
self.assertOutputEquals(
|
|
332
|
-
[
|
|
333
|
-
"=== Has accelerometer (orientation: undefined)",
|
|
334
|
-
"=== No ambient light sensor",
|
|
335
|
-
"=== No proximity sensor",
|
|
336
|
-
]
|
|
337
|
-
)
|
|
338
|
-
|
|
339
|
-
def test_accelerometer_changes(self):
|
|
340
|
-
self.test_accelerometer_added()
|
|
341
|
-
self.set_internal_property("AccelerometerOrientation", "normal")
|
|
342
|
-
self.set_internal_property("AccelerometerOrientation", "left-up")
|
|
343
|
-
self.set_internal_property("AccelerometerOrientation", "bottom-up")
|
|
344
|
-
self.assertOutputEquals(
|
|
345
|
-
[
|
|
346
|
-
" Accelerometer orientation changed: normal",
|
|
347
|
-
" Accelerometer orientation changed: left-up",
|
|
348
|
-
" Accelerometer orientation changed: bottom-up",
|
|
349
|
-
]
|
|
350
|
-
)
|
|
351
|
-
|
|
352
|
-
def test_ambient_light_added(self):
|
|
353
|
-
self.set_internal_property("HasAmbientLight", True)
|
|
354
|
-
self.start_monitor_sensor()
|
|
355
|
-
|
|
356
|
-
self.assertOutputEquals(
|
|
357
|
-
[
|
|
358
|
-
"=== No accelerometer",
|
|
359
|
-
"=== Has ambient light sensor (value: 0.000000, unit: lux)",
|
|
360
|
-
"=== No proximity sensor",
|
|
361
|
-
]
|
|
362
|
-
)
|
|
363
|
-
|
|
364
|
-
def test_ambient_light_changes(self):
|
|
365
|
-
self.test_ambient_light_added()
|
|
366
|
-
self.set_internal_property("LightLevelUnit", "vendor")
|
|
367
|
-
self.set_internal_property("LightLevel", 0.3)
|
|
368
|
-
self.set_internal_property("LightLevel", 0.5)
|
|
369
|
-
self.set_internal_property("LightLevelUnit", "lux")
|
|
370
|
-
self.set_internal_property("LightLevel", 111100.0)
|
|
371
|
-
|
|
372
|
-
self.assertOutputEquals(
|
|
373
|
-
[
|
|
374
|
-
" Light changed: 0.300000 (vendor)",
|
|
375
|
-
" Light changed: 0.500000 (vendor)",
|
|
376
|
-
" Light changed: 111100.000000 (lux)",
|
|
377
|
-
]
|
|
378
|
-
)
|
|
379
|
-
|
|
380
|
-
def test_proximity_sensor_added(self):
|
|
381
|
-
self.set_internal_property("HasProximity", True)
|
|
382
|
-
self.start_monitor_sensor()
|
|
383
|
-
|
|
384
|
-
self.assertOutputEquals(
|
|
385
|
-
[
|
|
386
|
-
"=== No accelerometer",
|
|
387
|
-
"=== No ambient light sensor",
|
|
388
|
-
"=== Has proximity sensor (near: 0)",
|
|
389
|
-
]
|
|
390
|
-
)
|
|
391
|
-
|
|
392
|
-
def test_proximity_sensor_changes(self):
|
|
393
|
-
self.test_proximity_sensor_added()
|
|
394
|
-
|
|
395
|
-
self.set_internal_property("ProximityNear", True)
|
|
396
|
-
self.set_internal_property("ProximityNear", False)
|
|
397
|
-
|
|
398
|
-
self.assertOutputEquals(
|
|
399
|
-
[
|
|
400
|
-
" Proximity value changed: 1",
|
|
401
|
-
" Proximity value changed: 0",
|
|
402
|
-
]
|
|
403
|
-
)
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
if __name__ == "__main__":
|
|
407
|
-
# avoid writing to stderr
|
|
408
|
-
unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout))
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/dbusmock/templates/power_profiles_daemon.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/dbusmock/templates/upower_power_profiles_daemon.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{python_dbusmock-0.36.0 → python_dbusmock-0.37.1}/python_dbusmock.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|