From b8bf6d511e35b9a4c98d6f5086010ccd2168bd27 Mon Sep 17 00:00:00 2001 From: Moul <moul@moul.re> Date: Sun, 26 Sep 2021 13:28:10 +0200 Subject: [PATCH] [mod] #194: tests: Use f-string --- tests/test_checksum.py | 6 +++--- tests/test_crypto_tools.py | 2 +- tests/test_tui.py | 14 ++++---------- tests/test_verify_blocks.py | 4 ++-- 4 files changed, 10 insertions(+), 16 deletions(-) diff --git a/tests/test_checksum.py b/tests/test_checksum.py index 0f71e4c6..add5e74e 100644 --- a/tests/test_checksum.py +++ b/tests/test_checksum.py @@ -21,7 +21,7 @@ from silkaj.cli import cli pubkey = "3rp7ahDGeXqffBQTnENiXEFXYS7BRjYmS33NbgfCuDc8" checksum = "DFQ" -pubkey_checksum = pubkey + ":" + checksum +pubkey_checksum = f"{pubkey}:{checksum}" pubkey_seedhex_authfile = ( "3bc6f2484e441e40562155235cdbd8ce04c25e7df35bf5f87c067bf239db8511" ) @@ -31,7 +31,7 @@ pubkey_seedhex_authfile = ( "command, excepted_output", [ (["checksum", pubkey_checksum], "The checksum is valid"), - (["checksum", pubkey + ":vAK"], "The checksum is invalid"), + (["checksum", f"{pubkey}:vAK"], "The checksum is invalid"), (["checksum", pubkey], pubkey_checksum), (["checksum", "uid"], "Error: Wrong public key format"), (["checksum"], MESSAGE), @@ -44,4 +44,4 @@ def test_checksum_command(command, excepted_output): with open("authfile", "w") as f: f.write(pubkey_seedhex_authfile) result = CliRunner().invoke(cli, args=command) - assert result.output == excepted_output + "\n" + assert result.output == f"{excepted_output}\n" diff --git a/tests/test_crypto_tools.py b/tests/test_crypto_tools.py index e2247f5d..299175bd 100644 --- a/tests/test_crypto_tools.py +++ b/tests/test_crypto_tools.py @@ -42,7 +42,7 @@ def test_gen_checksum(pubkey, checksum): ], ) def test_validate_checksum(pubkey, checksum, expected, capsys): - pubkey_with_ck = str(pubkey + ":" + checksum) + pubkey_with_ck = f"{pubkey}:{checksum}" if expected == None: assert pubkey == crypto_tools.validate_checksum(pubkey_with_ck) else: diff --git a/tests/test_tui.py b/tests/test_tui.py index 972bfa60..9ac6faaa 100644 --- a/tests/test_tui.py +++ b/tests/test_tui.py @@ -30,14 +30,8 @@ def test_display_amount(message, amount, currency_symbol): amount_UD = round(amount / mock_ud_value, 2) expected = [ [ - message + " (unit|relative)", - str(amount / 100) - + " " - + currency_symbol - + " | " - + str(amount_UD) - + " UD " - + currency_symbol, + f"{message} (unit|relative)", + f"{str(amount / 100)} {currency_symbol} | {str(amount_UD)} UD {currency_symbol}", ] ] tx = list() @@ -56,9 +50,9 @@ def test_display_amount(message, amount, currency_symbol): def test_display_pubkey(message, pubkey, id, monkeypatch): monkeypatch.setattr(wot_tools, "is_member", patched_is_member) - expected = [[message + " (pubkey:checksum)", display_pubkey_and_checksum(pubkey)]] + expected = [[f"{message} (pubkey:checksum)", display_pubkey_and_checksum(pubkey)]] if id: - expected.append([message + " (id)", id]) + expected.append([f"{message} (id)", id]) tx = list() display_pubkey(tx, message, pubkey) assert tx == expected diff --git a/tests/test_verify_blocks.py b/tests/test_verify_blocks.py index af48140d..16396ca3 100644 --- a/tests/test_verify_blocks.py +++ b/tests/test_verify_blocks.py @@ -55,8 +55,8 @@ def test_check_passed_blocks_range(from_block, to_block, capsys, monkeypatch): assert pytest_wrapped_e.value.code == FAILURE_EXIT_STATUS captured = capsys.readouterr() if to_block == HEAD_BLOCK + 1: - expected = "Passed TO_BLOCK argument is bigger than the head block: " + str( - HEAD_BLOCK + expected = ( + f"Passed TO_BLOCK argument is bigger than the head block: {str(HEAD_BLOCK)}" ) else: expected = "TO_BLOCK should be bigger or equal to FROM_BLOCK\n" -- GitLab