test: Make exceptions compatible with Python 3
authorMartin Pitt <martin.pitt@ubuntu.com>
Tue, 11 Mar 2014 16:39:19 +0000 (17:39 +0100)
committerDenis Kenzior <denkenz@gmail.com>
Wed, 12 Mar 2014 00:32:46 +0000 (19:32 -0500)
Use "except Type as var" syntax to work with both Python >= 2.6
and Python 3.

17 files changed:
test/activate-context
test/deactivate-context
test/disable-call-forwarding
test/set-call-forwarding
test/set-context-property
test/test-advice-of-charge
test/test-call-barring
test/test-call-forwarding
test/test-call-settings
test/test-cbs
test/test-gnss
test/test-network-registration
test/test-sms
test/test-ss
test/test-ss-control-cb
test/test-ss-control-cs
test/test-stk-menu

index 1c4a105..937b7db 100755 (executable)
@@ -35,6 +35,6 @@ for path, properties in modems:
 
        try:
                context.SetProperty("Active", dbus.Boolean(1), timeout = 100)
-       except dbus.DBusException, e:
+       except dbus.DBusException as e:
                print("Error activating %s: %s" % (path, str(e)))
                exit(2)
index 9544c19..848bcbd 100755 (executable)
@@ -33,6 +33,6 @@ for path, properties in modems:
 
        try:
                context.SetProperty("Active", dbus.Boolean(0))
-       except dbus.DBusException, e:
+       except dbus.DBusException as e:
                print("Error activating %s: %s" % (path, str(e)))
                exit(2)
index a88821d..1e6ec20 100755 (executable)
@@ -41,7 +41,7 @@ if __name__ == "__main__":
 
        try:
                cf.DisableAll(type, timeout = 100)
-       except dbus.DBusException, e:
+       except dbus.DBusException as e:
                print("Unable to DisableAll %s" % e)
                sys.exit(1);
 
index a22a673..8f0722e 100755 (executable)
@@ -46,13 +46,13 @@ if __name__ == "__main__":
                try:
                        cf.SetProperty(property, dbus.UInt16(value),
                                                        timeout = 100)
-               except dbus.DBusException, e:
+               except dbus.DBusException as e:
                        print("Unable SetProperty %s" % e)
                        sys.exit(1);
        else:
                try:
                        cf.SetProperty(property, value, timeout = 100)
-               except dbus.DBusException, e:
+               except dbus.DBusException as e:
                        print("Unable SetProperty %s" % e)
                        sys.exit(1);
 
index c18e55a..64a6fb8 100755 (executable)
@@ -33,7 +33,7 @@ for path, properties in modems:
 
        try:
                context.SetProperty(sys.argv[2], sys.argv[3])
-       except dbus.DBusException, e:
+       except dbus.DBusException as e:
                print("Error setting context %s property %s: %s" %\
                                (path, sys.argv[2], str(e)))
                exit(2)
index bb52f5b..6fa3a7c 100755 (executable)
@@ -67,7 +67,7 @@ if __name__ == "__main__":
                print("Resetting Accumulated Call Meter")
                try:
                        cm.Reset(pin)
-               except dbus.DBusException, e:
+               except dbus.DBusException as e:
                        print("Unable to reset ACM: %s" % e)
                        sys.exit(1)
        else:
@@ -77,7 +77,7 @@ if __name__ == "__main__":
                        elif property == 'PricePerUnit':
                                newvalue = float(newvalue)
                        cm.SetProperty(property, newvalue, pin)
-               except dbus.DBusException, e:
+               except dbus.DBusException as e:
                        print("Unable to set property: %s" % e)
                        sys.exit(1)
 
index 51b3778..bc11de0 100755 (executable)
@@ -60,13 +60,13 @@ if __name__ == "__main__":
                print("Disabling all barrings")
                try:
                        cb.DisableAll(pin)
-               except dbus.DBusException, e:
+               except dbus.DBusException as e:
                        print("Unable to Disable All barrings: ", e)
                        sys.exit(1)
        elif (sys.argv[1] == 'passwd'):
                try:
                        cb.ChangePassword(old_password, new_password)
-               except dbus.DBusException, e:
+               except dbus.DBusException as e:
                        print("Unable to change password: ", e)
                        sys.exit(1)
                print("Password changed")
@@ -74,7 +74,7 @@ if __name__ == "__main__":
        else:
                try:
                        cb.SetProperty(property, newvalue, pin)
-               except dbus.DBusException, e:
+               except dbus.DBusException as e:
                        print("Unable to set property: ", e)
                        sys.exit(1)
 
index 772948b..a7ec1e4 100755 (executable)
@@ -36,47 +36,47 @@ if __name__ == "__main__":
 
        try:
                cf.SetProperty("FoobarNoReplyTimeout", dbus.UInt16(19))
-       except dbus.DBusException, e:
+       except dbus.DBusException as e:
                print("Unable to set timeout - Good")
 
        try:
                cf.SetProperty("VoiceNotReachableTimeout", dbus.UInt16(19))
-       except dbus.DBusException, e:
+       except dbus.DBusException as e:
                print("Unable to set timeout - Good")
 
        try:
                cf.SetProperty("VoiceNoReplyTimeout", dbus.UInt16(19))
-       except dbus.DBusException, e:
+       except dbus.DBusException as e:
                print("Unable to set timeout - Good")
 
        try:
                cf.SetProperty("DataNoReplyTimeout", dbus.UInt16(19))
-       except dbus.DBusException, e:
+       except dbus.DBusException as e:
                print("Unable to set timeout - Good")
 
        try:
                cf.SetProperty("FaxNoReplyTimeout", dbus.UInt16(19))
-       except dbus.DBusException, e:
+       except dbus.DBusException as e:
                print("Unable to set timeout - Good")
 
        try:
                cf.SetProperty("SmsNoReplyTimeout", dbus.UInt16(19))
-       except dbus.DBusException, e:
+       except dbus.DBusException as e:
                print("Unable to set timeout - Good")
 
        try:
                cf.SetProperty("VoiceNoReply", "")
-       except dbus.DBusException, e:
+       except dbus.DBusException as e:
                print("Unable to erase voice no reply rule - Bad")
 
        try:
                cf.SetProperty("VoiceNoReply", "+134444")
-       except dbus.DBusException, e:
+       except dbus.DBusException as e:
                print("Unable to register voice no reply rule - Bad")
 
        try:
                cf.SetProperty("VoiceNoReplyTimeout", dbus.UInt16(30))
-       except dbus.DBusException, e:
+       except dbus.DBusException as e:
                print("Unable to set voice no reply timeout - Bad")
 
        properties = cf.GetProperties()
@@ -86,7 +86,7 @@ if __name__ == "__main__":
 
        try:
                cf.SetProperty("VoiceUnconditional", "+155555")
-       except dbus.DBusException, e:
+       except dbus.DBusException as e:
                print("Unable to set Voice Unconditional - Bad")
 
        properties = cf.GetProperties()
@@ -95,12 +95,12 @@ if __name__ == "__main__":
 
        try:
                cf.DisableAll("foobar")
-       except dbus.DBusException, e:
+       except dbus.DBusException as e:
                print("Unable to delete invalids - Good")
 
        try:
                cf.DisableAll("conditional")
-       except dbus.DBusException, e:
+       except dbus.DBusException as e:
                print("Unable to delete all conditional - Bad")
 
        properties = cf.GetProperties()
@@ -110,7 +110,7 @@ if __name__ == "__main__":
 
        try:
                cf.DisableAll("all")
-       except dbus.DBusException, e:
+       except dbus.DBusException as e:
                print("Unable to delete all conditional - Bad")
 
        print(properties["VoiceUnconditional"])
index f30756e..187ce06 100755 (executable)
@@ -67,7 +67,7 @@ if __name__ == "__main__":
 
        try:
                cs.SetProperty(property, newvalue)
-       except dbus.DBusException, e:
+       except dbus.DBusException as e:
                print("Unable to set property: %s" % e)
                sys.exit(1);
 
index 2e7884b..8d8438f 100755 (executable)
@@ -103,7 +103,7 @@ def set_topics(cbs):
                try:
                        print("Setting Cell Broadcast topics...")
                        cbs.SetProperty("Topics", topics);
-               except dbus.DBusException, e:
+               except dbus.DBusException as e:
                        print("Unable to set topic: %s" % e)
 
        print("-----------------------------------------------------------")
index 9824627..62b56f9 100755 (executable)
@@ -44,21 +44,21 @@ def stdin_handler(fd, condition, gnss, path):
                try:
                        gnss.SendPositioningElement(dbus.String(xml))
                        print("ok")
-               except dbus.DBusException, e:
+               except dbus.DBusException as e:
                        print("Unable to send positioning element")
 
        elif in_key == '1':
                try:
                        gnss.RegisterPositioningRequestAgent("/test/posagent")
                        print("ok")
-               except dbus.DBusException, e:
+               except dbus.DBusException as e:
                        print("Unable to register positioning agent")
 
        elif in_key == '2':
                try:
                        gnss.UnregisterPositioningRequestAgent(path)
                        print("ok")
-               except dbus.DBusException, e:
+               except dbus.DBusException as e:
                        print("Unable to unregister positioning agent")
        elif in_key == 'x':
                sys.exit(1)
index f692efa..5d3f75e 100755 (executable)
@@ -61,7 +61,7 @@ if __name__ == "__main__":
                        obj = bus.get_object('org.ofono', plmn);
                        op = dbus.Interface(obj, 'org.ofono.NetworkOperator')
                        op.Register()
-       except dbus.DBusException, e:
+       except dbus.DBusException as e:
                print("Unable to register: %s" % e)
                sys.exit(1)
 
index 5c0bfbb..33d4ccd 100755 (executable)
@@ -48,7 +48,7 @@ def message_delivery_report(sms, value):
        try:
                sms.SetProperty("UseDeliveryReports", dbus.Boolean(value))
 
-       except dbus.DBusException, e:
+       except dbus.DBusException as e:
                if value == 1:
                        print("Unable to activate Delivery Reports - FAIL")
 
@@ -58,13 +58,13 @@ def message_delivery_report(sms, value):
 def message_service_center_address(sms, value):
        try:
                sms.SetProperty("ServiceCenterAddress",dbus.String(value))
-       except dbus.DBusException, e:
+       except dbus.DBusException as e:
                print("Unable to set correct Service Center Address - FAIL")
 
 def message_bearer(sms, value):
        try:
                sms.SetProperty("Bearer", dbus.String(value))
-       except dbus.DBusException, e:
+       except dbus.DBusException as e:
                print("Unable to set Bearer[%s] - FAIL" % (value))
 
 
index 7bd18af..2c80806 100755 (executable)
@@ -22,7 +22,7 @@ ss = dbus.Interface(bus.get_object('org.ofono', modem),
 
 try:
        ss_type, properties = ss.Initiate(ss_code, timeout=100)
-except dbus.DBusException, e:
+except dbus.DBusException as e:
        print("Unable to perform operation: %s" % e)
        sys.exit(1);
 
index 505bcd7..d972097 100755 (executable)
@@ -37,25 +37,25 @@ if __name__ == "__main__":
        print("Trying invalid SS request for CB")
        try:
                print(ss.Initiate("*33#456666"))
-       except dbus.DBusException, e:
+       except dbus.DBusException as e:
                print("Failed with %s - Good" % e)
 
        print("Trying invalid SS request for CB")
        try:
                print(ss.Initiate("*33*ABC#"))
-       except dbus.DBusException, e:
+       except dbus.DBusException as e:
                print("Failed with %s - Good" % e)
 
        print("Trying invalid SS request for CB")
        try:
                print(ss.Initiate("*33**ABC#"))
-       except dbus.DBusException, e:
+       except dbus.DBusException as e:
                print("Failed with %s - Good" % e)
 
        print("Trying invalid SS request for CB")
        try:
                print(ss.Initiate("*33***12#"))
-       except dbus.DBusException, e:
+       except dbus.DBusException as e:
                print("Failed with %s - Good" % e)
 
        print("Query Outgoing All")
index 6ce022f..2d5442f 100755 (executable)
@@ -37,19 +37,19 @@ if __name__ == "__main__":
        print("Trying invalid SS request for CLIR")
        try:
                print(ss.Initiate("*31#456666"))
-       except dbus.DBusException, e:
+       except dbus.DBusException as e:
                print("Failed with %s - Good" % e)
 
        print("Trying invalid SS request for CLIR")
        try:
                print(ss.Initiate("*31*455*4#"))
-       except dbus.DBusException, e:
+       except dbus.DBusException as e:
                print("Failed with %s - Good" % e)
 
        print("Trying invalid SS request for CLIR")
        try:
                print(ss.Initiate("*31**44435#"))
-       except dbus.DBusException, e:
+       except dbus.DBusException as e:
                print("Failed with %s - Good" % e)
 
        print("Query CLIP")
@@ -77,19 +77,19 @@ if __name__ == "__main__":
        print("Trying invalid SS request for CW")
        try:
                print(ss.Initiate("*43#456666"))
-       except dbus.DBusException, e:
+       except dbus.DBusException as e:
                print("Failed with %s - Good" % e)
 
        print("Trying invalid SS request for CW")
        try:
                print(ss.Initiate("*43*455*4#"))
-       except dbus.DBusException, e:
+       except dbus.DBusException as e:
                print("Failed with %s - Good" % e)
 
        print("Trying invalid SS request for CW")
        try:
                print(ss.Initiate("*43**44435#"))
-       except dbus.DBusException, e:
+       except dbus.DBusException as e:
                print("Failed with %s - Good" % e)
 
        print("Query CW")
index eaba994..7952abd 100755 (executable)
@@ -238,7 +238,7 @@ class StkAgent(dbus.service.Object):
                        if key == 't':
                                raise EndSession("User wishes to terminate"
                                                                 " session")
-               except Exception, exc:
+               except Exception as exc:
                        print(exc)
 
        @dbus.service.method("org.ofono.SimToolkitAgent",