File: test_api_pytest.py

package info (click to toggle)
python-dbusmock 0.36.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 812 kB
  • sloc: python: 7,324; sh: 73; makefile: 4
file content (40 lines) | stat: -rw-r--r-- 1,300 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 3 of the License, or (at your option) any
# later version.  See http://www.gnu.org/copyleft/lgpl.html for the full text
# of the license.

__author__ = "Martin Pitt"
__copyright__ = """
(c) 2023 Martin Pitt <martin@piware.de>
"""

import subprocess

import pytest

import dbusmock


def test_dbusmock_test(dbusmock_session):
    assert dbusmock_session
    test_iface = "org.freedesktop.Test.Main"

    with dbusmock.SpawnedMock.spawn_for_name("org.freedesktop.Test", "/", test_iface) as server:
        obj_test = server.obj
        obj_test.AddMethod("", "Upper", "s", "s", "ret = args[0].upper()", interface_name=dbusmock.MOCK_IFACE)
        assert obj_test.Upper("hello", interface=test_iface) == "HELLO"


@pytest.fixture(name="upower_mock")
def fixture_upower_mock(dbusmock_system):
    assert dbusmock_system
    with dbusmock.SpawnedMock.spawn_with_template("upower") as server:
        yield server.obj


def test_dbusmock_test_template(upower_mock):
    assert upower_mock
    out = subprocess.check_output(["upower", "--dump"], text=True)
    assert "version:" in out
    assert "0.99" in out