diff options
Diffstat (limited to 'Examples/test-suite/python/primitive_types_runme.py')
-rw-r--r-- | Examples/test-suite/python/primitive_types_runme.py | 102 |
1 files changed, 47 insertions, 55 deletions
diff --git a/Examples/test-suite/python/primitive_types_runme.py b/Examples/test-suite/python/primitive_types_runme.py index 04588ddf2..f550fc2ab 100644 --- a/Examples/test-suite/python/primitive_types_runme.py +++ b/Examples/test-suite/python/primitive_types_runme.py @@ -31,8 +31,7 @@ v_check() def pyerror(name, val, cte): - print "bad val/cte", name, val, cte - raise RuntimeError + raise RuntimeError("bad val/cte {} {} {}".format(name, val, cte)) pass if cvar.var_bool != cct_bool: @@ -173,7 +172,7 @@ p = PyTest() # internal call check if t.c_check() != p.c_check(): - raise RuntimeError, "bad director" + raise RuntimeError("bad director") p.var_bool = p.stc_bool p.var_schar = p.stc_schar @@ -228,63 +227,57 @@ t.v_check() # this value contains a '0' char! if def_namet != "hola": - print "bad namet", def_namet - raise RuntimeError + raise RuntimeError("bad namet {}".format(def_namet)) t.var_namet = def_namet if t.var_namet != def_namet: - print "bad namet", t.var_namet, def_namet - raise RuntimeError + raise RuntimeError("bad namet {} {}".format(t.var_namet, def_namet)) t.var_namet = "hola" if t.var_namet != "hola": - print "bad namet", t.var_namet - raise RuntimeError + raise RuntimeError("bad namet {}".format(t.var_namet)) t.var_namet = "hol" if t.var_namet != "hol": # if t.var_namet != "hol\0\0": - print "bad namet", t.var_namet - raise RuntimeError + raise RuntimeError("bad namet {}".format(t.var_namet)) cvar.var_char = "\0" if cvar.var_char != "\0": - raise RuntimeError, "bad char '0' case" + raise RuntimeError("bad char '0' case") cvar.var_char = 0 if cvar.var_char != "\0": - raise RuntimeError, "bad char '0' case" + raise RuntimeError("bad char '0' case") cvar.var_namet = "\0" # if cvar.var_namet != "\0\0\0\0\0": if cvar.var_namet != "": - print "hola", "", cvar.var_namet - raise RuntimeError, "bad char '\0' case" + raise RuntimeError("bad char '\0' case hola {}".format(cvar.var_namet)) cvar.var_namet = "" # if cvar.var_namet != "\0\0\0\0\0": if cvar.var_namet != "": - raise RuntimeError, "bad char empty case" + raise RuntimeError("bad char empty case") cvar.var_pchar = None if cvar.var_pchar != None: - raise RuntimeError, "bad None case" + raise RuntimeError("bad None case") cvar.var_pchar = "" if cvar.var_pchar != "": - print "%c" % (cvar.var_pchar[0],) - raise RuntimeError, "bad char empty case" + raise RuntimeError("bad char empty case %c" % (cvar.var_pchar[0],)) cvar.var_pcharc = None if cvar.var_pcharc != None: - raise RuntimeError, "bad None case" + raise RuntimeError("bad None case") cvar.var_pcharc = "" if cvar.var_pcharc != "": - raise RuntimeError, "bad char empty case" + raise RuntimeError("bad char empty case") # @@ -300,13 +293,12 @@ pchar_setitem(pc, 4, 0) cvar.var_pchar = pc if cvar.var_pchar != "hola": - print cvar.var_pchar - raise RuntimeError, "bad pointer case" + raise RuntimeError("bad pointer case {}".format(cvar.var_pchar)) cvar.var_namet = pc # if cvar.var_namet != "hola\0": if cvar.var_namet != "hola": - raise RuntimeError, "bad pointer case" + raise RuntimeError("bad pointer case") delete_pchar(pc) @@ -325,7 +317,7 @@ except OverflowError: error = 1 pass if error: - raise RuntimeError, "bad uchar typemap" + raise RuntimeError("bad uchar typemap") try: @@ -338,7 +330,7 @@ except TypeError: error = 1 pass if error: - raise RuntimeError, "bad char typemap" + raise RuntimeError("bad char typemap") try: error = 0 @@ -350,7 +342,7 @@ except OverflowError: error = 1 pass if error: - raise RuntimeError, "bad ushort typemap" + raise RuntimeError("bad ushort typemap") try: error = 0 @@ -362,7 +354,7 @@ except OverflowError: error = 1 pass if error: - raise RuntimeError, "bad uint typemap" + raise RuntimeError("bad uint typemap") try: error = 0 @@ -374,7 +366,7 @@ except OverflowError: error = 1 pass if error: - raise RuntimeError, "bad sizet typemap" + raise RuntimeError("bad sizet typemap") try: error = 0 @@ -386,7 +378,7 @@ except OverflowError: error = 1 pass if error: - raise RuntimeError, "bad ulong typemap" + raise RuntimeError("bad ulong typemap") # # @@ -400,43 +392,43 @@ except TypeError: error = 1 pass if error: - raise RuntimeError, "bad namet typemap" + raise RuntimeError("bad namet typemap") # # # t2 = p.vtest(t) if t.var_namet != t2.var_namet: - raise RuntimeError, "bad SWIGTYPE* typemap" + raise RuntimeError("bad SWIGTYPE* typemap") if cvar.fixsize != "ho\0la\0\0\0": - raise RuntimeError, "bad FIXSIZE typemap" + raise RuntimeError("bad FIXSIZE typemap") cvar.fixsize = "ho" if cvar.fixsize != "ho\0\0\0\0\0\0": - raise RuntimeError, "bad FIXSIZE typemap" + raise RuntimeError("bad FIXSIZE typemap") f = Foo(3) f1 = fptr_val(f) f2 = fptr_ref(f) if f1._a != f2._a: - raise RuntimeError, "bad const ptr& typemap" + raise RuntimeError("bad const ptr& typemap") v = char_foo(1, 3) if v != 3: - raise RuntimeError, "bad int typemap" + raise RuntimeError("bad int typemap") s = char_foo(1, "hello") if s != "hello": - raise RuntimeError, "bad char* typemap" + raise RuntimeError("bad char* typemap") v = SetPos(1, 3) if v != 4: - raise RuntimeError, "bad int typemap" + raise RuntimeError("bad int typemap") # # Check the bounds for converting various types @@ -480,8 +472,8 @@ maxllong = overllong - 1 maxullong = 2 * maxllong + 1 # Make sure Python 2's sys.maxint is the same as the maxlong we calculated -if sys.version_info[0] <= 2 and maxlong != sys.maxint: - raise RuntimeError, "sys.maxint is not the maximum value of a signed long" +if sys.version_info[0] <= 2 and maxlong != sys.maxsize: + raise RuntimeError("sys.maxint is not the maximum value of a signed long") def checkType(t, e, val, delta): """t = Test object, e = type name (e.g. ulong), val = max or min allowed value, delta = +1 for max, -1 for min""" @@ -511,7 +503,7 @@ def checkType(t, e, val, delta): except OverflowError: pass if error: - raise RuntimeError, "bad " + e + " typemap" + raise RuntimeError("bad " + e + " typemap") def checkFull(t, e, maxval, minval): """Check the maximum and minimum bounds for the type given by e""" @@ -543,17 +535,17 @@ def checkOverload(t, name, val, delta, prevval, limit): if val != prevval: # Make sure the most extreme value of this type gives the name of this type if t.ovr_str(val) != name: - raise RuntimeError, "bad " + name + " typemap" + raise RuntimeError("bad " + name + " typemap") # Make sure a more extreme value doesn't give the name of this type try: if t.ovr_str(val + delta) == name: - raise RuntimeError, "bad " + name + " typemap" + raise RuntimeError("bad " + name + " typemap") if val == limit: # Should raise TypeError here since this is the largest integral type - raise RuntimeError, "bad " + name + " typemap" + raise RuntimeError("bad " + name + " typemap") except TypeError: if val != limit: - raise RuntimeError, "bad " + name + " typemap" + raise RuntimeError("bad " + name + " typemap") # Check that overloading works: uchar > schar > ushort > short > uint > int > ulong > long > ullong > llong checkOverload(t, "uchar", maxuchar, +1, 0, maxullong) @@ -568,22 +560,22 @@ checkOverload(t, "long", minlong, -1, minint, minllong) checkOverload(t, "llong", minllong, -1, minlong, minllong) # Make sure that large ints can be converted to doubles properly -if val_double(sys.maxint + 1) != float(sys.maxint + 1): - raise RuntimeError, "bad double typemap" -if val_double(-sys.maxint - 2) != float(-sys.maxint - 2): - raise RuntimeError, "bad double typemap" +if val_double(sys.maxsize + 1) != float(sys.maxsize + 1): + raise RuntimeError("bad double typemap") +if val_double(-sys.maxsize - 2) != float(-sys.maxsize - 2): + raise RuntimeError("bad double typemap") # Check the minimum and maximum values that fit in ptrdiff_t and size_t def checkType(name, maxfunc, maxval, minfunc, minval, echofunc): if maxfunc() != maxval: - raise RuntimeError, "bad " + name + " typemap" + raise RuntimeError("bad " + name + " typemap") if minfunc() != minval: - raise RuntimeError, "bad " + name + " typemap" + raise RuntimeError("bad " + name + " typemap") if echofunc(maxval) != maxval: - raise RuntimeError, "bad " + name + " typemap" + raise RuntimeError("bad " + name + " typemap") if echofunc(minval) != minval: - raise RuntimeError, "bad " + name + " typemap" + raise RuntimeError("bad " + name + " typemap") error = 0 try: echofunc(maxval + 1) @@ -591,14 +583,14 @@ def checkType(name, maxfunc, maxval, minfunc, minval, echofunc): except OverflowError: pass if error == 1: - raise RuntimeError, "bad " + name + " typemap" + raise RuntimeError("bad " + name + " typemap") try: echofunc(minval - 1) error = 1 except OverflowError: pass if error == 1: - raise RuntimeError, "bad " + name + " typemap" + raise RuntimeError("bad " + name + " typemap") # sys.maxsize is the largest value supported by Py_ssize_t, which should be the same as ptrdiff_t if sys.version_info[0:2] >= (2, 6): |