# Path: tapes/reporting/stream.py
# class ThreadedStreamReporter(ScheduledReporter):
#     """Dumps JSON serialized metrics to a stream with an interval"""
#     def __init__(self, interval, stream=sys.stdout, registry=None):
#         """
#         :param interval: a timedelta
#         :param stream: the stream to write to, defaults to stdout
#         :param registry: the registry to report from, defaults to the global one
#         """
#         super(ThreadedStreamReporter, self).__init__(interval, registry)
#         self.stream = stream
# 
#     def report(self):
#         stats = self.registry.get_stats()
#         json.dump(stats, self.stream)
#         self.stream.write(os.linesep)
# 
# Path: tests/local/base.py
# class StatsTest(unittest.TestCase):
#     def setUp(self):
#         self.registry = Registry()


from datetime import timedelta
from time import sleep
from six import StringIO
from six.moves import map
from tapes.reporting.stream import ThreadedStreamReporter
from tests.local.base import StatsTest
import json
import os
from __future__ import print_function




class StreamReportingTestCase(StatsTest):
    def test_threaded_stream_reporter_prints_stats_with_intervals(self):
        counter = self.registry.counter(
            'some.path'
        )

        counter.increment(42)

        s = StringIO()
        reporter = ThreadedStreamReporter(timedelta(milliseconds=100), stream=s, registry=self.registry)

# Path: tapes/reporting/stream.py
# class ThreadedStreamReporter(ScheduledReporter):
#     """Dumps JSON serialized metrics to a stream with an interval"""
#     def __init__(self, interval, stream=sys.stdout, registry=None):
#         """
#         :param interval: a timedelta
#         :param stream: the stream to write to, defaults to stdout
#         :param registry: the registry to report from, defaults to the global one
#         """
#         super(ThreadedStreamReporter, self).__init__(interval, registry)
#         self.stream = stream
# 
#     def report(self):
#         stats = self.registry.get_stats()
#         json.dump(stats, self.stream)
#         self.stream.write(os.linesep)
# 
# Path: tests/local/base.py
# class StatsTest(unittest.TestCase):
#     def setUp(self):
#         self.registry = Registry()


# Path: tests/reporting/test_stream_reporting.py
from datetime import timedelta
from time import sleep
from six import StringIO
from six.moves import map
from tapes.reporting.stream import ThreadedStreamReporter
from tests.local.base import StatsTest
import json
import os

from __future__ import print_function




class StreamReportingTestCase(StatsTest):
    def test_threaded_stream_reporter_prints_stats_with_intervals(self):
        counter = self.registry.counter(
            'some.path'
        )

        counter.increment(42)

        s = StringIO()
        reporter = ThreadedStreamReporter(timedelta(milliseconds=100), stream=s, registry=self.registry)

        reporter.start()