[qa] add assert_raises_message to check specific error message
This commit is contained in:
parent
018a4eb120
commit
307acdd3df
2 changed files with 7 additions and 3 deletions
|
@ -531,10 +531,14 @@ def assert_greater_than(thing1, thing2):
|
||||||
raise AssertionError("%s <= %s"%(str(thing1),str(thing2)))
|
raise AssertionError("%s <= %s"%(str(thing1),str(thing2)))
|
||||||
|
|
||||||
def assert_raises(exc, fun, *args, **kwds):
|
def assert_raises(exc, fun, *args, **kwds):
|
||||||
|
assert_raises_message(exc, None, fun, *args, **kwds)
|
||||||
|
|
||||||
|
def assert_raises_message(exc, message, fun, *args, **kwds):
|
||||||
try:
|
try:
|
||||||
fun(*args, **kwds)
|
fun(*args, **kwds)
|
||||||
except exc:
|
except exc as e:
|
||||||
pass
|
if message is not None and message not in e.error['message']:
|
||||||
|
raise AssertionError("Expected substring not found:"+e.error['message'])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise AssertionError("Unexpected exception raised: "+type(e).__name__)
|
raise AssertionError("Unexpected exception raised: "+type(e).__name__)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -71,7 +71,7 @@ class WalletTest (BitcoinTestFramework):
|
||||||
unspent_0 = self.nodes[2].listunspent()[0]
|
unspent_0 = self.nodes[2].listunspent()[0]
|
||||||
unspent_0 = {"txid": unspent_0["txid"], "vout": unspent_0["vout"]}
|
unspent_0 = {"txid": unspent_0["txid"], "vout": unspent_0["vout"]}
|
||||||
self.nodes[2].lockunspent(False, [unspent_0])
|
self.nodes[2].lockunspent(False, [unspent_0])
|
||||||
assert_raises(JSONRPCException, self.nodes[2].sendtoaddress, self.nodes[2].getnewaddress(), 20)
|
assert_raises_message(JSONRPCException, "Insufficient funds", self.nodes[2].sendtoaddress, self.nodes[2].getnewaddress(), 20)
|
||||||
assert_equal([unspent_0], self.nodes[2].listlockunspent())
|
assert_equal([unspent_0], self.nodes[2].listlockunspent())
|
||||||
self.nodes[2].lockunspent(True, [unspent_0])
|
self.nodes[2].lockunspent(True, [unspent_0])
|
||||||
assert_equal(len(self.nodes[2].listlockunspent()), 0)
|
assert_equal(len(self.nodes[2].listlockunspent()), 0)
|
||||||
|
|
Loading…
Reference in a new issue