LEW21 / pydbus

Pythonic DBus library
GNU Lesser General Public License v2.1
326 stars 76 forks source link

Testing BlueZ applications created using pydbus #53

Open ukBaz opened 7 years ago

ukBaz commented 7 years ago

Hello,

Apologies if this is off topic. Please feel free to direct me to a more appropriate place to ask these questions.

I've found pydbus really easy to use with the BlueZ DBus API and am having great fun creating Bluetooth applications. However the piece that I am struggling with is how to test my Python scripts on a CI server. Is there functionality within pydbus that would help me test my scripts?

Thanks, Barry

ukBaz commented 7 years ago

I've been looking at creating a mock of the BlueZ DBus API. The underlying idea behind my solution is to use mock.patch to replace the pydbus.SystemBus() call in scripts being tested so that they use a mock BlueZ API on the SessionBus (rather than the real BlueZ interface on the SystemBus.) The key line for doing this is:

mock_bus.SystemBus.return_value = pydbus.SessionBus()

There are a few more details that need to be worked out/polished up but I think this is the most promising of the ideas I've experimented with. One issue I'm having is getting GetManagedObjects() to work on the mock API I've created. I am successfully publishes interfaces like org.bluez.Adapter1 however I am not sure of the mechanism to also get that interface published on the org.freedesktop.DBus.ObjectManager interface. This needs to happen so that the GetManagedObjects() call will work on my mock API. What am I missing?

elsampsa commented 4 years ago

This sounds cool! Are you able to pair bt devices using pydbus dbus interface?