Remove print statements from Python tests
Use exceptions instead of printing to stdout. Part of an effort to convert Python tests to python 3 syntax.
This commit is contained in:
parent
e535190c34
commit
365d4961d4
40 changed files with 123 additions and 254 deletions
|
|
@ -6,7 +6,6 @@ if mainc(largs) != 3:
|
|||
|
||||
targs = ("hi", "hola")
|
||||
if mainv(targs, 1) != "hola":
|
||||
print(mainv(targs, 1))
|
||||
raise RuntimeError("bad main typemap")
|
||||
|
||||
targs = ("hi", "hola")
|
||||
|
|
|
|||
|
|
@ -2,11 +2,9 @@ from char_binary import *
|
|||
|
||||
t = Test()
|
||||
if t.strlen("hile") != 4:
|
||||
print t.strlen("hile")
|
||||
raise RuntimeError, "bad multi-arg typemap"
|
||||
raise RuntimeError("bad multi-arg typemap {}".format(t.strlen("hile")))
|
||||
if t.ustrlen("hile") != 4:
|
||||
print t.ustrlen("hile")
|
||||
raise RuntimeError, "bad multi-arg typemap"
|
||||
raise RuntimeError("bad multi-arg typemap {}".format(t.ustrlen("hile")))
|
||||
|
||||
if t.strlen("hil\0") != 4:
|
||||
raise RuntimeError, "bad multi-arg typemap"
|
||||
|
|
@ -31,8 +29,7 @@ if t.ustrlen(pc) != 4:
|
|||
|
||||
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":
|
||||
|
|
|
|||
|
|
@ -4,33 +4,26 @@ error = 0
|
|||
|
||||
p = constover.test("test")
|
||||
if p != "test":
|
||||
print "test failed!"
|
||||
error = 1
|
||||
raise RuntimeError("test failed!")
|
||||
|
||||
p = constover.test_pconst("test")
|
||||
if p != "test_pconst":
|
||||
print "test_pconst failed!"
|
||||
error = 1
|
||||
raise RuntimeError("test_pconst failed!")
|
||||
|
||||
f = constover.Foo()
|
||||
p = f.test("test")
|
||||
if p != "test":
|
||||
print "member-test failed!"
|
||||
error = 1
|
||||
raise RuntimeError("member-test failed!")
|
||||
|
||||
p = f.test_pconst("test")
|
||||
if p != "test_pconst":
|
||||
print "member-test_pconst failed!"
|
||||
error = 1
|
||||
raise RuntimeError("member-test_pconst failed!")
|
||||
|
||||
p = f.test_constm("test")
|
||||
if p != "test_constmethod":
|
||||
print "member-test_constm failed!"
|
||||
error = 1
|
||||
raise RuntimeError("member-test_constm failed!")
|
||||
|
||||
p = f.test_pconstm("test")
|
||||
if p != "test_pconstmethod":
|
||||
print "member-test_pconstm failed!"
|
||||
error = 1
|
||||
raise RuntimeError("member-test_pconstm failed!")
|
||||
|
||||
sys.exit(error)
|
||||
|
|
|
|||
|
|
@ -3,21 +3,17 @@ import cpp_enum
|
|||
f = cpp_enum.Foo()
|
||||
|
||||
if f.hola != f.Hello:
|
||||
print f.hola
|
||||
raise RuntimeError
|
||||
raise RuntimeError("f.hola: {}".format(f.hola))
|
||||
|
||||
f.hola = f.Hi
|
||||
if f.hola != f.Hi:
|
||||
print f.hola
|
||||
raise RuntimeError
|
||||
raise RuntimeError("f.hola: {}".format(f.hola))
|
||||
|
||||
f.hola = f.Hello
|
||||
|
||||
if f.hola != f.Hello:
|
||||
print f.hola
|
||||
raise RuntimeError
|
||||
raise RuntimeError("f.hola: {}".format(f.hola))
|
||||
|
||||
cpp_enum.cvar.hi = cpp_enum.Hello
|
||||
if cpp_enum.cvar.hi != cpp_enum.Hello:
|
||||
print cpp_enum.cvar.hi
|
||||
raise RuntimeError
|
||||
raise RuntimeError("cpp_enum.cvar.hi: {}".format(cpp_enum.cvar.hi))
|
||||
|
|
|
|||
|
|
@ -108,48 +108,34 @@ def run(module_name):
|
|||
if Klass_inc().val != 0:
|
||||
raise RuntimeError("Klass::inc failed")
|
||||
|
||||
tricky_failure = False
|
||||
tricky = default_args.TrickyInPython()
|
||||
if tricky.value_m1(10) != -1:
|
||||
print "trickyvalue_m1 failed"
|
||||
tricky_failure = True
|
||||
raise RuntimeError("trickyvalue_m1 failed")
|
||||
if tricky.value_m1(10, 10) != 10:
|
||||
print "trickyvalue_m1 failed"
|
||||
tricky_failure = True
|
||||
raise RuntimeError("trickyvalue_m1 failed")
|
||||
if tricky.value_0xabcdef(10) != 0xabcdef:
|
||||
print "trickyvalue_0xabcdef failed"
|
||||
tricky_failure = True
|
||||
raise RuntimeError("trickyvalue_0xabcdef failed")
|
||||
if tricky.value_0644(10) != 420:
|
||||
print "trickyvalue_0644 failed"
|
||||
tricky_failure = True
|
||||
raise RuntimeError("trickyvalue_0644 failed")
|
||||
if tricky.value_perm(10) != 420:
|
||||
print "trickyvalue_perm failed"
|
||||
tricky_failure = True
|
||||
raise RuntimeError("trickyvalue_perm failed")
|
||||
if tricky.value_m01(10) != -1:
|
||||
print "trickyvalue_m01 failed"
|
||||
tricky_failure = True
|
||||
raise RuntimeError("trickyvalue_m01 failed")
|
||||
if not tricky.booltest2():
|
||||
print "booltest2 failed"
|
||||
tricky_failure = True
|
||||
raise RuntimeError("booltest2 failed")
|
||||
|
||||
if tricky.max_32bit_int1() != 0x7FFFFFFF:
|
||||
print "max_32bit_int1 failed"
|
||||
tricky_failure = True
|
||||
raise RuntimeError("max_32bit_int1 failed")
|
||||
if tricky.min_32bit_int1() != -2147483648:
|
||||
print "min_32bit_int1 failed"
|
||||
tricky_failure = True
|
||||
raise RuntimeError("min_32bit_int1 failed")
|
||||
if tricky.max_32bit_int2() != 0x7FFFFFFF:
|
||||
print "max_32bit_int2 failed"
|
||||
tricky_failure = True
|
||||
raise RuntimeError("max_32bit_int2 failed")
|
||||
|
||||
tricky.too_big_32bit_int1()
|
||||
tricky.too_small_32bit_int1()
|
||||
tricky.too_big_32bit_int2()
|
||||
tricky.too_small_32bit_int2()
|
||||
|
||||
if tricky_failure:
|
||||
raise RuntimeError
|
||||
|
||||
default_args.seek()
|
||||
default_args.seek(10)
|
||||
|
||||
|
|
|
|||
|
|
@ -34,68 +34,48 @@ class MyFoo4(Foo):
|
|||
|
||||
# Check that the NotImplementedError raised by MyFoo.ping() is returned by
|
||||
# MyFoo.pong().
|
||||
ok = 0
|
||||
a = MyFoo()
|
||||
b = launder(a)
|
||||
try:
|
||||
b.pong()
|
||||
except NotImplementedError, e:
|
||||
if str(e) == "MyFoo::ping() EXCEPTION":
|
||||
ok = 1
|
||||
else:
|
||||
print "Unexpected error message: %s" % str(e)
|
||||
except:
|
||||
if not str(e) == "MyFoo::ping() EXCEPTION":
|
||||
raise RuntimeError("Unexpected error message: %s" % str(e))
|
||||
except TypeError:
|
||||
pass
|
||||
if not ok:
|
||||
raise RuntimeError
|
||||
|
||||
|
||||
# Check that the director returns the appropriate TypeError if the return type
|
||||
# is wrong.
|
||||
ok = 0
|
||||
a = MyFoo2()
|
||||
b = launder(a)
|
||||
try:
|
||||
b.pong()
|
||||
except TypeError, e:
|
||||
# fastdispatch mode adds on Additional Information to the exception message - just check the main exception message exists
|
||||
if str(e).startswith("SWIG director type mismatch in output value of type 'std::string'"):
|
||||
ok = 1
|
||||
else:
|
||||
print "Unexpected error message: %s" % str(e)
|
||||
if not ok:
|
||||
raise RuntimeError
|
||||
if not str(e).startswith("SWIG director type mismatch in output value of type 'std::string'"):
|
||||
raise RuntimeError("Unexpected error message: %s" % str(e))
|
||||
|
||||
|
||||
# Check that the director can return an exception which requires two arguments
|
||||
# to the constructor, without mangling it.
|
||||
ok = 0
|
||||
a = MyFoo3()
|
||||
b = launder(a)
|
||||
try:
|
||||
b.pong()
|
||||
except MyException, e:
|
||||
if e.msg == "foobar":
|
||||
ok = 1
|
||||
else:
|
||||
print "Unexpected error message: %s" % str(e)
|
||||
if not ok:
|
||||
raise RuntimeError
|
||||
if e.msg != "foobar":
|
||||
raise RuntimeError("Unexpected error message: %s" % str(e))
|
||||
|
||||
|
||||
# Check that the director returns the appropriate TypeError thrown in a director method
|
||||
ok = 0
|
||||
a = MyFoo4()
|
||||
b = launder(a)
|
||||
try:
|
||||
b.pong()
|
||||
except TypeError as e:
|
||||
if str(e).startswith("type() takes 1 or 3 arguments"):
|
||||
ok = 1
|
||||
else:
|
||||
print "Unexpected error message: %s" % str(e)
|
||||
if not ok:
|
||||
raise RuntimeError
|
||||
if not str(e).startswith("type() takes 1 or 3 arguments"):
|
||||
raise RuntimeError("Unexpected error message: %s" % str(e))
|
||||
|
||||
|
||||
# This is expected to fail with -builtin option
|
||||
|
|
|
|||
|
|
@ -38,4 +38,4 @@ while i:
|
|||
a = fi(a) # 20
|
||||
i -= 1
|
||||
|
||||
print a
|
||||
print("a: {}".format(a))
|
||||
|
|
|
|||
|
|
@ -18,12 +18,10 @@ b = B("hello")
|
|||
|
||||
b.get(0)
|
||||
if b.get_first() != "hello world!":
|
||||
print b.get_first()
|
||||
raise RuntimeError
|
||||
raise RuntimeError("b.get_first(): {}".format(b.get_first()))
|
||||
|
||||
|
||||
b.call_process_func()
|
||||
|
||||
if b.smem != "hello":
|
||||
print smem
|
||||
raise RuntimeError
|
||||
raise RuntimeError("smem: {}".format(smem))
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ d = Derived()
|
|||
d.run()
|
||||
|
||||
if d.val >= 0:
|
||||
print d.val
|
||||
raise RuntimeError
|
||||
raise RuntimeError("d.val: {}".format(d.val))
|
||||
|
||||
d.stop()
|
||||
|
|
|
|||
|
|
@ -16,5 +16,4 @@ c = b.get()
|
|||
|
||||
|
||||
if not (a.this == c.this):
|
||||
print a, c
|
||||
raise RuntimeError
|
||||
raise RuntimeError("{} {}".format(a, c))
|
||||
|
|
|
|||
|
|
@ -17,12 +17,10 @@ b = B(u"hello")
|
|||
|
||||
b.get(0)
|
||||
if b.get_first() != u"hello world!":
|
||||
print b.get_first()
|
||||
raise RuntimeError
|
||||
raise RuntimeError("b.get_first(): {}".format(b.get_first()))
|
||||
|
||||
|
||||
b.call_process_func()
|
||||
|
||||
if b.smem != u"hello":
|
||||
print smem
|
||||
raise RuntimeError
|
||||
raise RuntimeError("smem: {}".format(smem))
|
||||
|
|
|
|||
|
|
@ -8,4 +8,4 @@ y = b.blah()
|
|||
|
||||
a = dynamic_cast.do_test(y)
|
||||
if a != "Bar::test":
|
||||
print "Failed!!"
|
||||
raise RuntimeError("Failed!!")
|
||||
|
|
|
|||
|
|
@ -25,8 +25,7 @@ try:
|
|||
a.foobar()
|
||||
except RuntimeError, e:
|
||||
if e.args[0] != "postcatch unknown":
|
||||
print "bad exception order",
|
||||
raise RuntimeError, e.args
|
||||
raise RuntimeError("bad exception order {}".format(e.args))
|
||||
|
||||
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -1,31 +1,21 @@
|
|||
import inctest
|
||||
|
||||
error = 0
|
||||
try:
|
||||
a = inctest.A()
|
||||
except:
|
||||
print "didn't find A"
|
||||
print "therefore, I didn't include 'testdir/subdir1/hello.i'"
|
||||
error = 1
|
||||
raise RuntimeError("didn't find A, therefore, I didn't include 'testdir/subdir1/hello.i'")
|
||||
pass
|
||||
|
||||
|
||||
try:
|
||||
b = inctest.B()
|
||||
except:
|
||||
print "didn't find B"
|
||||
print "therefore, I didn't include 'testdir/subdir2/hello.i'"
|
||||
error = 1
|
||||
raise RuntimeError("didn't find B, therefore, I didn't include 'testdir/subdir2/hello.i'")
|
||||
pass
|
||||
|
||||
if error == 1:
|
||||
raise RuntimeError
|
||||
|
||||
# Check the import in subdirectory worked
|
||||
if inctest.importtest1(5) != 15:
|
||||
print "import test 1 failed"
|
||||
raise RuntimeError
|
||||
raise RuntimeError("import test 1 failed")
|
||||
|
||||
if inctest.importtest2("black") != "white":
|
||||
print "import test 2 failed"
|
||||
raise RuntimeError
|
||||
raise RuntimeError("import test 2 failed")
|
||||
|
|
|
|||
|
|
@ -6,14 +6,14 @@ c = inherit_missing.Spam()
|
|||
|
||||
x = inherit_missing.do_blah(a)
|
||||
if x != "Foo::blah":
|
||||
print "Whoa! Bad return", x
|
||||
raise RuntimeError("Whoa! Bad return {}".format(x))
|
||||
|
||||
x = inherit_missing.do_blah(b)
|
||||
if x != "Bar::blah":
|
||||
print "Whoa! Bad return", x
|
||||
raise RuntimeError("Whoa! Bad return {}".format(x))
|
||||
|
||||
x = inherit_missing.do_blah(c)
|
||||
if x != "Spam::blah":
|
||||
print "Whoa! Bad return", x
|
||||
raise RuntimeError("Whoa! Bad return {}".format(x))
|
||||
|
||||
inherit_missing.delete_Foo(a)
|
||||
|
|
|
|||
|
|
@ -3,8 +3,7 @@ a = inplaceadd.A(7)
|
|||
|
||||
a += 5
|
||||
if a.val != 12:
|
||||
print a.val
|
||||
raise RuntimeError
|
||||
raise RuntimeError("a.val: {}".format(a.val))
|
||||
|
||||
a -= 5
|
||||
if a.val != 7:
|
||||
|
|
|
|||
|
|
@ -8,12 +8,10 @@ if aa.a != 1:
|
|||
raise RuntimeError
|
||||
aa.a = 3
|
||||
if aa.a != 3:
|
||||
print aa.a
|
||||
raise RuntimeError
|
||||
raise RuntimeError("aa.a: {}".format(aa.a))
|
||||
|
||||
if aa.b != 2:
|
||||
print aa.b
|
||||
raise RuntimeError
|
||||
raise RuntimeError("aa.b: {}".format(aa.b))
|
||||
aa.b = 5
|
||||
if aa.b != 5:
|
||||
raise RuntimeError
|
||||
|
|
|
|||
|
|
@ -7,8 +7,7 @@ chell = li_attribute_template.Cintint(1, 2, 3)
|
|||
|
||||
def rassert(what, master):
|
||||
if what != master:
|
||||
print what
|
||||
raise RuntimeError
|
||||
raise RuntimeError("what: {}".format(what))
|
||||
|
||||
# Testing primitive by value attribute
|
||||
rassert(chell.a, 1)
|
||||
|
|
|
|||
|
|
@ -11,12 +11,10 @@ if test2() != " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^
|
|||
raise RuntimeError
|
||||
|
||||
if test3("hello") != "hello-suffix":
|
||||
print test3("hello")
|
||||
raise RuntimeError
|
||||
raise RuntimeError("test3(\"hello\")")
|
||||
|
||||
if test4("hello") != "hello-suffix":
|
||||
print test4("hello")
|
||||
raise RuntimeError
|
||||
raise RuntimeError("test4(\"hello\")")
|
||||
|
||||
if test5(4) != "xxxx":
|
||||
raise RuntimeError
|
||||
|
|
|
|||
|
|
@ -25,8 +25,7 @@ for k in m:
|
|||
|
||||
for k in m:
|
||||
if pm[k].this != m[k].this:
|
||||
print pm[k], m[k]
|
||||
raise RuntimeError
|
||||
raise RuntimeError("Not equal {} {}".format(pm[k], m[k]))
|
||||
|
||||
|
||||
m = {}
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue