From f0a4903a2f52a7208da4cae26cfed44d711ef85c Mon Sep 17 00:00:00 2001
From: Moul <moul@moul.re>
Date: Sun, 5 Jun 2022 16:43:10 +0200
Subject: [PATCH] [mypy] Define class for tx tests counter (#163)

It was wrongly done before
Defining an attribute of a function
---
 tests/patched/money.py | 13 +++++++------
 tests/test_unit_tx.py  | 12 ++++++------
 2 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/tests/patched/money.py b/tests/patched/money.py
index 7574a195..067f8151 100644
--- a/tests/patched/money.py
+++ b/tests/patched/money.py
@@ -86,10 +86,10 @@ def patched_get_sources(pubkey):
         max_ud = 0
         max_tx = 3
     elif pubkey == "HcRgKh4LwbQVYuAc3xAdCynYXpKoiPE6qdxCMa8JeHat":
-        if patched_get_sources.counter == 0:
+        if Counter.counter == 0:
             max_ud = 0
             max_tx = 53
-        elif patched_get_sources.counter == 1:
+        elif Counter.counter == 1:
             listinput.append(
                 InputSource(
                     amount=100 * MAX_INPUTS_PER_TX,  # 100 * 46 = 4600
@@ -105,10 +105,10 @@ def patched_get_sources(pubkey):
         max_ud = 10
         max_tx = 0
     elif pubkey == "9cwBBgXcSVMT74xiKYygX6FM5yTdwd3NABj1CfHbbAmp":
-        if patched_get_sources.counter == 0:
+        if Counter.counter == 0:
             max_ud = 50
             max_tx = 20
-        elif patched_get_sources.counter == 1:
+        elif Counter.counter == 1:
             listinput.append(
                 InputSource(
                     amount=mock_ud_value * MAX_INPUTS_PER_TX,  # 46 UD = 46*314 = 1444
@@ -139,8 +139,9 @@ def patched_get_sources(pubkey):
     balance = listinput_UD(listinput, balance, pubkey, max_ud)
     balance = listinput_TX(listinput, balance, max_tx)
 
-    patched_get_sources.counter += 1
+    Counter.counter += 1
     return listinput, balance
 
 
-patched_get_sources.counter = 0
+class Counter:
+    counter = 0
diff --git a/tests/test_unit_tx.py b/tests/test_unit_tx.py
index 2b940ea0..0a5db454 100644
--- a/tests/test_unit_tx.py
+++ b/tests/test_unit_tx.py
@@ -28,7 +28,7 @@ from duniterpy.documents.transaction import (
 
 from patched.auth import patched_auth_method
 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.money import Counter, 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.wot import patched_is_member
@@ -421,8 +421,8 @@ def test_get_list_input_for_transaction(
 
     # patched functions
     monkeypatch.setattr(money, "get_sources", patched_get_sources)
-    # reset patched_get_sources counter
-    patched_get_sources.counter = 0
+    # reset Counter.counter
+    Counter.counter = 0
     # testing error exit
     if isinstance(expected, str):
         with pytest.raises(SystemExit) as pytest_exit:
@@ -830,7 +830,7 @@ def test_handle_intermediaries_transactions(
         tx, "generate_and_send_transaction", patched_generate_and_send_transaction
     )
 
-    patched_get_sources.counter = 0
+    Counter.counter = 0
 
     # testing
     tx.handle_intermediaries_transactions(
@@ -1025,8 +1025,8 @@ def test_send_transaction(
     monkeypatch.setattr(money, "get_sources", patched_get_sources)
     monkeypatch.setattr(money, "get_ud_value", patched_get_ud_value)
 
-    # reset patched_get_sources
-    patched_get_sources.counter = 0
+    # reset Counter.counter
+    Counter.counter = 0
     # total amount for pubkey_fifi
     total_amount = 5300
     # compute amounts list
-- 
GitLab