def test_get_proxy_object_class_send_right_args(self, tcpc):
     """_get_proxy_object_class should send the right arguments to
     _try_custom_proxy_classes."""
     class_dict = {'DefaultSelector': self.DefaultSelector}
     path = '/path/to/DefaultSelector'
     state = {}
     object_registry._get_proxy_object_class(class_dict, path, state)
     tcpc.assert_called_once_with(class_dict, path, state)
 def test_get_proxy_object_class_default_args(self, gdpc, tcpc):
     """_get_proxy_object_class should pass the correct arguments to
     _get_default_proxy_class"""
     tcpc.return_value = None
     obj_id = 123
     path = '/path/to/DefaultSelector'
     object_registry._get_proxy_object_class(obj_id, path, None)
     gdpc.assert_called_once_with(obj_id,
                                  xpathselect.get_classname_from_path(path))
 def test_get_proxy_object_class_not_handle_error(self, tcpc):
     """_get_proxy_object_class should not handle an exception raised by
     _try_custom_proxy_classes."""
     tcpc.side_effect = ValueError
     self.assertThat(
         lambda: object_registry._get_proxy_object_class(
             "None",  # Cannot be set to None, but don't care about value
             None,
             None),
         raises(ValueError))
    def test_get_proxy_object_class_return_from_list(self, gdpc, tcpc):
        """_get_proxy_object_class should return the value of
        _try_custom_proxy_classes if there is one."""
        token = self.getUniqueString()
        tcpc.return_value = token
        gpoc_return = object_registry._get_proxy_object_class(
            "fake_id",  # cannot set to none.
            None,
            None)

        self.assertThat(gpoc_return, Equals(token))
        self.assertFalse(gdpc.called)
 def test_get_proxy_object_class_default(self, gcfp, gdpc, tcpc):
     """_get_proxy_object_class should return the value of
     _get_default_proxy_class if _try_custom_proxy_classes returns None."""
     token = self.getUniqueString()
     gdpc.return_value = token
     tcpc.return_value = None
     gpoc_return = object_registry._get_proxy_object_class(
         None,
         None,
         None,
     )
     self.assertThat(gpoc_return, Equals(token))
Example #6
0
 def build_proxy(introspection_xml, cls_name, path, cls_state):
     # Figure out if the backend has any extension methods, and return
     # classes that understand how to use each of those extensions:
     extension_classes = _get_proxy_bases_from_introspection_xml(
         introspection_xml)
     # Register those base classes for everything that will derive from this
     # emulator base class.
     _object_registry.register_extension_classes_for_proxy_base(
         emulator_base,
         extension_classes,
     )
     proxy_class = _object_registry._get_proxy_object_class(
         emulator_base._id, path, cls_state)
     reply_handler(
         proxy_class(cls_state, path, backends.Backend(data_source)))
Example #7
0
def make_introspection_object(dbus_tuple, backend, object_id):
    """Make an introspection object given a DBus tuple of
    (path, state_dict).

    :param dbus_tuple: A two-item iterable containing a dbus.String object that
        contains the object path, and a dbus.Dictionary object that contains
        the objects state dictionary.
    :param backend: An instance of the Backend class.
    :returns: A proxy object that derives from DBusIntrospectionObject
    :raises ValueError: if more than one class is appropriate for this
             dbus_tuple

    """
    path, state = dbus_tuple
    path = path.encode('utf-8')
    class_object = _get_proxy_object_class(object_id, path, state)
    return class_object(state, path, backend)
Example #8
0
def _make_proxy_object(dbus_address, emulator_base):
    """Returns a root proxy object given a DBus service name.

    :param dbus_address: The DBusAddress object we're querying.
    :param emulator_base: The emulator base object (or None), as provided by
        the user.
    """
    # make sure we always have an emulator base. Either use the one the user
    # gave us, or make one:
    emulator_base = emulator_base or _make_default_emulator_base()
    _raise_if_base_class_not_actually_base(emulator_base)

    # Get the dbus introspection Xml for the backend.
    intro_xml = _get_introspection_xml_from_backend(dbus_address)
    try:
        # Figure out if the backend has any extension methods, and return
        # classes that understand how to use each of those extensions:
        extension_classes = _get_proxy_bases_from_introspection_xml(intro_xml)

        # Register those base classes for everything that will derive from this
        # emulator base class.
        _object_registry.register_extension_classes_for_proxy_base(
            emulator_base,
            extension_classes,
        )
    except RuntimeError as e:
        e.args = ("Could not find Autopilot interface on dbus address '%s'." %
                  dbus_address, )
        raise e

    cls_name, path, cls_state = _get_proxy_object_class_name_and_state(
        dbus_address)

    proxy_class = _object_registry._get_proxy_object_class(
        emulator_base._id, path, cls_state)
    # For this object only, add the ApplicationProxy class, since it's the
    # root of the tree. Ideally this would be nicer...
    if ApplicationProxyObject not in proxy_class.__bases__:
        proxy_class.__bases__ += (ApplicationProxyObject, )
    return proxy_class(cls_state, path, backends.Backend(dbus_address))
 def test_get_proxy_object_class_call_default_call(self, gcfp, gdpc, tcpc):
     """_get_proxy_object_class should call _get_default_proxy_class if
     _try_custom_proxy_classes returns None."""
     tcpc.return_value = None
     object_registry._get_proxy_object_class(None, None, None)
     self.assertTrue(gdpc.called)