# Path: metrology/registry.py
# class Registry(object):
#     def __init__(self):
#         self.lock = RLock()
#         self.metrics = {}
# 
#     def clear(self):
#         with self.lock:
#             for metric in self.metrics.values():
#                 if hasattr(metric, 'stop'):
#                     metric.stop()
#             self.metrics.clear()
# 
#     def counter(self, name):
#         return self.add_or_get(name, Counter)
# 
#     def meter(self, name):
#         return self.add_or_get(name, Meter)
# 
#     def gauge(self, name, klass):
#         return self.add_or_get(name, klass)
# 
#     def timer(self, name):
#         return self.add_or_get(name, Timer)
# 
#     def utilization_timer(self, name):
#         return self.add_or_get(name, UtilizationTimer)
# 
#     def health_check(self, name, klass):
#         return self.add_or_get(name, klass)
# 
#     def histogram(self, name, klass=None):
#         if not klass:
#             klass = HistogramUniform
#         return self.add_or_get(name, klass)
# 
#     def derive(self, name):
#         return self.add_or_get(name, Derive)
# 
#     def get(self, name):
#         with self.lock:
#             return self.metrics[name]
# 
#     def add(self, name, metric):
#         with self.lock:
#             if name in self.metrics:
#                 raise RegistryException("{0} already present "
#                                         "in the registry.".format(name))
#             else:
#                 self.metrics[name] = metric
# 
#     def add_or_get(self, name, klass):
#         with self.lock:
#             metric = self.metrics.get(name)
#             if metric is not None:
#                 if not isinstance(metric, klass):
#                     raise RegistryException("{0} is not of "
#                                             "type {1}.".format(name, klass))
#             else:
#                 if inspect.isclass(klass):
#                     metric = klass()
#                 else:
#                     metric = klass
#                 self.metrics[name] = metric
#             return metric
# 
#     def stop(self):
#         self.clear()
# 
#     def __iter__(self):
#         with self.lock:
#             for name, metric in self.metrics.items():
#                 yield name, metric
# 
# Path: metrology/instruments/gauge.py
# class Gauge(object):
#     """
#     A gauge is an instantaneous measurement of a value ::
# 
#       class JobGauge(metrology.instruments.Gauge):
#           @property
#           def value(self):
#               return len(queue)
# 
#       gauge = Metrology.gauge('pending-jobs', JobGauge())
# 
#     """
#     @property
#     def value(self):
#         """"""
#         raise NotImplementedError
# 
# Path: metrology/instruments/healthcheck.py
# class HealthCheck(object):
#     """
#     A health check is a small self-test to verify that a specific component or
#     responsibility is performing correctly ::
# 
#       class DatabaseHealthCheck(metrology.healthcheck.HealthCheck):
#           def __init__(self, database):
#               self.database = database
# 
#           def check(self):
#               if database.ping():
#                   return True
#               return False
# 
#       health_check = Metrology.health_check('database',
#                                             DatabaseHealthCheck(database))
#       health_check.check()
# 
#     """
#     def check(self):
#         """Returns True if what is being checked is healthy"""
#         raise NotImplementedError


from unittest import TestCase
from metrology.registry import Registry
from metrology.instruments.gauge import Gauge
from metrology.instruments.healthcheck import HealthCheck



class DummyGauge(Gauge):
    def value(self):
        return "wow"


class DummyHealthCheck(HealthCheck):
    def check(self):
        return True


class RegistryTest(TestCase):
    def setUp(self):
        self.registry = Registry()

    def tearDown(self):
        self.registry.stop()


# Path: metrology/registry.py
# class Registry(object):
#     def __init__(self):
#         self.lock = RLock()
#         self.metrics = {}
# 
#     def clear(self):
#         with self.lock:
#             for metric in self.metrics.values():
#                 if hasattr(metric, 'stop'):
#                     metric.stop()
#             self.metrics.clear()
# 
#     def counter(self, name):
#         return self.add_or_get(name, Counter)
# 
#     def meter(self, name):
#         return self.add_or_get(name, Meter)
# 
#     def gauge(self, name, klass):
#         return self.add_or_get(name, klass)
# 
#     def timer(self, name):
#         return self.add_or_get(name, Timer)
# 
#     def utilization_timer(self, name):
#         return self.add_or_get(name, UtilizationTimer)
# 
#     def health_check(self, name, klass):
#         return self.add_or_get(name, klass)
# 
#     def histogram(self, name, klass=None):
#         if not klass:
#             klass = HistogramUniform
#         return self.add_or_get(name, klass)
# 
#     def derive(self, name):
#         return self.add_or_get(name, Derive)
# 
#     def get(self, name):
#         with self.lock:
#             return self.metrics[name]
# 
#     def add(self, name, metric):
#         with self.lock:
#             if name in self.metrics:
#                 raise RegistryException("{0} already present "
#                                         "in the registry.".format(name))
#             else:
#                 self.metrics[name] = metric
# 
#     def add_or_get(self, name, klass):
#         with self.lock:
#             metric = self.metrics.get(name)
#             if metric is not None:
#                 if not isinstance(metric, klass):
#                     raise RegistryException("{0} is not of "
#                                             "type {1}.".format(name, klass))
#             else:
#                 if inspect.isclass(klass):
#                     metric = klass()
#                 else:
#                     metric = klass
#                 self.metrics[name] = metric
#             return metric
# 
#     def stop(self):
#         self.clear()
# 
#     def __iter__(self):
#         with self.lock:
#             for name, metric in self.metrics.items():
#                 yield name, metric
# 
# Path: metrology/instruments/gauge.py
# class Gauge(object):
#     """
#     A gauge is an instantaneous measurement of a value ::
# 
#       class JobGauge(metrology.instruments.Gauge):
#           @property
#           def value(self):
#               return len(queue)
# 
#       gauge = Metrology.gauge('pending-jobs', JobGauge())
# 
#     """
#     @property
#     def value(self):
#         """"""
#         raise NotImplementedError
# 
# Path: metrology/instruments/healthcheck.py
# class HealthCheck(object):
#     """
#     A health check is a small self-test to verify that a specific component or
#     responsibility is performing correctly ::
# 
#       class DatabaseHealthCheck(metrology.healthcheck.HealthCheck):
#           def __init__(self, database):
#               self.database = database
# 
#           def check(self):
#               if database.ping():
#                   return True
#               return False
# 
#       health_check = Metrology.health_check('database',
#                                             DatabaseHealthCheck(database))
#       health_check.check()
# 
#     """
#     def check(self):
#         """Returns True if what is being checked is healthy"""
#         raise NotImplementedError


# Path: tests/test_registry.py
from unittest import TestCase
from metrology.registry import Registry
from metrology.instruments.gauge import Gauge
from metrology.instruments.healthcheck import HealthCheck




class DummyGauge(Gauge):
    def value(self):
        return "wow"


class DummyHealthCheck(HealthCheck):
    def check(self):
        return True


class RegistryTest(TestCase):
    def setUp(self):
        self.registry = Registry()

    def tearDown(self):
        self.registry.stop()


    def test_counter(self):