Пример #1
0
 def signal_test(self):
     """Test interface with signals."""
     xml = '''
     <node>
         <interface name="Interface">
             <signal name="SignalSomething">
                 <arg direction="out" name="x" type="i"/>
                 <arg direction="out" name="y" type="s"/>
             </signal>
             <signal name="SomethingHappened"/>
         </interface>
     </node>
     '''
     self._compare(xml, [
         DBusSpecification.Signal(
             name='SignalSomething',
             interface_name='Interface',
             type='(is)'
         ),
         DBusSpecification.Signal(
             name='SomethingHappened',
             interface_name='Interface',
             type=None
         )
     ])
Пример #2
0
 def method_test(self):
     """Test XML with methods."""
     xml = '''
     <node>
         <interface name="Interface">
             <method name="Method1"/>
             <method name="Method2">
                 <arg direction="in" name="x" type="i"/>
             </method>
             <method name="Method3">
                 <arg direction="out" name="return" type="i"/>
             </method>
             <method name="Method4">
                 <arg direction="in" name="x" type="ad"/>
                 <arg direction="in" name="y" type="h"/>
                 <arg direction="out" name="return" type="(ib)"/>
             </method>
         </interface>
     </node>
     '''
     self._compare(xml, [
         DBusSpecification.Method(
             name='Method1',
             interface_name='Interface',
             in_type=None,
             out_type=None
         ),
         DBusSpecification.Method(
             name='Method2',
             interface_name='Interface',
             in_type='(i)',
             out_type=None
         ),
         DBusSpecification.Method(
             name='Method3',
             interface_name='Interface',
             in_type=None,
             out_type='(i)'
         ),
         DBusSpecification.Method(
             name='Method4',
             interface_name='Interface',
             in_type='(adh)',
             out_type='((ib))'
         )
     ])
Пример #3
0
    def ignore_test(self):
        """Ignore invalid XML elements.."""
        xml = '''
        <node>
           <interface name="InterfaceA">
                <method name="MethodA">
                    <arg direction="out" name="return" type="i"/>
                    <ignored />
                </method>
                <property access="read" name="PropertyA" type="d"/>
                <signal name="SignalA">
                   <ignored />
                </signal>
                <ignored />
            </interface>
            <ignored />
        </node>
        '''
        self._compare(xml, [
            DBusSpecification.Method(
                name='MethodA',
                interface_name='InterfaceA',
                in_type=None,
                out_type='(i)'
            ),
            DBusSpecification.Property(
                name='PropertyA',
                interface_name='InterfaceA',
                readable=True,
                writable=False,
                type='d'
            ),
            DBusSpecification.Signal(
                name='SignalA',
                interface_name='InterfaceA',
                type=None
            )
        ])

        self._compare("<ignored />", [])
Пример #4
0
 def simple_signal_test(self):
     """Test interface with a simple signal."""
     xml = '''
     <node>
         <interface name="Interface">
             <signal name="SimpleSignal"/>
         </interface>
     </node>
     '''
     self._compare(xml, [
         DBusSpecification.Signal(
             name='SimpleSignal',
             interface_name='Interface',
             type=None
         )
     ])
Пример #5
0
 def property_writeonly_test(self):
     """Test writeonly property."""
     xml = '''
     <node>
         <interface name="Interface">
             <property name="Property" type="i" access="write" />
         </interface>
     </node>
     '''
     self._compare(xml, [
         DBusSpecification.Property(
             name='Property',
             interface_name='Interface',
             readable=False,
             writable=True,
             type='i'
         )
     ])
Пример #6
0
 def standard_interfaces_test(self):
     """Test with the standard interfaces."""
     specification = DBusSpecificationParser.parse_specification('<node />')
     self.assertEqual(specification.members, [
         DBusSpecification.Method(
             name='Introspect',
             interface_name='org.freedesktop.DBus.Introspectable',
             in_type=None,
             out_type='(s)'
         ),
         DBusSpecification.Method(
             name='Ping',
             interface_name='org.freedesktop.DBus.Peer',
             in_type=None,
             out_type=None
         ),
         DBusSpecification.Method(
             name='GetMachineId',
             interface_name='org.freedesktop.DBus.Peer',
             in_type=None,
             out_type='(s)'
         ),
         DBusSpecification.Method(
             name='Get',
             interface_name='org.freedesktop.DBus.Properties',
             in_type='(ss)',
             out_type='(v)'
         ),
         DBusSpecification.Method(
             name='GetAll',
             interface_name='org.freedesktop.DBus.Properties',
             in_type='(s)',
             out_type='(a{sv})'
         ),
         DBusSpecification.Method(
             name='Set',
             interface_name='org.freedesktop.DBus.Properties',
             in_type='(ssv)',
             out_type=None
         ),
         DBusSpecification.Signal(
             name='PropertiesChanged',
             interface_name='org.freedesktop.DBus.Properties',
             type='(sa{sv}as)'
         )
     ])
Пример #7
0
    def introspect_test(self):
        """Test the introspection."""
        self._set_reply(
            get_variant("(s)", (dedent("""
        <node>
            <interface name="Interface">
                <method name="Method1"/>
            </interface>
        </node>
        """), )))

        self.handler = ClientObjectHandler(self.message_bus, self.service_name,
                                           self.object_path)
        self.assertIsNotNone(self.handler.specification)
        self._check_call("org.freedesktop.DBus.Introspectable",
                         "Introspect",
                         reply_type=get_variant_type("(s)"))

        self.assertIn(
            DBusSpecification.Method("Method1", "Interface", None, None),
            self.handler.specification.members)
Пример #8
0
    def _find_properties_specs(self, obj):
        """Find specifications of DBus properties.

        :param obj: an object with DBus properties
        :return: a map of property names and their specifications
        """
        specification = DBusSpecification.from_xml(get_xml(obj))
        properties_specs = {}

        for member in specification.members:
            if not isinstance(member, DBusSpecification.Property):
                continue

            if member.name in properties_specs:
                raise DBusSpecificationError(
                    "The property {} is defined in {} and {}.".format(
                        member.name, member.interface_name,
                        properties_specs[member.name].interface_name))

            properties_specs[member.name] = member

        return properties_specs
Пример #9
0
    def _get_specification(self):
        """Introspect the DBus object."""
        xml = self._call_method("org.freedesktop.DBus.Introspectable",
                                "Introspect", None, "(s)")

        return DBusSpecification.from_xml(xml)
Пример #10
0
    def _get_specification(self):
        """Introspect the DBus object.

        :return: a DBus specification
        """
        return DBusSpecification()
Пример #11
0
    def _get_specification(self):
        """Get the DBus specification.

        :return: a DBus specification
        """
        return DBusSpecification.from_xml(self._get_xml_specification())
Пример #12
0
    def from_xml_test(self):
        """Test a specification created from XML."""
        xml = '''
        <node>
           <interface name="ComplexA">
                <method name="MethodA">
                    <arg direction="out" name="return" type="i"/>
                </method>
                <property access="read" name="PropertyA" type="d"/>
                <signal name="SignalA">
                   <arg direction="out" name="x" type="i"/>
                </signal>
            </interface>
            <interface name="ComplexB">
                <method name="MethodB">
                    <arg direction="in" name="a" type="s"/>
                    <arg direction="in" name="b" type="ad"/>
                    <arg direction="in" name="c" type="i"/>
                    <arg direction="out" name="return" type="i"/>
                </method>
                <property access="read" name="PropertyB" type="d"/>
                <signal name="SignalB">
                    <arg direction="out" name="x" type="b"/>
                    <arg direction="out" name="y" type="d"/>
                    <arg direction="out" name="z" type="(ii)"/>
                </signal>
            </interface>
        </node>
        '''
        specification = DBusSpecification.from_xml(xml)
        self.assertEqual(specification.interfaces, [
            'org.freedesktop.DBus.Introspectable',
            'org.freedesktop.DBus.Peer',
            'org.freedesktop.DBus.Properties',
            'ComplexA',
            'ComplexB',
        ])

        self.assertEqual(specification.members, [
            DBusSpecification.Method(
                name='Introspect',
                interface_name='org.freedesktop.DBus.Introspectable',
                in_type=None,
                out_type='(s)'
            ),
            DBusSpecification.Method(
                name='Ping',
                interface_name='org.freedesktop.DBus.Peer',
                in_type=None,
                out_type=None
            ),
            DBusSpecification.Method(
                name='GetMachineId',
                interface_name='org.freedesktop.DBus.Peer',
                in_type=None,
                out_type='(s)'
            ),
            DBusSpecification.Method(
                name='Get',
                interface_name='org.freedesktop.DBus.Properties',
                in_type='(ss)',
                out_type='(v)'
            ),
            DBusSpecification.Method(
                name='GetAll',
                interface_name='org.freedesktop.DBus.Properties',
                in_type='(s)',
                out_type='(a{sv})'
            ),
            DBusSpecification.Method(
                name='Set',
                interface_name='org.freedesktop.DBus.Properties',
                in_type='(ssv)',
                out_type=None
            ),
            DBusSpecification.Signal(
                name='PropertiesChanged',
                interface_name='org.freedesktop.DBus.Properties',
                type='(sa{sv}as)'
            ),
            DBusSpecification.Method(
                name='MethodA',
                interface_name='ComplexA',
                in_type=None,
                out_type='(i)'
            ),
            DBusSpecification.Property(
                name='PropertyA',
                interface_name='ComplexA',
                readable=True,
                writable=False,
                type='d'
            ),
            DBusSpecification.Signal(
                name='SignalA',
                interface_name='ComplexA',
                type='(i)'
            ),
            DBusSpecification.Method(
                name='MethodB',
                interface_name='ComplexB',
                in_type='(sadi)',
                out_type='(i)'
            ),
            DBusSpecification.Property(
                name='PropertyB',
                interface_name='ComplexB',
                readable=True,
                writable=False,
                type='d'
            ),
            DBusSpecification.Signal(
                name='SignalB',
                interface_name='ComplexB',
                type='(bd(ii))'
            )
        ])
Пример #13
0
    def from_members_test(self):
        """Test a specification created from members."""
        method = DBusSpecification.Method(
            name="Method",
            interface_name="A",
            in_type="()",
            out_type="(s)"
        )

        signal = DBusSpecification.Signal(
            name="Signal",
            interface_name="B",
            type="(ii)"
        )

        prop = DBusSpecification.Property(
            name="Property",
            interface_name="B",
            readable=True,
            writable=False,
            type="i"
        )

        specification = DBusSpecification()
        specification.add_member(method)
        specification.add_member(signal)
        specification.add_member(prop)

        with self.assertRaises(DBusSpecificationError):
            specification.get_member("A", "Invalid")

        with self.assertRaises(DBusSpecificationError):
            specification.get_member("Invalid", "Method")

        self.assertEqual(specification.interfaces, ["A", "B"])
        self.assertEqual(specification.members, [method, signal, prop])
        self.assertEqual(specification.get_member("A", "Method"), method)
        self.assertEqual(specification.get_member("B", "Signal"), signal)
        self.assertEqual(specification.get_member("B", "Property"), prop)
Пример #14
0
 def _compare(self, xml, expected_members):
     """Compare members of the specification."""
     specification = DBusSpecification()
     DBusSpecificationParser._parse_xml(specification, xml)
     self.assertEqual(specification.members, expected_members)
Пример #15
0
 def _create_proxy(self, xml, proxy_factory=ObjectProxy):
     """Create a proxy with a mocked message bus."""
     self.proxy = proxy_factory(self.message_bus, self.service_name,
                                self.object_path)
     self.handler = self.proxy._handler
     self.handler._specification = DBusSpecification.from_xml(xml)