python-dbusmock 0.35.0__tar.gz → 0.37.0__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.
Files changed (80) hide show
  1. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/.github/workflows/pages.yml +1 -1
  2. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/.github/workflows/release.yml +1 -1
  3. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/.github/workflows/tests.yml +1 -2
  4. {python_dbusmock-0.35.0/python_dbusmock.egg-info → python_dbusmock-0.37.0}/PKG-INFO +1 -5
  5. python_dbusmock-0.37.0/dbusmock/_version.py +1 -0
  6. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/dbusmock/mockobject.py +6 -3
  7. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/dbusmock/testcase.py +10 -61
  8. {python_dbusmock-0.35.0/packaging → python_dbusmock-0.37.0/distro}/python-dbusmock.spec +7 -6
  9. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/packit.yaml +5 -3
  10. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0/python_dbusmock.egg-info}/PKG-INFO +1 -5
  11. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/python_dbusmock.egg-info/SOURCES.txt +1 -6
  12. python_dbusmock-0.37.0/setup.cfg +4 -0
  13. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/tests/run-centos +1 -1
  14. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/tests/run-fedora +1 -1
  15. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/tests/test_api.py +37 -11
  16. python_dbusmock-0.35.0/.github/release.eloquent.yml +0 -2
  17. python_dbusmock-0.35.0/dbusmock/_version.py +0 -1
  18. python_dbusmock-0.35.0/dbusmock/templates/iio-sensors-proxy.py +0 -208
  19. python_dbusmock-0.35.0/setup.cfg +0 -35
  20. python_dbusmock-0.35.0/setup.py +0 -7
  21. python_dbusmock-0.35.0/tests/test_iio_sensors_proxy.py +0 -408
  22. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/.fmf/version +0 -0
  23. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/.gitignore +0 -0
  24. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/.pre-commit-config.yaml +0 -0
  25. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/COPYING +0 -0
  26. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/NEWS +0 -0
  27. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/README.md +0 -0
  28. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/dbusmock/__init__.py +0 -0
  29. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/dbusmock/__main__.py +0 -0
  30. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/dbusmock/pytest_fixtures.py +0 -0
  31. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/dbusmock/templates/SKELETON +0 -0
  32. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/dbusmock/templates/__init__.py +0 -0
  33. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/dbusmock/templates/bluez5-obex.py +0 -0
  34. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/dbusmock/templates/bluez5.py +0 -0
  35. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/dbusmock/templates/gnome_screensaver.py +0 -0
  36. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/dbusmock/templates/gsd_rfkill.py +0 -0
  37. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/dbusmock/templates/logind.py +0 -0
  38. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/dbusmock/templates/low_memory_monitor.py +0 -0
  39. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/dbusmock/templates/modemmanager.py +0 -0
  40. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/dbusmock/templates/networkmanager.py +0 -0
  41. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/dbusmock/templates/notification_daemon.py +0 -0
  42. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/dbusmock/templates/ofono.py +0 -0
  43. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/dbusmock/templates/polkitd.py +0 -0
  44. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/dbusmock/templates/power_profiles_daemon.py +0 -0
  45. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/dbusmock/templates/systemd.py +0 -0
  46. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/dbusmock/templates/timedated.py +0 -0
  47. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/dbusmock/templates/upower.py +0 -0
  48. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/dbusmock/templates/upower_power_profiles_daemon.py +0 -0
  49. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/dbusmock/templates/urfkill.py +0 -0
  50. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/doc/conf.py +0 -0
  51. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/doc/index.rst +0 -0
  52. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/plans/all.fmf +0 -0
  53. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/pyproject.toml +0 -0
  54. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/python_dbusmock.egg-info/dependency_links.txt +0 -0
  55. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/python_dbusmock.egg-info/requires.txt +0 -0
  56. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/python_dbusmock.egg-info/top_level.txt +0 -0
  57. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/tests/__init__.py +0 -0
  58. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/tests/conftest.py +0 -0
  59. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/tests/main.fmf +0 -0
  60. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/tests/run +0 -0
  61. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/tests/run-debian +0 -0
  62. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/tests/run-ubuntu +0 -0
  63. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/tests/test_api_pytest.py +0 -0
  64. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/tests/test_bluez5.py +0 -0
  65. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/tests/test_cli.py +0 -0
  66. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/tests/test_code.py +0 -0
  67. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/tests/test_gnome_screensaver.py +0 -0
  68. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/tests/test_gsd_rfkill.py +0 -0
  69. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/tests/test_logind.py +0 -0
  70. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/tests/test_low_memory_monitor.py +0 -0
  71. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/tests/test_modemmanager.py +0 -0
  72. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/tests/test_networkmanager.py +0 -0
  73. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/tests/test_notification_daemon.py +0 -0
  74. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/tests/test_ofono.py +0 -0
  75. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/tests/test_polkitd.py +0 -0
  76. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/tests/test_power_profiles_daemon.py +0 -0
  77. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/tests/test_systemd.py +0 -0
  78. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/tests/test_timedated.py +0 -0
  79. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/tests/test_upower.py +0 -0
  80. {python_dbusmock-0.35.0 → python_dbusmock-0.37.0}/tests/test_urfkill.py +0 -0
@@ -19,7 +19,7 @@ jobs:
19
19
  contents: read
20
20
 
21
21
  steps:
22
- - uses: actions/checkout@v4
22
+ - uses: actions/checkout@v5
23
23
 
24
24
  - name: Set up Python
25
25
  uses: actions/setup-python@v4
@@ -15,7 +15,7 @@ jobs:
15
15
  contents: write
16
16
  steps:
17
17
  - name: Clone repository
18
- uses: actions/checkout@v4
18
+ uses: actions/checkout@v5
19
19
  with:
20
20
  # need this to also fetch tags
21
21
  fetch-depth: 0
@@ -17,13 +17,12 @@ jobs:
17
17
  - docker.io/ubuntu:latest
18
18
  - registry.fedoraproject.org/fedora:latest
19
19
  - registry.fedoraproject.org/fedora:rawhide
20
- - quay.io/centos/centos:stream9
21
20
  - quay.io/centos/centos:stream10-development
22
21
 
23
22
  timeout-minutes: 30
24
23
  steps:
25
24
  - name: Clone repository
26
- uses: actions/checkout@v4
25
+ uses: actions/checkout@v5
27
26
  with:
28
27
  # need this to also fetch tags
29
28
  fetch-depth: 0
@@ -1,10 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-dbusmock
3
- Version: 0.35.0
3
+ Version: 0.37.0
4
4
  Summary: Mock D-Bus objects
5
- Home-page: https://github.com/martinpitt/python-dbusmock
6
- Download-URL: https://pypi.python.org/pypi/python-dbusmock/
7
- Author: Martin Pitt
8
5
  Author-email: Martin Pitt <martin@piware.de>
9
6
  License: GNU LESSER GENERAL PUBLIC LICENSE
10
7
  Version 3, 29 June 2007
@@ -188,7 +185,6 @@ Requires-Python: >=3.8
188
185
  Description-Content-Type: text/markdown
189
186
  License-File: COPYING
190
187
  Requires-Dist: dbus-python
191
- Dynamic: download-url
192
188
  Dynamic: license-file
193
189
 
194
190
  ![CI status](https://github.com/martinpitt/python-dbusmock/actions/workflows/tests.yml/badge.svg)
@@ -0,0 +1 @@
1
+ __version__ = "0.37.0"
@@ -116,10 +116,8 @@ def _wrap_in_dbus_variant(value):
116
116
  dbus.types.ByteArray,
117
117
  dbus.types.Int16,
118
118
  dbus.types.ObjectPath,
119
- dbus.types.Struct,
120
119
  dbus.types.UInt64,
121
120
  dbus.types.Boolean,
122
- dbus.types.Dictionary,
123
121
  dbus.types.Int32,
124
122
  dbus.types.Signature,
125
123
  dbus.types.UInt16,
@@ -130,9 +128,14 @@ def _wrap_in_dbus_variant(value):
130
128
  dbus.types.String,
131
129
  dbus.types.UInt32,
132
130
  ]
131
+ container_types = [
132
+ dbus.types.Array,
133
+ dbus.types.Struct,
134
+ dbus.types.Dictionary,
135
+ ]
133
136
  if isinstance(value, dbus.String):
134
137
  return dbus.String(str(value), variant_level=1)
135
- if isinstance(value, dbus.types.Array):
138
+ if type(value) in container_types:
136
139
  return value
137
140
  if type(value) in dbus_types:
138
141
  return type(value)(value.conjugate(), variant_level=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 _ in range(10):
179
- if self._socket.exists():
180
- break
181
- time.sleep(0.1)
182
- else:
183
- assert self._socket.exists(), "D-Bus socket never created"
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,9 +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: python3-setuptools
17
15
  BuildRequires: python3-gobject
18
16
  BuildRequires: python3-pytest
19
17
  BuildRequires: dbus-x11
@@ -37,18 +35,21 @@ Requires: python3-dbus, python3-gobject, dbus-x11
37
35
  %autosetup -n python_%{modname}-%{version}
38
36
  rm -rf python-%{modname}.egg-info
39
37
 
38
+ %generate_buildrequires
39
+ %pyproject_buildrequires
40
40
 
41
41
  %build
42
- %py3_build
42
+ %pyproject_wheel
43
43
 
44
44
  %install
45
- %py3_install
45
+ %pyproject_install
46
+ %pyproject_save_files -l dbusmock
46
47
 
47
48
  %check
48
49
  %{__python3} -m unittest -v
49
50
 
50
- %files -n python3-dbusmock
51
+ %files -n python3-dbusmock -f %{pyproject_files}
52
+
51
53
  %doc README.md COPYING
52
- %{python3_sitelib}/*%{modname}*
53
54
 
54
55
  %changelog
@@ -2,7 +2,7 @@
2
2
  # https://packit.dev/docs/configuration/
3
3
  upstream_project_url: https://github.com/martinpitt/python-dbusmock
4
4
  # HACK: should work without, but propose_downstream fails; https://github.com/packit/packit-service/issues/1511
5
- specfile_path: packaging/python-dbusmock.spec
5
+ specfile_path: distro/python-dbusmock.spec
6
6
  issue_repository: https://github.com/martinpitt/python-dbusmock
7
7
  copy_upstream_release_description: true
8
8
  upstream_package_name: python-dbusmock
@@ -12,7 +12,7 @@ actions:
12
12
  create-archive:
13
13
  - python3 -m build --sdist
14
14
  # spec and tarball need to be in the same directory
15
- - sh -c 'mv dist/*.tar.* packaging; ls packaging/python_dbusmock-*.tar.*'
15
+ - sh -c 'mv dist/*.tar.* distro; ls distro/python_dbusmock-*.tar.*'
16
16
 
17
17
  srpm_build_deps:
18
18
  - python3-build
@@ -28,12 +28,14 @@ jobs:
28
28
  - fedora-latest-ppc64le
29
29
  - fedora-latest-s390x
30
30
  - fedora-latest-armhfp
31
+ # needed for tests
32
+ - fedora-all
33
+ - centos-stream-10-x86_64
31
34
 
32
35
  - job: tests
33
36
  trigger: pull_request
34
37
  targets:
35
38
  - fedora-all
36
- - centos-stream-9-x86_64
37
39
  - centos-stream-10-x86_64
38
40
 
39
41
  - job: propose_downstream
@@ -1,10 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-dbusmock
3
- Version: 0.35.0
3
+ Version: 0.37.0
4
4
  Summary: Mock D-Bus objects
5
- Home-page: https://github.com/martinpitt/python-dbusmock
6
- Download-URL: https://pypi.python.org/pypi/python-dbusmock/
7
- Author: Martin Pitt
8
5
  Author-email: Martin Pitt <martin@piware.de>
9
6
  License: GNU LESSER GENERAL PUBLIC LICENSE
10
7
  Version 3, 29 June 2007
@@ -188,7 +185,6 @@ Requires-Python: >=3.8
188
185
  Description-Content-Type: text/markdown
189
186
  License-File: COPYING
190
187
  Requires-Dist: dbus-python
191
- Dynamic: download-url
192
188
  Dynamic: license-file
193
189
 
194
190
  ![CI status](https://github.com/martinpitt/python-dbusmock/actions/workflows/tests.yml/badge.svg)
@@ -5,10 +5,7 @@ NEWS
5
5
  README.md
6
6
  packit.yaml
7
7
  pyproject.toml
8
- setup.cfg
9
- setup.py
10
8
  .fmf/version
11
- .github/release.eloquent.yml
12
9
  .github/workflows/pages.yml
13
10
  .github/workflows/release.yml
14
11
  .github/workflows/tests.yml
@@ -24,7 +21,6 @@ dbusmock/templates/bluez5-obex.py
24
21
  dbusmock/templates/bluez5.py
25
22
  dbusmock/templates/gnome_screensaver.py
26
23
  dbusmock/templates/gsd_rfkill.py
27
- dbusmock/templates/iio-sensors-proxy.py
28
24
  dbusmock/templates/logind.py
29
25
  dbusmock/templates/low_memory_monitor.py
30
26
  dbusmock/templates/modemmanager.py
@@ -38,9 +34,9 @@ dbusmock/templates/timedated.py
38
34
  dbusmock/templates/upower.py
39
35
  dbusmock/templates/upower_power_profiles_daemon.py
40
36
  dbusmock/templates/urfkill.py
37
+ distro/python-dbusmock.spec
41
38
  doc/conf.py
42
39
  doc/index.rst
43
- packaging/python-dbusmock.spec
44
40
  plans/all.fmf
45
41
  python_dbusmock.egg-info/PKG-INFO
46
42
  python_dbusmock.egg-info/SOURCES.txt
@@ -62,7 +58,6 @@ tests/test_cli.py
62
58
  tests/test_code.py
63
59
  tests/test_gnome_screensaver.py
64
60
  tests/test_gsd_rfkill.py
65
- tests/test_iio_sensors_proxy.py
66
61
  tests/test_logind.py
67
62
  tests/test_low_memory_monitor.py
68
63
  tests/test_modemmanager.py
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -6,7 +6,7 @@ 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
- dnf -y install power-profiles-daemon iio-sensor-proxy python3-pytest
9
+ dnf -y install power-profiles-daemon python3-pytest
10
10
  else
11
11
  dnf -y install python3-pip
12
12
  pip install pytest
@@ -6,7 +6,7 @@ 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
- dnf -y install power-profiles-daemon iio-sensor-proxy python3-pytest
9
+ dnf -y install power-profiles-daemon python3-pytest
10
10
  else
11
11
  dnf -y install python3-pip
12
12
  pip install pytest
@@ -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
@@ -343,6 +344,32 @@ assert args[2] == 5
343
344
  self.assertEqual(self.dbus_props.GetAll("org.freedesktop.Test.Other"), {"color": "yellow"})
344
345
  self.assertEqual(self.dbus_props.Get("org.freedesktop.Test.Other", "color"), "yellow")
345
346
 
347
+ # add properties with complex types
348
+ self.dbus_mock.AddProperty("org.freedesktop.Test.Main", "intarray", dbus.Array([1, 2]))
349
+ self.dbus_mock.AddProperty("org.freedesktop.Test.Main", "vardict", dbus.Dictionary({"a": 1}))
350
+ self.dbus_mock.AddProperty("org.freedesktop.Test.Main", "struct", dbus.Struct((1, "a")))
351
+
352
+ changes = [
353
+ {
354
+ "version": 5,
355
+ "connected": False,
356
+ },
357
+ {
358
+ "intarray": [1, 3],
359
+ },
360
+ {
361
+ "vardict": {"b": "2"},
362
+ },
363
+ {
364
+ "struct": (2, "b"),
365
+ },
366
+ {
367
+ "intarray": [3, 7],
368
+ "vardict": {"d": dbus.Array([42, 1])},
369
+ "struct": (0, "test"),
370
+ },
371
+ ]
372
+
346
373
  changed_props = []
347
374
  ml = GLib.MainLoop()
348
375
 
@@ -357,28 +384,26 @@ assert args[2] == 5
357
384
  self.assertEqual(iface, "org.freedesktop.Test.Main")
358
385
 
359
386
  changed_props.append(changed)
360
- ml.quit()
387
+
388
+ if len(changed_props) == len(changes):
389
+ ml.quit()
361
390
 
362
391
  match = self.dbus_con.add_signal_receiver(
363
392
  catch, interface_keyword="interface", path_keyword="path", member_keyword="member"
364
393
  )
365
394
 
366
395
  # change property using mock helper
367
- self.dbus_mock.UpdateProperties(
368
- "org.freedesktop.Test.Main",
369
- {
370
- "version": 5,
371
- "connected": False,
372
- },
373
- )
396
+ for change in changes:
397
+ self.dbus_mock.UpdateProperties("org.freedesktop.Test.Main", change)
398
+ self.assertTrue(change.items() <= self.dbus_props.GetAll("org.freedesktop.Test.Main").items())
374
399
 
375
400
  GLib.timeout_add(3000, ml.quit)
376
401
  ml.run()
377
402
 
378
403
  match.remove()
379
404
 
380
- self.assertEqual(self.dbus_props.GetAll("org.freedesktop.Test.Main"), {"version": 5, "connected": False})
381
- self.assertEqual(changed_props, [{"version": 5, "connected": False}])
405
+ for i, change in enumerate(changes):
406
+ self.assertEqual(changed_props[i], change)
382
407
 
383
408
  # test adding properties with the array type
384
409
  self.dbus_mock.AddProperty("org.freedesktop.Test.Main", "array", dbus.Array(["first"], signature="s"))
@@ -1002,7 +1027,8 @@ class TestCleanup(dbusmock.DBusTestCase):
1002
1027
 
1003
1028
  self.start_session_bus()
1004
1029
  p_mock = self.spawn_server("org.freedesktop.Test", "/", "org.freedesktop.Test.Main")
1005
- self.stop_dbus(self.session_bus_pid)
1030
+ assert self.session_bus_pid is not None
1031
+ os.kill(self.session_bus_pid, signal.SIGTERM)
1006
1032
 
1007
1033
  # give the mock 2 seconds to terminate
1008
1034
  timeout = 20
@@ -1,2 +0,0 @@
1
- assets:
2
- - path: dist/python_dbusmock*.tar.*
@@ -1 +0,0 @@
1
- __version__ = "0.35.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,35 +0,0 @@
1
- [metadata]
2
- name = python-dbusmock
3
- version = attr: dbusmock.__version__
4
- description = Mock D-Bus objects
5
- long_description = file: README.md
6
- long_description_content_type = text/markdown
7
- author = Martin Pitt
8
- author_email = martin@piware.de
9
- url = https://github.com/martinpitt/python-dbusmock
10
- download_url = https://pypi.python.org/pypi/python-dbusmock/
11
- license = LGPL 3+
12
- classifiers =
13
- License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)
14
- Programming Language :: Python :: 3
15
- Development Status :: 6 - Mature
16
- Operating System :: POSIX :: Linux
17
- Operating System :: POSIX :: BSD
18
- Operating System :: Unix
19
- Topic :: Software Development :: Quality Assurance
20
- Topic :: Software Development :: Testing
21
- Topic :: Software Development :: Testing :: Mocking
22
- Topic :: Software Development :: Testing :: Unit
23
- Topic :: Software Development :: Libraries :: Python Modules
24
-
25
- [options]
26
- packages =
27
- dbusmock
28
- dbusmock.templates
29
- install_requires =
30
- dbus-python
31
-
32
- [egg_info]
33
- tag_build =
34
- tag_date = 0
35
-