python-dbusmock 0.32.2__tar.gz → 0.33.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 (79) hide show
  1. {python-dbusmock-0.32.2/python_dbusmock.egg-info → python-dbusmock-0.33.0}/PKG-INFO +1 -1
  2. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/dbusmock/__init__.py +0 -1
  3. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/dbusmock/__main__.py +0 -1
  4. python-dbusmock-0.33.0/dbusmock/_version.py +1 -0
  5. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/dbusmock/mockobject.py +32 -3
  6. python-dbusmock-0.33.0/dbusmock/templates/gsd_rfkill.py +54 -0
  7. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/dbusmock/testcase.py +1 -1
  8. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/pyproject.toml +2 -2
  9. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0/python_dbusmock.egg-info}/PKG-INFO +1 -1
  10. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/python_dbusmock.egg-info/SOURCES.txt +2 -0
  11. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/tests/test_api.py +39 -0
  12. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/tests/test_api_pytest.py +1 -1
  13. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/tests/test_bluez5.py +9 -14
  14. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/tests/test_cli.py +6 -6
  15. python-dbusmock-0.33.0/tests/test_gsd_rfkill.py +63 -0
  16. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/tests/test_logind.py +12 -12
  17. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/tests/test_networkmanager.py +8 -12
  18. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/tests/test_notification_daemon.py +1 -1
  19. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/tests/test_ofono.py +1 -1
  20. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/tests/test_power_profiles_daemon.py +4 -4
  21. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/tests/test_timedated.py +1 -1
  22. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/tests/test_upower.py +5 -5
  23. python-dbusmock-0.32.2/dbusmock/_version.py +0 -1
  24. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/.fmf/version +0 -0
  25. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/.github/release.eloquent.yml +0 -0
  26. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/.github/workflows/pages.yml +0 -0
  27. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/.github/workflows/release.yml +0 -0
  28. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/.github/workflows/tests.yml +0 -0
  29. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/.gitignore +0 -0
  30. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/.pre-commit-config.yaml +0 -0
  31. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/COPYING +0 -0
  32. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/NEWS +0 -0
  33. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/README.md +0 -0
  34. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/dbusmock/pytest_fixtures.py +0 -0
  35. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/dbusmock/templates/SKELETON +0 -0
  36. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/dbusmock/templates/__init__.py +0 -0
  37. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/dbusmock/templates/bluez5-obex.py +0 -0
  38. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/dbusmock/templates/bluez5.py +0 -0
  39. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/dbusmock/templates/gnome_screensaver.py +0 -0
  40. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/dbusmock/templates/iio-sensors-proxy.py +0 -0
  41. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/dbusmock/templates/logind.py +0 -0
  42. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/dbusmock/templates/low_memory_monitor.py +0 -0
  43. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/dbusmock/templates/modemmanager.py +0 -0
  44. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/dbusmock/templates/networkmanager.py +0 -0
  45. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/dbusmock/templates/notification_daemon.py +0 -0
  46. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/dbusmock/templates/ofono.py +0 -0
  47. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/dbusmock/templates/polkitd.py +0 -0
  48. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/dbusmock/templates/power_profiles_daemon.py +0 -0
  49. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/dbusmock/templates/systemd.py +0 -0
  50. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/dbusmock/templates/timedated.py +0 -0
  51. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/dbusmock/templates/upower.py +0 -0
  52. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/dbusmock/templates/upower_power_profiles_daemon.py +0 -0
  53. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/dbusmock/templates/urfkill.py +0 -0
  54. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/doc/conf.py +0 -0
  55. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/doc/index.rst +0 -0
  56. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/packaging/python-dbusmock.spec +0 -0
  57. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/packit.yaml +0 -0
  58. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/plans/all.fmf +0 -0
  59. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/python_dbusmock.egg-info/dependency_links.txt +0 -0
  60. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/python_dbusmock.egg-info/requires.txt +0 -0
  61. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/python_dbusmock.egg-info/top_level.txt +0 -0
  62. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/setup.cfg +0 -0
  63. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/setup.py +0 -0
  64. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/tests/__init__.py +0 -0
  65. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/tests/conftest.py +0 -0
  66. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/tests/main.fmf +0 -0
  67. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/tests/run +0 -0
  68. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/tests/run-centos +0 -0
  69. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/tests/run-debian +0 -0
  70. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/tests/run-fedora +0 -0
  71. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/tests/run-ubuntu +0 -0
  72. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/tests/test_code.py +0 -0
  73. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/tests/test_gnome_screensaver.py +0 -0
  74. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/tests/test_iio_sensors_proxy.py +0 -0
  75. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/tests/test_low_memory_monitor.py +0 -0
  76. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/tests/test_modemmanager.py +0 -0
  77. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/tests/test_polkitd.py +0 -0
  78. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/tests/test_systemd.py +0 -0
  79. {python-dbusmock-0.32.2 → python-dbusmock-0.33.0}/tests/test_urfkill.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-dbusmock
3
- Version: 0.32.2
3
+ Version: 0.33.0
4
4
  Summary: Mock D-Bus objects
5
5
  Home-page: https://github.com/martinpitt/python-dbusmock
6
6
  Author: Martin Pitt
@@ -1,4 +1,3 @@
1
- # coding: UTF-8
2
1
  """Mock D-Bus objects for test suites."""
3
2
 
4
3
  # This program is free software; you can redistribute it and/or modify it under
@@ -1,4 +1,3 @@
1
- # coding: UTF-8
2
1
  """Main entry point for running mock server."""
3
2
 
4
3
  # This program is free software; you can redistribute it and/or modify it under
@@ -0,0 +1 @@
1
+ __version__ = "0.33.0"
@@ -1,4 +1,3 @@
1
- # coding: UTF-8
2
1
  """Mock D-Bus objects for test suites."""
3
2
 
4
3
  # This program is free software; you can redistribute it and/or modify it under
@@ -199,6 +198,7 @@ class DBusMockObject(dbus.service.Object): # pylint: disable=too-many-instance-
199
198
  props: PropsType,
200
199
  logfile: Optional[str] = None,
201
200
  is_object_manager: bool = False,
201
+ mock_data: Any = None,
202
202
  ) -> None:
203
203
  """Create a new DBusMockObject
204
204
 
@@ -234,6 +234,7 @@ class DBusMockObject(dbus.service.Object): # pylint: disable=too-many-instance-
234
234
  self.logfile = open(logfile, "wb") if logfile else None # noqa: SIM115
235
235
  self.is_logfile_owner = True
236
236
  self.call_log: List[CallLogType] = []
237
+ self.mock_data = mock_data
237
238
 
238
239
  if props is None:
239
240
  props = {}
@@ -323,7 +324,9 @@ class DBusMockObject(dbus.service.Object): # pylint: disable=too-many-instance-
323
324
  )
324
325
 
325
326
  @dbus.service.method(MOCK_IFACE, in_signature="ssa{sv}a(ssss)", out_signature="")
326
- def AddObject(self, path: str, interface: str, properties: PropsType, methods: List[MethodType]) -> None:
327
+ def AddObject(
328
+ self, path: str, interface: str, properties: PropsType, methods: List[MethodType], **kwargs
329
+ ) -> None:
327
330
  """Dynamically add a new D-Bus object to the mock
328
331
 
329
332
  :param path: D-Bus object path
@@ -335,6 +338,12 @@ class DBusMockObject(dbus.service.Object): # pylint: disable=too-many-instance-
335
338
  methods to add to "interface"; see AddMethod() for details of
336
339
  the tuple values
337
340
 
341
+ Keyword Arguments:
342
+ :param mock_class: A DBusMockObject derived class name (this is only possible
343
+ when the method is not called via dbus)
344
+ :param mock_data: Additional data which will be passed to the DBusMockObject
345
+ constructor
346
+
338
347
  If this is a D-Bus ObjectManager instance, the InterfacesAdded signal
339
348
  will *not* be emitted for the object automatically; it must be emitted
340
349
  manually if desired. This is because AddInterface may be called after
@@ -352,13 +361,33 @@ class DBusMockObject(dbus.service.Object): # pylint: disable=too-many-instance-
352
361
  ('EchoInt', 'i', 'i', 'ret = args[0]'),
353
362
  ('GetClients', '', 'ao', 'ret = ["/com/example/Foo/Client1"]'),
354
363
  ])
364
+
365
+ Example 2 (in a template)::
366
+
367
+ class FooManager(dbusmock.mockobject.DBusMockObject):
368
+ def __init__(self, *args, **kwargs):
369
+ super(FooManager, self).__init__(*args, **kwargs)
370
+ self.magic = kwargs.get('mock_data')
371
+
372
+ @dbus.service.method('com.example.Foo.Control', in_signature='i', out_signature='i')
373
+ def EchoMagic(self, input):
374
+ return self.magic + input
375
+
376
+ dbus_proxy.AddObject('/com/example/Foo/Manager',
377
+ 'com.example.Foo.Control',
378
+ {}, [],
379
+ mock_class=FooManager,
380
+ mock_data=42)
355
381
  """
356
382
  if path in objects:
357
383
  raise dbus.exceptions.DBusException(
358
384
  f"object {path} already exists", name="org.freedesktop.DBus.Mock.NameError"
359
385
  )
360
386
 
361
- obj = DBusMockObject(self.bus_name, path, interface, properties)
387
+ mock_class = kwargs.get("mock_class", DBusMockObject)
388
+ mock_data = kwargs.get("mock_data")
389
+
390
+ obj = mock_class(self.bus_name, path, interface, properties, mock_data=mock_data)
362
391
  # make sure created objects inherit the log file stream
363
392
  obj.logfile = self.logfile
364
393
  obj.object_manager = self.object_manager
@@ -0,0 +1,54 @@
1
+ """gsd-rfkill mock template
2
+
3
+ This creates the expected properties of the GNOME Settings Daemon's
4
+ rfkill object. You can specify any property such as AirplaneMode in
5
+ "parameters".
6
+ """
7
+
8
+ # This program is free software; you can redistribute it and/or modify it under
9
+ # the terms of the GNU Lesser General Public License as published by the Free
10
+ # Software Foundation; either version 3 of the License, or (at your option) any
11
+ # later version. See http://www.gnu.org/copyleft/lgpl.html for the full text
12
+ # of the license.
13
+
14
+ __author__ = "Guido Günther"
15
+ __copyright__ = "2024 The Phosh Developers"
16
+
17
+ import dbus
18
+
19
+ from dbusmock import MOCK_IFACE
20
+
21
+ SYSTEM_BUS = False
22
+ BUS_NAME = "org.gnome.SettingsDaemon.Rfkill"
23
+ MAIN_OBJ = "/org/gnome/SettingsDaemon/Rfkill"
24
+ MAIN_IFACE = "org.gnome.SettingsDaemon.Rfkill"
25
+
26
+
27
+ def load(mock, parameters):
28
+ props = dbus.Dictionary(
29
+ {
30
+ "AirplaneMode": parameters.get("AirplaneMode", False),
31
+ "BluetoothAirplaneMode": parameters.get("BluetoothAirplaneMode", False),
32
+ "BluetoothHardwareAirplaneMode": parameters.get("BluetoothHardwareAirplaneMode", False),
33
+ "BluetoothHasAirplaneMode": parameters.get("BluetoothHasAirplanemode", True),
34
+ "HardwareAirplaneMode": parameters.get("HardwareAirplaneMode", False),
35
+ "HasAirplaneMode": parameters.get("HasAirplaneMode", True),
36
+ "ShouldShowAirplaneMode": parameters.get("ShouldShowAirplaneMode", True),
37
+ "WwanAirplaneMode": parameters.get("WwanAirplaneMode", False),
38
+ "WwanHardwareAirplaneMode": parameters.get("WwanHardwareAirplaneMode", False),
39
+ "WwanHasAirplaneMode": parameters.get("WwanHasAirplaneMode", True),
40
+ },
41
+ signature="sv",
42
+ )
43
+ mock.AddProperties(MAIN_IFACE, props)
44
+
45
+
46
+ @dbus.service.method(MOCK_IFACE, in_signature="b", out_signature="b")
47
+ def SetAirplaneMode(self, mode):
48
+ """
49
+ Convenience method to toggle airplane mode
50
+ """
51
+ self.props[MAIN_IFACE]["AirplaneMode"] = mode
52
+ self.props[MAIN_IFACE]["BluetoothAirplaneMode"] = mode
53
+ self.props[MAIN_IFACE]["WwanAirplaneMode"] = mode
54
+ return mode
@@ -321,7 +321,7 @@ class DBusTestCase(unittest.TestCase):
321
321
  argv.append("--config-file=" + str(conf))
322
322
  else:
323
323
  argv.append("--session")
324
- lines = subprocess.check_output(argv, universal_newlines=True).strip().splitlines()
324
+ lines = subprocess.check_output(argv, text=True).strip().splitlines()
325
325
  assert len(lines) == 2, "expected exactly 2 lines of output from dbus-daemon"
326
326
  # usually the first line is the address, but be lenient and accept any order
327
327
  try:
@@ -24,7 +24,7 @@ classifiers = [
24
24
  "Topic :: Software Development :: Libraries :: Python Modules",
25
25
  ]
26
26
  dynamic = ["version"]
27
- requires-python = ">=3.6"
27
+ requires-python = ">=3.8"
28
28
 
29
29
  dependencies = ["dbus-python"]
30
30
 
@@ -43,7 +43,7 @@ version_scheme = 'post-release'
43
43
 
44
44
  [tool.pylint]
45
45
  format = { max-line-length = 130 }
46
- "messages control" = { disable = ["invalid-name"] }
46
+ "messages control" = { disable = ["invalid-name", "too-many-arguments", "too-many-positional-arguments"] }
47
47
  design = { max-args = 7, max-locals = 25, max-public-methods = 25 }
48
48
 
49
49
  [tool.mypy]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-dbusmock
3
- Version: 0.32.2
3
+ Version: 0.33.0
4
4
  Summary: Mock D-Bus objects
5
5
  Home-page: https://github.com/martinpitt/python-dbusmock
6
6
  Author: Martin Pitt
@@ -23,6 +23,7 @@ dbusmock/templates/__init__.py
23
23
  dbusmock/templates/bluez5-obex.py
24
24
  dbusmock/templates/bluez5.py
25
25
  dbusmock/templates/gnome_screensaver.py
26
+ dbusmock/templates/gsd_rfkill.py
26
27
  dbusmock/templates/iio-sensors-proxy.py
27
28
  dbusmock/templates/logind.py
28
29
  dbusmock/templates/low_memory_monitor.py
@@ -60,6 +61,7 @@ tests/test_bluez5.py
60
61
  tests/test_cli.py
61
62
  tests/test_code.py
62
63
  tests/test_gnome_screensaver.py
64
+ tests/test_gsd_rfkill.py
63
65
  tests/test_iio_sensors_proxy.py
64
66
  tests/test_logind.py
65
67
  tests/test_low_memory_monitor.py
@@ -923,6 +923,45 @@ def load(mock, parameters):
923
923
  self.assertIn('<node name="Thing1" />', xml)
924
924
  self.assertIn('<node name="Thing2" />', xml)
925
925
 
926
+ def test_add_object_with_subclass(self):
927
+ """Template with DBusMockObject subclass"""
928
+
929
+ with tempfile.NamedTemporaryFile(prefix="objmgr_", suffix=".py") as my_template:
930
+ my_template.write(
931
+ b"""
932
+ import dbus
933
+ import dbusmock
934
+ BUS_NAME = 'org.test.Things'
935
+ MAIN_OBJ = '/org/test/Things'
936
+ MAIN_IFACE = 'org.test.Do'
937
+ SYSTEM_BUS = False
938
+
939
+ class Thing1(dbusmock.mockobject.DBusMockObject):
940
+ def __init__(self, *args, **kwargs):
941
+ super(Thing1, self).__init__(*args, **kwargs)
942
+ self.magic = kwargs.get('mock_data')
943
+
944
+ @dbus.service.method(MAIN_IFACE, in_signature='i', out_signature='i')
945
+ def Do0(self, input):
946
+ return self.magic + input
947
+
948
+ def load(mock, parameters):
949
+ mock.AddObject('/org/test/Things/Thing1', MAIN_IFACE, {}, [],
950
+ mock_class=Thing1,
951
+ mock_data=42)
952
+ """
953
+ )
954
+ my_template.flush()
955
+ (p_mock, _) = self.spawn_server_template(my_template.name, stdout=subprocess.PIPE, system_bus=False)
956
+ self.addCleanup(p_mock.wait)
957
+ self.addCleanup(p_mock.terminate)
958
+ self.addCleanup(p_mock.stdout.close)
959
+
960
+ dbus_con = self.get_dbus(system_bus=False)
961
+ thing1 = dbus_con.get_object("org.test.Things", "/org/test/Things/Thing1")
962
+ self.assertEqual(thing1.Do0(0), 42)
963
+ self.assertEqual(thing1.Do0(1), 43)
964
+
926
965
  def test_reset(self):
927
966
  """Reset() puts the template back to pristine state"""
928
967
 
@@ -35,6 +35,6 @@ def fixture_upower_mock(dbusmock_system):
35
35
 
36
36
  def test_dbusmock_test_template(upower_mock):
37
37
  assert upower_mock
38
- out = subprocess.check_output(["upower", "--dump"], universal_newlines=True)
38
+ out = subprocess.check_output(["upower", "--dump"], text=True)
39
39
  assert "version:" in out
40
40
  assert "0.99" in out
@@ -12,6 +12,7 @@ __copyright__ = """
12
12
 
13
13
 
14
14
  import os
15
+ import re
15
16
  import shutil
16
17
  import subprocess
17
18
  import sys
@@ -34,7 +35,8 @@ dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
34
35
  have_bluetoothctl = shutil.which("bluetoothctl")
35
36
  have_pbap_client = shutil.which("pbap-client")
36
37
 
37
- el10 = "platform:el10" in Path("/etc/os-release").read_text("UTF-8")
38
+ os_release = Path("/etc/os-release")
39
+ el10 = os_release.exists() and "platform:el10" in os_release.read_text("UTF-8")
38
40
 
39
41
 
40
42
  def _run_bluetoothctl(command):
@@ -58,21 +60,14 @@ def _run_bluetoothctl(command):
58
60
  name="org.freedesktop.DBus.Mock.Error",
59
61
  )
60
62
 
61
- # Strip the prompt from the start of every line, then remove empty
62
- # lines.
63
+ # Strip the prompt and escape sequences from the start of every line,
64
+ # then remove empty lines.
63
65
  #
64
66
  # The prompt looks like `[bluetooth]# `, potentially containing command
65
- # line colour control codes. Split at the first space.
66
- #
67
- # Sometimes we end up with the final line being `\x1b[K` (partial
68
- # control code), which we need to ignore.
67
+ # line colour control codes.
69
68
  def remove_prefix(line):
70
- if line.startswith(("[bluetooth]#", "\x1b")):
71
- parts = line.split(" ", 1)
72
- try:
73
- return parts[1].strip()
74
- except IndexError:
75
- return ""
69
+ line = re.sub(r"\x1b\[[0-9;]*[mPK]", "", line)
70
+ line = re.sub(r"^\[bluetooth\]# ", "", line)
76
71
  return line.strip()
77
72
 
78
73
  lines = out.split("\n")
@@ -493,7 +488,7 @@ class TestBlueZ5(dbusmock.DBusTestCase):
493
488
  adapter = self.dbus_con.get_object("org.bluez", path)
494
489
 
495
490
  # When an advertisement monitor is configured via bluetoothctl
496
- out = _run_bluetoothctl("monitor.add-or-pattern 0 255 0x01")
491
+ out = _run_bluetoothctl("monitor.add-or-pattern 0 255 01")
497
492
 
498
493
  # Then bluetoothctl reports success
499
494
  self.assertIn("Advertisement Monitor 0 added", out)
@@ -59,7 +59,7 @@ class TestCLI(dbusmock.DBusTestCase):
59
59
  self.wait_for_bus_object(wait_name, wait_path, wait_system)
60
60
 
61
61
  def start_mock_process(self, args):
62
- return subprocess.check_output([sys.executable, "-m", "dbusmock", *args], universal_newlines=True)
62
+ return subprocess.check_output([sys.executable, "-m", "dbusmock", *args], text=True)
63
63
 
64
64
  def test_session_bus(self):
65
65
  self.start_mock(["com.example.Test", "/", "TestIface"], "com.example.Test", "/")
@@ -80,7 +80,7 @@ class TestCLI(dbusmock.DBusTestCase):
80
80
  def check_upower_running(self):
81
81
  # check that it actually ran the template, if we have upower
82
82
  if have_upower:
83
- out = subprocess.check_output(["upower", "--dump"], universal_newlines=True)
83
+ out = subprocess.check_output(["upower", "--dump"], text=True)
84
84
  self.assertRegex(out, r"on-battery:\s+no")
85
85
 
86
86
  mock_out = self.p_mock.stdout.readline()
@@ -99,7 +99,7 @@ class TestCLI(dbusmock.DBusTestCase):
99
99
  subprocess.check_output(
100
100
  [sys.executable, "-m", "dbusmock", "--system", "--session", "-t", "upower"],
101
101
  stderr=subprocess.STDOUT,
102
- universal_newlines=True,
102
+ text=True,
103
103
  )
104
104
  err = cm.exception
105
105
  self.assertEqual(err.returncode, 2)
@@ -115,7 +115,7 @@ class TestCLI(dbusmock.DBusTestCase):
115
115
 
116
116
  # check that it actually ran the template, if we have upower
117
117
  if have_upower:
118
- out = subprocess.check_output(["upower", "--dump"], universal_newlines=True)
118
+ out = subprocess.check_output(["upower", "--dump"], text=True)
119
119
  self.assertRegex(out, r"daemon-version:\s+0\.99\.0")
120
120
  self.assertRegex(out, r"on-battery:\s+yes")
121
121
 
@@ -124,7 +124,7 @@ class TestCLI(dbusmock.DBusTestCase):
124
124
  subprocess.check_output(
125
125
  [sys.executable, "-m", "dbusmock", "-t", "upower", "-p", '{"DaemonVersion: "0.99.0"}'],
126
126
  stderr=subprocess.STDOUT,
127
- universal_newlines=True,
127
+ text=True,
128
128
  )
129
129
  err = cm.exception
130
130
  self.assertEqual(err.returncode, 2)
@@ -135,7 +135,7 @@ class TestCLI(dbusmock.DBusTestCase):
135
135
  subprocess.check_output(
136
136
  [sys.executable, "-m", "dbusmock", "-t", "upower", "-p", '"banana"'],
137
137
  stderr=subprocess.STDOUT,
138
- universal_newlines=True,
138
+ text=True,
139
139
  )
140
140
  err = cm.exception
141
141
  self.assertEqual(err.returncode, 2)
@@ -0,0 +1,63 @@
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__ = "Guido Günther"
8
+ __copyright__ = "2024 The Phosh Developers"
9
+
10
+ import fcntl
11
+ import os
12
+ import subprocess
13
+ import sys
14
+ import unittest
15
+
16
+ import dbus
17
+
18
+ import dbusmock
19
+
20
+
21
+ class TestGsdRfkill(dbusmock.DBusTestCase):
22
+ """Test mocked GNOME Settings Daemon Rfkill"""
23
+
24
+ @classmethod
25
+ def setUpClass(cls):
26
+ cls.start_session_bus()
27
+ cls.dbus_con = cls.get_dbus()
28
+
29
+ def setUp(self):
30
+ (self.p_mock, self.p_obj) = self.spawn_server_template("gsd_rfkill", {}, stdout=subprocess.PIPE)
31
+ # set log to nonblocking
32
+ flags = fcntl.fcntl(self.p_mock.stdout, fcntl.F_GETFL)
33
+ fcntl.fcntl(self.p_mock.stdout, fcntl.F_SETFL, flags | os.O_NONBLOCK)
34
+
35
+ def tearDown(self):
36
+ self.p_mock.stdout.close()
37
+ self.p_mock.terminate()
38
+ self.p_mock.wait()
39
+
40
+ def test_mainobject(self):
41
+ propiface = dbus.Interface(self.p_obj, dbus.PROPERTIES_IFACE)
42
+
43
+ mode = propiface.Get("org.gnome.SettingsDaemon.Rfkill", "AirplaneMode")
44
+ self.assertEqual(mode, False)
45
+ mode = propiface.Get("org.gnome.SettingsDaemon.Rfkill", "HasAirplaneMode")
46
+ self.assertEqual(mode, True)
47
+
48
+ def test_airplane_mode(self):
49
+ propiface = dbus.Interface(self.p_obj, dbus.PROPERTIES_IFACE)
50
+
51
+ self.p_obj.SetAirplaneMode(True)
52
+
53
+ mode = propiface.Get("org.gnome.SettingsDaemon.Rfkill", "AirplaneMode")
54
+ self.assertEqual(mode, True)
55
+ mode = propiface.Get("org.gnome.SettingsDaemon.Rfkill", "BluetoothAirplaneMode")
56
+ self.assertEqual(mode, True)
57
+ mode = propiface.Get("org.gnome.SettingsDaemon.Rfkill", "WwanAirplaneMode")
58
+ self.assertEqual(mode, True)
59
+
60
+
61
+ if __name__ == "__main__":
62
+ # avoid writing to stderr
63
+ unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout))
@@ -37,7 +37,7 @@ class TestLogind(dbusmock.DBusTestCase):
37
37
  cls.dbus_con = cls.get_dbus(True)
38
38
 
39
39
  if have_loginctl:
40
- out = subprocess.check_output(["loginctl", "--version"], universal_newlines=True)
40
+ out = subprocess.check_output(["loginctl", "--version"], text=True)
41
41
  cls.version = re.search(r"(\d+)", out.splitlines()[0]).group(1)
42
42
 
43
43
  def setUp(self):
@@ -54,13 +54,13 @@ class TestLogind(dbusmock.DBusTestCase):
54
54
  cmd = ["loginctl"]
55
55
  if self.version >= "209":
56
56
  cmd.append("--no-legend")
57
- out = subprocess.check_output([*cmd, "list-sessions"], universal_newlines=True)
57
+ out = subprocess.check_output([*cmd, "list-sessions"], text=True)
58
58
  self.assertEqual(out, "")
59
59
 
60
- out = subprocess.check_output([*cmd, "list-seats"], universal_newlines=True)
60
+ out = subprocess.check_output([*cmd, "list-seats"], text=True)
61
61
  self.assertEqual(out, "")
62
62
 
63
- out = subprocess.check_output([*cmd, "list-users"], universal_newlines=True)
63
+ out = subprocess.check_output([*cmd, "list-users"], text=True)
64
64
  self.assertEqual(out, "")
65
65
 
66
66
  def test_session(self):
@@ -68,16 +68,16 @@ class TestLogind(dbusmock.DBusTestCase):
68
68
 
69
69
  obj_logind.AddSession("c1", "seat0", 500, "joe", True)
70
70
 
71
- out = subprocess.check_output(["loginctl", "list-seats"], universal_newlines=True)
71
+ out = subprocess.check_output(["loginctl", "list-seats"], text=True)
72
72
  self.assertRegex(out, r"(^|\n)seat0\s+")
73
73
 
74
- out = subprocess.check_output(["loginctl", "show-seat", "seat0"], universal_newlines=True)
74
+ out = subprocess.check_output(["loginctl", "show-seat", "seat0"], text=True)
75
75
  self.assertRegex(out, "Id=seat0")
76
76
  if self.version <= "208":
77
77
  self.assertRegex(out, "ActiveSession=c1")
78
78
  self.assertRegex(out, "Sessions=c1")
79
79
 
80
- out = subprocess.check_output(["loginctl", "list-users"], universal_newlines=True)
80
+ out = subprocess.check_output(["loginctl", "list-users"], text=True)
81
81
  self.assertRegex(out, r"(^|\n)\s*500\s+joe\s*")
82
82
 
83
83
  # note, this does an actual getpwnam() in the client, so we cannot call
@@ -90,10 +90,10 @@ class TestLogind(dbusmock.DBusTestCase):
90
90
  # self.assertRegex(out, 'Sessions=c1')
91
91
  # self.assertRegex(out, 'State=active')
92
92
 
93
- out = subprocess.check_output(["loginctl", "list-sessions"], universal_newlines=True)
93
+ out = subprocess.check_output(["loginctl", "list-sessions"], text=True)
94
94
  self.assertRegex(out, "c1 +500 +joe +seat0")
95
95
 
96
- out = subprocess.check_output(["loginctl", "show-session", "c1"], universal_newlines=True)
96
+ out = subprocess.check_output(["loginctl", "show-session", "c1"], text=True)
97
97
  self.assertRegex(out, "Id=c1")
98
98
  self.assertRegex(out, "Class=user")
99
99
  self.assertRegex(out, "Active=yes")
@@ -107,7 +107,7 @@ class TestLogind(dbusmock.DBusTestCase):
107
107
  )
108
108
  session_mock.SetLockedHint(True)
109
109
 
110
- out = subprocess.check_output(["loginctl", "show-session", "c1"], universal_newlines=True)
110
+ out = subprocess.check_output(["loginctl", "show-session", "c1"], text=True)
111
111
  self.assertRegex(out, "Id=c1")
112
112
  self.assertRegex(out, "LockedHint=yes")
113
113
 
@@ -124,7 +124,7 @@ class TestLogind(dbusmock.DBusTestCase):
124
124
  fd = obj_logind.Inhibit("suspend", "testcode", "purpose", "delay")
125
125
 
126
126
  # Our inhibitor is held
127
- out = subprocess.check_output(["systemd-inhibit"], universal_newlines=True)
127
+ out = subprocess.check_output(["systemd-inhibit"], text=True)
128
128
  self.assertRegex(
129
129
  out.replace("\n", " "),
130
130
  "(testcode +[0-9]+ +[^ ]* +[0-9]+ +[^ ]* +suspend purpose delay)|"
@@ -133,7 +133,7 @@ class TestLogind(dbusmock.DBusTestCase):
133
133
 
134
134
  del fd
135
135
  # No inhibitor is held
136
- out = subprocess.check_output(["systemd-inhibit"], universal_newlines=True)
136
+ out = subprocess.check_output(["systemd-inhibit"], text=True)
137
137
  self.assertRegex(out, "No inhibitors|0 inhibitors listed")
138
138
 
139
139
 
@@ -79,31 +79,27 @@ class TestNetworkManager(dbusmock.DBusTestCase):
79
79
  self.p_mock.wait()
80
80
 
81
81
  def read_general(self):
82
- return subprocess.check_output(["nmcli", "--nocheck", "general"], env=self.lang_env, universal_newlines=True)
82
+ return subprocess.check_output(["nmcli", "--nocheck", "general"], env=self.lang_env, text=True)
83
83
 
84
84
  def read_networking(self):
85
- return subprocess.check_output(
86
- ["nmcli", "--nocheck", "networking"], env=self.lang_env, universal_newlines=True
87
- )
85
+ return subprocess.check_output(["nmcli", "--nocheck", "networking"], env=self.lang_env, text=True)
88
86
 
89
87
  def read_connection(self):
90
- return subprocess.check_output(
91
- ["nmcli", "--nocheck", "connection"], env=self.lang_env, universal_newlines=True
92
- )
88
+ return subprocess.check_output(["nmcli", "--nocheck", "connection"], env=self.lang_env, text=True)
93
89
 
94
90
  def read_active_connection(self):
95
91
  return subprocess.check_output(
96
- ["nmcli", "--nocheck", "connection", "show", "--active"], env=self.lang_env, universal_newlines=True
92
+ ["nmcli", "--nocheck", "connection", "show", "--active"], env=self.lang_env, text=True
97
93
  )
98
94
 
99
95
  def read_device(self):
100
- return subprocess.check_output(["nmcli", "--nocheck", "dev"], env=self.lang_env, universal_newlines=True)
96
+ return subprocess.check_output(["nmcli", "--nocheck", "dev"], env=self.lang_env, text=True)
101
97
 
102
98
  def read_device_wifi(self):
103
99
  return subprocess.check_output(
104
100
  ["nmcli", "--nocheck", "dev", "wifi", "list", "--rescan", "no"],
105
101
  env=self.lang_env,
106
- universal_newlines=True,
102
+ text=True,
107
103
  )
108
104
 
109
105
  def test_one_eth_disconnected(self):
@@ -174,7 +170,7 @@ class TestNetworkManager(dbusmock.DBusTestCase):
174
170
 
175
171
  # TODO: for connecting to password protected Wifi we need to implement secrets agent
176
172
  # https://github.com/martinpitt/python-dbusmock/issues/216
177
- out = subprocess.check_output(["nmcli", "--version"], universal_newlines=True)
173
+ out = subprocess.check_output(["nmcli", "--version"], text=True)
178
174
  m = re.search(r"([1-9.]+[0-9])", out)
179
175
  assert m, "could not parse version from " + out
180
176
  if Version(m.group(1)) >= Version("1.49.3"):
@@ -254,7 +250,7 @@ class TestNetworkManager(dbusmock.DBusTestCase):
254
250
  self.assertEqual(con1, "/org/freedesktop/NetworkManager/Settings/Mock_Con1")
255
251
 
256
252
  settings = subprocess.check_output(
257
- ["nmcli", "--nocheck", "connection", "show", "The_SSID"], env=self.lang_env, universal_newlines=True
253
+ ["nmcli", "--nocheck", "connection", "show", "The_SSID"], env=self.lang_env, text=True
258
254
  )
259
255
  self.assertRegex(settings, r"ipv4.method:\s*auto")
260
256
  self.assertRegex(settings, r"ipv4.gateway:\s*--")
@@ -21,7 +21,7 @@ import dbus
21
21
  import dbusmock
22
22
 
23
23
  try:
24
- notify_send_version = subprocess.check_output(["notify-send", "--version"], universal_newlines=True)
24
+ notify_send_version = subprocess.check_output(["notify-send", "--version"], text=True)
25
25
  notify_send_version = notify_send_version.split()[-1]
26
26
  except (OSError, subprocess.CalledProcessError):
27
27
  notify_send_version = ""
@@ -104,7 +104,7 @@ class TestOfono(dbusmock.DBusTestCase):
104
104
  def test_list_operators(self):
105
105
  """list operators"""
106
106
 
107
- out = subprocess.check_output([script_dir / "list-operators"], universal_newlines=True)
107
+ out = subprocess.check_output([script_dir / "list-operators"], text=True)
108
108
  self.assertTrue(out.startswith("[ /ril_0 ]"), out)
109
109
  self.assertIn("[ /ril_0/operator/op1 ]", out)
110
110
  self.assertIn("Status = current", out)
@@ -64,7 +64,7 @@ class TestPowerProfilesDaemon(dbusmock.DBusTestCase):
64
64
  def test_list_profiles(self):
65
65
  """List Profiles and check active profile"""
66
66
 
67
- out = subprocess.check_output(["powerprofilesctl"], universal_newlines=True)
67
+ out = subprocess.check_output(["powerprofilesctl"], text=True)
68
68
 
69
69
  self.assertIn("performance:\n", out)
70
70
  self.assertIn("\n* balanced:\n", out)
@@ -72,12 +72,12 @@ class TestPowerProfilesDaemon(dbusmock.DBusTestCase):
72
72
  def test_change_profile(self):
73
73
  """Change ActiveProfile"""
74
74
 
75
- subprocess.check_output(["powerprofilesctl", "set", "performance"], universal_newlines=True)
76
- out = subprocess.check_output(["powerprofilesctl", "get"], universal_newlines=True)
75
+ subprocess.check_output(["powerprofilesctl", "set", "performance"], text=True)
76
+ out = subprocess.check_output(["powerprofilesctl", "get"], text=True)
77
77
  self.assertEqual(out, "performance\n")
78
78
 
79
79
  def run_powerprofilesctl_list_holds(self):
80
- return subprocess.check_output(["powerprofilesctl", "list-holds"], universal_newlines=True)
80
+ return subprocess.check_output(["powerprofilesctl", "list-holds"], text=True)
81
81
 
82
82
  def test_list_holds(self):
83
83
  """Test holds"""
@@ -45,7 +45,7 @@ class TestTimedated(dbusmock.DBusTestCase):
45
45
  self.p_mock.wait()
46
46
 
47
47
  def run_timedatectl(self):
48
- return subprocess.check_output(["timedatectl"], universal_newlines=True)
48
+ return subprocess.check_output(["timedatectl"], text=True)
49
49
 
50
50
  def test_default_timezone(self):
51
51
  out = self.run_timedatectl()
@@ -60,7 +60,7 @@ class TestUPower(dbusmock.DBusTestCase):
60
60
  self.p_mock.wait()
61
61
 
62
62
  def test_no_devices(self):
63
- out = subprocess.check_output(["upower", "--dump"], universal_newlines=True)
63
+ out = subprocess.check_output(["upower", "--dump"], text=True)
64
64
  self.assertIn("/DisplayDevice\n", out)
65
65
  # should not have any other device
66
66
  for line in out.splitlines():
@@ -82,7 +82,7 @@ class TestUPower(dbusmock.DBusTestCase):
82
82
  b'emit /org/freedesktop/UPower org.freedesktop.UPower.DeviceAdded "/org/freedesktop/UPower/devices/mock_AC"\n',
83
83
  )
84
84
 
85
- out = subprocess.check_output(["upower", "--dump"], universal_newlines=True)
85
+ out = subprocess.check_output(["upower", "--dump"], text=True)
86
86
  self.assertRegex(out, "Device: " + path)
87
87
  # note, Add* is not magic: this just adds an object, not change
88
88
  # properties
@@ -109,7 +109,7 @@ class TestUPower(dbusmock.DBusTestCase):
109
109
  b'emit /org/freedesktop/UPower org.freedesktop.UPower.DeviceAdded "/org/freedesktop/UPower/devices/mock_BAT"\n',
110
110
  )
111
111
 
112
- out = subprocess.check_output(["upower", "--dump"], universal_newlines=True)
112
+ out = subprocess.check_output(["upower", "--dump"], text=True)
113
113
  self.assertRegex(out, "Device: " + path)
114
114
  # note, Add* is not magic: this just adds an object, not change
115
115
  # properties
@@ -129,7 +129,7 @@ class TestUPower(dbusmock.DBusTestCase):
129
129
  b'emit /org/freedesktop/UPower org.freedesktop.UPower.DeviceAdded "/org/freedesktop/UPower/devices/mock_BAT"\n',
130
130
  )
131
131
 
132
- out = subprocess.check_output(["upower", "--dump"], universal_newlines=True)
132
+ out = subprocess.check_output(["upower", "--dump"], text=True)
133
133
  self.assertRegex(out, "Device: " + path)
134
134
  # note, Add* is not magic: this just adds an object, not change
135
135
  # properties
@@ -193,7 +193,7 @@ class TestUPower(dbusmock.DBusTestCase):
193
193
  except KeyError:
194
194
  pass
195
195
 
196
- out = subprocess.check_output(["upower", "--dump"], universal_newlines=True, env=env)
196
+ out = subprocess.check_output(["upower", "--dump"], text=True, env=env)
197
197
  self.assertIn("/DisplayDevice\n", out)
198
198
  self.assertIn(" battery\n", out) # type
199
199
  self.assertRegex(out, r"state:\s+charging")
@@ -1 +0,0 @@
1
- __version__ = "0.32.2"
File without changes