From 5b0806116402f2d15b414d34d5e4234716b7af52 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 13 Nov 2023 15:45:32 +1000 Subject: [PATCH] testcase: remove unnecessary compat methods 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. --- dbusmock/testcase.py | 37 ------------------------------------ tests/test_api_pytest.py | 41 +++++----------------------------------- 2 files changed, 5 insertions(+), 73 deletions(-) diff --git a/dbusmock/testcase.py b/dbusmock/testcase.py index a921ebf7..887bc30f 100644 --- a/dbusmock/testcase.py +++ b/dbusmock/testcase.py @@ -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. diff --git a/tests/test_api_pytest.py b/tests/test_api_pytest.py index d4ce6382..c62ab01d 100644 --- a/tests/test_api_pytest.py +++ b/tests/test_api_pytest.py @@ -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' @@ -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