From d9e37d7123b2958ff3de5c7290449fb31ecd23c2 Mon Sep 17 00:00:00 2001 From: Moul <moul@moul.re> Date: Sat, 7 May 2022 15:11:01 +0200 Subject: [PATCH] [mod] #424: Apply flake8 --- silkaj/blocks.py | 1 - silkaj/cert.py | 2 +- silkaj/commands.py | 2 +- silkaj/idty_tools.py | 4 ++-- silkaj/license.py | 6 +++--- silkaj/membership.py | 1 - silkaj/money.py | 6 +----- silkaj/revocation.py | 9 ++------- silkaj/tui.py | 1 - silkaj/tx.py | 1 - silkaj/tx_history.py | 3 +-- silkaj/wot.py | 2 -- silkaj/wot_tools.py | 8 +++----- tests/patched/blockchain_tools.py | 2 +- tests/patched/money.py | 20 +------------------- tests/patched/tx.py | 12 ++++++------ tests/patched/tx_history.py | 1 - tests/test_crypto_tools.py | 8 ++++---- tests/test_idty_tools.py | 7 +++---- tests/test_membership.py | 5 ++--- tests/test_money.py | 1 - tests/test_network_tools.py | 10 ++++++---- tests/test_revocation.py | 29 +++++++++++------------------ tests/test_tx.py | 7 ------- tests/test_tx_file.py | 2 +- tests/test_tx_history.py | 13 ++++--------- tests/test_unit_cert.py | 8 ++++---- tests/test_unit_tx.py | 23 +++++------------------ 28 files changed, 62 insertions(+), 132 deletions(-) diff --git a/silkaj/blocks.py b/silkaj/blocks.py index 521287e3..a20947ec 100644 --- a/silkaj/blocks.py +++ b/silkaj/blocks.py @@ -19,7 +19,6 @@ from click import INT, argument, command, progressbar from duniterpy.api import bma from duniterpy.api.errors import DuniterError from duniterpy.documents import Block -from duniterpy.key.verifying_key import VerifyingKey from silkaj.constants import BMA_MAX_BLOCKS_CHUNK_SIZE from silkaj.network_tools import client_instance diff --git a/silkaj/cert.py b/silkaj/cert.py index a3104443..82b51859 100644 --- a/silkaj/cert.py +++ b/silkaj/cert.py @@ -25,7 +25,7 @@ from silkaj import tui, wot from silkaj import wot_tools as wt from silkaj.auth import auth_method from silkaj.blockchain_tools import get_blockchain_parameters, get_head_block -from silkaj.constants import ALL, DATE, SUCCESS_EXIT_STATUS +from silkaj.constants import ALL, DATE from silkaj.crypto_tools import is_pubkey_and_check from silkaj.license import license_approval from silkaj.network_tools import client_instance, send_document diff --git a/silkaj/commands.py b/silkaj/commands.py index 72cad11b..ab51fe39 100644 --- a/silkaj/commands.py +++ b/silkaj/commands.py @@ -25,7 +25,7 @@ from tabulate import tabulate from websocket._exceptions import WebSocketConnectionClosedException from silkaj.blockchain_tools import get_head_block -from silkaj.constants import ALL, HOUR +from silkaj.constants import ALL from silkaj.network_tools import client_instance, determine_endpoint from silkaj.tools import get_currency_symbol from silkaj.wot_tools import identity_of diff --git a/silkaj/idty_tools.py b/silkaj/idty_tools.py index 00031c89..d370a6bd 100644 --- a/silkaj/idty_tools.py +++ b/silkaj/idty_tools.py @@ -62,7 +62,7 @@ def check_many_identities(document: Union[Identity, Revocation]): try: results_pubkey = wt.wot_lookup(idty.pubkey) results_uid = wt.wot_lookup(idty.uid) - except urllib.error.HTTPError as e: + except urllib.error.HTTPError: sys.exit( f"{error_no_identical_id}\nuid: {idty.uid}\npubkey: {display_pubkey_and_checksum(idty.pubkey)}" ) @@ -76,7 +76,7 @@ def check_many_identities(document: Union[Identity, Revocation]): match = True break alternate_ids = display_alternate_ids(lookup_ids).draw() - if match == True: + if match: if len(lookup_ids) >= 1: click.echo(f"One matching identity!\nSimilar identities:\n{alternate_ids}") return True diff --git a/silkaj/license.py b/silkaj/license.py index 4110a617..323e45cb 100644 --- a/silkaj/license.py +++ b/silkaj/license.py @@ -14,7 +14,6 @@ # along with Silkaj. If not, see <https://www.gnu.org/licenses/>. from pathlib import Path -from typing import List import click import g1_monetary_license as gml @@ -39,7 +38,8 @@ def license_command() -> None: class G1MonetaryLicense: def __init__(self): - self.licenses_dir_path = gml.__path__.__dict__["_path"][0] # type: ignore # mypy issue #1422 + # mypy issue #1422 + self.licenses_dir_path = gml.__path__.__dict__["_path"][0] # type: ignore self._available_languages() def display_license(self) -> None: @@ -55,7 +55,7 @@ class G1MonetaryLicense: def language_prompt(self) -> str: return click.prompt( - f"In which language would you like to display Ğ1 monetary license?", + "In which language would you like to display Ğ1 monetary license?", type=click.Choice(self.languages_codes), show_choices=True, show_default=True, diff --git a/silkaj/membership.py b/silkaj/membership.py index e7ce01fe..fab1f723 100644 --- a/silkaj/membership.py +++ b/silkaj/membership.py @@ -54,7 +54,6 @@ def send_membership(ctx): license_approval(currency) # Confirmation - client = client_instance() display_confirmation_table(identity_uid, key.pubkey, identity_block_id) if not dry_run and not ctx.obj["DISPLAY_DOCUMENT"]: tui.send_doc_confirmation("membership document for this identity") diff --git a/silkaj/money.py b/silkaj/money.py index 0bb9ca82..0f0d3f64 100644 --- a/silkaj/money.py +++ b/silkaj/money.py @@ -24,11 +24,7 @@ from tabulate import tabulate from silkaj import wot_tools as wt from silkaj.auth import auth_method, has_auth_method from silkaj.blockchain_tools import get_head_block -from silkaj.crypto_tools import ( - check_pubkey_format, - is_pubkey_and_check, - validate_checksum, -) +from silkaj.crypto_tools import is_pubkey_and_check from silkaj.network_tools import client_instance from silkaj.tools import get_currency_symbol from silkaj.tui import display_amount, display_pubkey_and_checksum diff --git a/silkaj/revocation.py b/silkaj/revocation.py index c191a82f..f2785200 100644 --- a/silkaj/revocation.py +++ b/silkaj/revocation.py @@ -14,7 +14,6 @@ # along with Silkaj. If not, see <https://www.gnu.org/licenses/>. -import logging import sys from pathlib import Path @@ -47,7 +46,7 @@ def save(ctx: click.core.Context, file: str): currency = get_currency() key = auth.auth_method() - pubkey_ck = tui.display_pubkey_and_checksum(key.pubkey) + tui.display_pubkey_and_checksum(key.pubkey) id = (wot.choose_identity(key.pubkey))[0] rev_doc = create_revocation_doc(id, key.pubkey, currency) rev_doc.sign(key) @@ -80,7 +79,7 @@ def revoke_now(ctx: click.core.Context): warn_before_dry_run_or_display(ctx) key = auth.auth_method() - pubkey_ck = tui.display_pubkey_and_checksum(key.pubkey) + tui.display_pubkey_and_checksum(key.pubkey) id = (wot.choose_identity(key.pubkey))[0] rev_doc = create_revocation_doc(id, key.pubkey, currency) rev_doc.sign(key) @@ -109,8 +108,6 @@ Optionnaly takes the document filename.", ) @click.pass_context def verify(ctx: click.core.Context, file: str): - currency = get_currency() - rev_doc = verify_document(file) if ctx.obj["DRY_RUN"]: @@ -137,8 +134,6 @@ Optionnaly takes the document filename.", ) @click.pass_context def publish(ctx: click.core.Context, file: str): - currency = get_currency() - warn_before_dry_run_or_display(ctx) rev_doc = verify_document(file) diff --git a/silkaj/tui.py b/silkaj/tui.py index 46e65d82..c3558251 100644 --- a/silkaj/tui.py +++ b/silkaj/tui.py @@ -14,7 +14,6 @@ # along with Silkaj. If not, see <https://www.gnu.org/licenses/>. import sys -from datetime import datetime import click diff --git a/silkaj/tx.py b/silkaj/tx.py index a5bc63a3..37d5eca3 100644 --- a/silkaj/tx.py +++ b/silkaj/tx.py @@ -16,7 +16,6 @@ import math import shlex -import sys from re import compile, search from typing import List diff --git a/silkaj/tx_history.py b/silkaj/tx_history.py index 238478bf..7dca8b00 100644 --- a/silkaj/tx_history.py +++ b/silkaj/tx_history.py @@ -22,7 +22,6 @@ from duniterpy.documents.transaction import Transaction from pendulum import from_timestamp, now from texttable import Texttable -from silkaj import wot from silkaj import wot_tools as wt from silkaj.constants import ALL, ALL_DIGITAL from silkaj.crypto_tools import check_pubkey_format, validate_checksum @@ -59,7 +58,7 @@ def transaction_history(pubkey, uids, full_pubkey): def generate_header(pubkey, currency_symbol, ud_value): try: idty = wt.identity_of(pubkey) - except: + except Exception: idty = dict([("uid", "")]) balance = get_amount_from_pubkey(pubkey) balance_ud = round(balance[1] / ud_value, 2) diff --git a/silkaj/wot.py b/silkaj/wot.py index b767619b..0f315cf7 100644 --- a/silkaj/wot.py +++ b/silkaj/wot.py @@ -18,7 +18,6 @@ from collections import OrderedDict import click from duniterpy.api.bma import blockchain, wot -from duniterpy.api.errors import DuniterError from pendulum import from_timestamp, now from tabulate import tabulate @@ -27,7 +26,6 @@ from silkaj.blockchain_tools import get_blockchain_parameters from silkaj.constants import DATE from silkaj.crypto_tools import is_pubkey_and_check from silkaj.network_tools import client_instance, exit_on_http_error -from silkaj.tools import message_exit from silkaj.tui import display_pubkey_and_checksum diff --git a/silkaj/wot_tools.py b/silkaj/wot_tools.py index 817e3a6f..13281dee 100644 --- a/silkaj/wot_tools.py +++ b/silkaj/wot_tools.py @@ -13,8 +13,6 @@ # You should have received a copy of the GNU Affero General Public License # along with Silkaj. If not, see <https://www.gnu.org/licenses/>. -import sys - from duniterpy.api.bma import wot from silkaj.network_tools import client_instance @@ -29,7 +27,7 @@ def identity_of(pubkey_uid): client = client_instance() try: return client(wot.identity_of, pubkey_uid) - except ValueError as e: + except ValueError: pass @@ -40,7 +38,7 @@ def is_member(pubkey_uid): """ try: return identity_of(pubkey_uid) - except: + except Exception: return False @@ -67,6 +65,6 @@ def identities_from_pubkeys(pubkeys, uids): for pubkey in uniq_pubkeys: try: identities.append(identity_of(pubkey)) - except Exception as e: + except Exception: pass return identities diff --git a/tests/patched/blockchain_tools.py b/tests/patched/blockchain_tools.py index 6a0b61aa..c8fcbd7b 100644 --- a/tests/patched/blockchain_tools.py +++ b/tests/patched/blockchain_tools.py @@ -51,7 +51,7 @@ def patched_block(self, number): return mocked_block -## mock get_head_block() +# mock get_head_block() def patched_get_head_block(): return mocked_block diff --git a/tests/patched/money.py b/tests/patched/money.py index 32d0f815..7574a195 100644 --- a/tests/patched/money.py +++ b/tests/patched/money.py @@ -13,29 +13,11 @@ # You should have received a copy of the GNU Affero General Public License # along with Silkaj. If not, see <https://www.gnu.org/licenses/>. -""" -Copyright 2016-2020 Maël Azimi <m.a@moul.re> - -Silkaj is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -Silkaj is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with Silkaj. If not, see <https://www.gnu.org/licenses/>. -""" - # This file contains patched functions for testing purposes. from duniterpy.documents.transaction import InputSource from patched.test_constants import mock_ud_value -from silkaj.constants import G1_SYMBOL from silkaj.money import amount_in_current_base from silkaj.tx import MAX_INPUTS_PER_TX @@ -98,7 +80,7 @@ def patched_get_sources(pubkey): a += 1 return balance - listinput, n = list(), 0 + listinput = list() balance = 0 if pubkey == "CtM5RZHopnSRAAoWNgTWrUhDEmspcCAxn6fuCEWDWudp": max_ud = 0 diff --git a/tests/patched/tx.py b/tests/patched/tx.py index 53a535c9..e123ae53 100644 --- a/tests/patched/tx.py +++ b/tests/patched/tx.py @@ -23,7 +23,7 @@ def patched_gen_confirmation_table( pubkey_amount, tx_amounts, outputAddresses, - outputBackChange, + OutputBackChange, comment, ): if not ( @@ -33,7 +33,7 @@ def patched_gen_confirmation_table( and isinstance(tx_amounts, list) and isinstance(outputAddresses, list) and isinstance(comment, str) - and isinstance(outputBackchange, str) + and isinstance(OutputBackChange, str) ) and len(tx_amounts) == len(outputAddresses) and sum(tx_amounts) <= pubkey_amount @@ -49,7 +49,7 @@ def patched_handle_intermediaries_transactions( tx_amounts, outputAddresses, Comment="", - OutputbackChange=None, + OutputBackChange=None, ): if not ( ( @@ -58,7 +58,7 @@ def patched_handle_intermediaries_transactions( and isinstance(tx_amounts, list) and isinstance(outputAddresses, list) and isinstance(Comment, str) - and (isinstance(OutputBackchange, str) or OutputbackChange == None) + and (isinstance(OutputBackChange, str) or not OutputBackChange) ) and len(tx_amounts) == len(outputAddresses) and key.pubkey() == issuers @@ -75,7 +75,7 @@ def patched_generate_and_send_transaction( listinput_and_amount, outputAddresses, Comment, - OutputbackChange, + OutputBackChange, ): if not ( ( @@ -85,7 +85,7 @@ def patched_generate_and_send_transaction( and isinstance(listinput_and_amount, tuple) and isinstance(outputAddresses, list) and isinstance(Comment, str) - and isinstance(OutputBackchange, str) + and isinstance(OutputBackChange, str) ) and len(tx_amounts) == len(outputAddresses) and sum(tx_amounts) <= listinput_and_amount[2] diff --git a/tests/patched/tx_history.py b/tests/patched/tx_history.py index 10e88642..b8228c57 100644 --- a/tests/patched/tx_history.py +++ b/tests/patched/tx_history.py @@ -16,7 +16,6 @@ from duniterpy.documents.transaction import Transaction from patched.blockchain_tools import currency -from patched.wot import pubkey_list fake_received_tx_hist = [ { diff --git a/tests/test_crypto_tools.py b/tests/test_crypto_tools.py index 08b4335b..8fa5eeba 100644 --- a/tests/test_crypto_tools.py +++ b/tests/test_crypto_tools.py @@ -43,11 +43,11 @@ def test_gen_checksum(pubkey, checksum): ) def test_validate_checksum(pubkey, checksum, expected, capsys): pubkey_with_ck = f"{pubkey}:{checksum}" - if expected == None: + if not expected: assert pubkey == crypto_tools.validate_checksum(pubkey_with_ck) else: with pytest.raises(SystemExit) as pytest_exit: - test = crypto_tools.validate_checksum(pubkey_with_ck) + crypto_tools.validate_checksum(pubkey_with_ck) assert capsys.readouterr().out == expected assert pytest_exit.type == SystemExit @@ -65,7 +65,7 @@ def test_validate_checksum(pubkey, checksum, expected, capsys): 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) + crypto_tools.check_pubkey_format(pubkey, display_error) assert capsys.readouterr().out == expected assert pytest_exit.type == SystemExit else: @@ -107,6 +107,6 @@ def test_is_pubkey_and_check(uid_pubkey, expected): ) def test_is_pubkey_and_check_errors(uid_pubkey, expected, capsys): with pytest.raises(SystemExit) as pytest_exit: - test = crypto_tools.is_pubkey_and_check(uid_pubkey) + crypto_tools.is_pubkey_and_check(uid_pubkey) assert capsys.readouterr() == expected assert pytest_exit.type == SystemExit diff --git a/tests/test_idty_tools.py b/tests/test_idty_tools.py index 99577c20..e0525e0f 100644 --- a/tests/test_idty_tools.py +++ b/tests/test_idty_tools.py @@ -19,7 +19,6 @@ import urllib import pendulum import pytest from duniterpy.api import bma -from duniterpy.api.client import DuniterError from duniterpy.documents.block_id import BlockID from duniterpy.documents.identity import Identity @@ -35,7 +34,7 @@ from silkaj import idty_tools from silkaj.constants import ALL, PUBKEY_PATTERN from silkaj.tui import display_pubkey_and_checksum -## used test identities +# used test identities id_moul_test_1 = Identity( currency="g1-test", @@ -366,7 +365,7 @@ def test_check_many_identities( hdrs={}, fp=None, ) - if re.search(PUBKEY_PATTERN, lookup) != None: + if re.search(PUBKEY_PATTERN, lookup): if not lookup_pk: raise http_error return lookup_pk @@ -390,6 +389,6 @@ def test_check_many_identities( result = idty_tools.check_many_identities(idty) assert result == expect_bool display_result = capsys.readouterr().out - if expected != None: + if expected: for expect in expected: assert expect in display_result diff --git a/tests/test_membership.py b/tests/test_membership.py index d413c00b..2643e9dc 100644 --- a/tests/test_membership.py +++ b/tests/test_membership.py @@ -13,7 +13,6 @@ # You should have received a copy of the GNU Affero General Public License # along with Silkaj. If not, see <https://www.gnu.org/licenses/>. -import sys from unittest.mock import Mock import pendulum @@ -38,7 +37,7 @@ from patched.wot import ( from silkaj import auth, blockchain_tools, membership, wot from silkaj.blockchain_tools import get_blockchain_parameters from silkaj.cli import cli -from silkaj.constants import DATE, FAILURE_EXIT_STATUS, SUCCESS_EXIT_STATUS +from silkaj.constants import DATE from silkaj.network_tools import client_instance from silkaj.tui import display_pubkey_and_checksum @@ -113,7 +112,7 @@ def test_membership_cmd(dry_run, display, confirmation, monkeypatch): if dry_run or display: assert "Type: Membership" in result.output else: - signing_key = patched_auth_method() + # signing_key = patched_auth_method() patched_generate_membership_document.assert_called_once() # membership_block_id is different # patched_generate_membership_document.assert_called_once_with( diff --git a/tests/test_money.py b/tests/test_money.py index 68a93701..6a4a9d70 100644 --- a/tests/test_money.py +++ b/tests/test_money.py @@ -14,7 +14,6 @@ # along with Silkaj. If not, see <https://www.gnu.org/licenses/>. import duniterpy.api.bma.tx as bma_tx -import pytest from click.testing import CliRunner from silkaj.cli import cli diff --git a/tests/test_network_tools.py b/tests/test_network_tools.py index 7234d219..b09db732 100644 --- a/tests/test_network_tools.py +++ b/tests/test_network_tools.py @@ -13,15 +13,17 @@ # You should have received a copy of the GNU Affero General Public License # along with Silkaj. If not, see <https://www.gnu.org/licenses/>. -import urllib -from unittest.mock import patch +# import urllib +# from unittest.mock import patch import pytest -from duniterpy.api import bma + +# from duniterpy.api import bma from duniterpy.api import endpoint as du_ep from silkaj import constants, network_tools -from silkaj.membership import generate_membership_document + +# from silkaj.membership import generate_membership_document from tests import helpers ipv6 = "2001:0db8:85a3:0000:0000:8a2e:0370:7334" diff --git a/tests/test_revocation.py b/tests/test_revocation.py index 223bdb05..647ac653 100644 --- a/tests/test_revocation.py +++ b/tests/test_revocation.py @@ -14,8 +14,6 @@ # along with Silkaj. If not, see <https://www.gnu.org/licenses/>. -import os -import sys import urllib from pathlib import Path from unittest.mock import Mock @@ -24,8 +22,6 @@ import click import pytest from click.testing import CliRunner from duniterpy.api import bma -from duniterpy.api.errors import DuniterError -from duniterpy.documents.identity import Identity from duniterpy.documents.revocation import Revocation from patched.auth import patched_auth_method @@ -37,7 +33,7 @@ from silkaj.constants import FAILURE_EXIT_STATUS, SUCCESS_EXIT_STATUS from silkaj.network_tools import client_instance from silkaj.tui import display_pubkey_and_checksum -### useful function ### +# Useful function def display_dry_options(display, dry_run): @@ -49,8 +45,7 @@ def display_dry_options(display, dry_run): return [] -### values ### - +# Values # idty1 REV_DOC = Revocation( @@ -99,7 +94,7 @@ ERROR_CODE = 1005 ERROR_MESSAGE = "Document has unkown fields or wrong line ending format" -## patched functions +# patched functions def patch_get_id_block(node, number): return idty_block @@ -134,7 +129,7 @@ def patched_send_bma_revoke_error(wot_useless, rev_doc_useless): ) -### tests ### +# tests # test cli dry-run @pytest.mark.parametrize( @@ -190,7 +185,7 @@ def test_revocation_cli_dry_run(subcommand, expected_warn, monkeypatch): if expected_warn: assert warning in result.output else: - assert not warning in result.output + assert warning not in result.output # test cli save @@ -433,7 +428,7 @@ def test_revocation_cli_verify( for expect in expected: assert expect in result.output for not_expect in not_expected: - assert not not_expect in result.output + assert not_expect not in result.output # test cli publish @@ -665,7 +660,7 @@ def test_revocation_cli_publish( display, dry_run, doc, lookup, file, user_input, expected, monkeypatch ): def patched_lookup(node, id_pubkey): - if lookup == False: + if not lookup: raise urllib.error.HTTPError( url="this/is/a/test.url", code=404, @@ -777,7 +772,6 @@ def test_revocation_cli_publish_send_errors( file = revocation.REVOCATION_LOCAL_PATH # test publication - client = client_instance() runner = CliRunner() with runner.isolated_filesystem(): with open(file, "w") as f: @@ -911,7 +905,6 @@ def test_revocation_cli_revoke_errors(display, user_input, doc, expected, monkey command = display_dry_options(display, False) command.extend(["revocation", "revoke"]) - client = client_instance() result = CliRunner().invoke(cli, args=command, input=user_input) for expect in expected: @@ -1022,7 +1015,7 @@ def test_verify_document(doc, lookup, capsys, monkeypatch): ) def test_verify_document_missing_id(doc, lookup, capsys, monkeypatch): def patched_lookup(node, id_pubkey): - if lookup == False: + if not lookup: http_error = urllib.error.HTTPError( url="this.is/a/test/url", code=2001, @@ -1043,10 +1036,10 @@ def test_verify_document_missing_id(doc, lookup, capsys, monkeypatch): with open(path, "w") as f: f.write(doc.signed_raw()) with pytest.raises(SystemExit) as pytest_exit: - result = revocation.verify_document(path) + revocation.verify_document(path) assert pytest_exit.type == SystemExit display = capsys.readouterr().out - if lookup == False: + if not lookup: assert "Revocation document does not match any valid identity." in str( pytest_exit.value.code ) @@ -1081,7 +1074,7 @@ def test_verify_document_sign_errors(doc, currency, monkeypatch): elif isinstance(doc, Revocation): f.write(doc.signed_raw()) with pytest.raises(SystemExit) as pytest_exit: - result = revocation.verify_document(path) + revocation.verify_document(path) assert pytest_exit.type == SystemExit if isinstance(doc, str): assert ( diff --git a/tests/test_tx.py b/tests/test_tx.py index 0bc7ac82..bc055d13 100644 --- a/tests/test_tx.py +++ b/tests/test_tx.py @@ -13,7 +13,6 @@ # You should have received a copy of the GNU Affero General Public License # along with Silkaj. If not, see <https://www.gnu.org/licenses/>. -import sys from unittest.mock import Mock import pytest @@ -23,7 +22,6 @@ from click.testing import CliRunner from patched.auth import patched_auth_method from patched.money import patched_get_sources, patched_get_ud_value from patched.test_constants import mock_ud_value -from patched.tx import patched_gen_confirmation_table from silkaj import auth, money, tx from silkaj.cli import cli from silkaj.constants import ( @@ -119,11 +117,6 @@ def test_transaction_amount_errors( return True return False - # run tests - if amounts: - given_amounts = amounts - if UDs_amounts: - given_amounts = UDs_amounts # check program exit on error with pytest.raises(SystemExit) as pytest_exit: # read output to check error. diff --git a/tests/test_tx_file.py b/tests/test_tx_file.py index 48b00a35..1c02a44e 100644 --- a/tests/test_tx_file.py +++ b/tests/test_tx_file.py @@ -74,6 +74,6 @@ def test_parse_file_containing_amounts_recipients_errors(file_content, error, ca with runner.isolated_filesystem(): with open(FILE_PATH, "w") as f: f.write(file_content) - with pytest.raises(SystemExit) as pytest_exit: + with pytest.raises(SystemExit): parse_file_containing_amounts_recipients(FILE_PATH) assert error in capsys.readouterr().out diff --git a/tests/test_tx_history.py b/tests/test_tx_history.py index e89b4da6..496686c1 100644 --- a/tests/test_tx_history.py +++ b/tests/test_tx_history.py @@ -18,13 +18,8 @@ import pytest from patched.blockchain_tools import currency from patched.tx_history import patched_get_transactions_history from patched.wot import patched_identities_from_pubkeys -from silkaj import tx_history, wot, wot_tools -from silkaj.constants import ( - G1_DEFAULT_ENDPOINT, - PUBKEY_MAX_LENGTH, - PUBKEY_MIN_LENGTH, - SHORT_PUBKEY_SIZE, -) +from silkaj import tx_history, wot_tools +from silkaj.constants import PUBKEY_MAX_LENGTH, PUBKEY_MIN_LENGTH, SHORT_PUBKEY_SIZE from silkaj.crypto_tools import CHECKSUM_SIZE SHORT_PUBKEY_LENGTH_WITH_CHECKSUM = ( @@ -110,7 +105,7 @@ def test_tx_history_generate_table_and_pubkey_uid_display(monkeypatch): for tx_list in txs_list_full: assert len(tx_list) == table_columns if tx_list != txs_list_full[0]: - assert not "…:" in tx_list[1] + assert "…:" not in tx_list[1] assert ":" in tx_list[1] # this length is not true for multisig txs, which are very unlikely for now. assert ( @@ -131,7 +126,7 @@ def test_tx_history_generate_table_and_pubkey_uid_display(monkeypatch): for tx_list in txs_list_uids_full: assert len(tx_list) == table_columns if tx_list != txs_list_uids_full[0]: - assert not "…:" in tx_list[1] + assert "…:" not in tx_list[1] assert ":" in tx_list[1] # check all lines assert len(txs_list_uids_full[1][1]) >= min_pubkey_length_with_uid( diff --git a/tests/test_unit_cert.py b/tests/test_unit_cert.py index 41610821..994df17e 100644 --- a/tests/test_unit_cert.py +++ b/tests/test_unit_cert.py @@ -13,10 +13,10 @@ # You should have received a copy of the GNU Affero General Public License # along with Silkaj. If not, see <https://www.gnu.org/licenses/>. -from unittest.mock import patch - -from silkaj.cert import certification_confirmation - +# from unittest.mock import patch +# +# from silkaj.cert import certification_confirmation +# # @patch('builtins.input') # def test_certification_confirmation(mock_input): # id_to_certify = {"pubkey": "pubkeyid to certify"} diff --git a/tests/test_unit_tx.py b/tests/test_unit_tx.py index ced3d49d..1b718f72 100644 --- a/tests/test_unit_tx.py +++ b/tests/test_unit_tx.py @@ -31,23 +31,10 @@ from patched.blockchain_tools import fake_block_id, patched_get_head_block from patched.money import patched_get_sources, patched_get_ud_value from patched.test_constants import mock_ud_value from patched.tools import patched_get_currency_symbol -from patched.tx import ( - patched_gen_confirmation_table, - patched_handle_intermediaries_transactions, -) from patched.wot import patched_is_member -from silkaj import ( - auth, - blockchain_tools, - money, - network_tools, - tools, - tx, - wot, - wot_tools, -) +from silkaj import auth, blockchain_tools, money, network_tools, tools, tx, wot_tools from silkaj.cli import cli -from silkaj.constants import CENT_MULT_TO_UNIT, G1_SYMBOL, MINIMAL_ABSOLUTE_TX_AMOUNT +from silkaj.constants import CENT_MULT_TO_UNIT, G1_SYMBOL from silkaj.tui import display_amount, display_pubkey # Values @@ -847,7 +834,7 @@ def test_handle_intermediaries_transactions( key, issuers, tx_amounts, outputAddresses, Comment, OutputbackChange ) - if expected_listinput_amount[2] == True: + if expected_listinput_amount[2]: patched_generate_and_send_transaction.assert_any_call( key, issuers, @@ -1014,7 +1001,7 @@ def test_send_transaction( if comment: args_list.append("--comment") args_list.append(comment) - if outputbackchange != None: + if outputbackchange is not None: args_list.append("--outputBackChange") args_list.append(outputbackchange) return args_list @@ -1402,7 +1389,7 @@ def test_check_transaction_values_errors( comment, outputAddresses, outputBackChange, enough_source, issuer_pubkey, capsys ): with pytest.raises(SystemExit) as pytest_exit: - result = tx.check_transaction_values( + tx.check_transaction_values( comment, outputAddresses, outputBackChange, enough_source, issuer_pubkey ) assert pytest_exit.type == SystemExit -- GitLab