Improve Python testing catching exceptions
Catch expected exceptions only
This commit is contained in:
parent
7c34d3828f
commit
64d3617b3c
3 changed files with 35 additions and 35 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue