From 942259e6adbecd7105ce9382ce94b8cab10091b5 Mon Sep 17 00:00:00 2001 From: matograine <tom.ngr@zaclys.net> Date: Sat, 28 Nov 2020 19:13:04 +0100 Subject: [PATCH] [test] #213: use directly mock_ud_value instead of copying it to variables --- tests/test_tui.py | 5 ++--- tests/test_tx.py | 16 ++++++++++------ tests/test_unit_tx.py | 25 +++++++++++-------------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/tests/test_tui.py b/tests/test_tui.py index 9161786a..3edd27b5 100644 --- a/tests/test_tui.py +++ b/tests/test_tui.py @@ -27,8 +27,7 @@ from patched.money import mock_ud_value "message, amount, currency_symbol", [("Total", 1000, G1_SYMBOL)] ) def test_display_amount(message, amount, currency_symbol): - ud_value = mock_ud_value - amount_UD = round(amount / ud_value, 2) + amount_UD = round(amount / mock_ud_value, 2) expected = [ [ message + " (unit|relative)", @@ -42,7 +41,7 @@ def test_display_amount(message, amount, currency_symbol): ] ] tx = list() - display_amount(tx, message, amount, ud_value, currency_symbol) + display_amount(tx, message, amount, mock_ud_value, currency_symbol) assert tx == expected diff --git a/tests/test_tx.py b/tests/test_tx.py index 5f662992..469baf06 100644 --- a/tests/test_tx.py +++ b/tests/test_tx.py @@ -32,7 +32,6 @@ async def test_transaction_amount(monkeypatch): float ≠100 does not give the exact value""" monkeypatch.setattr(UDValue, "get_ud_value", patched_ud_value) - udvalue = mock_ud_value trials = ( # tests for --amount (unit) ([141.89], None, ["A"], [14189]), @@ -41,7 +40,7 @@ async def test_transaction_amount(monkeypatch): ([141.89], None, ["A", "B"], [14189, 14189]), ([141.89, 141.99], None, ["A", "B"], [14189, 14199]), # tests for --amount_UD - (None, [1.1], ["A"], [round(1.1 * udvalue)]), + (None, [1.1], ["A"], [round(1.1 * mock_ud_value)]), ( None, [1.9], @@ -49,11 +48,16 @@ async def test_transaction_amount(monkeypatch): "A", "B", ], - [round(1.9 * udvalue), round(1.9 * udvalue)], + [round(1.9 * mock_ud_value), round(1.9 * mock_ud_value)], + ), + (None, [1.0001], ["A"], [round(1.0001 * mock_ud_value)]), + (None, [9.9999], ["A"], [round(9.9999 * mock_ud_value)]), + ( + None, + [1.9, 2.3], + ["A", "B"], + [round(1.9 * mock_ud_value), round(2.3 * mock_ud_value)], ), - (None, [1.0001], ["A"], [round(1.0001 * udvalue)]), - (None, [9.9999], ["A"], [round(9.9999 * udvalue)]), - (None, [1.9, 2.3], ["A", "B"], [round(1.9 * udvalue), round(2.3 * udvalue)]), ) for trial in trials: diff --git a/tests/test_unit_tx.py b/tests/test_unit_tx.py index f2c89eef..d848b2c3 100644 --- a/tests/test_unit_tx.py +++ b/tests/test_unit_tx.py @@ -126,7 +126,6 @@ async def test_transaction_confirmation( ) # creating expected list - ud_value = mock_ud_value expected = list() total_tx_amount = sum(tx_amounts) # display account situation @@ -134,28 +133,28 @@ async def test_transaction_confirmation( expected, "Initial balance", pubkey_balance, - ud_value, + mock_ud_value, currency_symbol, ) display_amount( expected, "Total transaction amount", total_tx_amount, - ud_value, + mock_ud_value, currency_symbol, ) display_amount( expected, "Balance after transaction", (pubkey_balance - total_tx_amount), - ud_value, + mock_ud_value, currency_symbol, ) await display_pubkey(expected, "From", issuer_pubkey) # display recipients and amounts for outputAddress, tx_amount in zip(outputAddresses, tx_amounts): await display_pubkey(expected, "To", outputAddress) - display_amount(expected, "Amount", tx_amount, ud_value, currency_symbol) + display_amount(expected, "Amount", tx_amount, mock_ud_value, currency_symbol) # display backchange and comment if outputBackChange: await display_pubkey(expected, "Backchange", outputBackChange) @@ -190,7 +189,6 @@ def test_compute_amounts_errors(capsys): def test_compute_amounts(): - ud_value = 314 assert compute_amounts((10.0, 2.0, 0.01, 0.011, 0.019), 100) == [ 1000, 200, @@ -198,12 +196,12 @@ def test_compute_amounts(): 1, 2, ] - assert compute_amounts([0.0032], ud_value) == [1] - assert compute_amounts([1.00], ud_value) == [314] - assert compute_amounts([1.01], ud_value) == [317] - assert compute_amounts([1.99], ud_value) == [625] - assert compute_amounts([1.001], ud_value) == [314] - assert compute_amounts([1.009], ud_value) == [317] + assert compute_amounts([0.0032], mock_ud_value) == [1] + assert compute_amounts([1.00], mock_ud_value) == [314] + assert compute_amounts([1.01], mock_ud_value) == [317] + assert compute_amounts([1.99], mock_ud_value) == [625] + assert compute_amounts([1.001], mock_ud_value) == [314] + assert compute_amounts([1.009], mock_ud_value) == [317] # This case will not happen in real use, but this particular function will allow it. assert compute_amounts([0.0099], 100) == [1] @@ -279,7 +277,6 @@ async def test_transaction_amount( ): # patched functions monkeypatch.setattr("silkaj.money.UDValue.get_ud_value", patched_ud_value) - udvalue = mock_ud_value def too_little_amount(amounts, multiplicator): for amount in amounts: @@ -295,7 +292,7 @@ async def test_transaction_amount( # test errors if ( (len(given_amounts) > 1 and len(outputAddresses) != len(given_amounts)) - or (UDs_amounts and too_little_amount(given_amounts, udvalue)) + or (UDs_amounts and too_little_amount(given_amounts, mock_ud_value)) or (amounts and too_little_amount(given_amounts, CENT_MULT_TO_UNIT)) ): # check program exit on error -- GitLab