<commit_before>import functools

import pytest

from plenum.common.average_strategies import MedianLowStrategy
from plenum.server.instances import Instances
from plenum.server.monitor import Monitor
from plenum.test.helper import sdk_eval_timeout, sdk_send_random_request, sdk_get_reply
from plenum.test.testing_utils import FakeSomething


@pytest.fixture()
def requests(looper, sdk_wallet_client, sdk_pool_handle):
    requests = []
    for i in range(5):
        req = sdk_send_random_request(looper, sdk_pool_handle, sdk_wallet_client)
        req, _ = sdk_get_reply(looper, req, timeout=sdk_eval_timeout(1, 4))
        requests.append(req)
    return requests


@pytest.fixture
def decreasedMonitoringTimeouts(tconf, request):
    oldDashboardUpdateFreq = tconf.DashboardUpdateFreq
    tconf.DashboardUpdateFreq = 1

    def reset():
        tconf.DashboardUpdateFreq = oldDashboardUpdateFreq

    request.addfinalizer(reset)
    return tconf


NUM_OF_REPLICAS = 3

@pytest.fixture(scope='function')
def fake_monitor(tconf):
    def getThroughput(self, instId):
        return self.throughputs[instId].throughput

    throughputs = dict()
    instances = Instances()
    num_of_replicas = 5
    for i in range(num_of_replicas):
        throughputs[i] = Monitor.create_throughput_measurement(tconf, start_ts=0)
        instances.add(i)
    monitor = FakeSomething(
        throughputs=throughputs,
        instances=instances,
        Delta=tconf.DELTA,
        throughput_avg_strategy_cls=MedianLowStrategy,
        )
    monitor.numOrderedRequests = dict()<commit_msg>INDY-1682: refactoring<commit_after>import functools

import pytest

from plenum.common.average_strategies import MedianLowStrategy
from plenum.server.instances import Instances
from plenum.server.monitor import Monitor
from plenum.test.helper import sdk_eval_timeout, sdk_send_random_request, sdk_get_reply
from plenum.test.testing_utils import FakeSomething


@pytest.fixture()
def requests(looper, sdk_wallet_client, sdk_pool_handle):
    requests = []
    for i in range(5):
        req = sdk_send_random_request(looper, sdk_pool_handle, sdk_wallet_client)
        req, _ = sdk_get_reply(looper, req, timeout=sdk_eval_timeout(1, 4))
        requests.append(req)
    return requests


@pytest.fixture
def decreasedMonitoringTimeouts(tconf, request):
    oldDashboardUpdateFreq = tconf.DashboardUpdateFreq
    tconf.DashboardUpdateFreq = 1

    def reset():
        tconf.DashboardUpdateFreq = oldDashboardUpdateFreq

    request.addfinalizer(reset)
    return tconf


@pytest.fixture(scope='function')
def fake_monitor(tconf):
    def getThroughput(self, instId):
        return self.throughputs[instId].throughput

    throughputs = dict()
    instances = Instances()
    num_of_replicas = 5
    for i in range(num_of_replicas):
        throughputs[i] = Monitor.create_throughput_measurement(tconf, start_ts=0)
        instances.add(i)
    monitor = FakeSomething(
        throughputs=throughputs,
        instances=instances,
        Delta=tconf.DELTA,
        throughput_avg_strategy_cls=MedianLowStrategy,
        )
    monitor.numOrderedRequests = dict()
{'fraction_non_alphanumeric': 0.078125, 'fraction_numerical': 0.005420918367346939, 'mean_word_length': 4.202321724709784, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5267203', 'n_tokens_mistral': 1042, 'n_tokens_neox': 1024, 'n_words': 188}