test(dbus): Add unit test framework for dbus_middleware1 module
Introduces test infrastructure and mockup classes for `dbus_middleware1`. Includes `BusProvider` test setup, fake device implementations, and initialization logic to support session bus testing. Enhances testability and isolation of the D-Bus middleware components.
This commit is contained in:
36
tests/dbus_middleware1/bus_provider.py
Normal file
36
tests/dbus_middleware1/bus_provider.py
Normal file
@@ -0,0 +1,36 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# SPDX-FileCopyrightText: 2025 KUNBUS GmbH
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
from time import sleep
|
||||
|
||||
from tests.dbus_middleware1.fake_devices import PiControlDeviceMockup
|
||||
|
||||
|
||||
class TestBusProvider(PiControlDeviceMockup):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
# Do not import things on top of the module. Some classes or functions need to be mocked up first.
|
||||
from revpi_middleware.dbus_middleware1 import BusProvider
|
||||
|
||||
# Prepare the bus provider and start it
|
||||
self.bp = BusProvider(
|
||||
self.picontrol.name,
|
||||
use_system_bus=False,
|
||||
)
|
||||
self.bp.start()
|
||||
|
||||
# Wait 5 seconds until the bus provider has started the main loop
|
||||
counter = 50
|
||||
while not self.bp.running and counter > 0:
|
||||
counter -= 1
|
||||
sleep(0.1)
|
||||
|
||||
def tearDown(self):
|
||||
self.bp.stop()
|
||||
self.bp.join(10.0)
|
||||
if self.bp.is_alive():
|
||||
raise RuntimeError("Bus provider thread is still running")
|
||||
|
||||
super().tearDown()
|
||||
Reference in New Issue
Block a user