Skip to content

Commit

Permalink
testcase: remove unnecessary compat methods
Browse files Browse the repository at this point in the history
Some of these could've only been exposed by the recently added pytest
fixtures - those have never been in a release so let's drop them.
  • Loading branch information
whot committed Nov 29, 2023
1 parent 60276e6 commit 5b08061
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 73 deletions.
37 changes: 0 additions & 37 deletions dbusmock/testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,43 +241,6 @@ def disable_service(self, service):
if self._daemon:
self.bustype.reload_configuration()

def spawn_server(self, name: str, path: str, interface: str, system_bus: bool = False, stdout=None) -> subprocess.Popen:
'''
Wrapper around ``spawn_server`` for backwards compatibility.
'''
assert not system_bus or self.bustype == BusType.SYSTEM, "Mismatching bus types"
server = SpawnedServer.spawn_for_name(name, path, interface, bustype=self.bustype, stdout=stdout)
return server.process

def wait_for_bus_object(self, dest: str, path: str, system_bus: bool = False, timeout: int = 600):
'''
Wrapper around ``BusType.wait_for_bus_object()`` for backwards compatibility.
'''
assert not system_bus or self.bustype == BusType.SYSTEM, "Mismatching bus types"
self.bustype.wait_for_bus_object(dest, path, timeout)

def spawn_server_template(self,
template: str,
parameters: Optional[Dict[str, Any]] = None,
stdout=None,
system_bus: Optional[bool] = None) -> Tuple[subprocess.Popen, dbus.proxies.ProxyObject]:
'''
Wrapper around ``spawn_server_template`` for backwards compatibility.
'''
if system_bus is not None: # noqa: SIM108
bustype = BusType.SYSTEM if system_bus else BusType.SESSION
else:
bustype = None
server = SpawnedServer.spawn_server_template(template=template, parameters=parameters, bustype=bustype, stdout=stdout)
return server.process, server.obj

def get_dbus(self, system_bus: bool = False) -> dbus.Bus:
'''
Wrapper around ``BusType.get_connection()`` for backwards compatibility.
'''
assert not system_bus or self.bustype == BusType.SYSTEM, "Mismatching bus types"
return self.bustype.get_connection()


class DBusTestCase(unittest.TestCase):
'''Base class for D-Bus mock tests.
Expand Down
41 changes: 5 additions & 36 deletions tests/test_api_pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,13 @@
'''

import subprocess
import tempfile

import pytest

import dbusmock


def test_dbusmock_test_spawn_server(dbusmock_session):
test_iface = 'org.freedesktop.Test.Main'

p_mock = dbusmock_session.spawn_server(
'org.freedesktop.Test', '/', test_iface, stdout=tempfile.TemporaryFile())

obj_test = dbusmock_session.get_dbus().get_object('org.freedesktop.Test', '/')

obj_test.AddMethod('', 'Upper', 's', 's', 'ret = args[0].upper()', interface_name=dbusmock.MOCK_IFACE)
assert obj_test.Upper('hello', interface=test_iface) == 'HELLO'

p_mock.terminate()
p_mock.wait()


@pytest.fixture(name='upower_mock')
def fixture_upower_mock(dbusmock_system):
p_mock, obj = dbusmock_system.spawn_server_template('upower', stdout=subprocess.DEVNULL)
yield obj
p_mock.terminate()
p_mock.wait()


def test_dbusmock_test_spawn_system_template(upower_mock):
assert upower_mock
out = subprocess.check_output(['upower', '--dump'], universal_newlines=True)
assert 'version:' in out
assert '0.99' in out


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

Expand All @@ -57,15 +26,15 @@ def test_dbusmock_test_spawnedserver(dbusmock_session):
assert obj_test.Upper('hello', interface=test_iface) == 'HELLO'


@pytest.fixture(name='upower_mock_spawned')
def fixture_upower_mock_spawned(dbusmock_system):
@pytest.fixture(name='upower_mock')
def fixture_upower_mock(dbusmock_system):
assert dbusmock_system
with dbusmock.SpawnedServer.spawn_server_template('upower') as server:
yield server.obj


def test_dbusmock_test_spawnedserver_template(upower_mock_spawned):
assert upower_mock_spawned
def test_dbusmock_test_template(upower_mock):
assert upower_mock
out = subprocess.check_output(['upower', '--dump'], universal_newlines=True)
assert 'version:' in out
assert '0.99' in out

0 comments on commit 5b08061

Please sign in to comment.