From 467002a47196782e8ba04d8fca36f89d2ee21b6f Mon Sep 17 00:00:00 2001 From: matograine <tom.ngr@zaclys.net> Date: Fri, 23 Apr 2021 19:06:50 +0200 Subject: [PATCH] [enh] #203 remove tabulate from money.py * import tui module * update balance test --- silkaj/money.py | 18 ++++++++++-------- tests/test_end_to_end.py | 3 ++- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/silkaj/money.py b/silkaj/money.py index a4596771..b63e46c0 100644 --- a/silkaj/money.py +++ b/silkaj/money.py @@ -16,9 +16,9 @@ along with Silkaj. If not, see <https://www.gnu.org/licenses/>. """ from click import command, argument, pass_context, echo -from tabulate import tabulate from silkaj import wot_tools as wt +from silkaj import tui from silkaj.network_tools import ClientInstance from silkaj.blockchain_tools import HeadBlock from silkaj.tools import CurrencySymbol, message_exit, coroutine @@ -28,7 +28,6 @@ from silkaj.crypto_tools import ( check_pubkey_format, validate_checksum, ) -from silkaj.tui import display_amount, display_pubkey_and_checksum from duniterpy.api.bma import tx, blockchain from duniterpy.documents.transaction import InputSource @@ -54,7 +53,7 @@ async def cmd_amount(ctx, pubkeys): print(f"ERROR: pubkey {inputPubkey} has a wrong format") elif pubkey in pubkeys_list: message_exit( - f"ERROR: pubkey {display_pubkey_and_checksum(pubkey)} was specified many times" + f"ERROR: pubkey {tui.display_pubkey_and_checksum(pubkey)} was specified many times" ) pubkeys_list.append(pubkey) if wrong_pubkeys: @@ -90,7 +89,7 @@ async def show_amount_from_pubkey(label, inputs_balance): # if `pubkey` is a pubkey, get pubkey:checksum and uid if label != "Total": member = await wt.is_member(label) - label = display_pubkey_and_checksum(label) + label = tui.display_pubkey_and_checksum(label) # display balance table display = list() display.append(["Balance of pubkey", label]) @@ -99,22 +98,25 @@ async def show_amount_from_pubkey(label, inputs_balance): display.append(["User identifier", member["uid"]]) if totalAmountInput - balance != 0: - display_amount(display, "Blockchain", balance, ud_value, currency_symbol) - display_amount( + tui.display_amount(display, "Blockchain", balance, ud_value, currency_symbol) + tui.display_amount( display, "Pending transaction", (totalAmountInput - balance), ud_value, currency_symbol, ) - display_amount(display, "Total amount", totalAmountInput, ud_value, currency_symbol) + tui.display_amount( + display, "Total amount", totalAmountInput, ud_value, currency_symbol + ) display.append( [ "Total relative to M/N", "{0} x M/N".format(round(totalAmountInput / average, 2)), ] ) - echo(tabulate(display, tablefmt="fancy_grid")) + table = tui.create_table() + echo(tui.vert_table(table, display)) async def get_average(): diff --git a/tests/test_end_to_end.py b/tests/test_end_to_end.py index 51ccb213..e54e9479 100644 --- a/tests/test_end_to_end.py +++ b/tests/test_end_to_end.py @@ -51,8 +51,9 @@ def test_balance(): output = check_output( silkaj + ["--gtest", "balance", "3dnbnYY9i2bHMQUGyFp5GVvJ2wBkVpus31cDJA5cfRpj"] ).decode() + print(output) # debug assert ( - "│ Balance of pubkey │ 3dnbnYY9i2bHMQUGyFp5GVvJ2wBkVpus31cDJA5cfRpj:EyF │" + "│ Balance of pubkey │ 3dnbnYY9i2bHMQUGyFp5GVvJ2wBkVpus31cDJA5cfRpj: │" in output ) assert "│ Total amount (unit|relative) │" in output -- GitLab