test: unit tests for lndrpc (#2442)
This commit is contained in:
parent
4f118c5f98
commit
67fdb77339
5 changed files with 1082 additions and 112 deletions
|
|
@ -55,7 +55,7 @@ def _tests_for_funding_source(
|
|||
|
||||
|
||||
def build_test_id(test: WalletTest):
|
||||
return f"{test.funding_source}.{test.function}({test.description})"
|
||||
return f"{test.funding_source.name}.{test.function}({test.description})"
|
||||
|
||||
|
||||
def load_funding_source(funding_source: FundingSourceConfig) -> BaseWallet:
|
||||
|
|
@ -83,7 +83,13 @@ async def check_assertions(wallet, _test_data: WalletTest):
|
|||
call_params = _test_data.call_params
|
||||
|
||||
if "expect" in test_data:
|
||||
await _assert_data(wallet, tested_func, call_params, _test_data.expect)
|
||||
await _assert_data(
|
||||
wallet,
|
||||
tested_func,
|
||||
call_params,
|
||||
_test_data.expect,
|
||||
_test_data.description,
|
||||
)
|
||||
# if len(_test_data.mocks) == 0:
|
||||
# # all calls should fail after this method is called
|
||||
# await wallet.cleanup()
|
||||
|
|
@ -96,14 +102,25 @@ async def check_assertions(wallet, _test_data: WalletTest):
|
|||
raise AssertionError("Expected outcome not specified")
|
||||
|
||||
|
||||
async def _assert_data(wallet, tested_func, call_params, expect):
|
||||
async def _assert_data(wallet, tested_func, call_params, expect, description):
|
||||
resp = await getattr(wallet, tested_func)(**call_params)
|
||||
fn_prefix = "__eval__:"
|
||||
for key in expect:
|
||||
received = getattr(resp, key)
|
||||
expected = expect[key]
|
||||
assert (
|
||||
getattr(resp, key) == expect[key]
|
||||
), f"""Field "{key}". Received: "{received}". Expected: "{expected}"."""
|
||||
if key.startswith(fn_prefix):
|
||||
key = key[len(fn_prefix) :]
|
||||
received = getattr(resp, key)
|
||||
expected = expected.format(**{key: received, "description": description})
|
||||
_assert = eval(expected)
|
||||
else:
|
||||
received = getattr(resp, key)
|
||||
_assert = getattr(resp, key) == expect[key]
|
||||
|
||||
assert _assert, (
|
||||
f""" Field "{key}"."""
|
||||
f""" Received: "{received}"."""
|
||||
f""" Expected: "{expected}"."""
|
||||
)
|
||||
|
||||
|
||||
async def _assert_error(wallet, tested_func, call_params, expect_error):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue