Tests

Adapter

Tests for the Adapter.

This test class makes use of sample DBus data captured from a live device, imported as tests.obj_data.

class tests.test_adapter.TestBluezeroAdapter(methodName='runTest')

Mock a BLE Adapter.

setUp()

Patch the DBus module using MagicMock from unittest.mock

Returns:None

Three modules are mocked and patched into the system:

  1. DBus
    • Calls to GetManagedObjects(), Get(), Set(), and GetAll() are mocked using a captured DBus dictionary.
  2. DBus Mainloop
  3. GObject
tearDown()

Stop the module patching.

test_adapter_address()

Test the adapter address property.

test_adapter_alias()

Test the adapter alias property.

test_adapter_alias_write()

Test that an adapter alias can be set.

test_adapter_default()

Test the default Adapter() instantation gets the correct address.

test_adapter_discoverable()

Test the adapter discoverable property.

test_adapter_discoverable_timeout()

Test the adapter discoverabletimeout property.

test_adapter_discoverable_write()

Test that the adapter discoverable property can be set.

test_adapter_discoverabletimeout_write()

Test that the adapter discoverabletimeout property can be set.

test_adapter_discovering()

Test the adapter discovering property.

test_adapter_name()

Test the adapter name property.

test_adapter_pairable()

Test the adapter pairable property.

test_adapter_pairable_write()

Test that the adapter pairable property can be set.

test_adapter_pairabletimeout()

Test the adapter pairabletimeout property.

test_adapter_pairabletimeout_write()

Test that the adapter pairabletimeout property can be set.

test_adapter_power()

Test the adapter powered property.

test_adapter_power_write()

Test that the adapter powered property can be set.

test_class()

Test the adapter bt_class property.

test_get_all()

Test the get_all() method for retrieving all the DBus properties.

test_list_adapters()

Test Adapter.list_adapters()

test_start_discovery()

Test the adapter nearby_discovering() method.

tests.test_adapter.mock_get(iface, prop)

Mock the DBus Get() operation for a property on an interface.

Parameters:
  • iface (string) – DBus interface, e.g. 'org.bluez.Adapter1'
  • prop (string) – DBus property name, e.g. 'Name'
Returns:

DBus property

Return type:

property dependent

tests.test_adapter.mock_get_all(iface)

Mock the DBus GetAll() operation for an interface.

Parameters:iface (string) – DBus interface to GetAll() on (e.g. 'org.bluez.Adapter1')
Returns:DBus Interface Properties
Return type:Dictionary
tests.test_adapter.mock_set(iface, prop, value)

Mock the DBus Set() operation for a property on an interface.

Parameters:
  • iface (string) – DBus interface, e.g. 'org.bluez.Adapter1'
  • prop (string) – DBus property name, e.g. 'Name'
  • value – Value to set the DBus property to
Returns:

None