python-dbusmock 0.29.0__tar.gz → 0.30.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.
- python-dbusmock-0.30.0/.github/workflows/pages.yml +52 -0
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/.github/workflows/release.yml +0 -3
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/.gitignore +6 -4
- {python-dbusmock-0.29.0/python_dbusmock.egg-info → python-dbusmock-0.30.0}/PKG-INFO +97 -6
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/README.md +96 -5
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/dbusmock/__init__.py +3 -4
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/dbusmock/__main__.py +35 -4
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/dbusmock/_version.py +1 -1
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/dbusmock/mockobject.py +125 -133
- python-dbusmock-0.30.0/dbusmock/pytest_fixtures.py +32 -0
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/dbusmock/templates/bluez5-obex.py +2 -4
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/dbusmock/templates/bluez5.py +7 -9
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/dbusmock/templates/iio-sensors-proxy.py +3 -2
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/dbusmock/templates/logind.py +2 -1
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/dbusmock/templates/networkmanager.py +3 -6
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/dbusmock/templates/notification_daemon.py +2 -5
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/dbusmock/templates/ofono.py +3 -3
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/dbusmock/templates/polkitd.py +1 -0
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/dbusmock/templates/systemd.py +2 -3
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/dbusmock/templates/urfkill.py +1 -4
- python-dbusmock-0.30.0/dbusmock/testcase.py +610 -0
- python-dbusmock-0.30.0/doc/conf.py +49 -0
- python-dbusmock-0.30.0/doc/index.rst +22 -0
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/packaging/python-dbusmock.spec +2 -1
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/pyproject.toml +36 -0
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0/python_dbusmock.egg-info}/PKG-INFO +97 -6
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/python_dbusmock.egg-info/SOURCES.txt +6 -1
- python-dbusmock-0.30.0/tests/conftest.py +1 -0
- python-dbusmock-0.30.0/tests/run +18 -0
- python-dbusmock-0.30.0/tests/run-centos +29 -0
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/tests/run-debian +3 -2
- python-dbusmock-0.30.0/tests/run-fedora +29 -0
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/tests/run-ubuntu +3 -2
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/tests/test_api.py +3 -5
- python-dbusmock-0.30.0/tests/test_api_pytest.py +40 -0
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/tests/test_bluez5.py +16 -23
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/tests/test_cli.py +27 -4
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/tests/test_code.py +16 -11
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/tests/test_gnome_screensaver.py +3 -5
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/tests/test_iio_sensors_proxy.py +1 -2
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/tests/test_logind.py +4 -5
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/tests/test_low_memory_monitor.py +3 -5
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/tests/test_networkmanager.py +17 -16
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/tests/test_notification_daemon.py +4 -5
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/tests/test_ofono.py +1 -2
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/tests/test_polkitd.py +0 -2
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/tests/test_power_profiles_daemon.py +1 -3
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/tests/test_systemd.py +1 -3
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/tests/test_timedated.py +0 -2
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/tests/test_upower.py +4 -6
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/tests/test_urfkill.py +4 -6
- python-dbusmock-0.29.0/.flake8 +0 -7
- python-dbusmock-0.29.0/dbusmock/testcase.py +0 -350
- python-dbusmock-0.29.0/tests/run +0 -18
- python-dbusmock-0.29.0/tests/run-centos +0 -26
- python-dbusmock-0.29.0/tests/run-fedora +0 -26
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/.fmf/version +0 -0
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/.github/release.eloquent.yml +0 -0
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/.github/workflows/tests.yml +0 -0
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/COPYING +0 -0
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/NEWS +0 -0
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/dbusmock/templates/SKELETON +0 -0
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/dbusmock/templates/__init__.py +0 -0
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/dbusmock/templates/gnome_screensaver.py +0 -0
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/dbusmock/templates/low_memory_monitor.py +0 -0
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/dbusmock/templates/power_profiles_daemon.py +0 -0
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/dbusmock/templates/timedated.py +0 -0
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/dbusmock/templates/upower.py +1 -1
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/packit.yaml +0 -0
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/plans/all.fmf +0 -0
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/python_dbusmock.egg-info/dependency_links.txt +0 -0
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/python_dbusmock.egg-info/requires.txt +0 -0
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/python_dbusmock.egg-info/top_level.txt +0 -0
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/setup.cfg +0 -0
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/setup.py +0 -0
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/tests/__init__.py +0 -0
- {python-dbusmock-0.29.0 → python-dbusmock-0.30.0}/tests/main.fmf +0 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
name: Deploy to GitHub pages
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: ["main"]
|
|
6
|
+
|
|
7
|
+
# Allow running this workflow manually from the Actions tab
|
|
8
|
+
workflow_dispatch:
|
|
9
|
+
|
|
10
|
+
permissions:
|
|
11
|
+
contents: read
|
|
12
|
+
pages: write
|
|
13
|
+
id-token: write
|
|
14
|
+
|
|
15
|
+
# Allow only one concurrent deployment
|
|
16
|
+
concurrency:
|
|
17
|
+
group: "pages"
|
|
18
|
+
cancel-in-progress: false
|
|
19
|
+
|
|
20
|
+
jobs:
|
|
21
|
+
deploy:
|
|
22
|
+
runs-on: ubuntu-22.04
|
|
23
|
+
environment:
|
|
24
|
+
name: github-pages
|
|
25
|
+
url: ${{ steps.deployment.outputs.page_url }}
|
|
26
|
+
|
|
27
|
+
steps:
|
|
28
|
+
- uses: actions/checkout@v3
|
|
29
|
+
|
|
30
|
+
- name: Set up Python
|
|
31
|
+
uses: actions/setup-python@v4
|
|
32
|
+
|
|
33
|
+
- name: Install dependencies from pip
|
|
34
|
+
run: pip install sphinx sphinx-rtd-theme sphinx-autoapi myst-parser
|
|
35
|
+
|
|
36
|
+
- name: Build with sphinx
|
|
37
|
+
run: sphinx-build -M html doc/ doc/
|
|
38
|
+
|
|
39
|
+
- name: Move output to target directory
|
|
40
|
+
run: mv doc/html public_html/
|
|
41
|
+
|
|
42
|
+
- name: Setup Pages
|
|
43
|
+
uses: actions/configure-pages@v3
|
|
44
|
+
|
|
45
|
+
- name: Upload pages artifact
|
|
46
|
+
uses: actions/upload-pages-artifact@v1
|
|
47
|
+
with:
|
|
48
|
+
path: public_html/
|
|
49
|
+
|
|
50
|
+
- name: Deploy to GitHub Pages
|
|
51
|
+
id: deployment
|
|
52
|
+
uses: actions/deploy-pages@v2
|
|
@@ -18,9 +18,6 @@ jobs:
|
|
|
18
18
|
- name: Pacify git's permission check
|
|
19
19
|
run: git config --global --add safe.directory /__w
|
|
20
20
|
|
|
21
|
-
- name: Workaround for https://github.com/actions/checkout/pull/697
|
|
22
|
-
run: git fetch --force origin $(git describe --tags):refs/tags/$(git describe --tags)
|
|
23
|
-
|
|
24
21
|
- name: Install dependencies
|
|
25
22
|
run: |
|
|
26
23
|
sudo apt-get update
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: python-dbusmock
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.30.0
|
|
4
4
|
Summary: Mock D-Bus objects
|
|
5
5
|
Home-page: https://github.com/martinpitt/python-dbusmock
|
|
6
6
|
Author: Martin Pitt
|
|
@@ -60,7 +60,8 @@ When using a local system/session bus, you can do unit or integration
|
|
|
60
60
|
testing without needing root privileges or disturbing a running system.
|
|
61
61
|
The Python API offers some convenience functions like
|
|
62
62
|
`start_session_bus()` and `start_system_bus()` for this, in a
|
|
63
|
-
`DBusTestCase` class (subclass of the standard `unittest.TestCase`)
|
|
63
|
+
`DBusTestCase` class (subclass of the standard `unittest.TestCase`) or
|
|
64
|
+
alternatively as a `@pytest.fixture`.
|
|
64
65
|
|
|
65
66
|
You can use this with any programming language, as you can run the
|
|
66
67
|
mocker as a normal program. The actual setup of the mock (adding
|
|
@@ -68,15 +69,19 @@ objects, methods, properties, and signals) all happen via D-Bus methods
|
|
|
68
69
|
on the `org.freedesktop.DBus.Mock` interface. You just don't have the
|
|
69
70
|
convenience D-Bus launch API that way.
|
|
70
71
|
|
|
71
|
-
## Simple example
|
|
72
|
+
## Simple example using Python's unittest
|
|
72
73
|
|
|
73
74
|
Picking up the above example about mocking upower's `Suspend()` method,
|
|
74
75
|
this is how you would set up a mock upower in your test case:
|
|
75
76
|
|
|
76
77
|
```python
|
|
78
|
+
import subprocess
|
|
79
|
+
|
|
77
80
|
import dbus
|
|
81
|
+
|
|
78
82
|
import dbusmock
|
|
79
83
|
|
|
84
|
+
|
|
80
85
|
class TestMyProgram(dbusmock.DBusTestCase):
|
|
81
86
|
@classmethod
|
|
82
87
|
def setUpClass(cls):
|
|
@@ -145,6 +150,80 @@ Let's walk through:
|
|
|
145
150
|
together with a time stamp; you can use the latter for doing
|
|
146
151
|
timing related tests, but we just ignore it here.
|
|
147
152
|
|
|
153
|
+
## Simple example using pytest
|
|
154
|
+
|
|
155
|
+
The same functionality as above but instead using the pytest fixture provided
|
|
156
|
+
by this package.
|
|
157
|
+
|
|
158
|
+
```python
|
|
159
|
+
import subprocess
|
|
160
|
+
|
|
161
|
+
import dbus
|
|
162
|
+
import pytest
|
|
163
|
+
|
|
164
|
+
import dbusmock
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
@pytest.fixture
|
|
168
|
+
def upower_mock(dbusmock_system):
|
|
169
|
+
p_mock = dbusmock_system.spawn_server(
|
|
170
|
+
'org.freedesktop.UPower',
|
|
171
|
+
'/org/freedesktop/UPower',
|
|
172
|
+
'org.freedesktop.UPower',
|
|
173
|
+
system_bus=True,
|
|
174
|
+
stdout=subprocess.PIPE)
|
|
175
|
+
|
|
176
|
+
# Get a proxy for the UPower object's Mock interface
|
|
177
|
+
dbus_upower_mock = dbus.Interface(dbusmock_system.get_dbus(True).get_object(
|
|
178
|
+
'org.freedesktop.UPower',
|
|
179
|
+
'/org/freedesktop/UPower'
|
|
180
|
+
), dbusmock.MOCK_IFACE)
|
|
181
|
+
dbus_upower_mock.AddMethod('', 'Suspend', '', '', '')
|
|
182
|
+
|
|
183
|
+
yield p_mock
|
|
184
|
+
|
|
185
|
+
p_mock.stdout.close()
|
|
186
|
+
p_mock.terminate()
|
|
187
|
+
p_mock.wait()
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def test_suspend_on_idle(upower_mock):
|
|
191
|
+
# run your program in a way that should trigger one suspend call
|
|
192
|
+
|
|
193
|
+
# now check the log that we got one Suspend() call
|
|
194
|
+
assert upower_mock.stdout.readline() == b'^[0-9.]+ Suspend$'
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Let's walk through:
|
|
198
|
+
|
|
199
|
+
- We import the `dbusmock_system` fixture from dbusmock which provides us
|
|
200
|
+
with a system bus started for our test case wherever the
|
|
201
|
+
`dbusmock_system` argument is used by a test case and/or a pytest
|
|
202
|
+
fixture.
|
|
203
|
+
|
|
204
|
+
- The `upower_mock` fixture spawns the mock D-Bus server process for an initial
|
|
205
|
+
`/org/freedesktop/UPower` object with an `org.freedesktop.UPower`
|
|
206
|
+
D-Bus interface on the system bus. We capture its stdout to be
|
|
207
|
+
able to verify that methods were called.
|
|
208
|
+
|
|
209
|
+
We then call `org.freedesktop.DBus.Mock.AddMethod()` to add a
|
|
210
|
+
`Suspend()` method to our new object to the default D-Bus
|
|
211
|
+
interface. This will not do anything (except log its call to
|
|
212
|
+
stdout). It takes no input arguments, returns nothing, and does
|
|
213
|
+
not run any custom code.
|
|
214
|
+
|
|
215
|
+
This mock server process is yielded to the test function that uses
|
|
216
|
+
the `upower_mock` fixture - once the test is complete the process is
|
|
217
|
+
terminated again.
|
|
218
|
+
|
|
219
|
+
- `test_suspend_on_idle()` is the actual test case. It needs to run
|
|
220
|
+
your program in a way that should trigger one suspend call. Your
|
|
221
|
+
program will try to call `Suspend()`, but as that's now being
|
|
222
|
+
served by our mock instead of upower, there will not be any actual
|
|
223
|
+
machine suspend. Our mock process will log the method call
|
|
224
|
+
together with a time stamp; you can use the latter for doing
|
|
225
|
+
timing related tests, but we just ignore it here.
|
|
226
|
+
|
|
148
227
|
## Simple example from shell
|
|
149
228
|
|
|
150
229
|
We use the actual session bus for this example. You can use
|
|
@@ -189,6 +268,20 @@ call.
|
|
|
189
268
|
You can do the same operations in e. g. d-feet or any other D-Bus
|
|
190
269
|
language binding.
|
|
191
270
|
|
|
271
|
+
## Interactive debugging
|
|
272
|
+
|
|
273
|
+
It's possible to use dbus-mock to run interactive sessions using something like:
|
|
274
|
+
|
|
275
|
+
python3 -m dbusmock com.example.Foo / com.example.Foo.Manager -e $SHELL
|
|
276
|
+
|
|
277
|
+
Where a shell session with the defined mocks is set and others can be added.
|
|
278
|
+
|
|
279
|
+
Or more complex ones such as:
|
|
280
|
+
|
|
281
|
+
python3 -m dbusmock --session -t upower -e \
|
|
282
|
+
python3 -m dbusmock com.example.Foo / com.example.Foo.Manager -e \
|
|
283
|
+
gdbus introspect --session -d com.example.Foo -o /
|
|
284
|
+
|
|
192
285
|
## Logging
|
|
193
286
|
|
|
194
287
|
Usually you want to verify which methods have been called on the mock
|
|
@@ -307,9 +400,7 @@ the mock server as a program.
|
|
|
307
400
|
|
|
308
401
|
python-dbusmock is hosted on https://github.com/martinpitt/python-dbusmock
|
|
309
402
|
|
|
310
|
-
Run the unit tests with
|
|
311
|
-
|
|
312
|
-
python3 -m unittest
|
|
403
|
+
Run the unit tests with `python3 -m unittest` or `pytest`.
|
|
313
404
|
|
|
314
405
|
In CI, the unit tests run in containers. You can run them locally with e.g.
|
|
315
406
|
|
|
@@ -36,7 +36,8 @@ When using a local system/session bus, you can do unit or integration
|
|
|
36
36
|
testing without needing root privileges or disturbing a running system.
|
|
37
37
|
The Python API offers some convenience functions like
|
|
38
38
|
`start_session_bus()` and `start_system_bus()` for this, in a
|
|
39
|
-
`DBusTestCase` class (subclass of the standard `unittest.TestCase`)
|
|
39
|
+
`DBusTestCase` class (subclass of the standard `unittest.TestCase`) or
|
|
40
|
+
alternatively as a `@pytest.fixture`.
|
|
40
41
|
|
|
41
42
|
You can use this with any programming language, as you can run the
|
|
42
43
|
mocker as a normal program. The actual setup of the mock (adding
|
|
@@ -44,15 +45,19 @@ objects, methods, properties, and signals) all happen via D-Bus methods
|
|
|
44
45
|
on the `org.freedesktop.DBus.Mock` interface. You just don't have the
|
|
45
46
|
convenience D-Bus launch API that way.
|
|
46
47
|
|
|
47
|
-
## Simple example
|
|
48
|
+
## Simple example using Python's unittest
|
|
48
49
|
|
|
49
50
|
Picking up the above example about mocking upower's `Suspend()` method,
|
|
50
51
|
this is how you would set up a mock upower in your test case:
|
|
51
52
|
|
|
52
53
|
```python
|
|
54
|
+
import subprocess
|
|
55
|
+
|
|
53
56
|
import dbus
|
|
57
|
+
|
|
54
58
|
import dbusmock
|
|
55
59
|
|
|
60
|
+
|
|
56
61
|
class TestMyProgram(dbusmock.DBusTestCase):
|
|
57
62
|
@classmethod
|
|
58
63
|
def setUpClass(cls):
|
|
@@ -121,6 +126,80 @@ Let's walk through:
|
|
|
121
126
|
together with a time stamp; you can use the latter for doing
|
|
122
127
|
timing related tests, but we just ignore it here.
|
|
123
128
|
|
|
129
|
+
## Simple example using pytest
|
|
130
|
+
|
|
131
|
+
The same functionality as above but instead using the pytest fixture provided
|
|
132
|
+
by this package.
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
import subprocess
|
|
136
|
+
|
|
137
|
+
import dbus
|
|
138
|
+
import pytest
|
|
139
|
+
|
|
140
|
+
import dbusmock
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
@pytest.fixture
|
|
144
|
+
def upower_mock(dbusmock_system):
|
|
145
|
+
p_mock = dbusmock_system.spawn_server(
|
|
146
|
+
'org.freedesktop.UPower',
|
|
147
|
+
'/org/freedesktop/UPower',
|
|
148
|
+
'org.freedesktop.UPower',
|
|
149
|
+
system_bus=True,
|
|
150
|
+
stdout=subprocess.PIPE)
|
|
151
|
+
|
|
152
|
+
# Get a proxy for the UPower object's Mock interface
|
|
153
|
+
dbus_upower_mock = dbus.Interface(dbusmock_system.get_dbus(True).get_object(
|
|
154
|
+
'org.freedesktop.UPower',
|
|
155
|
+
'/org/freedesktop/UPower'
|
|
156
|
+
), dbusmock.MOCK_IFACE)
|
|
157
|
+
dbus_upower_mock.AddMethod('', 'Suspend', '', '', '')
|
|
158
|
+
|
|
159
|
+
yield p_mock
|
|
160
|
+
|
|
161
|
+
p_mock.stdout.close()
|
|
162
|
+
p_mock.terminate()
|
|
163
|
+
p_mock.wait()
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def test_suspend_on_idle(upower_mock):
|
|
167
|
+
# run your program in a way that should trigger one suspend call
|
|
168
|
+
|
|
169
|
+
# now check the log that we got one Suspend() call
|
|
170
|
+
assert upower_mock.stdout.readline() == b'^[0-9.]+ Suspend$'
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Let's walk through:
|
|
174
|
+
|
|
175
|
+
- We import the `dbusmock_system` fixture from dbusmock which provides us
|
|
176
|
+
with a system bus started for our test case wherever the
|
|
177
|
+
`dbusmock_system` argument is used by a test case and/or a pytest
|
|
178
|
+
fixture.
|
|
179
|
+
|
|
180
|
+
- The `upower_mock` fixture spawns the mock D-Bus server process for an initial
|
|
181
|
+
`/org/freedesktop/UPower` object with an `org.freedesktop.UPower`
|
|
182
|
+
D-Bus interface on the system bus. We capture its stdout to be
|
|
183
|
+
able to verify that methods were called.
|
|
184
|
+
|
|
185
|
+
We then call `org.freedesktop.DBus.Mock.AddMethod()` to add a
|
|
186
|
+
`Suspend()` method to our new object to the default D-Bus
|
|
187
|
+
interface. This will not do anything (except log its call to
|
|
188
|
+
stdout). It takes no input arguments, returns nothing, and does
|
|
189
|
+
not run any custom code.
|
|
190
|
+
|
|
191
|
+
This mock server process is yielded to the test function that uses
|
|
192
|
+
the `upower_mock` fixture - once the test is complete the process is
|
|
193
|
+
terminated again.
|
|
194
|
+
|
|
195
|
+
- `test_suspend_on_idle()` is the actual test case. It needs to run
|
|
196
|
+
your program in a way that should trigger one suspend call. Your
|
|
197
|
+
program will try to call `Suspend()`, but as that's now being
|
|
198
|
+
served by our mock instead of upower, there will not be any actual
|
|
199
|
+
machine suspend. Our mock process will log the method call
|
|
200
|
+
together with a time stamp; you can use the latter for doing
|
|
201
|
+
timing related tests, but we just ignore it here.
|
|
202
|
+
|
|
124
203
|
## Simple example from shell
|
|
125
204
|
|
|
126
205
|
We use the actual session bus for this example. You can use
|
|
@@ -165,6 +244,20 @@ call.
|
|
|
165
244
|
You can do the same operations in e. g. d-feet or any other D-Bus
|
|
166
245
|
language binding.
|
|
167
246
|
|
|
247
|
+
## Interactive debugging
|
|
248
|
+
|
|
249
|
+
It's possible to use dbus-mock to run interactive sessions using something like:
|
|
250
|
+
|
|
251
|
+
python3 -m dbusmock com.example.Foo / com.example.Foo.Manager -e $SHELL
|
|
252
|
+
|
|
253
|
+
Where a shell session with the defined mocks is set and others can be added.
|
|
254
|
+
|
|
255
|
+
Or more complex ones such as:
|
|
256
|
+
|
|
257
|
+
python3 -m dbusmock --session -t upower -e \
|
|
258
|
+
python3 -m dbusmock com.example.Foo / com.example.Foo.Manager -e \
|
|
259
|
+
gdbus introspect --session -d com.example.Foo -o /
|
|
260
|
+
|
|
168
261
|
## Logging
|
|
169
262
|
|
|
170
263
|
Usually you want to verify which methods have been called on the mock
|
|
@@ -283,9 +376,7 @@ the mock server as a program.
|
|
|
283
376
|
|
|
284
377
|
python-dbusmock is hosted on https://github.com/martinpitt/python-dbusmock
|
|
285
378
|
|
|
286
|
-
Run the unit tests with
|
|
287
|
-
|
|
288
|
-
python3 -m unittest
|
|
379
|
+
Run the unit tests with `python3 -m unittest` or `pytest`.
|
|
289
380
|
|
|
290
381
|
In CI, the unit tests run in containers. You can run them locally with e.g.
|
|
291
382
|
|
|
@@ -14,9 +14,8 @@ __copyright__ = '''
|
|
|
14
14
|
'''
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
from dbusmock.mockobject import
|
|
18
|
-
|
|
19
|
-
from dbusmock.testcase import DBusTestCase
|
|
17
|
+
from dbusmock.mockobject import MOCK_IFACE, OBJECT_MANAGER_IFACE, DBusMockObject, get_object, get_objects
|
|
18
|
+
from dbusmock.testcase import BusType, DBusTestCase, PrivateDBus, SpawnedMock
|
|
20
19
|
|
|
21
20
|
try:
|
|
22
21
|
# created by setuptools_scm
|
|
@@ -26,4 +25,4 @@ except ImportError:
|
|
|
26
25
|
|
|
27
26
|
|
|
28
27
|
__all__ = ['DBusMockObject', 'MOCK_IFACE', 'OBJECT_MANAGER_IFACE',
|
|
29
|
-
'DBusTestCase', 'get_object', 'get_objects']
|
|
28
|
+
'DBusTestCase', 'PrivateDBus', 'BusType', 'SpawnedMock', 'get_object', 'get_objects']
|
|
@@ -15,6 +15,8 @@ __copyright__ = '''
|
|
|
15
15
|
|
|
16
16
|
import argparse
|
|
17
17
|
import json
|
|
18
|
+
import os
|
|
19
|
+
import subprocess
|
|
18
20
|
import sys
|
|
19
21
|
|
|
20
22
|
import dbusmock.mockobject
|
|
@@ -43,6 +45,8 @@ def parse_args():
|
|
|
43
45
|
help='automatically implement the org.freedesktop.DBus.ObjectManager interface')
|
|
44
46
|
parser.add_argument('-p', '--parameters',
|
|
45
47
|
help='JSON dictionary of parameters to pass to the template')
|
|
48
|
+
parser.add_argument('-e', '--exec', nargs=argparse.REMAINDER,
|
|
49
|
+
help='Command to run in the mock environment')
|
|
46
50
|
|
|
47
51
|
arguments = parser.parse_args()
|
|
48
52
|
|
|
@@ -61,8 +65,9 @@ def parse_args():
|
|
|
61
65
|
|
|
62
66
|
if __name__ == '__main__':
|
|
63
67
|
import ctypes
|
|
64
|
-
|
|
68
|
+
|
|
65
69
|
import dbus.mainloop.glib
|
|
70
|
+
import dbus.service
|
|
66
71
|
|
|
67
72
|
args = parse_args()
|
|
68
73
|
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
|
|
@@ -119,8 +124,34 @@ if __name__ == '__main__':
|
|
|
119
124
|
if args.template:
|
|
120
125
|
main_object.AddTemplate(args.template, parameters)
|
|
121
126
|
|
|
127
|
+
libglib = ctypes.cdll.LoadLibrary('libglib-2.0.so.0')
|
|
128
|
+
|
|
122
129
|
dbusmock.mockobject.objects[args.path] = main_object
|
|
123
130
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
131
|
+
if args.exec:
|
|
132
|
+
with subprocess.Popen(args.exec) as exec_proc:
|
|
133
|
+
exit_status = set()
|
|
134
|
+
|
|
135
|
+
@ctypes.CFUNCTYPE(None, ctypes.c_int, ctypes.c_int)
|
|
136
|
+
def on_process_watch(_pid, status):
|
|
137
|
+
""" Check if the launched process is still alive """
|
|
138
|
+
if os.WIFEXITED(status):
|
|
139
|
+
exit_status.add(os.WEXITSTATUS(status))
|
|
140
|
+
else:
|
|
141
|
+
exit_status.add(1)
|
|
142
|
+
should_run.pop()
|
|
143
|
+
|
|
144
|
+
libglib.g_child_watch_add(exec_proc.pid, on_process_watch)
|
|
145
|
+
|
|
146
|
+
while should_run:
|
|
147
|
+
libglib.g_main_context_iteration(None, True)
|
|
148
|
+
|
|
149
|
+
try:
|
|
150
|
+
exec_proc.terminate()
|
|
151
|
+
exec_proc.wait()
|
|
152
|
+
except ProcessLookupError:
|
|
153
|
+
pass
|
|
154
|
+
sys.exit(exit_status.pop() if exit_status else exec_proc.returncode)
|
|
155
|
+
else:
|
|
156
|
+
while should_run:
|
|
157
|
+
libglib.g_main_context_iteration(None, True)
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
'''auto-generated version from setuptools_scm'''
|
|
2
|
-
__version__ = "0.
|
|
2
|
+
__version__ = "0.30.0"
|