From 5b728c8e98a4d3d72b1ca5f6ac287b453b0fb5d6 Mon Sep 17 00:00:00 2001 From: John Newbery Date: Wed, 12 Jul 2017 10:29:02 -0400 Subject: [tests] remove direct testing on JSONRPCException from individual test cases Github-Pull: #10853 Rebased-From: 5864e9c1611e6034a8d49b78231abe6bfade686d --- test/functional/test_framework/util.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'test/functional/test_framework/util.py') diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py index 64966adb97..44d7e04a89 100644 --- a/test/functional/test_framework/util.py +++ b/test/functional/test_framework/util.py @@ -99,6 +99,13 @@ def assert_raises_jsonrpc(code, message, fun, *args, **kwds): args*: positional arguments for the function. kwds**: named arguments for the function. """ + assert try_rpc(code, message, fun, *args, **kwds), "No exception raised" + +def try_rpc(code, message, fun, *args, **kwds): + """Tries to run an rpc command. + + Test against error code and message if the rpc fails. + Returns whether a JSONRPCException was raised.""" try: fun(*args, **kwds) except JSONRPCException as e: @@ -107,10 +114,11 @@ def assert_raises_jsonrpc(code, message, fun, *args, **kwds): raise AssertionError("Unexpected JSONRPC error code %i" % e.error["code"]) if (message is not None) and (message not in e.error['message']): raise AssertionError("Expected substring not found:" + e.error['message']) + return True except Exception as e: raise AssertionError("Unexpected exception raised: " + type(e).__name__) else: - raise AssertionError("No exception raised") + return False def assert_is_hex_string(string): try: -- cgit v1.2.3 From 623de0acbb7a586adba8d1f9a64c77fabb0e98a4 Mon Sep 17 00:00:00 2001 From: John Newbery Date: Wed, 12 Jul 2017 10:29:21 -0400 Subject: [tests] do not allow assert_raises_message to be called with JSONRPCException Github-Pull: #10853 Rebased-From: 677d893ff758b61f66203730da224bd7ef8f0b43 --- test/functional/test_framework/util.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test/functional/test_framework/util.py') diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py index 44d7e04a89..ed35bf576e 100644 --- a/test/functional/test_framework/util.py +++ b/test/functional/test_framework/util.py @@ -51,6 +51,8 @@ def assert_raises(exc, fun, *args, **kwds): def assert_raises_message(exc, message, fun, *args, **kwds): try: fun(*args, **kwds) + except JSONRPCException: + raise AssertionError("Use assert_raises_jsonrpc() to test RPC failures") except exc as e: if message is not None and message not in e.error['message']: raise AssertionError("Expected substring not found:" + e.error['message']) -- cgit v1.2.3 From d94fc336c47b5fd0f42217806faad1aa201b9d63 Mon Sep 17 00:00:00 2001 From: John Newbery Date: Wed, 1 Nov 2017 10:41:28 -0400 Subject: scripted-diff: rename assert_raises_jsonrpc to assert_raises_rpc error -BEGIN VERIFY SCRIPT- sed -i 's/assert_raises_jsonrpc/assert_raises_rpc_error/g' test/functional/*py test/functional/test_framework/*py -END VERIFY SCRIPT- Github-Pull: #10853 Rebased-From: 47ba8cf71e9a3a6f7452488fc9ab3b350f0fae36 --- test/functional/test_framework/util.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/functional/test_framework/util.py') diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py index ed35bf576e..102c903018 100644 --- a/test/functional/test_framework/util.py +++ b/test/functional/test_framework/util.py @@ -52,7 +52,7 @@ def assert_raises_message(exc, message, fun, *args, **kwds): try: fun(*args, **kwds) except JSONRPCException: - raise AssertionError("Use assert_raises_jsonrpc() to test RPC failures") + raise AssertionError("Use assert_raises_rpc_error() to test RPC failures") except exc as e: if message is not None and message not in e.error['message']: raise AssertionError("Expected substring not found:" + e.error['message']) @@ -85,7 +85,7 @@ def assert_raises_process_error(returncode, output, fun, *args, **kwds): else: raise AssertionError("No exception raised") -def assert_raises_jsonrpc(code, message, fun, *args, **kwds): +def assert_raises_rpc_error(code, message, fun, *args, **kwds): """Run an RPC and verify that a specific JSONRPC exception code and message is raised. Calls function `fun` with arguments `args` and `kwds`. Catches a JSONRPCException -- cgit v1.2.3