def test_object_path(self): self.assertRaises(Exception, types.ObjectPath, 'a') self.assertEqual(types.ObjectPath('/ab', variant_level=23), '/ab') self.assertEqual(types.ObjectPath('/ab', variant_level=23).variant_level, 23) self.assertTrue(isinstance(types.ObjectPath('/ab'), str)) self.assertEqual(str(types.ObjectPath('/ab')), '/ab') self.assertIs(type(str(types.ObjectPath('/ab'))), str)
def test_path(self): s = lowlevel.SignalMessage('/a/b/c', 'foo.bar', 'baz') self.assertEqual(s.get_path(), types.ObjectPath('/a/b/c')) self.assertEqual(type(s.get_path()), types.ObjectPath) self.assertEqual(s.get_path_decomposed(), ['a', 'b', 'c']) # this is true in both major versions: it's a bytestring in # Python 2 and a Unicode string in Python 3 self.assertEqual(type(s.get_path_decomposed()[0]), str) self.assertTrue(s.has_path('/a/b/c')) self.assertFalse(s.has_path('/a/b')) self.assertFalse(s.has_path('/a/b/c/d')) s = lowlevel.SignalMessage('/', 'foo.bar', 'baz') self.assertEqual(s.get_path(), types.ObjectPath('/')) self.assertEqual(s.get_path().__class__, types.ObjectPath) self.assertEqual(s.get_path_decomposed(), []) self.assertTrue(s.has_path('/')) self.assertFalse(s.has_path(None))
def test_guess_signature(self): aeq = self.assertEqual from _dbus_bindings import Message aeq(Message.guess_signature(('a','b')), '(ss)') aeq(Message.guess_signature('a','b'), 'ss') aeq(Message.guess_signature(['a','b']), 'as') aeq(Message.guess_signature(('a',)), '(s)') aeq(Message.guess_signature('abc'), 's') aeq(Message.guess_signature(types.Int32(123)), 'i') aeq(Message.guess_signature(types.ByteArray(b'abc')), 'ay') aeq(Message.guess_signature(('a',)), '(s)') aeq(Message.guess_signature(['a']), 'as') aeq(Message.guess_signature({'a':'b'}), 'a{ss}') aeq(Message.guess_signature(types.ObjectPath('/')), 'o') aeq(Message.guess_signature(types.Signature('x')), 'g')