summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam S Fulton <wsf@fultondesigns.co.uk>2020-08-13 21:40:11 +0100
committerWilliam S Fulton <wsf@fultondesigns.co.uk>2020-08-13 21:40:11 +0100
commit64d3617b3c354dcaa243cc0a864ab729e75dbfab (patch)
treebfd73b5b20445c101dfdd29c3a427cb5266a7973
parent7c34d3828fc013fcf2e5d2a4ebc4c7bd2f8f4517 (diff)
downloadswig-64d3617b3c354dcaa243cc0a864ab729e75dbfab.tar.gz
Improve Python testing catching exceptions
Catch expected exceptions only
-rw-r--r--Examples/test-suite/python/contract_runme.py44
-rw-r--r--Examples/test-suite/python/default_constructor_runme.py14
-rw-r--r--Examples/test-suite/python/smart_pointer_not_runme.py12
3 files changed, 35 insertions, 35 deletions
diff --git a/Examples/test-suite/python/contract_runme.py b/Examples/test-suite/python/contract_runme.py
index 8bfda8930..b6bab3a09 100644
--- a/Examples/test-suite/python/contract_runme.py
+++ b/Examples/test-suite/python/contract_runme.py
@@ -3,14 +3,14 @@ import contract
contract.test_preassert(1, 2)
try:
contract.test_preassert(-1, 3)
- print "Failed! Preassertions are broken"
+ raise Exception("Failed! Preassertions are broken")
except RuntimeError:
pass
contract.test_postassert(3)
try:
contract.test_postassert(-3)
- print "Failed! Postassertions are broken"
+ raise Exception("Failed! Postassertions are broken")
except RuntimeError:
pass
@@ -18,13 +18,13 @@ contract.test_prepost(2, 3)
contract.test_prepost(5, -4)
try:
contract.test_prepost(-3, 4)
- print "Failed! Preassertions are broken"
+ raise Exception("Failed! Preassertions are broken")
except RuntimeError:
pass
try:
contract.test_prepost(4, -10)
- print "Failed! Postassertions are broken"
+ raise Exception("Failed! Postassertions are broken")
except RuntimeError:
pass
@@ -33,14 +33,14 @@ f = contract.Foo()
f.test_preassert(4, 5)
try:
f.test_preassert(-2, 3)
- print "Failed! Method preassertion."
+ raise Exception("Failed! Method preassertion.")
except RuntimeError:
pass
f.test_postassert(4)
try:
f.test_postassert(-4)
- print "Failed! Method postassertion"
+ raise Exception("Failed! Method postassertion")
except RuntimeError:
pass
@@ -48,33 +48,33 @@ f.test_prepost(3, 4)
f.test_prepost(4, -3)
try:
f.test_prepost(-4, 2)
- print "Failed! Method preassertion."
+ raise Exception("Failed! Method preassertion.")
except RuntimeError:
pass
try:
f.test_prepost(4, -10)
- print "Failed! Method postassertion."
+ raise Exception("Failed! Method postassertion.")
except RuntimeError:
pass
contract.Foo_stest_prepost(4, 0)
try:
contract.Foo_stest_prepost(-4, 2)
- print "Failed! Static method preassertion"
+ raise Exception("Failed! Static method preassertion")
except RuntimeError:
pass
try:
contract.Foo_stest_prepost(4, -10)
- print "Failed! Static method posteassertion"
+ raise Exception("Failed! Static method posteassertion")
except RuntimeError:
pass
b = contract.Bar()
try:
b.test_prepost(2, -4)
- print "Failed! Inherited preassertion."
+ raise Exception("Failed! Inherited preassertion.")
except RuntimeError:
pass
@@ -82,54 +82,54 @@ except RuntimeError:
d = contract.D()
try:
d.foo(-1, 1, 1, 1, 1)
- print "Failed! Inherited preassertion (D)."
+ raise Exception("Failed! Inherited preassertion (D).")
except RuntimeError:
pass
try:
d.foo(1, -1, 1, 1, 1)
- print "Failed! Inherited preassertion (D)."
+ raise Exception("Failed! Inherited preassertion (D).")
except RuntimeError:
pass
try:
d.foo(1, 1, -1, 1, 1)
- print "Failed! Inherited preassertion (D)."
+ raise Exception("Failed! Inherited preassertion (D).")
except RuntimeError:
pass
try:
d.foo(1, 1, 1, -1, 1)
- print "Failed! Inherited preassertion (D)."
+ raise Exception("Failed! Inherited preassertion (D).")
except RuntimeError:
pass
try:
d.foo(1, 1, 1, 1, -1)
- print "Failed! Inherited preassertion (D)."
+ raise Exception("Failed! Inherited preassertion (D).")
except RuntimeError:
pass
try:
d.bar(-1, 1, 1, 1, 1)
- print "Failed! Inherited preassertion (D)."
+ raise Exception("Failed! Inherited preassertion (D).")
except RuntimeError:
pass
try:
d.bar(1, -1, 1, 1, 1)
- print "Failed! Inherited preassertion (D)."
+ raise Exception("Failed! Inherited preassertion (D).")
except RuntimeError:
pass
try:
d.bar(1, 1, -1, 1, 1)
- print "Failed! Inherited preassertion (D)."
+ raise Exception("Failed! Inherited preassertion (D).")
except RuntimeError:
pass
try:
d.bar(1, 1, 1, -1, 1)
- print "Failed! Inherited preassertion (D)."
+ raise Exception("Failed! Inherited preassertion (D).")
except RuntimeError:
pass
try:
d.bar(1, 1, 1, 1, -1)
- print "Failed! Inherited preassertion (D)."
+ raise Exception("Failed! Inherited preassertion (D).")
except RuntimeError:
pass
@@ -137,6 +137,6 @@ except RuntimeError:
my = contract.myClass(1)
try:
my = contract.myClass(0)
- print "Failed! constructor preassertion"
+ raise Exception("Failed! constructor preassertion")
except RuntimeError:
pass
diff --git a/Examples/test-suite/python/default_constructor_runme.py b/Examples/test-suite/python/default_constructor_runme.py
index 1e877adda..301f422cf 100644
--- a/Examples/test-suite/python/default_constructor_runme.py
+++ b/Examples/test-suite/python/default_constructor_runme.py
@@ -17,7 +17,7 @@ dc.delete_AA(aa)
try:
b = dc.new_B()
print "Whoa. new_BB created."
-except:
+except TypeError:
pass
del_b = dc.delete_B
@@ -25,7 +25,7 @@ del_b = dc.delete_B
try:
bb = dc.new_BB()
print "Whoa. new_BB created."
-except:
+except AttributeError:
pass
del_bb = dc.delete_BB
@@ -33,7 +33,7 @@ del_bb = dc.delete_BB
try:
c = dc.new_C()
print "Whoa. new_C created."
-except:
+except AttributeError:
pass
del_c = dc.delete_C
@@ -44,7 +44,7 @@ dc.delete_CC(cc)
try:
d = dc.new_D()
print "Whoa. new_D created"
-except:
+except AttributeError:
pass
del_d = dc.delete_D
@@ -52,7 +52,7 @@ del_d = dc.delete_D
try:
dd = dc.new_DD()
print "Whoa. new_DD created"
-except:
+except AttributeError:
pass
dd = dc.delete_DD
@@ -60,7 +60,7 @@ dd = dc.delete_DD
try:
ad = dc.new_AD()
print "Whoa. new_AD created"
-except:
+except AttributeError:
pass
del_ad = dc.delete_AD
@@ -74,7 +74,7 @@ dc.delete_EE(ee)
try:
eb = dc.new_EB()
print "Whoa. new_EB created"
-except:
+except AttributeError:
pass
del_eb = dc.delete_EB
diff --git a/Examples/test-suite/python/smart_pointer_not_runme.py b/Examples/test-suite/python/smart_pointer_not_runme.py
index 69704c4ef..53006bce4 100644
--- a/Examples/test-suite/python/smart_pointer_not_runme.py
+++ b/Examples/test-suite/python/smart_pointer_not_runme.py
@@ -8,35 +8,35 @@ g = Grok(f)
try:
x = b.x
print "Error! b.x"
-except:
+except AttributeError:
pass
try:
x = s.x
print "Error! s.x"
-except:
+except AttributeError:
pass
try:
x = g.x
print "Error! g.x"
-except:
+except AttributeError:
pass
try:
x = b.getx()
print "Error! b.getx()"
-except:
+except AttributeError:
pass
try:
x = s.getx()
print "Error! s.getx()"
-except:
+except AttributeError:
pass
try:
x = g.getx()
print "Error! g.getx()"
-except:
+except AttributeError:
pass