'Test the high level method for loading metrics from text format'

def test_parse_metric_family_text(self):

    _text_data = None
    f_name = os.path.join(os.path.dirname(__file__), 'fixtures', 'prometheus', 'metrics.txt')
    with open(f_name, 'r') as f:
        _text_data = f.read()
        self.assertEqual(len(_text_data), 14488)
    messages = list(self.check.parse_metric_family(_text_data, 'text/plain;    version=0.0.4'))
    self.assertEqual(len(messages), 41)
    _counter = metrics_pb2.MetricFamily()
    _counter.name = 'skydns_skydns_dns_cachemiss_count_total'
    _counter.help = 'Counter    of    DNS    requests    that    result    in    a    cache    miss.'
    _counter.type = 0
    _c = _counter.metric.add()
    _c.counter.value = 1359194.0
    _lc = _c.label.add()
    _lc.name = 'cache'
    _lc.value = 'response'
    self.assertIn(_counter, messages)
    _gauge = metrics_pb2.MetricFamily()
    _gauge.name = 'go_memstats_heap_alloc_bytes'
    _gauge.help = 'Number    of    heap    bytes    allocated    and    still    in    use.'
    _gauge.type = 1
    _gauge.metric.add().gauge.value = 6396288.0
    self.assertIn(_gauge, messages)
    _summary = metrics_pb2.MetricFamily()
    _summary.name = 'http_response_size_bytes'
    _summary.help = 'The    HTTP    response    sizes    in    bytes.'
    _summary.type = 2
    _sm = _summary.metric.add()
    _lsm = _sm.label.add()
    _lsm.name = 'handler'
    _lsm.value = 'prometheus'
    _sm.summary.sample_count = 25
    _sm.summary.sample_sum = 147728.0
    _sq1 = _sm.summary.quantile.add()
    _sq1.quantile = 0.5
    _sq1.value = 21470.0
    _sq2 = _sm.summary.quantile.add()
    _sq2.quantile = 0.9
    _sq2.value = 21470.0
    _sq3 = _sm.summary.quantile.add()
    _sq3.quantile = 0.99
    _sq3.value = 21470.0
    self.assertIn(_summary, messages)
    _histo = metrics_pb2.MetricFamily()
    _histo.name = 'skydns_skydns_dns_response_size_bytes'
    _histo.help = 'Size    of    the    returns    response    in    bytes.'
    _histo.type = 4
    _sample_data = [{'ct': 1359194, 'sum': 199427281.0, 'lbl': {'system': 'auth'}, 'buckets': {0.0: 0, 512.0: 1359194, 1024.0: 1359194, 1500.0: 1359194, 2048.0: 1359194, float('+Inf'): 1359194}}, {'ct': 1359194, 'sum': 199427281.0, 'lbl': {'system': 'recursive'}, 'buckets': {0.0: 0, 512.0: 520924, 1024.0: 520924, 1500.0: 520924, 2048.0: 520924, float('+Inf'): 520924}}, {'ct': 1359194, 'sum': 199427281.0, 'lbl': {'system': 'reverse'}, 'buckets': {0.0: 0, 512.0: 67648, 1024.0: 67648, 1500.0: 67648, 2048.0: 67648, float('+Inf'): 67648}}]
    for _data in _sample_data:
        _h = _histo.metric.add()
        _h.histogram.sample_count = _data['ct']
        _h.histogram.sample_sum = _data['sum']
        for (k, v) in _data['lbl'].items():
            _lh = _h.label.add()
            _lh.name = k
            _lh.value = v
        for _b in sorted(_data['buckets'].iterkeys()):
            _subh = _h.histogram.bucket.add()
            _subh.upper_bound = _b
            _subh.cumulative_count = _data['buckets'][_b]
    self.assertIn(_histo, messages)
