示例#1
0
    def run_synchronous_tests(self, obj):
        # We can't test that coercion works correctly unless the server has
        # sent us introspection data. Java doesn't :-/
        have_signatures = True

        # "Single tests"
        if have_signatures:
            self.assert_method_eq(INTERFACE_SINGLE_TESTS, 6, 'Sum', [1, 2, 3])
            self.assert_method_eq(INTERFACE_SINGLE_TESTS, 6, 'Sum',
                                  ['\x01', '\x02', '\x03'])
        self.assert_method_eq(INTERFACE_SINGLE_TESTS, 6, 'Sum',
                              [Byte(1), Byte(2), Byte(3)])
        self.assert_method_eq(INTERFACE_SINGLE_TESTS, 6, 'Sum',
                              ByteArray('\x01\x02\x03'))

        # Main tests
        self.assert_method_eq(INTERFACE_TESTS, String(u'foo', variant_level=1),
                              'Identity', String('foo'))
        self.assert_method_eq(INTERFACE_TESTS, String(u'foo', variant_level=1),
                              'Identity', UTF8String('foo'))
        self.assert_method_eq(INTERFACE_TESTS, Byte(42, variant_level=1),
                              'Identity', Byte(42))
        self.assert_method_eq(INTERFACE_TESTS, Byte(42, variant_level=23),
                              'Identity', Byte(42, variant_level=23))
        self.assert_method_eq(INTERFACE_TESTS, Double(42.5, variant_level=1),
                              'Identity', 42.5)
        self.assert_method_eq(INTERFACE_TESTS, Double(-42.5, variant_level=1),
                              'Identity', -42.5)

        if have_signatures:
            self.assert_method_eq(INTERFACE_TESTS,
                                  String(u'foo', variant_level=1), 'Identity',
                                  'foo')
            self.assert_method_eq(INTERFACE_TESTS, Byte(42, variant_level=1),
                                  'Identity', Byte(42))
            self.assert_method_eq(INTERFACE_TESTS, Double(42.5,
                                                          variant_level=1),
                                  'Identity', Double(42.5))
            self.assert_method_eq(INTERFACE_TESTS,
                                  Double(-42.5, variant_level=1), 'Identity',
                                  -42.5)

        for i in (0, 42, 255):
            self.assert_method_eq(INTERFACE_TESTS, Byte(i), 'IdentityByte',
                                  Byte(i))
        for i in (True, False):
            self.assert_method_eq(INTERFACE_TESTS, i, 'IdentityBool', i)

        for i in (-0x8000, 0, 42, 0x7fff):
            self.assert_method_eq(INTERFACE_TESTS, i, 'IdentityInt16',
                                  Int16(i))
        for i in (0, 42, 0xffff):
            self.assert_method_eq(INTERFACE_TESTS, i, 'IdentityUInt16',
                                  UInt16(i))
        for i in (-0x7fffffff - 1, 0, 42, 0x7fffffff):
            self.assert_method_eq(INTERFACE_TESTS, i, 'IdentityInt32',
                                  Int32(i))
        for i in (0L, 42L, 0xffffffffL):
            self.assert_method_eq(INTERFACE_TESTS, i, 'IdentityUInt32',
                                  UInt32(i))
示例#2
0
    def get_option(self, section, option, default="__None__"):
        """ Wrapper around ConfigParser.get. 
        
        Automatically adds any missing sections, adds the ability
        to write a default value, and if one is provided prints if
        the default or a previously saved value is returned.
        
        """
        if not self.has_section(section):
            if default != "__None__":
                self.add_section(section)
            else:
                return None

        if self.has_option(section, option):
            ret = RawConfigParser.get(self, section, option)
            if (isinstance(ret, str) and ret.startswith(self.mrk_ws)
                    and ret.endswith(self.mrk_ws)):
                ret = ret[3:-3]
            ret = to_unicode(ret)
            if default:
                if self.debug:
                    # mask out sensitive information
                    if option in [
                            'apsk', 'password', 'identity', 'private_key',
                            'private_key_passwd', 'key', 'passphrase'
                    ]:
                        print(''.join(
                            ['found ', option, ' in configuration *****']))
                    else:
                        print(''.join(
                            ['found ', option, ' in configuration ',
                             str(ret)]))
        else:
            if default != "__None__":
                print('did not find {0} in configuration, setting default {1}'.
                      format(option, str(default)))
                self.set(section, option, str(default), write=True)
                ret = default
            else:
                ret = None

        # Try to intelligently handle the type of the return value.
        try:
            if not ret.startswith('0') or len(ret) == 1:
                ret = int(ret)
        except (ValueError, TypeError, AttributeError):
            ret = Noneify(ret)
        # This is a workaround for a python-dbus issue on 64-bit systems.
        if isinstance(ret, (int, )):
            try:
                Int32(ret)
            except OverflowError:
                ret = str(ret)
        return to_unicode(ret)
示例#3
0
    def run_synchronous_tests(self, obj):
        # We can't test that coercion works correctly unless the server has
        # sent us introspection data. Java doesn't :-/
        have_signatures = True

        # "Single tests"
        if have_signatures:
            self.assert_method_eq(INTERFACE_SINGLE_TESTS, 6, 'Sum', [1, 2, 3])
            self.assert_method_eq(INTERFACE_SINGLE_TESTS, 6, 'Sum',
                                  [b'\x01', b'\x02', b'\x03'])
        self.assert_method_eq(INTERFACE_SINGLE_TESTS, 6, 'Sum',
                              [Byte(1), Byte(2), Byte(3)])
        self.assert_method_eq(INTERFACE_SINGLE_TESTS, 6, 'Sum',
                              ByteArray(b'\x01\x02\x03'))

        # Main tests
        self.assert_method_eq(INTERFACE_TESTS, String('foo', variant_level=1),
                              'Identity', String('foo'))
        if is_py2:
            self.assert_method_eq(INTERFACE_TESTS,
                                  String('foo', variant_level=1), 'Identity',
                                  UTF8String('foo'))
        self.assert_method_eq(INTERFACE_TESTS, Byte(42, variant_level=1),
                              'Identity', Byte(42))
        self.assert_method_eq(INTERFACE_TESTS, Byte(42, variant_level=23),
                              'Identity', Byte(42, variant_level=23))
        self.assert_method_eq(INTERFACE_TESTS, Double(42.5, variant_level=1),
                              'Identity', 42.5)
        self.assert_method_eq(INTERFACE_TESTS, Double(-42.5, variant_level=1),
                              'Identity', -42.5)

        if have_signatures:
            self.assert_method_eq(INTERFACE_TESTS,
                                  String('foo', variant_level=1), 'Identity',
                                  'foo')
            self.assert_method_eq(INTERFACE_TESTS, Byte(42, variant_level=1),
                                  'Identity', Byte(42))
            self.assert_method_eq(INTERFACE_TESTS, Double(42.5,
                                                          variant_level=1),
                                  'Identity', Double(42.5))
            self.assert_method_eq(INTERFACE_TESTS,
                                  Double(-42.5, variant_level=1), 'Identity',
                                  -42.5)

        for i in (0, 42, 255):
            self.assert_method_eq(INTERFACE_TESTS, Byte(i), 'IdentityByte',
                                  Byte(i))
        for i in (True, False):
            self.assert_method_eq(INTERFACE_TESTS, i, 'IdentityBool', i)

        for i in (-0x8000, 0, 42, 0x7fff):
            self.assert_method_eq(INTERFACE_TESTS, i, 'IdentityInt16',
                                  Int16(i))
        for i in (0, 42, 0xffff):
            self.assert_method_eq(INTERFACE_TESTS, i, 'IdentityUInt16',
                                  UInt16(i))
        for i in (-0x7fffffff - 1, 0, 42, 0x7fffffff):
            self.assert_method_eq(INTERFACE_TESTS, i, 'IdentityInt32',
                                  Int32(i))
        for i in (0, 42, 0xffffffff):
            i = make_long(i)
            self.assert_method_eq(INTERFACE_TESTS, i, 'IdentityUInt32',
                                  UInt32(i))
        MANY = 1
        for n in (0x8000, 0x10000, 0x10000, 0x10000):
            MANY *= make_long(n)
        for i in (-MANY, 0, 42, MANY - 1):
            self.assert_method_eq(INTERFACE_TESTS, i, 'IdentityInt64',
                                  Int64(i))
        for i in (0, 42, 2 * MANY - 1):
            self.assert_method_eq(INTERFACE_TESTS, i, 'IdentityUInt64',
                                  UInt64(i))

        self.assert_method_eq(INTERFACE_TESTS, 42.3, 'IdentityDouble', 42.3)
        for i in ('', 'foo'):
            self.assert_method_eq(INTERFACE_TESTS, i, 'IdentityString', i)
        for i in ('\xa9', b'\xc2\xa9'):
            self.assert_method_eq(INTERFACE_TESTS, '\xa9', 'IdentityString', i)

        if have_signatures:
            self.assert_method_eq(INTERFACE_TESTS, Byte(0x42), 'IdentityByte',
                                  b'\x42')
            self.assert_method_eq(INTERFACE_TESTS, True, 'IdentityBool', 42)
            self.assert_method_eq(INTERFACE_TESTS, 42, 'IdentityInt16', 42)
            self.assert_method_eq(INTERFACE_TESTS, 42, 'IdentityUInt16', 42)
            self.assert_method_eq(INTERFACE_TESTS, 42, 'IdentityInt32', 42)
            self.assert_method_eq(INTERFACE_TESTS, 42, 'IdentityUInt32', 42)
            self.assert_method_eq(INTERFACE_TESTS, 42, 'IdentityInt64', 42)
            self.assert_method_eq(INTERFACE_TESTS, 42, 'IdentityUInt64', 42)
            self.assert_method_eq(INTERFACE_TESTS, 42.0, 'IdentityDouble', 42)

        self.assert_method_eq(
            INTERFACE_TESTS, [
                Byte(b'\x01', variant_level=1),
                Byte(b'\x02', variant_level=1),
                Byte(b'\x03', variant_level=1)
            ], 'IdentityArray',
            Array([Byte(b'\x01'), Byte(b'\x02'),
                   Byte(b'\x03')], signature='v'))

        self.assert_method_eq(
            INTERFACE_TESTS, [
                Int32(1, variant_level=1),
                Int32(2, variant_level=1),
                Int32(3, variant_level=1)
            ], 'IdentityArray',
            Array([Int32(1), Int32(2), Int32(3)], signature='v'))
        self.assert_method_eq(
            INTERFACE_TESTS, [
                String('a', variant_level=1),
                String('b', variant_level=1),
                String('c', variant_level=1)
            ], 'IdentityArray',
            Array([String('a'), String('b'),
                   String('c')], signature='v'))

        if have_signatures:
            self.assert_method_eq(INTERFACE_TESTS, [
                Byte(b'\x01', variant_level=1),
                Byte(b'\x02', variant_level=1),
                Byte(b'\x03', variant_level=1)
            ], 'IdentityArray', ByteArray(b'\x01\x02\x03'))
            self.assert_method_eq(
                INTERFACE_TESTS, [
                    Int32(1, variant_level=1),
                    Int32(2, variant_level=1),
                    Int32(3, variant_level=1)
                ], 'IdentityArray',
                [Int32(1), Int32(2), Int32(3)])
            self.assert_method_eq(INTERFACE_TESTS, [
                String('a', variant_level=1),
                String('b', variant_level=1),
                String('c', variant_level=1)
            ], 'IdentityArray', ['a', 'b', 'c'])

        self.assert_method_eq(INTERFACE_TESTS,
                              [Byte(1), Byte(2), Byte(3)], 'IdentityByteArray',
                              ByteArray(b'\x01\x02\x03'))
        if have_signatures:
            self.assert_method_eq(INTERFACE_TESTS, [1, 2, 3],
                                  'IdentityByteArray',
                                  [b'\x01', b'\x02', b'\x03'])
        self.assert_method_eq(INTERFACE_TESTS, [False, True],
                              'IdentityBoolArray', [False, True])
        if have_signatures:
            self.assert_method_eq(INTERFACE_TESTS, [False, True, True],
                                  'IdentityBoolArray', [0, 1, 2])

        self.assert_method_eq(
            INTERFACE_TESTS, [1, 2, 3], 'IdentityInt16Array',
            [Int16(1), Int16(2), Int16(3)])
        self.assert_method_eq(
            INTERFACE_TESTS, [1, 2, 3], 'IdentityUInt16Array',
            [UInt16(1), UInt16(2), UInt16(3)])
        self.assert_method_eq(
            INTERFACE_TESTS, [1, 2, 3], 'IdentityInt32Array',
            [Int32(1), Int32(2), Int32(3)])
        self.assert_method_eq(
            INTERFACE_TESTS, [1, 2, 3], 'IdentityUInt32Array',
            [UInt32(1), UInt32(2), UInt32(3)])
        self.assert_method_eq(
            INTERFACE_TESTS, [1, 2, 3], 'IdentityInt64Array',
            [Int64(1), Int64(2), Int64(3)])
        self.assert_method_eq(
            INTERFACE_TESTS, [1, 2, 3], 'IdentityUInt64Array',
            [UInt64(1), UInt64(2), UInt64(3)])

        if have_signatures:
            self.assert_method_eq(INTERFACE_TESTS, [1, 2, 3],
                                  'IdentityInt16Array', [1, 2, 3])
            self.assert_method_eq(INTERFACE_TESTS, [1, 2, 3],
                                  'IdentityUInt16Array', [1, 2, 3])
            self.assert_method_eq(INTERFACE_TESTS, [1, 2, 3],
                                  'IdentityInt32Array', [1, 2, 3])
            self.assert_method_eq(INTERFACE_TESTS, [1, 2, 3],
                                  'IdentityUInt32Array', [1, 2, 3])
            self.assert_method_eq(INTERFACE_TESTS, [1, 2, 3],
                                  'IdentityInt64Array', [1, 2, 3])
            self.assert_method_eq(INTERFACE_TESTS, [1, 2, 3],
                                  'IdentityUInt64Array', [1, 2, 3])

        self.assert_method_eq(INTERFACE_TESTS, [1.0, 2.5, 3.1],
                              'IdentityDoubleArray', [1.0, 2.5, 3.1])
        if have_signatures:
            self.assert_method_eq(INTERFACE_TESTS, [1.0, 2.5, 3.1],
                                  'IdentityDoubleArray', [1, 2.5, 3.1])
        self.assert_method_eq(INTERFACE_TESTS, ['a', 'b', 'c'],
                              'IdentityStringArray', ['a', 'b', 'c'])
        self.assert_method_eq(
            INTERFACE_TESTS, 6, 'Sum',
            [Int32(1), Int32(2), Int32(3)])
        if have_signatures:
            self.assert_method_eq(INTERFACE_TESTS, 6, 'Sum', [1, 2, 3])

        self.assert_InvertMapping_eq(INTERFACE_TESTS, {
            'fps': ['unreal', 'quake'],
            'rts': ['warcraft']
        }, 'InvertMapping', {
            'unreal': 'fps',
            'quake': 'fps',
            'warcraft': 'rts'
        })

        self.assert_method_eq(INTERFACE_TESTS, ('a', 1, 2), 'DeStruct',
                              ('a', UInt32(1), Int16(2)))
        self.assert_method_eq(INTERFACE_TESTS,
                              Array([String('x', variant_level=1)]),
                              'Primitize', [String('x', variant_level=1)])
        self.assert_method_eq(INTERFACE_TESTS,
                              Array([String('x', variant_level=1)]),
                              'Primitize', [String('x', variant_level=23)])
        self.assert_method_eq(
            INTERFACE_TESTS,
            Array([
                String('x', variant_level=1),
                Byte(1, variant_level=1),
                Byte(2, variant_level=1)
            ]), 'Primitize',
            Array([String('x'), Byte(1), Byte(2)], signature='v'))
        self.assert_method_eq(
            INTERFACE_TESTS,
            Array([
                String('x', variant_level=1),
                Byte(1, variant_level=1),
                Byte(2, variant_level=1)
            ]), 'Primitize',
            Array([String('x'), Array([Byte(1), Byte(2)])], signature='v'))
        self.assert_method_eq(INTERFACE_TESTS, Boolean(False), 'Invert', True)
        self.assert_method_eq(INTERFACE_TESTS, Boolean(True), 'Invert', False)
        if have_signatures:
            self.assert_method_eq(INTERFACE_TESTS, Boolean(False), 'Invert',
                                  42)
            self.assert_method_eq(INTERFACE_TESTS, Boolean(True), 'Invert', 0)
示例#4
0
            self.assert_method_eq(INTERFACE_TESTS, 42, 'IdentityInt64', 42)
            self.assert_method_eq(INTERFACE_TESTS, 42, 'IdentityUInt64', 42)
            self.assert_method_eq(INTERFACE_TESTS, 42.0, 'IdentityDouble', 42)

        self.assert_method_eq(
            INTERFACE_TESTS, [
                Byte('\x01', variant_level=1),
                Byte('\x02', variant_level=1),
                Byte('\x03', variant_level=1)
            ], 'IdentityArray',
            Array([Byte('\x01'), Byte('\x02'),
                   Byte('\x03')], signature='v'))

        self.assert_method_eq(
            INTERFACE_TESTS, [
                Int32(1, variant_level=1),
                Int32(2, variant_level=1),
                Int32(3, variant_level=1)
            ], 'IdentityArray',
            Array([Int32(1), Int32(2), Int32(3)], signature='v'))
        self.assert_method_eq(
            INTERFACE_TESTS, [
                String(u'a', variant_level=1),
                String(u'b', variant_level=1),
                String(u'c', variant_level=1)
            ], 'IdentityArray',
            Array([String('a'), String('b'),
                   String('c')], signature='v'))

        if have_signatures:
            self.assert_method_eq(INTERFACE_TESTS, [