# Path: tapes/registry.py
# class Registry(BaseRegistry):
#     """Factory and storage location for all metrics stuff.
# 
#     Use producer methods to create metrics. Metrics are hierarchical, the names are split on '.'.
#     """
# 
#     def meter(self, name):
#         """Creates or gets an existing meter.
# 
#         :param name: The name
#         :return: The created or existing meter for the given name
#         """
#         return self._get_or_add_stat(name, Meter)
# 
#     def timer(self, name):
#         """Creates or gets an existing timer.
# 
#         :param name: The name
#         :return: The created or existing timer for the given name
#         """
#         return self._get_or_add_stat(name, Timer)
# 
#     def gauge(self, name, producer):
#         """Creates or gets an existing gauge.
# 
#         :param name: The name
#         :return: The created or existing gauge for the given name
#         """
#         return self._get_or_add_stat(name, functools.partial(Gauge, producer))
# 
#     def counter(self, name):
#         """Creates or gets an existing counter.
# 
#         :param name: The name
#         :return: The created or existing counter for the given name
#         """
#         return self._get_or_add_stat(name, Counter)
# 
#     def histogram(self, name):
#         """Creates or gets an existing histogram.
# 
#         :param name: The name
#         :return: The created or existing histogram for the given name
#         """
#         return self._get_or_add_stat(name, Histogram)
# 
#     def get_stats(self):
#         """Retrieves the current values of the metrics associated with this registry, formatted as a dict.
# 
#         The metrics form a hierarchy, their names are split on '.'. The returned dict is an `addict`, so you can
#         use it as either a regular dict or via attributes, e.g.,
# 
#         >>> import tapes
#         >>> registry = tapes.Registry()
#         >>> timer = registry.timer('my.timer')
#         >>> stats = registry.get_stats()
#         >>> print(stats['my']['timer']['count'])
#         0
#         >>> print(stats.my.timer.count)
#         0
# 
#         :return: The values of the metrics associated with this registry
#         """
#         def _get_value(stats):
#             try:
#                 return Dict((k, _get_value(v)) for k, v in stats.items())
#             except AttributeError:
#                 return Dict(stats.get_values())
# 
#         return _get_value(self.stats)
# 
# Path: tapes/reporting/tornado/stream.py
# class TornadoStreamReporter(TornadoScheduledReporter):
#     """Writes JSON serialized metrics to a stream using an ``IOLoop`` for scheduling"""
#     def __init__(self, interval, stream=sys.stdout, registry=None, io_loop=None):
#         """
#         :param interval: a timedelta
#         :param stream: the stream to write to, defaults to stdout
#         :param registry: the registry to report from, defaults to stdout
#         :param io_loop: the IOLoop to use, defaults to ``IOLoop.current()``
#         """
#         super(TornadoStreamReporter, self).__init__(interval, registry, io_loop)
#         self.stream = stream
# 
#     def report(self):
#         json.dump(self.registry.get_stats(), self.stream)
#         self.stream.write(os.linesep)


from datetime import timedelta
from six import StringIO
from tornado import gen, testing
from tapes.registry import Registry
from tapes.reporting.tornado.stream import TornadoStreamReporter
import json
import os


class TornadoConsoleReportingTestCase(testing.AsyncTestCase):
    @testing.gen_test
    def test_tornado_stream_reporting_writes_to_stream(self):

# Path: tapes/registry.py
# class Registry(BaseRegistry):
#     """Factory and storage location for all metrics stuff.
# 
#     Use producer methods to create metrics. Metrics are hierarchical, the names are split on '.'.
#     """
# 
#     def meter(self, name):
#         """Creates or gets an existing meter.
# 
#         :param name: The name
#         :return: The created or existing meter for the given name
#         """
#         return self._get_or_add_stat(name, Meter)
# 
#     def timer(self, name):
#         """Creates or gets an existing timer.
# 
#         :param name: The name
#         :return: The created or existing timer for the given name
#         """
#         return self._get_or_add_stat(name, Timer)
# 
#     def gauge(self, name, producer):
#         """Creates or gets an existing gauge.
# 
#         :param name: The name
#         :return: The created or existing gauge for the given name
#         """
#         return self._get_or_add_stat(name, functools.partial(Gauge, producer))
# 
#     def counter(self, name):
#         """Creates or gets an existing counter.
# 
#         :param name: The name
#         :return: The created or existing counter for the given name
#         """
#         return self._get_or_add_stat(name, Counter)
# 
#     def histogram(self, name):
#         """Creates or gets an existing histogram.
# 
#         :param name: The name
#         :return: The created or existing histogram for the given name
#         """
#         return self._get_or_add_stat(name, Histogram)
# 
#     def get_stats(self):
#         """Retrieves the current values of the metrics associated with this registry, formatted as a dict.
# 
#         The metrics form a hierarchy, their names are split on '.'. The returned dict is an `addict`, so you can
#         use it as either a regular dict or via attributes, e.g.,
# 
#         >>> import tapes
#         >>> registry = tapes.Registry()
#         >>> timer = registry.timer('my.timer')
#         >>> stats = registry.get_stats()
#         >>> print(stats['my']['timer']['count'])
#         0
#         >>> print(stats.my.timer.count)
#         0
# 
#         :return: The values of the metrics associated with this registry
#         """
#         def _get_value(stats):
#             try:
#                 return Dict((k, _get_value(v)) for k, v in stats.items())
#             except AttributeError:
#                 return Dict(stats.get_values())
# 
#         return _get_value(self.stats)
# 
# Path: tapes/reporting/tornado/stream.py
# class TornadoStreamReporter(TornadoScheduledReporter):
#     """Writes JSON serialized metrics to a stream using an ``IOLoop`` for scheduling"""
#     def __init__(self, interval, stream=sys.stdout, registry=None, io_loop=None):
#         """
#         :param interval: a timedelta
#         :param stream: the stream to write to, defaults to stdout
#         :param registry: the registry to report from, defaults to stdout
#         :param io_loop: the IOLoop to use, defaults to ``IOLoop.current()``
#         """
#         super(TornadoStreamReporter, self).__init__(interval, registry, io_loop)
#         self.stream = stream
# 
#     def report(self):
#         json.dump(self.registry.get_stats(), self.stream)
#         self.stream.write(os.linesep)


# Path: tests/reporting/test_tornado_stream_reporting.py
from datetime import timedelta
from six import StringIO
from tornado import gen, testing
from tapes.registry import Registry
from tapes.reporting.tornado.stream import TornadoStreamReporter
import json
import os



class TornadoConsoleReportingTestCase(testing.AsyncTestCase):
    @testing.gen_test
    def test_tornado_stream_reporting_writes_to_stream(self):

        registry = Registry()