From bf6cfe37edf275d68689ceb35e69b5a2995c33b2 Mon Sep 17 00:00:00 2001 From: matograine <tom.ngr@zaclys.net> Date: Fri, 12 Feb 2021 18:01:10 +0100 Subject: [PATCH] [test] [fix] #368 : wrong use of context `with pytest.raises() as...` * correct the form of tests --- tests/test_crypto_tools.py | 4 ++-- tests/test_unit_tx.py | 41 +++++++++++++++++--------------------- 2 files changed, 20 insertions(+), 25 deletions(-) diff --git a/tests/test_crypto_tools.py b/tests/test_crypto_tools.py index 191f1181..7534f891 100644 --- a/tests/test_crypto_tools.py +++ b/tests/test_crypto_tools.py @@ -49,7 +49,7 @@ def test_validate_checksum(pubkey, checksum, expected, capsys): else: with pytest.raises(SystemExit) as pytest_exit: test = crypto_tools.validate_checksum(pubkey_with_ck) - assert capsys.readouterr() == expected + assert capsys.readouterr() == expected assert pytest_exit.type == SystemExit @@ -67,7 +67,7 @@ def test_check_pubkey_format(pubkey, display_error, expected, capsys): if isinstance(expected, str): with pytest.raises(SystemExit) as pytest_exit: test = crypto_tools.check_pubkey_format(pubkey, display_error) - assert capsys.readouterr() == expected + assert capsys.readouterr() == expected assert pytest_exit.type == SystemExit else: assert expected == crypto_tools.check_pubkey_format(pubkey, display_error) diff --git a/tests/test_unit_tx.py b/tests/test_unit_tx.py index 58ce7552..57379c10 100644 --- a/tests/test_unit_tx.py +++ b/tests/test_unit_tx.py @@ -192,9 +192,9 @@ def test_compute_amounts_errors(capsys): trial[0], trial[1], ) - expected_error = "Error: amount {0} is too low.".format(trial[0][0]) - assert capsys.readouterr() == expected_error assert pytest_exit.type == SystemExit + expected_error = "Error: amount {0} is too low.".format(trial[0][0]) + assert capsys.readouterr().out == expected_error def test_compute_amounts(): @@ -1344,28 +1344,23 @@ def test_check_transaction_values_errors( result = tx.check_transaction_values( comment, outputAddresses, outputBackChange, enough_source, issuer_pubkey ) - display = capsys.readouterr() - if comment.find("Wrong_Char_") != -1: - assert display == "Error: the format of the comment is invalid" - elif len(comment) > tx.MAX_COMMENT_LENGTH: - assert display == "Error: the format of the comment is invalid" - elif "Wrong_Pubkey" in outputAddresses: - assert display.out.find("Error: bad format for following public key:") != -1 - elif outputBackChange: - if outputBackChange == "Wrong_Pubkey": - assert ( - display.out.find("Error: bad format for following public key:") - != -1 - ) - elif enough_source is True: - assert ( - display.out.find( - "pubkey doesn’t have enough money for this transaction." - ) - != -1 - ) - assert result == "" assert pytest_exit.type == SystemExit + display = capsys.readouterr() + if comment.find("Wrong_Char_") != -1: + assert display == "Error: the format of the comment is invalid" + elif len(comment) > tx.MAX_COMMENT_LENGTH: + assert display == "Error: the format of the comment is invalid" + elif "Wrong_Pubkey" in outputAddresses: + assert display.out.find("Error: bad format for following public key:") != -1 + elif outputBackChange: + if outputBackChange == "Wrong_Pubkey": + assert display.out.find("Error: bad format for following public key:") != -1 + elif enough_source is True: + assert ( + display.out.find("pubkey doesn’t have enough money for this transaction.") + != -1 + ) + assert result == "" # test generate_unlocks() -- GitLab