# Path: tests/mocks.py
# class MockClient(AugmentFixture):
# 
#     def __init__(self, transport=None):
#         self.events = []
#         self.augments = {}
#         self.tasks = []
#         self.transport = transport
# 
#     def event(self, **kwargs):
#         self.tasks.append(self.apply_augment(copy(kwargs)))
#         self.events.append(kwargs)
# 
#     def clear_queue(self):
#         self.events = []
# 
#     def flush(self, transport):
#         response = transport.send(self.events)
#         self.clear_queue()
#         return response
# 
# class MockTransport(BlankTransport):
# 
#     def __init__(self, host=None, port=None, broken=False):
#         self.connected = False
#         self.broken = broken
#         self.sneaky = False
# 
#     def connect(self):
#         if self.broken:
#             raise ConnectionRefusedError
#         self.connected = True
# 
#     def disconnect(self):
#         self.connected = False
# 
#     def send(self, message):
#         if self.broken or self.sneaky:
#             raise RiemannError
# 
#         return True
# 
# Path: oshino/augments/stats.py
# class SimpleMovingAverage(AugmentBase):
# 
#     def __init__(self, *args, **kwargs):
#         super(SimpleMovingAverage, self).__init__(*args, **kwargs)
#         self.dq = deque(maxlen=self.step)
# 
#     @property
#     def step(self):
#         return self._data.get("step", 5)
# 
#     def activate(self, client, g):
#         step = self.step
# 
#         stopped = False
#         while not stopped:
# 
#             try:
#                 event = next(g)
#                 self.dq.append(event)
#             except StopIteration:
#                 stopped = True
#                 break
# 
#             data = list(map(lambda x: x["metric_f"], list(self.dq)))
#             if len(data) == step:
#                 output = sum(data) / len(data)
# 
#                 self.send_event(client,
#                                 service=self.prefix + "value",
#                                 metric_f=output,
#                                 state="ok")


import sys
import asyncio
from concurrent.futures import ThreadPoolExecutor
from pytest import fixture
from .mocks import MockClient, MockTransport
from oshino.augments.stats import SimpleMovingAverage





@fixture
def mock_client(request):
    client = MockClient()
    request.addfinalizer(client.on_stop)
    return client


@fixture
def mock_transport():
    return MockTransport()


@fixture
def broken_transport():

# Path: tests/mocks.py
# class MockClient(AugmentFixture):
# 
#     def __init__(self, transport=None):
#         self.events = []
#         self.augments = {}
#         self.tasks = []
#         self.transport = transport
# 
#     def event(self, **kwargs):
#         self.tasks.append(self.apply_augment(copy(kwargs)))
#         self.events.append(kwargs)
# 
#     def clear_queue(self):
#         self.events = []
# 
#     def flush(self, transport):
#         response = transport.send(self.events)
#         self.clear_queue()
#         return response
# 
# class MockTransport(BlankTransport):
# 
#     def __init__(self, host=None, port=None, broken=False):
#         self.connected = False
#         self.broken = broken
#         self.sneaky = False
# 
#     def connect(self):
#         if self.broken:
#             raise ConnectionRefusedError
#         self.connected = True
# 
#     def disconnect(self):
#         self.connected = False
# 
#     def send(self, message):
#         if self.broken or self.sneaky:
#             raise RiemannError
# 
#         return True
# 
# Path: oshino/augments/stats.py
# class SimpleMovingAverage(AugmentBase):
# 
#     def __init__(self, *args, **kwargs):
#         super(SimpleMovingAverage, self).__init__(*args, **kwargs)
#         self.dq = deque(maxlen=self.step)
# 
#     @property
#     def step(self):
#         return self._data.get("step", 5)
# 
#     def activate(self, client, g):
#         step = self.step
# 
#         stopped = False
#         while not stopped:
# 
#             try:
#                 event = next(g)
#                 self.dq.append(event)
#             except StopIteration:
#                 stopped = True
#                 break
# 
#             data = list(map(lambda x: x["metric_f"], list(self.dq)))
#             if len(data) == step:
#                 output = sum(data) / len(data)
# 
#                 self.send_event(client,
#                                 service=self.prefix + "value",
#                                 metric_f=output,
#                                 state="ok")


# Path: tests/fixtures.py
import sys
import asyncio
from concurrent.futures import ThreadPoolExecutor
from pytest import fixture
from .mocks import MockClient, MockTransport
from oshino.augments.stats import SimpleMovingAverage






@fixture
def mock_client(request):
    client = MockClient()
    request.addfinalizer(client.on_stop)
    return client


@fixture
def mock_transport():
    return MockTransport()


@fixture
def broken_transport():

    return MockTransport(broken=True)