[PATCH 1/1] Update tests to be compatible with gi and python3

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Steve Langasek <steve.langasek@xxxxxxxxxxxxx>

This patch makes the python tests source-compatible with python 3, while
leaving the interpreter at python 2 for now.

The tradeoff is that this source is no longer compatible with python
versions < 2.6, and requires gobject-introspection for the glib-based tests.

Signed-off-by: Steve Langasek <steve.langasek@xxxxxxxxxxxxx>
---
 test/list-devices      |   30 ++++++++++---------
 test/monitor-bluetooth |    6 ++--
 test/simple-agent      |   41 +++++++++++++------------
 test/simple-endpoint   |   12 ++++----
 test/simple-service    |    8 +++--
 test/test-adapter      |   52 ++++++++++++++++----------------
 test/test-attrib       |   52 ++++++++++++++++----------------
 test/test-audio        |    8 +++--
 test/test-device       |   78 +++++++++++++++++++++++++-----------------------
 test/test-discovery    |   16 +++++-----
 test/test-health       |   62 +++++++++++++++++++-------------------
 test/test-health-sink  |   24 ++++++++-------
 test/test-input        |    8 +++--
 test/test-manager      |   12 ++++----
 test/test-nap          |    8 +++--
 test/test-network      |   10 ++++---
 test/test-oob          |   34 +++++++++++----------
 test/test-proximity    |   14 +++++----
 test/test-sap-server   |   64 ++++++++++++++++++++-------------------
 test/test-serial       |   10 ++++---
 test/test-serial-proxy |    6 ++--
 test/test-service      |   14 +++++----
 test/test-telephony    |   38 ++++++++++++-----------
 test/test-thermometer  |   28 +++++++++--------
 24 files changed, 342 insertions(+), 293 deletions(-)

diff --git a/test/list-devices b/test/list-devices
index cb564be..e2a5833 100755
--- a/test/list-devices
+++ b/test/list-devices
@@ -1,5 +1,7 @@
 #!/usr/bin/python
 
+from __future__ import absolute_import, print_function, unicode_literals
+
 import dbus
 
 bus = dbus.SystemBus()
@@ -32,19 +34,19 @@ adapter_list = manager.ListAdapters()
 for i in adapter_list:
 	adapter = dbus.Interface(bus.get_object("org.bluez", i),
 							"org.bluez.Adapter")
-	print "[ " + i + " ]"
+	print("[ " + i + " ]")
 
 	properties  = adapter.GetProperties()
 	for key in properties.keys():
 		value = properties[key]
 		if (key == "Devices"):
 			list = extract_objects(value)
-			print "    %s = %s" % (key, list)
+			print("    %s = %s" % (key, list))
 		elif (key == "UUIDs"):
 			list = extract_uuids(value)
-			print "    %s = %s" % (key, list)
+			print("    %s = %s" % (key, list))
 		else:
-			print "    %s = %s" % (key, value)
+			print("    %s = %s" % (key, value))
 
 	try:
 		device_list = properties["Devices"]
@@ -54,27 +56,27 @@ for i in adapter_list:
 	for n in device_list:
 		device = dbus.Interface(bus.get_object("org.bluez", n),
 							"org.bluez.Device")
-		print "    [ " + n + " ]"
+		print("    [ " + n + " ]")
 
 		properties = device.GetProperties()
 		for key in properties.keys():
 			value = properties[key]
 			if (key == "Nodes"):
 				list = extract_objects(value)
-				print "        %s = %s" % (key, list)
+				print("        %s = %s" % (key, list))
 			elif (key == "UUIDs"):
 				list = extract_uuids(value)
-				print "        %s = %s" % (key, list)
+				print("        %s = %s" % (key, list))
 			elif (key == "Class"):
-				print "        %s = 0x%06x" % (key, value)
+				print("        %s = 0x%06x" % (key, value))
 			elif (key == "Vendor"):
-				print "        %s = 0x%04x" % (key, value)
+				print("        %s = 0x%04x" % (key, value))
 			elif (key == "Product"):
-				print "        %s = 0x%04x" % (key, value)
+				print("        %s = 0x%04x" % (key, value))
 			elif (key == "Version"):
-				print "        %s = 0x%04x" % (key, value)
+				print("        %s = 0x%04x" % (key, value))
 			else:
-				print "        %s = %s" % (key, value)
+				print("        %s = %s" % (key, value))
 
 		try:
 			node_list = properties["Nodes"]
@@ -84,10 +86,10 @@ for i in adapter_list:
 		for x in node_list:
 			node = dbus.Interface(bus.get_object("org.bluez", x),
 							"org.bluez.Node")
-			print "        [ " + x + " ]"
+			print("        [ " + x + " ]")
 
 			properties = node.GetProperties()
 			for key in properties.keys():
-				print "            %s = %s" % (key, properties[key])
+				print("            %s = %s" % (key, properties[key]))
 
 	print
diff --git a/test/monitor-bluetooth b/test/monitor-bluetooth
index a5e5300..4a598e1 100755
--- a/test/monitor-bluetooth
+++ b/test/monitor-bluetooth
@@ -1,5 +1,7 @@
 #!/usr/bin/python
 
+from __future__ import absolute_import, print_function, unicode_literals
+
 import gobject
 
 import dbus
@@ -8,12 +10,12 @@ import dbus.mainloop.glib
 def property_changed(name, value, path, interface):
 	iface = interface[interface.rfind(".") + 1:]
 	val = str(value)
-	print "{%s.PropertyChanged} [%s] %s = %s" % (iface, path, name, val)
+	print("{%s.PropertyChanged} [%s] %s = %s" % (iface, path, name, val))
 
 def object_signal(value, path, interface, member):
 	iface = interface[interface.rfind(".") + 1:]
 	val = str(value)
-	print "{%s.%s} [%s] Path = %s" % (iface, member, path, val)
+	print("{%s.%s} [%s] Path = %s" % (iface, member, path, val))
 
 if __name__ == '__main__':
 	dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
diff --git a/test/simple-agent b/test/simple-agent
index 38d0235..5fe5da5 100755
--- a/test/simple-agent
+++ b/test/simple-agent
@@ -1,6 +1,8 @@
 #!/usr/bin/python
 
-import gobject
+from __future__ import absolute_import, print_function, unicode_literals
+
+from gi.repository import GObject
 
 import sys
 import dbus
@@ -20,15 +22,15 @@ class Agent(dbus.service.Object):
 	@dbus.service.method("org.bluez.Agent",
 					in_signature="", out_signature="")
 	def Release(self):
-		print "Release"
+		print("Release")
 		if self.exit_on_release:
 			mainloop.quit()
 
 	@dbus.service.method("org.bluez.Agent",
 					in_signature="os", out_signature="")
 	def Authorize(self, device, uuid):
-		print "Authorize (%s, %s)" % (device, uuid)
-		authorize = raw_input("Authorize connection (yes/no): ")
+		print("Authorize (%s, %s)" % (device, uuid))
+		authorize = input("Authorize connection (yes/no): ")
 		if (authorize == "yes"):
 			return
 		raise Rejected("Connection rejected by user")
@@ -36,20 +38,20 @@ class Agent(dbus.service.Object):
 	@dbus.service.method("org.bluez.Agent",
 					in_signature="o", out_signature="s")
 	def RequestPinCode(self, device):
-		print "RequestPinCode (%s)" % (device)
-		return raw_input("Enter PIN Code: ")
+		print("RequestPinCode (%s)" % (device))
+		return input("Enter PIN Code: ")
 
 	@dbus.service.method("org.bluez.Agent",
 					in_signature="o", out_signature="u")
 	def RequestPasskey(self, device):
-		print "RequestPasskey (%s)" % (device)
-		passkey = raw_input("Enter passkey: ")
+		print("RequestPasskey (%s)" % (device))
+		passkey = input("Enter passkey: ")
 		return dbus.UInt32(passkey)
 
 	@dbus.service.method("org.bluez.Agent",
 					in_signature="ou", out_signature="")
 	def DisplayPasskey(self, device, passkey):
-		print "DisplayPasskey (%s, %06d)" % (device, passkey)
+		print("DisplayPasskey (%s, %06d)" % (device, passkey))
 
 	@dbus.service.method("org.bluez.Agent",
 					in_signature="os", out_signature="")
@@ -59,8 +61,8 @@ class Agent(dbus.service.Object):
 	@dbus.service.method("org.bluez.Agent",
 					in_signature="ou", out_signature="")
 	def RequestConfirmation(self, device, passkey):
-		print "RequestConfirmation (%s, %06d)" % (device, passkey)
-		confirm = raw_input("Confirm passkey (yes/no): ")
+		print("RequestConfirmation (%s, %06d)" % (device, passkey))
+		confirm = input("Confirm passkey (yes/no): ")
 		if (confirm == "yes"):
 			return
 		raise Rejected("Passkey doesn't match")
@@ -68,8 +70,8 @@ class Agent(dbus.service.Object):
 	@dbus.service.method("org.bluez.Agent",
 					in_signature="s", out_signature="")
 	def ConfirmModeChange(self, mode):
-		print "ConfirmModeChange (%s)" % (mode)
-		authorize = raw_input("Authorize mode change (yes/no): ")
+		print("ConfirmModeChange (%s)" % (mode))
+		authorize = input("Authorize mode change (yes/no): ")
 		if (authorize == "yes"):
 			return
 		raise Rejected("Mode change by user")
@@ -77,14 +79,14 @@ class Agent(dbus.service.Object):
 	@dbus.service.method("org.bluez.Agent",
 					in_signature="", out_signature="")
 	def Cancel(self):
-		print "Cancel"
+		print("Cancel")
 
 def create_device_reply(device):
-	print "New device (%s)" % (device)
+	print("New device (%s)" % (device))
 	mainloop.quit()
 
 def create_device_error(error):
-	print "Creating device failed: %s" % (error)
+	print("Creating device failed: %s" % (error))
 	mainloop.quit()
 
 if __name__ == '__main__':
@@ -114,7 +116,7 @@ if __name__ == '__main__':
 	path = "/test/agent"
 	agent = Agent(bus, path)
 
-	mainloop = gobject.MainLoop()
+	mainloop = GObject.MainLoop()
 
 	if len(args) > 1:
 		if len(args) > 2:
@@ -127,9 +129,10 @@ if __name__ == '__main__':
 					error_handler=create_device_error)
 	else:
 		adapter.RegisterAgent(path, capability)
-		print "Agent registered"
+		print("Agent registered")
 
 	mainloop.run()
 
 	#adapter.UnregisterAgent(path)
-	#print "Agent unregistered"
+	#print("Agent unregistered")
+
diff --git a/test/simple-endpoint b/test/simple-endpoint
index e09a528..20c8159 100755
--- a/test/simple-endpoint
+++ b/test/simple-endpoint
@@ -1,5 +1,7 @@
 #!/usr/bin/python
 
+from __future__ import absolute_import, print_function, unicode_literals
+
 import sys
 import dbus
 import dbus.service
@@ -52,25 +54,25 @@ class Endpoint(dbus.service.Object):
 	@dbus.service.method("org.bluez.MediaEndpoint",
 					in_signature="", out_signature="")
 	def Release(self):
-		print "Release"
+		print("Release")
 		if self.exit_on_release:
 			mainloop.quit()
 
 	@dbus.service.method("org.bluez.MediaEndpoint",
 					in_signature="", out_signature="")
 	def ClearConfiguration(self):
-		print "ClearConfiguration"
+		print("ClearConfiguration")
 
 	@dbus.service.method("org.bluez.MediaEndpoint",
 					in_signature="oay", out_signature="")
 	def SetConfiguration(self, transport, config):
-		print "SetConfiguration (%s, %s)" % (transport, config)
+		print("SetConfiguration (%s, %s)" % (transport, config))
 		return
 
 	@dbus.service.method("org.bluez.MediaEndpoint",
 					in_signature="ay", out_signature="ay")
 	def SelectConfiguration(self, caps):
-		print "SelectConfiguration (%s)" % (caps)
+		print("SelectConfiguration (%s)" % (caps))
 		return self.configuration
 
 if __name__ == '__main__':
@@ -119,7 +121,7 @@ if __name__ == '__main__':
 							"Capabilities" :  PCM_CONFIGURATION })
 			endpoint.default_configuration(dbus.Array([]))
 
-	print properties
+	print(properties)
 
 	media.RegisterEndpoint(path, properties)
 
diff --git a/test/simple-service b/test/simple-service
index d03ec3d..ed27d0c 100755
--- a/test/simple-service
+++ b/test/simple-service
@@ -1,5 +1,7 @@
 #!/usr/bin/python
 
+from __future__ import absolute_import, print_function, unicode_literals
+
 import sys
 import time
 import dbus
@@ -114,13 +116,13 @@ service = dbus.Interface(bus.get_object("org.bluez", path),
 
 handle = service.AddRecord(xml)
 
-print "Service record with handle 0x%04x added" % (handle)
+print("Service record with handle 0x%04x added" % (handle))
 
-print "Press CTRL-C to remove service record"
+print("Press CTRL-C to remove service record")
 
 try:
 	time.sleep(1000)
-	print "Terminating session"
+	print("Terminating session")
 except:
 	pass
 
diff --git a/test/test-adapter b/test/test-adapter
index 762ef98..4e2f029 100755
--- a/test/test-adapter
+++ b/test/test-adapter
@@ -1,5 +1,7 @@
 #!/usr/bin/python
 
+from __future__ import absolute_import, print_function, unicode_literals
+
 import sys
 import dbus
 import time
@@ -26,28 +28,28 @@ adapter = dbus.Interface(bus.get_object("org.bluez", adapter_path),
 							"org.bluez.Adapter")
 
 if (len(args) < 1):
-	print "Usage: %s <command>" % (sys.argv[0])
-	print ""
-	print "  address"
-	print "  list"
-	print "  name [name]"
-	print "  powered [on/off]"
-	print "  pairable [on/off]"
-	print "  pairabletimeout [timeout]"
-	print "  discoverable [on/off]"
-	print "  discoverabletimeout [timeout]"
-	print "  discovering"
+	print("Usage: %s <command>" % (sys.argv[0]))
+	print("")
+	print("  address")
+	print("  list")
+	print("  name [name]")
+	print("  powered [on/off]")
+	print("  pairable [on/off]")
+	print("  pairabletimeout [timeout]")
+	print("  discoverable [on/off]")
+	print("  discoverabletimeout [timeout]")
+	print("  discovering")
 	sys.exit(1)
 
 if (args[0] == "address"):
 	properties = adapter.GetProperties()
-	print properties["Address"]
+	print(properties["Address"])
 	sys.exit(0)
 
 if (args[0] == "name"):
 	if (len(args) < 2):
 		properties = adapter.GetProperties()
-		print properties["Name"]
+		print(properties["Name"])
 	else:
 		adapter.SetProperty("Name", args[1])
 	sys.exit(0)
@@ -59,19 +61,19 @@ if (args[0] == "list"):
 			adapter = dbus.Interface(bus.get_object("org.bluez", adapter_path),
 								"org.bluez.Adapter")
 			prop = adapter.GetProperties()
-			print " [ %s ]" % (adapter_path)
-			for (key, value) in prop.iteritems():
+			print(" [ %s ]" % (adapter_path))
+			for (key, value) in prop.items():
 				if (key == "Class"):
-					print "    %s = 0x%06x" % (key, value)
+					print("    %s = 0x%06x" % (key, value))
 				else:
-					print "    %s = %s" % (key, value)
-			print
+					print("    %s = %s" % (key, value))
+			print()
 	sys.exit(0)
 
 if (args[0] == "powered"):
 	if (len(args) < 2):
 		properties = adapter.GetProperties()
-		print properties["Powered"]
+		print(properties["Powered"])
 	else:
 		if (args[1] == "on"):
 			value = dbus.Boolean(1)
@@ -85,7 +87,7 @@ if (args[0] == "powered"):
 if (args[0] == "pairable"):
 	if (len(args) < 2):
 		properties = adapter.GetProperties()
-		print properties["Pairable"]
+		print(properties["Pairable"])
 	else:
 		if (args[1] == "on"):
 			value = dbus.Boolean(1)
@@ -99,7 +101,7 @@ if (args[0] == "pairable"):
 if (args[0] == "pairabletimeout"):
 	if (len(args) < 2):
 		properties = adapter.GetProperties()
-		print properties["PairableTimeout"]
+		print(properties["PairableTimeout"])
 	else:
 		timeout = dbus.UInt32(args[1])
 		adapter.SetProperty("PairableTimeout", timeout)
@@ -108,7 +110,7 @@ if (args[0] == "pairabletimeout"):
 if (args[0] == "discoverable"):
 	if (len(args) < 2):
 		properties = adapter.GetProperties()
-		print properties["Discoverable"]
+		print(properties["Discoverable"])
 	else:
 		if (args[1] == "on"):
 			value = dbus.Boolean(1)
@@ -122,7 +124,7 @@ if (args[0] == "discoverable"):
 if (args[0] == "discoverabletimeout"):
 	if (len(args) < 2):
 		properties = adapter.GetProperties()
-		print properties["DiscoverableTimeout"]
+		print(properties["DiscoverableTimeout"])
 	else:
 		timeout = dbus.UInt32(args[1])
 		adapter.SetProperty("DiscoverableTimeout", timeout)
@@ -130,8 +132,8 @@ if (args[0] == "discoverabletimeout"):
 
 if (args[0] == "discovering"):
 	properties = adapter.GetProperties()
-	print properties["Discovering"]
+	print(properties["Discovering"])
 	sys.exit(0)
 
-print "Unknown command"
+print("Unknown command")
 sys.exit(1)
diff --git a/test/test-attrib b/test/test-attrib
index b9e83c5..52b399c 100755
--- a/test/test-attrib
+++ b/test/test-attrib
@@ -1,4 +1,6 @@
 #!/usr/bin/python
+
+from __future__ import absolute_import, print_function, unicode_literals
 # Script for testing the Attribute D-Bus API
 
 import sys
@@ -35,12 +37,12 @@ adapter = dbus.Interface(bus.get_object("org.bluez", adapter_path),
 							"org.bluez.Adapter")
 
 if (len(args) < 1):
-	print "Usage: %s <command>" % (sys.argv[0])
-	print ""
-	print "	 list"
-	print "	 services <address>"
-	print "	 discover <service path>"
-	print "	 chars <service path>"
+	print("Usage: %s <command>" % (sys.argv[0]))
+	print("")
+	print("	 list")
+	print("	 services <address>")
+	print("	 discover <service path>")
+	print("	 chars <service path>")
 	sys.exit(1)
 
 if (args[0] == "list"):
@@ -48,61 +50,61 @@ if (args[0] == "list"):
 		device = dbus.Interface(bus.get_object("org.bluez", path),
 							"org.bluez.Device")
 		devprop = device.GetProperties()
-		print "[ %s ]" % devprop["Address"]
+		print("[ %s ]" % devprop["Address"])
 		for path in devprop["Services"]:
 
 			service = dbus.Interface(bus.get_object("org.bluez", path),
 									 "org.bluez.Characteristic")
 			srvprop = service.GetProperties()
-			print " * %s" % (path)
-			print "	UUID: %s" % srvprop["UUID"]
-			print "	Chars: ",
+			print(" * %s" % (path))
+			print("	UUID: %s" % srvprop["UUID"])
+			print("	Chars: ",)
 			for char in srvprop["Characteristics"]:
-				print "%s " % char,
-			print
-			print
-		print
+				print("%s " % char,)
+			print()
+			print()
+		print()
 	sys.exit(0)
 
 if (args[0] == "services"):
 	if (len(args) < 2):
-		print "Need address parameter"
+		print("Need address parameter")
 	else:
 		path = adapter.FindDevice(args[1])
 		device = dbus.Interface(bus.get_object("org.bluez", path),
 							"org.bluez.Device")
 		properties = device.GetProperties()
 		for path in properties["Services"]:
-			print path
+			print(path)
 	sys.exit(0)
 
 if (args[0] == "discover"):
 	if (len(args) < 2):
-		print "Need service path parameter"
+		print("Need service path parameter")
 	else:
 		service = dbus.Interface(bus.get_object("org.bluez", args[1]),
 							"org.bluez.Characteristic")
 		for path in service.DiscoverCharacteristics():
-			print path
+			print(path)
 	sys.exit(0)
 
 if (args[0] == "chars"):
 	if (len(args) < 2):
-		print "Need service path parameter"
+		print("Need service path parameter")
 	else:
 		service = dbus.Interface(bus.get_object("org.bluez", args[1]),
 								 "org.bluez.Characteristic")
 		srvprop = service.GetProperties()
 		for path in srvprop["Characteristics"]:
-			print "[ %s ]" % (path)
+			print("[ %s ]" % (path))
 			char = dbus.Interface(bus.get_object("org.bluez", path),
 								 "org.bluez.Characteristic")
 			charprop = char.GetProperties()
-			print "	Name: %s" % charprop["Name"]
-			print "	UUID: %s" % charprop["UUID"]
-			print
-		print
+			print("	Name: %s" % charprop["Name"])
+			print("	UUID: %s" % charprop["UUID"])
+			print()
+		print()
 	sys.exit(0)
 
-print "Unknown command"
+print("Unknown command")
 sys.exit(1)
diff --git a/test/test-audio b/test/test-audio
index 8b7a62d..1ba2042 100755
--- a/test/test-audio
+++ b/test/test-audio
@@ -1,5 +1,7 @@
 #!/usr/bin/python
 
+from __future__ import absolute_import, print_function, unicode_literals
+
 import sys
 import dbus
 from optparse import OptionParser, make_option
@@ -25,11 +27,11 @@ adapter = dbus.Interface(bus.get_object("org.bluez", adapter_path),
 							"org.bluez.Adapter")
 
 if len(args) < 2:
-	print """Usage: %s <command>
+	print("""Usage: %s <command>
 
 	connect <bdaddr>
 	disconnect <bdaddr>
-	""" % sys.argv[0]
+	""" % sys.argv[0])
 	sys.exit(1)
 
 device = adapter.FindDevice(args[1])
@@ -41,5 +43,5 @@ if args[0] == "connect":
 elif args[0] == "disconnect":
 	audio.Disconnect()
 else:
-	print "Unknown command"
+	print("Unknown command")
 	sys.exit(1)
diff --git a/test/test-device b/test/test-device
index 154af19..81a44f8 100755
--- a/test/test-device
+++ b/test/test-device
@@ -1,6 +1,8 @@
 #!/usr/bin/python
 
-import gobject
+from __future__ import absolute_import, print_function, unicode_literals
+
+from gi.repository import GObject
 
 import sys
 import dbus
@@ -10,7 +12,7 @@ from optparse import OptionParser, make_option
 
 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
 bus = dbus.SystemBus()
-mainloop = gobject.MainLoop()
+mainloop = GObject.MainLoop()
 
 manager = dbus.Interface(bus.get_object("org.bluez", "/"), "org.bluez.Manager")
 
@@ -31,19 +33,19 @@ adapter = dbus.Interface(bus.get_object("org.bluez", adapter_path),
 							"org.bluez.Adapter")
 
 if (len(args) < 1):
-	print "Usage: %s <command>" % (sys.argv[0])
-	print ""
-	print "  list"
-	print "  services <address>"
-	print "  create <address>"
-	print "  remove <address|path>"
-	print "  disconnect <address>"
-	print "  discover <address> [pattern]"
-	print "  class <address>"
-	print "  name <address>"
-	print "  alias <address> [alias]"
-	print "  trusted <address> [yes/no]"
-	print "  blocked <address> [yes/no]"
+	print("Usage: %s <command>" % (sys.argv[0]))
+	print("")
+	print("  list")
+	print("  services <address>")
+	print("  create <address>")
+	print("  remove <address|path>")
+	print("  disconnect <address>")
+	print("  discover <address> [pattern]")
+	print("  class <address>")
+	print("  name <address>")
+	print("  alias <address> [alias]")
+	print("  trusted <address> [yes/no]")
+	print("  blocked <address> [yes/no]")
 	sys.exit(1)
 
 if (args[0] == "list"):
@@ -51,23 +53,23 @@ if (args[0] == "list"):
 		device = dbus.Interface(bus.get_object("org.bluez", path),
 							"org.bluez.Device")
 		properties = device.GetProperties()
-		print "%s %s" % (properties["Address"], properties["Alias"])
+		print("%s %s" % (properties["Address"], properties["Alias"]))
 
 	sys.exit(0)
 
 def create_device_reply(device):
-	print "New device (%s)" % device
+	print("New device (%s)" % device)
 	mainloop.quit()
 	sys.exit(0)
 
 def create_device_error(error):
-	print "Creating device failed: %s" % error
+	print("Creating device failed: %s" % error)
 	mainloop.quit()
 	sys.exit(1)
 
 if (args[0] == "create"):
 	if (len(args) < 2):
-		print "Need address parameter"
+		print("Need address parameter")
 	else:
 		adapter.CreateDevice(args[1],
 				reply_handler=create_device_reply,
@@ -76,7 +78,7 @@ if (args[0] == "create"):
 
 if (args[0] == "remove"):
 	if (len(args) < 2):
-		print "Need address or object path parameter"
+		print("Need address or object path parameter")
 	else:
 		try:
 			path = adapter.FindDevice(args[1])
@@ -87,7 +89,7 @@ if (args[0] == "remove"):
 
 if (args[0] == "disconnect"):
 	if (len(args) < 2):
-		print "Need address parameter"
+		print("Need address parameter")
 	else:
 		path = adapter.FindDevice(args[1])
 		device = dbus.Interface(bus.get_object("org.bluez", path),
@@ -97,7 +99,7 @@ if (args[0] == "disconnect"):
 
 if (args[0] == "discover"):
 	if (len(args) < 2):
-		print "Need address parameter"
+		print("Need address parameter")
 	else:
 		path = adapter.FindDevice(args[1])
 		device = dbus.Interface(bus.get_object("org.bluez", path),
@@ -110,57 +112,57 @@ if (args[0] == "discover"):
 		for key in services.keys():
 			p = re.compile(">.*?<")
 			xml = p.sub("><", services[key].replace("\n", ""))
-			print "[ 0x%5x ]" % (key)
-			print xml
-			print
+			print("[ 0x%5x ]" % (key))
+			print(xml)
+			print()
 	sys.exit(0)
 
 if (args[0] == "class"):
 	if (len(args) < 2):
-		print "Need address parameter"
+		print("Need address parameter")
 	else:
 		path = adapter.FindDevice(args[1])
 		device = dbus.Interface(bus.get_object("org.bluez", path),
 							"org.bluez.Device")
 		properties = device.GetProperties()
-		print "0x%06x" % (properties["Class"])
+		print("0x%06x" % (properties["Class"]))
 	sys.exit(0)
 
 if (args[0] == "name"):
 	if (len(args) < 2):
-		print "Need address parameter"
+		print("Need address parameter")
 	else:
 		path = adapter.FindDevice(args[1])
 		device = dbus.Interface(bus.get_object("org.bluez", path),
 							"org.bluez.Device")
 		properties = device.GetProperties()
-		print properties["Name"]
+		print(properties["Name"])
 	sys.exit(0)
 
 if (args[0] == "alias"):
 	if (len(args) < 2):
-		print "Need address parameter"
+		print("Need address parameter")
 	else:
 		path = adapter.FindDevice(args[1])
 		device = dbus.Interface(bus.get_object("org.bluez", path),
 							"org.bluez.Device")
 		if (len(args) < 3):
 			properties = device.GetProperties()
-			print properties["Alias"]
+			print(properties["Alias"])
 		else:
 			device.SetProperty("Alias", args[2])
 	sys.exit(0)
 
 if (args[0] == "trusted"):
 	if (len(args) < 2):
-		print "Need address parameter"
+		print("Need address parameter")
 	else:
 		path = adapter.FindDevice(args[1])
 		device = dbus.Interface(bus.get_object("org.bluez", path),
 							"org.bluez.Device")
 		if (len(args) < 3):
 			properties = device.GetProperties()
-			print properties["Trusted"]
+			print(properties["Trusted"])
 		else:
 			if (args[2] == "yes"):
 				value = dbus.Boolean(1)
@@ -173,14 +175,14 @@ if (args[0] == "trusted"):
 
 if (args[0] == "blocked"):
 	if (len(args) < 2):
-		print "Need address parameter"
+		print("Need address parameter")
 	else:
 		path = adapter.FindDevice(args[1])
 		device = dbus.Interface(bus.get_object("org.bluez", path),
 							"org.bluez.Device")
 		if (len(args) < 3):
 			properties = device.GetProperties()
-			print properties["Blocked"]
+			print(properties["Blocked"])
 		else:
 			if (args[2] == "yes"):
 				value = dbus.Boolean(1)
@@ -193,15 +195,15 @@ if (args[0] == "blocked"):
 
 if (args[0] == "services"):
 	if (len(args) < 2):
-		print "Need address parameter"
+		print("Need address parameter")
 	else:
 		path = adapter.FindDevice(args[1])
 		device = dbus.Interface(bus.get_object("org.bluez", path),
 							"org.bluez.Device")
 		properties = device.GetProperties()
 		for path in properties["Services"]:
-			print path
+			print(path)
 	sys.exit(0)
 
-print "Unknown command"
+print("Unknown command")
 sys.exit(1)
diff --git a/test/test-discovery b/test/test-discovery
index 20312f7..880d231 100755
--- a/test/test-discovery
+++ b/test/test-discovery
@@ -1,24 +1,26 @@
 #!/usr/bin/python
 
-import gobject
-
+from __future__ import absolute_import, print_function, unicode_literals
+ 
+from gi.repository import GObject
+ 
 import dbus
 import dbus.mainloop.glib
 from optparse import OptionParser, make_option
 
 def device_found(address, properties):
-	print "[ " + address + " ]"
+	print("[ " + address + " ]")
 
 	for key in properties.keys():
 		value = properties[key]
 		if type(value) is dbus.String:
 			value = unicode(value).encode('ascii', 'replace')
 		if (key == "Class"):
-			print "    %s = 0x%06x" % (key, value)
+			print("    %s = 0x%06x" % (key, value))
 		else:
-			print "    %s = %s" % (key, value)
+			print("    %s = %s" % (key, value))
 
-	print
+	print()
 
 def property_changed(name, value):
 	if (name == "Discovering" and not value):
@@ -57,5 +59,5 @@ if __name__ == '__main__':
 
 	adapter.StartDiscovery()
 
-	mainloop = gobject.MainLoop()
+	mainloop = GObject.MainLoop()
 	mainloop.run()
diff --git a/test/test-health b/test/test-health
index 16a5a2b..f7d4241 100755
--- a/test/test-health
+++ b/test/test-health
@@ -1,4 +1,6 @@
 #!/usr/bin/python
+
+from __future__ import absolute_import, print_function, unicode_literals
 # -*- coding: utf-8 -*-
 
 import dbus
@@ -19,15 +21,15 @@ def sig_received(*args, **kwargs):
 		return;
 	sig_name = kwargs["member"]
 	path = kwargs["path"]
-	print sig_name
-	print path
+	print(sig_name)
+	print(path)
 	if sig_name == "PropertyChanged":
 		k, v = args
-		print k
-		print v
+		print(k)
+		print(v)
 	else:
 		ob = args[0]
-		print ob
+		print(ob)
 
 
 def enter_mainloop():
@@ -38,21 +40,21 @@ def enter_mainloop():
 				interface_keyword="interface")
 
 	try:
-		print "Entering main lopp, push Ctrl+C for finish"
+		print("Entering main lopp, push Ctrl+C for finish")
 
 		mainloop = gobject.MainLoop()
 		mainloop.run()
 	except KeyboardInterrupt:
 		pass
 	finally:
-		print "Exiting, bye"
+		print("Exiting, bye")
 
 hdp_manager = dbus.Interface(bus.get_object("org.bluez", "/org/bluez"),
 						"org.bluez.HealthManager")
 
 role = None
 while role == None:
-	print "Select 1. source or 2. sink: ",
+	print("Select 1. source or 2. sink: ",)
 	try:
 		sel = int(sys.stdin.readline())
 		if sel == 1:
@@ -62,20 +64,20 @@ while role == None:
 		else:
 			raise ValueError
 	except (TypeError, ValueError):
-		print "Wrong selection, try again: ",
+		print("Wrong selection, try again: ",)
 	except KeyboardInterrupt:
 		sys.exit()
 
 dtype = None
 while dtype == None:
-	print "Select a data type: ",
+	print("Select a data type: ",)
 	try:
 		sel = int(sys.stdin.readline())
 		if (sel < 0) or (sel > 65535):
 			raise ValueError
 		dtype = sel;
 	except (TypeError, ValueError):
-		print "Wrong selection, try again: ",
+		print("Wrong selection, try again: ",)
 	except KeyboardInterrupt:
 		sys.exit()
 
@@ -83,8 +85,8 @@ pref = None
 if role == "Source":
 	while pref == None:
 		try:
-			print "Select a preferred data channel type 1.",
-			print "reliable 2. streaming: ",
+			print("Select a preferred data channel type 1.",)
+			print("reliable 2. streaming: ",)
 			sel = int(sys.stdin.readline())
 			if sel == 1:
 				pref = "Reliable"
@@ -94,7 +96,7 @@ if role == "Source":
 				raise ValueError
 
 		except (TypeError, ValueError):
-			print "Wrong selection, try again"
+			print("Wrong selection, try again")
 		except KeyboardInterrupt:
 			sys.exit()
 
@@ -109,19 +111,19 @@ else:
 					"Description": "Test sink",
 					"Role": role})
 
-print "New application created:", app_path
+print("New application created:", app_path)
 
 con = None
 while con == None:
 	try:
-		print "Connect to a remote device (y/n)? ",
+		print("Connect to a remote device (y/n)? ",)
 		sel = sys.stdin.readline()
 		if sel in ("y\n", "yes\n", "Y\n", "YES\n"):
 			con = True
 		elif sel in ("n\n", "no\n", "N\n", "NO\n"):
 			con = False
 		else:
-			print "Wrong selection, try again."
+			print("Wrong selection, try again.")
 	except KeyboardInterrupt:
 		sys.exit()
 
@@ -136,10 +138,10 @@ adapters = manager.ListAdapters()
 
 i = 1
 for ad in adapters:
-	print "%d. %s" % (i, ad)
+	print("%d. %s" % (i, ad))
 	i = i + 1
 
-print "Select an adapter: ",
+print("Select an adapter: ",)
 select = None
 while select == None:
 	try:
@@ -148,7 +150,7 @@ while select == None:
 			raise TypeError
 		select = adapters[pos]
 	except (TypeError, IndexError, ValueError):
-		print "Wrong selection, try again: ",
+		print("Wrong selection, try again: ",)
 	except KeyboardInterrupt:
 		sys.exit()
 
@@ -158,15 +160,15 @@ adapter =  dbus.Interface(bus.get_object("org.bluez", select),
 devices = adapter.ListDevices()
 
 if len(devices) == 0:
-	print "No devices available"
+	print("No devices available")
 	sys.exit()
 
 i = 1
 for dev in devices:
-	print "%d. %s" % (i, dev)
+	print("%d. %s" % (i, dev))
 	i = i + 1
 
-print "Select a device: ",
+print("Select a device: ",)
 select = None
 while select == None:
 	try:
@@ -175,7 +177,7 @@ while select == None:
 			raise TypeError
 		select = devices[pos]
 	except (TypeError, IndexError, ValueError):
-		print "Wrong selection, try again: ",
+		print("Wrong selection, try again: ",)
 	except KeyboardInterrupt:
 		sys.exit()
 
@@ -185,32 +187,32 @@ device = dbus.Interface(bus.get_object("org.bluez", select),
 echo = None
 while echo == None:
 	try:
-		print "Perform an echo (y/n)? ",
+		print("Perform an echo (y/n)? ",)
 		sel = sys.stdin.readline()
 		if sel in ("y\n", "yes\n", "Y\n", "YES\n"):
 			echo = True
 		elif sel in ("n\n", "no\n", "N\n", "NO\n"):
 			echo = False
 		else:
-			print "Wrong selection, try again."
+			print("Wrong selection, try again.")
 	except KeyboardInterrupt:
 		sys.exit()
 
 if echo:
 	if device.Echo():
-		print "Echo was ok"
+		print("Echo was ok")
 	else:
-		print "Echo war wrong, exiting"
+		print("Echo war wrong, exiting")
 		sys.exit()
 
-print "Connecting to device %s" % (select)
+print("Connecting to device %s" % (select))
 
 if role == "Source":
 	chan = device.CreateChannel(app_path, "Reliable")
 else:
 	chan = device.CreateChannel(app_path, "Any")
 
-print chan
+print(chan)
 
 enter_mainloop()
 
diff --git a/test/test-health-sink b/test/test-health-sink
index cb9d434..ce7337a 100755
--- a/test/test-health-sink
+++ b/test/test-health-sink
@@ -1,4 +1,6 @@
 #!/usr/bin/python
+
+from __future__ import absolute_import, print_function, unicode_literals
 # -*- coding: utf-8 -*-
 
 import dbus
@@ -17,7 +19,7 @@ hdp_manager = dbus.Interface(bus.get_object("org.bluez", "/org/bluez"),
 app_path = hdp_manager.CreateApplication({"DataType": dbus.types.UInt16(4103),
 					"Role": "sink"})
 
-print app_path
+print(app_path)
 
 manager = dbus.Interface(bus.get_object("org.bluez", "/"),
 						"org.bluez.Manager")
@@ -26,10 +28,10 @@ adapters = manager.ListAdapters()
 
 i = 1
 for ad in adapters:
-	print "%d. %s" % (i, ad)
+	print("%d. %s" % (i, ad))
 	i = i + 1
 
-print "Select an adapter: ",
+print("Select an adapter: ",)
 select = None
 while select == None:
 	try:
@@ -38,7 +40,7 @@ while select == None:
 			raise TypeError
 		select = adapters[pos]
 	except (TypeError, IndexError, ValueError):
-		print "Wrong selection, try again: ",
+		print("Wrong selection, try again: ",)
 	except KeyboardInterrupt:
 		sys.exit()
 
@@ -48,15 +50,15 @@ adapter =  dbus.Interface(bus.get_object("org.bluez", select),
 devices = adapter.ListDevices()
 
 if len(devices) == 0:
-	print "No devices available"
+	print("No devices available")
 	sys.exit()
 
 i = 1
 for dev in devices:
-	print "%d. %s" % (i, dev)
+	print("%d. %s" % (i, dev))
 	i = i + 1
 
-print "Select a device: ",
+print("Select a device: ",)
 select = None
 while select == None:
 	try:
@@ -65,19 +67,19 @@ while select == None:
 			raise TypeError
 		select = devices[pos]
 	except (TypeError, IndexError, ValueError):
-		print "Wrong selection, try again: ",
+		print("Wrong selection, try again: ",)
 	except KeyboardInterrupt:
 		sys.exit()
 
-print "Connecting to %s" % (select)
+print("Connecting to %s" % (select))
 device = dbus.Interface(bus.get_object("org.bluez", select),
 					"org.bluez.HealthDevice")
 
 chan = device.CreateChannel(app_path, "Any")
 
-print chan
+print(chan)
 
-print "Push Enter for finishing"
+print("Push Enter for finishing")
 sys.stdin.readline()
 
 hdp_manager.DestroyApplication(app_path)
diff --git a/test/test-input b/test/test-input
index 405bb59..110cbef 100755
--- a/test/test-input
+++ b/test/test-input
@@ -1,5 +1,7 @@
 #!/usr/bin/python
 
+from __future__ import absolute_import, print_function, unicode_literals
+
 import sys
 import dbus
 from optparse import OptionParser, make_option
@@ -25,11 +27,11 @@ adapter = dbus.Interface(bus.get_object("org.bluez", adapter_path),
 							"org.bluez.Adapter")
 
 if len(args) < 2:
-	print """Usage: %s <command>
+	print("""Usage: %s <command>
 
 	connect <bdaddr>
 	disconnect <bdaddr>
-	""" % sys.argv[0]
+	""" % sys.argv[0])
 	sys.exit(1)
 
 device = adapter.FindDevice(args[1])
@@ -41,5 +43,5 @@ if args[0] == "connect":
 elif args[0] == "disconnect":
 	input.Disconnect()
 else:
-	print "Unknown command"
+	print("Unknown command")
 	sys.exit(1)
diff --git a/test/test-manager b/test/test-manager
index c6cf560..8a7e2f6 100755
--- a/test/test-manager
+++ b/test/test-manager
@@ -1,18 +1,20 @@
 #!/usr/bin/python
 
-import gobject
+from __future__ import absolute_import, print_function, unicode_literals
+
+from gi.repository import GObject
 
 import dbus
 import dbus.mainloop.glib
 
 def adapter_added(path):
-	print "Adapter with path %s added" % (path)
+	print("Adapter with path %s added" % (path))
 
 def adapter_removed(path):
-	print "Adapter with path %s removed" % (path)
+	print("Adapter with path %s removed" % (path))
 
 def default_changed(path):
-	print "Default adapter is now at path %s" % (path)
+	print("Default adapter is now at path %s" % (path))
 
 if __name__ == "__main__":
 	dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
@@ -34,5 +36,5 @@ if __name__ == "__main__":
 	except:
 		pass
 
-	mainloop = gobject.MainLoop()
+	mainloop = GObject.MainLoop()
 	mainloop.run()
diff --git a/test/test-nap b/test/test-nap
index c83d928..dc779ad 100755
--- a/test/test-nap
+++ b/test/test-nap
@@ -1,5 +1,7 @@
 #!/usr/bin/python
 
+from __future__ import absolute_import, print_function, unicode_literals
+
 import sys
 import time
 import dbus
@@ -35,13 +37,13 @@ else:
 
 server.Register(service, bridge)
 
-print "Server for %s registered for %s" % (service, bridge)
+print("Server for %s registered for %s" % (service, bridge))
 
-print "Press CTRL-C to disconnect"
+print("Press CTRL-C to disconnect")
 
 try:
 	time.sleep(1000)
-	print "Terminating connection"
+	print("Terminating connection")
 except:
 	pass
 
diff --git a/test/test-network b/test/test-network
index 676fb30..2ade584 100755
--- a/test/test-network
+++ b/test/test-network
@@ -1,5 +1,7 @@
 #!/usr/bin/python
 
+from __future__ import absolute_import, print_function, unicode_literals
+
 import sys
 import time
 import dbus
@@ -27,7 +29,7 @@ adapter = dbus.Interface(bus.get_object("org.bluez", adapter_path),
 							"org.bluez.Adapter")
 
 if (len(args) < 1):
-	print "Usage: %s <address> [service]" % (sys.argv[0])
+	print("Usage: %s <address> [service]" % (sys.argv[0]))
 	sys.exit(1)
 
 address = args[0]
@@ -44,13 +46,13 @@ network = dbus.Interface(bus.get_object("org.bluez", device),
 
 iface = network.Connect(service)
 
-print "Connected %s to %s" % (device, address)
+print("Connected %s to %s" % (device, address))
 
-print "Press CTRL-C to disconnect"
+print("Press CTRL-C to disconnect")
 
 try:
 	time.sleep(1000)
-	print "Terminating connection"
+	print("Terminating connection")
 except:
 	pass
 
diff --git a/test/test-oob b/test/test-oob
index 3340c00..bec9de5 100755
--- a/test/test-oob
+++ b/test/test-oob
@@ -1,15 +1,17 @@
 #!/usr/bin/python
 
+from __future__ import absolute_import, print_function, unicode_literals
+
 import gobject
 
 import dbus.mainloop.glib
 
 def create_device_reply(device):
-	print "Pairing succeed!"
+	print("Pairing succeed!")
 	mainloop.quit()
 
 def create_device_error(error):
-	print "Pairing failed."
+	print("Pairing failed.")
 	mainloop.quit()
 
 if __name__ == '__main__':
@@ -31,12 +33,12 @@ if __name__ == '__main__':
 
 	adapter0_address = adapter0.GetProperties()["Address"]
 	adapter1_address = adapter1.GetProperties()["Address"]
-	print "Adapters:"
-	print "    hci0: " + adapter0_address
-	print "    hci1: " + adapter1_address
-	print
+	print("Adapters:")
+	print("    hci0: " + adapter0_address)
+	print("    hci1: " + adapter1_address)
+	print()
 
-	print "Removing any existing bond..."
+	print("Removing any existing bond...")
 
 	try:
 		device = adapter0.FindDevice(adapter1_address)
@@ -50,9 +52,9 @@ if __name__ == '__main__':
 	except:
 		pass
 
-	print "Done."
-	print
-	print "Reading local Out of Band data..."
+	print("Done.")
+	print()
+	print("Reading local Out of Band data...")
 
 	oob_adapter0 = dbus.Interface(bus.get_object("org.bluez",
 					adapter0_path), "org.bluez.OutOfBand")
@@ -62,16 +64,16 @@ if __name__ == '__main__':
 	oob0 = oob_adapter0.ReadLocalData()
 	oob1 = oob_adapter1.ReadLocalData()
 
-	print "Done."
-	print
-	print "Exchanging Out of Band data..."
+	print("Done.")
+	print()
+	print("Exchanging Out of Band data...")
 
 	oob_adapter0.AddRemoteData(adapter1_address, oob1[0], oob1[1])
 	oob_adapter1.AddRemoteData(adapter0_address, oob0[0], oob0[1])
 
-	print "Done."
-	print
-	print "Starting to pair."
+	print("Done.")
+	print()
+	print("Starting to pair.")
 	adapter1.CreatePairedDevice(adapter0_address, "/test/agent_oob",
 					"DisplayYesNo",
 					reply_handler=create_device_reply,
diff --git a/test/test-proximity b/test/test-proximity
index 130590c..b08a62a 100755
--- a/test/test-proximity
+++ b/test/test-proximity
@@ -1,5 +1,7 @@
 #!/usr/bin/python
 
+from __future__ import absolute_import, print_function, unicode_literals
+
 '''
 Proximity Monitor test script
 '''
@@ -13,7 +15,7 @@ from optparse import OptionParser, make_option
 
 def property_changed(name, value):
 
-	print "PropertyChanged('%s', '%s')" % (name, value)
+	print("PropertyChanged('%s', '%s')" % (name, value))
 	mainloop.quit()
 
 if __name__ == "__main__":
@@ -44,10 +46,10 @@ if __name__ == "__main__":
 							"org.bluez.Adapter")
 
 	if (len(args) < 1):
-		print "Usage: %s <command>" % (sys.argv[0])
-		print ""
-		print "  -b MAC LinkLossAlertLevel <none|mild|high>"
-		print "  -b MAC ImmediateAlertLevel <none|mild|high>"
+		print("Usage: %s <command>" % (sys.argv[0]))
+		print("")
+		print("  -b MAC LinkLossAlertLevel <none|mild|high>")
+		print("  -b MAC ImmediateAlertLevel <none|mild|high>")
 		sys.exit(1)
 
 	device_path = adapter.FindDevice(options.address)
@@ -59,7 +61,7 @@ if __name__ == "__main__":
 	proximity = dbus.Interface(bus.get_object("org.bluez",
 					device_path), "org.bluez.ProximityMonitor")
 
-	print "Proximity SetProperty('%s', '%s')" % (args[0], args[1])
+	print("Proximity SetProperty('%s', '%s')" % (args[0], args[1]))
 	proximity.SetProperty(args[0], args[1])
 
 	mainloop = gobject.MainLoop()
diff --git a/test/test-sap-server b/test/test-sap-server
index bea6ca9..df838f6 100755
--- a/test/test-sap-server
+++ b/test/test-sap-server
@@ -1,11 +1,13 @@
 #!/usr/bin/python
 
+from __future__ import absolute_import, print_function, unicode_literals
+
 from sap import *
 import time
 
 def connect_disconnect_by_client(sap):
 
-    print "[Test] Connect - Disconnect by client \n"
+    print("[Test] Connect - Disconnect by client \n")
 
     try:
         if not sap.isConnected():
@@ -13,19 +15,19 @@ def connect_disconnect_by_client(sap):
 
         if sap.proc_connect():
             if sap.proc_disconnectByClient():
-                print "OK"
+                print("OK")
                 return 0
 
-        print "NOT OK"
+        print("NOT OK")
         return 1
 
-    except BluetoothError , e:
-        print "Error " + str(e)
+    except BluetoothError as e:
+        print("Error " + str(e))
 
 
 def connect_disconnect_by_server_gracefully(sap, timeout=0):
 
-    print "[Test] Connect - Disconnect by server with timer \n"
+    print("[Test] Connect - Disconnect by server with timer \n")
 
     try:
         if not sap.isConnected():
@@ -33,19 +35,19 @@ def connect_disconnect_by_server_gracefully(sap, timeout=0):
 
         if sap.proc_connect():
             if sap.proc_disconnectByServer(timeout):
-                print "OK"
+                print("OK")
                 return 0
 
-        print "NOT OK"
+        print("NOT OK")
         return 1
 
-    except BluetoothError , e:
-        print "Error " + str(e)
+    except BluetoothError as e:
+        print("Error " + str(e))
 
 
 def connect_txAPDU_disconnect_by_client(sap):
 
-    print "[Test] Connect - TX APDU - Disconnect by client \n"
+    print("[Test] Connect - TX APDU - Disconnect by client \n")
 
     try:
         if not sap.isConnected():
@@ -53,44 +55,44 @@ def connect_txAPDU_disconnect_by_client(sap):
 
         if sap.proc_connect():
             if not sap.proc_transferAPDU():
-                print "NOT OK 1"
+                print("NOT OK 1")
                 return 1
 
             if not sap.proc_transferAPDU():
-                print "NOT OK 2"
+                print("NOT OK 2")
                 return 1
 
             if not sap.proc_transferAPDU():
-                print "NOT OK 3"
+                print("NOT OK 3")
                 return 1
 
             if not sap.proc_transferAPDU():
-                print "NOT OK 4"
+                print("NOT OK 4")
                 return 1
 
             if sap.proc_disconnectByClient():
-                print "OK"
+                print("OK")
                 return 0
 
-        print "NOT OK"
+        print("NOT OK")
         return 1
 
-    except BluetoothError , e:
-        print "Error " + str(e)
+    except BluetoothError as e:
+        print("Error " + str(e))
 
 def connect_rfcomm_only_and_wait_for_close_by_server(sap):
 
-    print "[Test] Connect rfcomm only  - Disconnect by server timeout \n"
+    print("[Test] Connect rfcomm only  - Disconnect by server timeout \n")
 
     if not sap.isConnected():
        sap.connect()
 
     time.sleep(40)
-    print "OK"
+    print("OK")
 
 def power_sim_off_on(sap):
 
-    print "[Test] Powe sim off \n"
+    print("[Test] Powe sim off \n")
 
     try:
         if not sap.isConnected():
@@ -98,26 +100,26 @@ def power_sim_off_on(sap):
 
         if sap.proc_connect():
             if not sap.proc_resetSim():
-                print "NOT OK"
+                print("NOT OK")
                 return 1
 
             if not sap.proc_powerSimOff():
-                print "NOT OK"
+                print("NOT OK")
                 return 1
 
             if not sap.proc_powerSimOn():
-                print "NOT OK"
+                print("NOT OK")
                 return 1
 
             if sap.proc_disconnectByClient():
-                print "OK"
+                print("OK")
                 return 0
 
-        print "NOT OK"
+        print("NOT OK")
         return 1
 
-    except BluetoothError , e:
-        print "Error " + str(e)
+    except BluetoothError as e:
+        print("Error " + str(e))
 
 
 if __name__ == "__main__":
@@ -127,8 +129,8 @@ if __name__ == "__main__":
 
     try:
         s = SAPClient(host, port)
-    except BluetoothError , e:
-        print "Error " + str(e)
+    except BluetoothError as e:
+        print("Error " + str(e))
 
     connect_disconnect_by_client(s)
     connect_disconnect_by_server_gracefully(s)
diff --git a/test/test-serial b/test/test-serial
index cc496df..8858dbd 100755
--- a/test/test-serial
+++ b/test/test-serial
@@ -1,5 +1,7 @@
 #!/usr/bin/python
 
+from __future__ import absolute_import, print_function, unicode_literals
+
 import sys
 import time
 import dbus
@@ -26,7 +28,7 @@ adapter = dbus.Interface(bus.get_object("org.bluez", adapter_path),
 							"org.bluez.Adapter")
 
 if (len(args) < 1):
-	print "Usage: %s <address> [service]" % (sys.argv[0])
+	print("Usage: %s <address> [service]" % (sys.argv[0]))
 	sys.exit(1)
 
 address = args[0]
@@ -43,13 +45,13 @@ serial = dbus.Interface(bus.get_object("org.bluez", path),
 
 node = serial.Connect(service)
 
-print "Connected %s to %s" % (node, address)
+print("Connected %s to %s" % (node, address))
 
-print "Press CTRL-C to disconnect"
+print("Press CTRL-C to disconnect")
 
 try:
 	time.sleep(1000)
-	print "Terminating connection"
+	print("Terminating connection")
 except:
 	pass
 
diff --git a/test/test-serial-proxy b/test/test-serial-proxy
index f6dbd6c..7963f23 100755
--- a/test/test-serial-proxy
+++ b/test/test-serial-proxy
@@ -1,5 +1,7 @@
 #!/usr/bin/python
 
+from __future__ import absolute_import, print_function, unicode_literals
+
 import sys
 import time
 import dbus
@@ -27,7 +29,7 @@ adapter = dbus.Interface(bus.get_object("org.bluez", adapter_path),
 							"org.bluez.Adapter")
 
 if (len(args) < 1):
-	print "Usage: %s <socket_name> [service]" % (sys.argv[0])
+	print("Usage: %s <socket_name> [service]" % (sys.argv[0]))
 	sys.exit(1)
 
 socket_name = args[0]
@@ -51,7 +53,7 @@ proxy.Enable()
 
 conn, addr = sk.accept()
 
-print "Waiting for message"
+print("Waiting for message")
 
 while 1:
 	data = conn.recv(1024)
diff --git a/test/test-service b/test/test-service
index 8958201..8eea9e2 100755
--- a/test/test-service
+++ b/test/test-service
@@ -1,5 +1,7 @@
 #!/usr/bin/python
 
+from __future__ import absolute_import, print_function, unicode_literals
+
 import sys
 import dbus
 import time
@@ -26,22 +28,22 @@ service = dbus.Interface(bus.get_object("org.bluez", adapter_path),
 						"org.bluez.Service")
 
 if (len(args) < 1):
-	print "Usage: %s <command>" % (sys.argv[0])
-	print ""
-	print "  addrecord <file>"
+	print("Usage: %s <command>" % (sys.argv[0]))
+	print("")
+	print("  addrecord <file>")
 	sys.exit(1)
 
 if (args[0] == "addrecord"):
 	if (len(args) < 2):
-		print "Need file parameter"
+		print("Need file parameter")
 	else:
 		f = open(args[1])
 		record = f.read()
 		f.close()
 		handle = service.AddRecord(record)
-		print "0x%x" % (handle)
+		print("0x%x" % (handle))
 		time.sleep(120)
 	sys.exit(0)
 
-print "Unknown command"
+print("Unknown command")
 sys.exit(1)
diff --git a/test/test-telephony b/test/test-telephony
index 5ef0ac8..bd7d3b2 100755
--- a/test/test-telephony
+++ b/test/test-telephony
@@ -1,5 +1,7 @@
 #!/usr/bin/python
 
+from __future__ import absolute_import, print_function, unicode_literals
+
 import sys
 import dbus
 from optparse import OptionParser, make_option
@@ -28,7 +30,7 @@ test = dbus.Interface(bus.get_object("org.bluez", "/org/bluez/test"),
 			"org.bluez.TelephonyTest")
 
 if len(args) < 1:
-	print """Usage: %s <command>
+	print("""Usage: %s <command>
 
 	connect <bdaddr>
 	disconnect <bdaddr>
@@ -44,12 +46,12 @@ if len(args) < 1:
 	microphonegain <bdaddr> [level]
 	play <bdaddr>
 	stop <bdaddr>
-	""" % sys.argv[0]
+	""" % sys.argv[0])
 	sys.exit(1)
 
 if args[0] == "connect":
 	if len(args) < 2:
-		print "Need device address parameter"
+		print("Need device address parameter")
 		sys.exit(1)
 	device = adapter.FindDevice(args[1])
 	headset = dbus.Interface(bus.get_object("org.bluez", device),
@@ -59,7 +61,7 @@ if args[0] == "connect":
 
 if args[0] == "disconnect":
 	if len(args) < 2:
-		print "Need device address parameter"
+		print("Need device address parameter")
 		sys.exit(1)
 	device = adapter.FindDevice(args[1])
 	headset = dbus.Interface(bus.get_object("org.bluez", device),
@@ -69,7 +71,7 @@ if args[0] == "disconnect":
 
 if args[0] == "speakergain":
 	if len(args) < 2:
-		print "Need device address parameter"
+		print("Need device address parameter")
 		sys.exit(1)
 	device = adapter.FindDevice(args[1])
 	headset = dbus.Interface(bus.get_object("org.bluez", device),
@@ -78,13 +80,13 @@ if args[0] == "speakergain":
 		headset.SetProperty('SpeakerGain', dbus.UInt16(args[2]))
 	else:
 		props = headset.GetProperties()
-		print props['SpeakerGain']
+		print(props['SpeakerGain'])
 
 	sys.exit(0)
 
 if args[0] == "microphonegain":
 	if len(args) < 2:
-		print "Need device address parameter"
+		print("Need device address parameter")
 		sys.exit(1)
 	device = adapter.FindDevice(args[1])
 	headset = dbus.Interface(bus.get_object("org.bluez", device),
@@ -93,13 +95,13 @@ if args[0] == "microphonegain":
 		headset.SetProperty('MicrophoneGain', dbus.UInt16(args[2]))
 	else:
 		props = headset.GetProperties()
-		print props['MicrophoneGain']
+		print(props['MicrophoneGain'])
 
 	sys.exit(0)
 
 if args[0] == "play":
 	if len(args) < 2:
-		print "Need device address parameter"
+		print("Need device address parameter")
 		sys.exit(1)
 	device = adapter.FindDevice(args[1])
 	headset = dbus.Interface(bus.get_object("org.bluez", device),
@@ -110,7 +112,7 @@ if args[0] == "play":
 
 if args[0] == "stop":
 	if len(args) < 2:
-		print "Need device address parameter"
+		print("Need device address parameter")
 		sys.exit(1)
 	device = adapter.FindDevice(args[1])
 	headset = dbus.Interface(bus.get_object("org.bluez", device),
@@ -123,14 +125,14 @@ if args[0] == "outgoing":
 	if len(args) > 1:
 		test.OutgoingCall(args[1])
 	else:
-		print "Need number parameter"
+		print("Need number parameter")
 	sys.exit(0)
 
 if args[0] == "incoming":
 	if len(args) > 1:
 		test.IncomingCall(args[1])
 	else:
-		print "Need number parameter"
+		print("Need number parameter")
 	sys.exit(0)
 
 if args[0] == "cancel":
@@ -141,36 +143,36 @@ if args[0] == "signal":
 	if len(args) > 1:
 		test.SignalStrength(args[1])
 	else:
-		print "Need signal strength parameter"
+		print("Need signal strength parameter")
 	sys.exit(0)
 
 if args[0] == "battery":
 	if len(args) > 1:
 		test.BatteryLevel(args[1])
 	else:
-		print "Need battery level parameter"
+		print("Need battery level parameter")
 	sys.exit(0)
 
 if args[0] == "roaming":
 	if len(args) > 1:
 		test.RoamingStatus(args[1] == "yes" or False)
 	else:
-		print "Need yes/no parameter"
+		print("Need yes/no parameter")
 	sys.exit(0)
 
 if args[0] == "registration":
 	if len(args) > 1:
 		test.RegistrationStatus(args[1] == "yes" or False)
 	else:
-		print "Need yes/no parameter"
+		print("Need yes/no parameter")
 	sys.exit(0)
 
 if args[0] == "subscriber":
 	if len(args) > 1:
 		test.SetSubscriberNumber(args[1])
 	else:
-		print "Need number parameter"
+		print("Need number parameter")
 	sys.exit(0)
 
-print "Unknown command"
+print("Unknown command")
 sys.exit(1)
diff --git a/test/test-thermometer b/test/test-thermometer
index bf3b83e..9216264 100755
--- a/test/test-thermometer
+++ b/test/test-thermometer
@@ -1,5 +1,7 @@
 #!/usr/bin/python
 
+from __future__ import absolute_import, print_function, unicode_literals
+
 '''
 Thermometer test script
 '''
@@ -16,20 +18,20 @@ class Watcher(dbus.service.Object):
 	@dbus.service.method("org.bluez.ThermometerWatcher",
 					in_signature="a{sv}", out_signature="")
 	def MeasurementReceived(self, measure):
-		print measure["Measurement"], " measurement received"
-		print "Exponent: ", measure["Exponent"]
-		print "Mantissa: ", measure["Mantissa"]
-		print "Unit: ", measure["Unit"]
+		print(measure["Measurement"], " measurement received")
+		print("Exponent: ", measure["Exponent"])
+		print("Mantissa: ", measure["Mantissa"])
+		print("Unit: ", measure["Unit"])
 
-		if measure.has_key("Time"):
-			print "Time: ", measure["Time"]
+		if "Time" in measure:
+			print("Time: ", measure["Time"])
 
-		if measure.has_key("Type"):
-			print "Type: ", measure["Type"]
+		if "Type" in measure:
+			print("Type: ", measure["Type"])
 
 def property_changed(name, value):
 
-	print "PropertyChanged('%s', '%s')" % (name, value)
+	print("PropertyChanged('%s', '%s')" % (name, value))
 
 if __name__ == "__main__":
 	dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
@@ -51,9 +53,9 @@ if __name__ == "__main__":
 	(options, args) = parser.parse_args()
 
 	if not options.address:
-		print "Usage: %s [-i <adapter>] -b <bdaddr> [command]" % (sys.argv[0])
-		print "Possible commands:"
-		print "\tEnableIntermediateMeasurement"
+		print("Usage: %s [-i <adapter>] -b <bdaddr> [command]" % (sys.argv[0]))
+		print("Possible commands:")
+		print("\tEnableIntermediateMeasurement")
 		sys.exit(1)
 
 	if options.adapter:
@@ -82,7 +84,7 @@ if __name__ == "__main__":
 		if args[0] == "EnableIntermediateMeasurement":
 			thermometer.EnableIntermediateMeasurement(path)
 		else:
-			print "unknown command"
+			print("unknown command")
 			sys.exit(1)
 
 	mainloop = gobject.MainLoop()
-- 
1.7.9.5

-- 
Steve Langasek                   Give me a lever long enough and a Free OS
Debian Developer                   to set it on, and I can move the world.
Ubuntu Developer                                    http://www.debian.org/
slangasek@xxxxxxxxxx                                     vorlon@xxxxxxxxxx

Attachment: signature.asc
Description: Digital signature


[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux