Skip to contentSkip to conversation

Update tests to be compatible with gi and python3

PATCH In review Steve Langasek 3 participants 4 messages May 25, 2012 – Jun 15, 2012 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

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

From: Steve Langasek <[email protected]>

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.

---
 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(-)
test/list-devices +16 -14
index cb564be..e2a5833 100755
@@ -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
test/monitor-bluetooth +4 -2
index a5e5300..4a598e1 100755
@@ -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)
test/simple-agent +22 -19

109 lines not on this page · raw message

test/simple-endpoint +7 -5
index e09a528..20c8159 100755
@@ -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)
 
test/simple-service +5 -3
index d03ec3d..ed27d0c 100755
@@ -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
 
test/test-adapter +27 -25

115 lines not on this page · raw message

test/test-attrib +27 -25

104 lines not on this page · raw message

test/test-audio +5 -3
index 8b7a62d..1ba2042 100755
@@ -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)
test/test-device +40 -38

202 lines not on this page · raw message

test/test-discovery +9 -7
index 20312f7..880d231 100755
@@ -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()
test/test-health +32 -30

197 lines not on this page · raw message

test/test-health-sink +13 -11
index cb9d434..ce7337a 100755
@@ -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)
test/test-input +5 -3
index 405bb59..110cbef 100755
@@ -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)
test/test-manager +7 -5
index c6cf560..8a7e2f6 100755
@@ -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()
test/test-nap +5 -3
index c83d928..dc779ad 100755
@@ -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
 
test/test-network +6 -4
index 676fb30..2ade584 100755
@@ -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
 
test/test-oob +18 -16
index 3340c00..bec9de5 100755
@@ -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,
test/test-proximity +8 -6
index 130590c..b08a62a 100755
@@ -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()
test/test-sap-server +33 -31

160 lines not on this page · raw message

test/test-serial +6 -4
index cc496df..8858dbd 100755
@@ -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
 
test/test-serial-proxy +4 -2
index f6dbd6c..7963f23 100755
@@ -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)
test/test-service +8 -6
index 8958201..8eea9e2 100755
@@ -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)
test/test-telephony +20 -18
index 5ef0ac8..bd7d3b2 100755
@@ -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)
test/test-thermometer +15 -13
index bf3b83e..9216264 100755
@@ -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()
Signature · 7 lines
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/
[email protected]                                     [email protected]
#1 lore raw

Hi Steve,

Quoted 9 lines · Steve Langasek

From: Steve Langasek <[email protected]>

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.

We don't use signed-off-by for user space patches so please leave it out from the commit message.

Quoted 18 lines
---
 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 +++++++++++----------
Quoted 8 lines
 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(-)

In general the patch looks ok, but unfortunately it doesn't apply cleanly:

Applying: Update tests to be compatible with gi and python3 /home/jh/src/bluez/.git/rebase-apply/patch:838: trailing whitespace.

/home/jh/src/bluez/.git/rebase-apply/patch:840: trailing whitespace.

fatal: 2 lines add whitespace errors.
Patch failed at 0001 Update tests to be compatible with gi and python3

Please fix this and resend. For the future you might want to add the following to your gitconfig:

[apply]
whitespace = error

Johan

#2 lore raw

Hi Steve,

Quoted 49 lines · Steve Langasek
Quoted 9 lines

From: Steve Langasek <[email protected]>

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.

We don't use signed-off-by for user space patches so please leave it out from the commit message.

Quoted 18 lines
---
 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 +++++++++++----------
Quoted 8 lines
 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(-)

In general the patch looks ok, but unfortunately it doesn't apply cleanly:

Applying: Update tests to be compatible with gi and python3 /home/jh/src/bluez/.git/rebase-apply/patch:838: trailing whitespace.

/home/jh/src/bluez/.git/rebase-apply/patch:840: trailing whitespace.

Quoted 8 lines

fatal: 2 lines add whitespace errors.
Patch failed at 0001 Update tests to be compatible with gi and python3

Please fix this and resend. For the future you might want to add the following to your gitconfig:

[apply]
whitespace = error

Since I haven't heard anything from you I went a head and fixed these issues for you and applied the patch.

Johan

#3 lore raw
Quoted 15 lines · Johan Hedberg

Hi Steve,

Quoted 13 lines · Steve Langasek
Quoted 9 lines

From: Steve Langasek <[email protected]>

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.

We don't use signed-off-by for user space patches so please leave it out from the commit message.

Woww... very nice.

Now I can stop having to manually call python2 binary in Archlinux (since they decided python3 to be the default interpreter for python) :-)

Lucas De Marchi