Merge pull request #78 from sr-gi/verbose-test

Enables stdout for unit tests
This commit is contained in:
Sergi Delgado Segura
2019-12-17 17:24:33 +01:00
committed by GitHub
14 changed files with 8 additions and 35 deletions

View File

@@ -27,7 +27,7 @@ from common.cryptographer import Cryptographer
@pytest.fixture(scope="session")
def run_bitcoind():
bitcoind_thread = Thread(target=run_simulator, kwargs={"mode": "event"})
bitcoind_thread = Thread(target=run_simulator, kwargs={"mode": "event", "verbose": False})
bitcoind_thread.daemon = True
bitcoind_thread.start()

View File

@@ -8,7 +8,7 @@ from cryptography.hazmat.primitives import serialization
from pisa.api import API
from pisa.watcher import Watcher
from pisa.tools import bitcoin_cli
from pisa import HOST, PORT, c_logger
from pisa import HOST, PORT
from pisa.conf import MAX_APPOINTMENTS
from test.pisa.unit.conftest import (
@@ -21,7 +21,6 @@ from test.pisa.unit.conftest import (
from common.constants import LOCATOR_LEN_BYTES
c_logger.disabled = True
PISA_API = "http://{}:{}".format(HOST, PORT)
MULTIPLE_APPOINTMENTS = 10

View File

@@ -4,8 +4,6 @@ from pisa import c_logger
from apps.cli.blob import Blob
from test.pisa.unit.conftest import get_random_value_hex
c_logger.disabled = True
def test_init_blob():
data = get_random_value_hex(64)

View File

@@ -4,7 +4,6 @@ from pisa import c_logger
from pisa.block_processor import BlockProcessor
from test.pisa.unit.conftest import get_random_value_hex, generate_block, generate_blocks
c_logger.disabled = True
hex_tx = (
"0100000001c997a5e56e104102fa209c6a852dd90660a20b2d9c352423edce25857fcd3704000000004847304402"

View File

@@ -1,11 +1,8 @@
from uuid import uuid4
from pisa import c_logger
from pisa.builder import Builder
from test.pisa.unit.conftest import get_random_value_hex, generate_dummy_appointment, generate_dummy_tracker
c_logger.disabled = True
def test_build_appointments():
appointments_data = {}

View File

@@ -1,13 +1,11 @@
import pytest
from pisa import c_logger
from pisa.carrier import Carrier
from test.simulator.utils import sha256d
from test.simulator.transaction import TX
from test.pisa.unit.conftest import generate_blocks, get_random_value_hex
from pisa.rpc_errors import RPC_VERIFY_ALREADY_IN_CHAIN, RPC_DESERIALIZATION_ERROR
c_logger.disabled = True
# FIXME: This test do not fully cover the carrier since the simulator does not support every single error bitcoind may
# return for RPC_VERIFY_REJECTED and RPC_VERIFY_ERROR. Further development of the simulator / mocks or simulation

View File

@@ -1,7 +1,6 @@
import random
from uuid import uuid4
from pisa import c_logger
from pisa.responder import TransactionTracker
from pisa.cleaner import Cleaner
from common.appointment import Appointment
@@ -16,8 +15,6 @@ ITEMS = 10
MAX_ITEMS = 100
ITERATIONS = 10
c_logger.disabled = True
# WIP: FIX CLEANER TESTS AFTER ADDING delete_complete_appointment
def set_up_appointments(db_manager, total_appointments):

View File

@@ -4,7 +4,6 @@ import pytest
import shutil
from uuid import uuid4
from pisa import c_logger
from pisa.db_manager import DBManager
from pisa.db_manager import WATCHER_LAST_BLOCK_KEY, RESPONDER_LAST_BLOCK_KEY, LOCATOR_MAP_PREFIX
@@ -12,8 +11,6 @@ from common.constants import LOCATOR_LEN_BYTES
from test.pisa.unit.conftest import get_random_value_hex, generate_dummy_appointment
c_logger.disabled = True
@pytest.fixture(scope="module")
def watcher_appointments():

View File

@@ -1,9 +1,6 @@
from pisa import c_logger
from pisa.encrypted_blob import EncryptedBlob
from test.pisa.unit.conftest import get_random_value_hex
c_logger.disabled = True
def test_init_encrypted_blob():
# No much to test here, basically that the object is properly created

View File

@@ -4,7 +4,6 @@ from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.asymmetric import ec
from cryptography.hazmat.primitives import serialization
from pisa import c_logger
from pisa.errors import *
from pisa.inspector import Inspector
from common.appointment import Appointment
@@ -16,7 +15,6 @@ from test.pisa.unit.conftest import get_random_value_hex, generate_dummy_appoint
from common.constants import LOCATOR_LEN_BYTES, LOCATOR_LEN_HEX
from common.cryptographer import Cryptographer
c_logger.disabled = True
inspector = Inspector()
APPOINTMENT_OK = (0, None)

View File

@@ -7,7 +7,6 @@ from copy import deepcopy
from threading import Thread
from queue import Queue, Empty
from pisa import c_logger
from pisa.db_manager import DBManager
from pisa.responder import Responder, TransactionTracker
from pisa.block_processor import BlockProcessor
@@ -20,8 +19,6 @@ from test.simulator.utils import sha256d
from test.simulator.bitcoind_sim import TX
from test.pisa.unit.conftest import generate_block, generate_blocks, get_random_value_hex
c_logger.disabled = True
@pytest.fixture(scope="module")
def responder(db_manager):

View File

@@ -1,10 +1,7 @@
from pisa import c_logger
from pisa.tools import can_connect_to_bitcoind, in_correct_network, bitcoin_cli
from common.tools import check_sha256_hex_format
c_logger.disabled = True
def test_in_correct_network(run_bitcoind):
# The simulator runs as if it was regtest, so every other network should fail

View File

@@ -4,7 +4,6 @@ from threading import Thread
from queue import Queue, Empty
from cryptography.hazmat.primitives import serialization
from pisa import c_logger
from pisa.watcher import Watcher
from pisa.responder import Responder
from pisa.tools import bitcoin_cli
@@ -20,7 +19,6 @@ from pisa.conf import EXPIRY_DELTA, MAX_APPOINTMENTS
from common.tools import check_sha256_hex_format
from common.cryptographer import Cryptographer
c_logger.disabled = True
APPOINTMENTS = 5
START_TIME_OFFSET = 1

View File

@@ -242,7 +242,7 @@ def load_data():
pass
def simulate_mining(mode, time_between_blocks):
def simulate_mining(mode, time_between_blocks, verbose=True):
global mempool, mined_transactions, blocks, blockchain, mine_new_block, prev_block_hash
mining_simulator = ZMQPublisher(
@@ -281,8 +281,9 @@ def simulate_mining(mode, time_between_blocks):
blockchain.append(block_hash)
prev_block_hash = block_hash
print("New block mined: {}".format(block_hash))
print("\tTransactions: {}".format(list(txs_to_mine.keys())))
if verbose:
print("New block mined: {}".format(block_hash))
print("\tTransactions: {}".format(list(txs_to_mine.keys())))
if mode == "time":
time.sleep(time_between_blocks)
@@ -291,11 +292,11 @@ def simulate_mining(mode, time_between_blocks):
mine_new_block.clear()
def run_simulator(mode="time", time_between_blocks=TIME_BETWEEN_BLOCKS):
def run_simulator(mode="time", time_between_blocks=TIME_BETWEEN_BLOCKS, verbose=True):
if mode not in ["time", "event"]:
raise ValueError("Node must be time or event")
mining_thread = Thread(target=simulate_mining, args=[mode, time_between_blocks])
mining_thread = Thread(target=simulate_mining, args=[mode, time_between_blocks, verbose])
mining_thread.start()
# Setting Flask log to ERROR only so it does not mess with out logging. Also disabling flask initial messages